Thread: Creating Controls on Window

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    21

    Creating Controls on Window

    I have created controls on window

    WndProc(.....){

    HWND hWndED;

    switch(uMsg){
    case WM_CREATE:
    hWndED=CreateWindow(....);
    ShowWindow(hWndED,SW_SHOW);
    break;
    case WM_COMMAND:
    SendMessage(hWndED,....);
    break;

    }


    }

    My problem is when I call Sendmessage it is complaining that
    hWndED is not initialized, So I clarified that becos WndProc is called every time when ever a message occurs in GetMessage Loop.

    Now can any body help me how to rectifty this prob. Is declaring static is the only solution to make hWndED available all times or is there any other message.

    bye

    vamshi

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    After the WinProc processes the WM_CREATE, it exits and your handle goes out of scope. Yes, you need to keep the value somehow, this is not Windows specific, just plain old C/C++, a different message would be treated in the same way. static is as good as any.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you use the WS_CHILD and cast the HMENU to an int resource ID number.

    Then you shold be able to use

    hWndEd = GetDlgItem( hWndParent , ID_EDIT );

    where ID_EDIT is your int resource ID

    else static or global is the answer.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> where ID_EDIT is your int resource ID

    Assuming, of course, that the ID value is available. If he is creating the edit boxes on the fly with CreateWindow() he may not have set up the ID's in a header as would be the normal case using a resource file.

    Sometimes I don't bother, I just stick a literal in there and static the handle, saves a call if nothing else.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    i always static HWNDs too. and sometimes if i am in bad practice () i would, instead of GetDlgItem, just have the HWND as a global. but i assume that's bad, so i use GetDlgItem.

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. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  3. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  4. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 04:49 PM
  5. Winamp Vis if anyone can help
    By Unregistered in forum Windows Programming
    Replies: 6
    Last Post: 01-27-2002, 12:43 AM