Archived

This topic is now archived and is closed to further replies.

InFerN0

MFC Assert

Recommended Posts

InFerN0    122
hey I am getting an assert with GetCurSel() in the combobox control. I tracked it down in the inl file and this is what it said _AFXWIN_INLINE int CComboBox::GetCurSel() const { ASSERT(::IsWindow(m_hWnd)); return (int)::SendMessage(m_hWnd, CB_GETCURSEL, 0, 0); } any ideas? Thanks. InFerN0 Not all who wander are lost...

Share this post


Link to post
Share on other sites
felisandria    739
Is your HWND valid?

Usually MFC controls will assert if they haven''t been created before you attempt to perform a function that requires a valid HWND.

-fel

Share this post


Link to post
Share on other sites
Gorky    122
Fel''s right.

You have probably called it from a dialog that is no longer modal or the window has not been created yet.
Try placing it in OnInitDialog if before showing the window.

I''m guessing, you have placed the call after the window has been destroyed. Move it instead to an OnOk function.

Share this post


Link to post
Share on other sites
InFerN0    122
I have the call in a function outside the forms class. Before calling GetCurSel() I check my combo box pointer.

if(g_pParent->m_pCBObjectType == NULL)
{
MessageBox("Not in scope");
return;
}

I haven''t destroyed the window cause I can still see it and I know that it has been created because I test it on creation. Thanks.

InFerN0

Not all who wander are lost...

Share this post


Link to post
Share on other sites
Stoffel    250
Your pointer to your class may be valid, but the hwnd of the combo box may not be. For instance, if the combo box is a member of a dialog that you have derived from CDialog, you can only operate on the combo box after calling "CDialog::InitDialog" from your OnInitDialog function. Before this function is called, all hwnds are invalid.

Share this post


Link to post
Share on other sites
InFerN0    122
The dialog itself was made using the dialog editor in VC++ and is bound to a member of CMainFrame which handles all its messages. Actually the dialog is a dialogbar. Also I tried having the dialog get a safe HWND

m_RBar.GetSafeHwnd();

no effect. I know this fixs asserts in other places but not here.

InFerN0

Not all who wander are lost...

Share this post


Link to post
Share on other sites
phueppl1    122
Inferno....

what we mean, is that we wanna know if you call your GetCurSel() before or after you called
dlg.Create(this, CBRS_RIGHT, );

cause otherwise the HWND is not ok... it''s only valid _AFTER_ you called this function and _BEFORE_ the window is destroyed..

otherwise... does your prog crash in release mode? If not.. who cares? j/k...

hope that helps a bit.
cya,
Phil

P.s.: Just bought myself a huge Assembler book today.. Yummy

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states

RAW!

Share this post


Link to post
Share on other sites