Thread: Creating a child window

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    36

    Creating a child window

    Hello,

    I am trying to make a simple control, by creating a child window. I have already created another window successfully, who's handle is "h_parent". (My application instance is "h_instance".) I have then tried to create the child window, using the code below, but it does not work. The program freezes for a few seconds at the CreateWindowEx function, and then gives me an unhandled exception from the file <xutility>. Any ideas what I am doing wrong? Thanks.


    Code:
    HWND CreateControl(HWND h_parent, HINSTANCE h_instance)
    {
    DWORD extended_window_style = 0;
    LPCSTR window_class_name = "my_control";
    LPCSTR window_name = "";
    DWORD window_style = WS_CHILD | WS_VISIBLE;
    int x = 0;
    int y = 0;
    int width = 100;
    int height = 100;
    HWND parent_window_handle = h_parent;
    HMENU menu_handle = NULL;
    HINSTANCE app_instance_handle = h_instance;
    LPVOID window_creation_data = NULL;
    
    HWND h_control = CreateWindowEx(extended_window_style, window_class_name, window_name, window_style, x, y, width, height, parent_window_handle, menu_handle, app_instance_handle, window_creation_data);
    
    return h_control;
    }

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    You have to use the control's class name, and it's case sensitive... For an edit control your window_class_name would be "EDIT"

    But why are you doing it the hard way, you could simply do this...

    Code:
        // text display window
        Wind[1] = CreateWindowEx(WS_EX_CLIENTEDGE,L"STATIC",RM_VERSION,
                      WS_CHILD | WS_VISIBLE |
                      SS_CENTER | SS_CENTERIMAGE | SS_NOTIFY,
                      0,0,300,20,Wind[0],(HMENU)100,PgmInst,NULL);
    There's no reason to pass everything through intermediate variables, that's just a waste of space.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    36
    Hi,

    Thanks for the help. I understand that I need to use the control's class name - this is in fact exactly "my_control" which was used to register the class.

    I've figured out some more information that might help. If I set the window style to "0", then it runs fine. However, if either "WS_CHILD" or "WS_VISIBLE" are present, then the CreateWindowEx() does not work. ALl other window styles that I have tried seem to work fine. But I need WS_CHILD, because I want it to be a child window, so it is odd that it causes an error...

    Any ideas? Thanks.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Please post the code for the custom control... I suspect that's where your problem is...

    Also you really should clean up that subroutine you posted. Using intermediate variables like that is just plain silly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a child window in a parent window
    By vopo in forum Windows Programming
    Replies: 8
    Last Post: 10-06-2007, 04:15 PM
  2. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  3. Question about creating a specific child window type
    By PJYelton in forum Windows Programming
    Replies: 8
    Last Post: 03-28-2005, 10:58 PM
  4. Child window inside child window
    By Magos in forum Windows Programming
    Replies: 13
    Last Post: 04-20-2004, 06:51 AM
  5. Creating Child with parent of Child
    By SilkySmooth in forum Windows Programming
    Replies: 3
    Last Post: 06-28-2003, 12:15 PM