Skip to main content
GameDev.net gamedev.net
🔒 Locked

MFC SetWindowPos question

Started by DavidGallagher Apr 15, 2002 at 2:04 PM 1 replies 1.8k views
Original Post
DavidGallagher
DavidGallagher
everytime I try to use this function it crashes my program. I''m not sure if it only works for certain controls, but it doesn''t seem to work for any for me. first I a variable m_button that is a CButtton to a button control and then I use this code in OnSize(); m_button.SetWindowPos(NULL,0,0,cx/3,cy/3,NULL); the program always freezes on the line: ASSERT(::IsWindow(m_hwnd)) inside the SetWindowPos function, and the m_hwnd variable is always 0x000000 . any help would be greatly appreciated Dave
mikenitro
mikenitro
Make sure that the window is actually realized (i.e., instantiated and rendered) before calling any window functions on it. In this case, the NULL window handle indicates that the window is not in existence yet, or that it is no longer in existence.
dalleboy
dalleboy
I remember I had the same problem once, it was because OnSize was called before OnInitDialog, and thus no controls where created yet.

Try this:

void DaClass::OnSize(...)
{
if (::IsWindow(m_button.GetSafeHwnd()) != 0)
{
m_button.SetWindowPos(NULL,0,0,cx/3,cy/3,NULL);
}
}

// Dalle

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.