Creating Controls on Window

This is a discussion on Creating Controls on Window within the Windows Programming forums, part of the Platform Specific Boards category; 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; } ...

  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,831
    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,859
    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,831
    >>> 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, 05:15 PM
  2. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11: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, 06:55 PM
  4. How to change window style at runtime?
    By Mr. Bitmap in forum Windows Programming
    Replies: 5
    Last Post: 06-09-2002, 05: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

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