   MFC question - GetClientRect acts strange
  Hi all,I have my main dialog, and when a button is pressed in that main dialog, I call a function in another dialog and load some variables, without showing the dialog,or calling DoModal. In the second dialog I call m_st1.GetClientRect( &rectStaticClient );where m_st1 is a CStatic control of a picture control. The width & height of the rect I get is zero. but when I call the same function from the second dialog I do get the right size. so my question is, do I have to DoModal in order to get the size of a picture control box ? or am Im missing something ?Thanks to all answers....[Edited by - jitterjaw on August 23, 2009 9:18:40 AM]
  GetClientRect is only able to deliver a valid size if the attached HWND is actually valid and existing. It does not have to be visible, but it has to be created.   ;Quote:Original post by EndurionGetClientRect is only able to deliver a valid size if the attached HWND is actually valid and existing. It does not have to be visible, but it has to be created.Hi and thanks for the answer,Im quite new to MFC so Ill ask 2 questions:1. I thought only the dialog box has a HWND, does every control box has a HWND of its own ?2. So how can I create a dialog box, I thought that declaring a variable which is a dialog box, calls the constructor, that on his side then calls the CDialog constructor, so after all a valid HWND should exist for the dialog.thanks...   ;  Every control on a window/dialog has its own HWND. You can use the Spy++ (should come with VS, is a free download) to check running applications (quite interesting).MFC is a C++ wrapper around the C style Win32 API. A CDialog or CWnd instance can be around without a valid HWND in the background.A HWND is only created once you call DoModal or CreateDialog (or one of its siblings CreateDialogIndirect). The HWND is gone once DoModal is left or Close has been called. The C++ instance however is still around.In the phase before the creation and after the destruction you have to be careful to not access anything that tries to use the HWND. You can however use all the other members of the class.This is useful, if you want a dialog to set values from its member variables to its controls up during OnInitDialog and read back the variables after the dialog is gone.   ;Quote:Original post by EndurionEvery control on a window/dialog has its own HWND. You can use the Spy++ (should come with VS, is a free download) to check running applications (quite interesting).MFC is a C++ wrapper around the C style Win32 API. A CDialog or CWnd instance can be around without a valid HWND in the background.A HWND is only created once you call DoModal or CreateDialog (or one of its siblings CreateDialogIndirect). The HWND is gone once DoModal is left or Close has been called. The C++ instance however is still around.In the phase before the creation and after the destruction you have to be careful to not access anything that tries to use the HWND. You can however use all the other members of the class.This is useful, if you want a dialog to set values from its member variables to its controls up during OnInitDialog and read back the variables after the dialog is gone.Hi,I played a bit with Spy++ it was really educating :), any way, I think I need to emphasize my problem : what I am trying to do, is to get the rect size of a picture control box that is in a different dialog. my question is then, how can I init the second dialog without showing it, and without doing domodal ? When I call Dialog2::m_st1.GetSafeHwnd() from within Dialog1, I get NULL, only after doing domodal I get something different than NULL. thanks,With Regards,JitterJaw;  I'm not exactly sure what your particular requirements are, but you could try creating the second dialog as modeless with a window style & ~WS_VISIBLE.