Thread: Edits and buttons

  1. #1
    Unregistered
    Guest

    Edits and buttons

    I'm having trouble getting this to work, i just have a button and a text box right now and when you click the button i want the text in the text box to change but it doesn't seem to work. Heres what i have for the code.

    Under Defines:
    #define ID_CAPCNV 100
    #define ID_EDBX 101

    Under WM_CREATE:
    HWND EBOX;
    HWND BTN;

    EBOX = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_CHILD|WS_VISIBLE|WS_BORDER, 5, 5, 200, 30, hwnd, (HMENU)ID_EDBX, 0, NULL);

    BTN = CreateWindow("button", "Text", WS_CHILD | WS_VISIBLE, 5, 50, 100, 20, hwnd, (HMENU)ID_EDBX, 0, NULL);
    return(0);

    Under WM_COMMAND:
    SetWindowText(EBOX, TEXT("Convert!!!"));
    SetDlgItemText(EBOX, ID_EDBX,"TEST");
    UpdateWindow(EBOX);

    I've tried SetWindowText and SetDlgItemText both seperatly but i included them both in here so maybe you can help

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    Does anyone know why the text in the edit box isn't changing, i can't figure this 1 out. Thanks. (that was my post earlier)

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Umm, first of all... Don't you use "CreateDialog()" to create a dialog box? (or are you even making a dialog box?) And then, what are EBOX and BTN?... the names aren't too descriptive. And besides, what's the error???
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    The HWND are not static so their value is lost by the time a WM_COMMAND msg is received. Many msg's per sec are flowing thru your callback. Most local variables should be static.

    Use a static or call GetDlgItem() or GetWindow() to find the ctrls HWND.

    CreateWindow() is fine.

    CreateDialog() requires a resource template.
    "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

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    >The HWND are not static so their value is lost by the time a WM_COMMAND msg is received
    HWNDs do not have to be static

    >what are EBOX and BTN?... the names aren't too descriptive.
    Actually they are quit descriptive, EBOX is clearly EditBox and BTN is clearly Button

    and, as for the question,
    you have to:
    #define ID_BTN 102

    you cant use the same ID for the Edit Box and button
    then after you do that, make ur WM_COMMAND: look like this:

    Code:
    case WM_COMMAND:
    {
    	switch(LOWORD(wParam)
    	{
    	case ID_BTN:
    		SetWindowText(EBOX, "Convert!!!");
    		break;
    	}
    }
    break;
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>>The HWND are not static so their value is lost by the time a WM_COMMAND msg is received
    HWNDs do not have to be static

    Yes, they way they are used here, they do.
    They are not global.
    They get a value under the WM_CREATE.
    This value will not be there after the next message passes thru the callback if they are not static.

    Try it.

    Also better to check if the button has been clicked rather than another message with

    if (BN_CLICKED == HIWORD(wParam))
    Last edited by novacain; 05-09-2002 at 09:09 PM.
    "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

  7. #7
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Oops i didnt notice that they were not global, sorry
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  2. Some questions aout edits
    By ColdFire in forum Windows Programming
    Replies: 3
    Last Post: 07-26-2002, 03:23 AM