Creating Child with parent of Child

This is a discussion on Creating Child with parent of Child within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am trying to figure out what I have done wrong with a little app I am working on ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2

    Creating Child with parent of Child

    Hi,

    I am trying to figure out what I have done wrong with a little app I am working on in C++ and if what I am doing is actually the best way.

    I create my main application window and have a single menu with two selections, I then have the following code to determine what to do when either of the options is selected:

    Code:
    LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {                                
    
    switch (message)                  /* handle the messages */
               {
               case WM_COMMAND:
               DestroyWindow(childhwnd);
               switch ( wParam )
                          {
                          case SM_PREF:
                                  childhwnd = CreateWindow(
                                  "static",
                                  "Pref",
                                  WS_CHILD | SS_CENTER | WS_VISIBLE,
                                  50,
                                  50,
                                  50,
                                  50,
                                  hwnd,
                                  NULL,
                                  hThisInstance,
                                  NULL);
                                 childhwnd1 = CreateWindow(
                                 "BUTTON",
                                 "test",
                                 WS_CHILD | WS_VISIBLE,
                                 200,
                                 200,
                                 100,
                                 100,
                                 childhwnd,
                                 NULL,
                                 hThisInstance,
                                 NULL);
                                 return 0;
                        case SM_STATS:
                                 childhwnd = CreateWindow(
                                 "static",
                                 "Stats",
                                 WS_CHILD | SS_CENTER | WS_VISIBLE,
                                 0,
                                 0,
                                 50,
                                 50,
                                 hwnd,
                                 NULL,
                                 hThisInstance,
                                 NULL);                                            
                                 return 0;
    etc.....
    If I select the PREF from the menu my first child window is created fine and displayed but the second (childwnd1) does not get created. If I select STATS from the menu then it creates and displays the Stats window fine. At the top I have the DestroyWindow so that when I switch between PREF and STATS it will destroy the previously created window.

    I changed the parent of the childwnd1 to hwnd which is my main app window and then both the static and button displays. So I am guessing that I cannot create a child of a child within the same thread. Am I correct or barking up the wrong tree here? Or is there someway to look ahead and collect the correct property or something?

    Is this a good way to switch between two different displays?

    Any help or advice appreciated.
    Ade

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,263
    It seems to me that you are creating a window of size 50x50 then creating a window inside that at (200, 200) that is 100x100. Do you see the problem?

    If you debug this, set a breakpoint after the CreateWindow function for childhwnd1 and I'm pretty sure it'll come out non-NULL, you just won't be able to see the thing (As your parent is too small).

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    2
    Ahhhh of course!! What a fool I am! Thank you... SMurf

    Do you have any thoughts on my method overall? Having multiple windows and then deleting the parent upon menu change thus deleting all before rendering a new set of windows?

    Is that standard or do people go for the TextOut type functions?

    BTW this is only a Windows API app.

  4. #4
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,263
    Well I'm not sure what sort of program this is. If you want to allow the user to manipulate different information windows simultaneously, you might want to look in Multiple Document Interface (MDI), like on Wordpad (One window for each document, not a separate process). Another way is using a tab control and assigning different controls to different pages, like on Display Properties.

    You should create one static text control for each piece of text you have (If you're not already doing this), that way you can group static and other controls together so you can use a keyboard shortcut to manipulate a particular control. Directly using GDI functions to draw text isn't really needed for standard dialogs and windows, you'd only need to do that if you're writing a paint program or something else graphical.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Creating a child window in a parent window
    By vopo in forum Windows Programming
    Replies: 8
    Last Post: 10-06-2007, 04:15 PM
  4. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21