Prev: Relay accurate time over network
Next: How to know exactly when a window is ceated for the first time (WM_CREATE and WM_NCCREATE not working )
From: claus.kick on 27 Sep 2009 17:45 On 27 Sep., 22:20, Giuliano Suminsky <yksni...(a)gmail.com> wrote: > Hi, I was just trying to create a button( BS_GROUP ) at the WM_CREATE > of the main window, but it fails.. > > But when I create it just after create the main window, its fine, > why? > Cant I create buttons at the WM_CREATE? Or is just something stupid Im > missing? > *snip* My guess is that hmainwnd is not valid during WM_CREATE?
From: r_z_aret on 28 Sep 2009 09:26 On Sun, 27 Sep 2009 13:20:22 -0700 (PDT), Giuliano Suminsky <yksnimus(a)gmail.com> wrote: >Hi, I was just trying to create a button( BS_GROUP ) at the WM_CREATE >of the main window, but it fails.. > >But when I create it just after create the main window, its fine, >why? >Cant I create buttons at the WM_CREATE? Or is just something stupid Im >missing? I _think_ the HWND for a window is not fully valid until after the WM_CREATE for that window is fully processed. So you can't create subwindows while processing WM_CREATE. I know I create subwindows when I process WM_INITDIALOG. > >That works ok: > >//******* > >hmainwnd = CreateWindow( TEXT("MAINWNDCLASS"), szCaption, > WS_OVERLAPPEDWINDOW, > wndrect.left, wndrect.top, wndrect.right, wndrect.bottom, > NULL, NULL, hInstance, NULL ); > > > hbgroupIPDisplay = CreateWindow( TEXT("Button"), TEXT("Your IP"), > WS_CHILD | WS_VISIBLE | BS_GROUPBOX, > 50, 50, 160, 160, > hmainwnd, (HMENU)100, //button ID > GetModuleHandle(NULL), > NULL ); >//********** > > >That dont: > >//********* > >case WM_CREATE: > > hbgroupIPDisplay = CreateWindow( TEXT("Button"), TEXT("Your IP"), > WS_CHILD | WS_VISIBLE | BS_GROUPBOX, > 50, 50, 160, 160, > hmainwnd, (HMENU)100, //button ID > GetModuleHandle(NULL), > NULL ); > > > > > return 0; > >//*********** ----------------------------------------- To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message). Robert E. Zaret, eMVP PenFact, Inc. 20 Park Plaza, Suite 400 Boston, MA 02116 www.penfact.com Useful reading (be sure to read its disclaimer first): http://catb.org/~esr/faqs/smart-questions.html
From: Markus Schaaf on 28 Sep 2009 09:58 r_z_aret(a)pen_fact.com wrote: > I _think_ the HWND for a window is not fully valid until after the > WM_CREATE for that window is fully processed. No. It is valid, whatever that means. The OP's problem was, that he (probably) used code like this: mainWindow = CreateWindow( ... ); So `mainWindow` is not initialized until `CreateWindow` returns. But the WM_CREATE message will be sent before that. An easy fix is to initialize the global in the window procedure: LRESULT CALLBACK mainWindowProc( self, msg, ... ) { switch( msg ) { case WM_CREATE: mainWindow = self; ....
From: claus.kick on 29 Sep 2009 07:37 On 28 Sep., 15:58, Markus Schaaf <msch...(a)elaboris.de> wrote: > r_z_aret(a)pen_fact.com wrote: > > I _think_ the HWND for a window is not fully valid until after the > > WM_CREATE for that window is fully processed. > > No. It is valid, whatever that means. The OP's problem was, that he > (probably) used code like this: A window handle has to be valid, i.e. in exitance before it can be used. > So `mainWindow` is not initialized until `CreateWindow` returns. But > the WM_CREATE message will be sent before that. An easy fix is to > initialize the global in the window procedure: > > LRESULT CALLBACK mainWindowProc( self, msg, ... ) > { > switch( msg ) > { > case WM_CREATE: > mainWindow = self; > .... Could you please explain how this should help? If you reference a window handle which is the result of a create window call, this has to be a valid handle, not just in scope?
From: Markus Schaaf on 29 Sep 2009 09:22
claus.kick(a)googlemail.com schrieb: > A window handle has to be valid, i.e. in exitance before it can be > used. I do not get your point. You do not excogitate handles. When you got a window handle, it refers to a specific window, and is valid until that window will be destroyed. There is no possibility of getting a window handle that will become valid later. |