Thread: Need help with with an "EDIT"

  1. #1
    Unregistered
    Guest

    Need help with with an "EDIT"

    When i click the send button, the messagebox wont display waht is in the txtMessage "EDIT" window. Instead of SendMessage i have used GetWindowText which also didnt work.
    Please Help

    LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
    HWND txtMessage, btnSend, txtHost;

    switch(msg){

    case WM_CREATE:
    {
    HFONT hfDefault;


    txtHost = CreateWindowEx(
    WS_EX_STATICEDGE,
    "EDIT", "",
    WS_VISIBLE | WS_CHILD,
    10, 10, 250, 25,
    hwnd, NULL, NULL, NULL
    );

    txtMessage = CreateWindowEx(
    WS_EX_STATICEDGE,
    "EDIT", "",
    WS_VISIBLE | WS_CHILD | ES_AUTOVSCROLL | WS_CHILD | ES_MULTILINE | WS_VSCROLL,
    10, 45, 250, 250,
    hwnd, (HMENU) 202, NULL, NULL
    );

    btnSend = CreateWindowEx(
    WS_EX_STATICEDGE,
    "BUTTON", "SEND",
    WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
    95, 300, 80, 30,
    hwnd, (HMENU) IDR_BUTTON, NULL, NULL
    );

    hfDefault = CreateFont(18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Times New Roman");
    SendMessage(txtHost, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    SendMessage(txtMessage, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    SetFocus(txtHost);
    }
    break;

    case WM_CLOSE:
    DestroyWindow(hwnd);
    break;

    case WM_COMMAND:
    {
    char buff[100];
    if(LOWORD(wParam) == IDR_BUTTON){
    SendMessage(txtMessage, WM_GETTEXT, (WPARAM)100, (LPARAM)buff);
    MessageBox(NULL, buff, "Hello", MB_OK);
    }
    }
    break;

    case WM_DESTROY:
    PostQuitMessage(0);
    break;

    default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
    }

    return 0;

    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Make the HWNDs static or they will have lost scope as soon as the callback has finished the WM_CREATE and breaks / returns.
    "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

  3. #3
    Unregistered
    Guest
    thanks a heap,
    its shocking to know that none of the tutorials i have seen on the net have even mentioned this.

  4. #4
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Yeah, just keep what novacain said in the back of your mind when you always program. Because, if that's the problem (for all data types, not just HWND) you usually look right over it and it's still not doing what you want...
    1978 Silver Anniversary Corvette

Popular pages Recent additions subscribe to a feed