Thread: Comparing EditBox data with a string.

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question Comparing EditBox data with a string.

    How would I gather the data that a user inputed into a editbox, and then compare it with a string?
    Thanks, August.

  2. #2
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    GetWindowText(Client_Edit_Message, Buffer, sizeof(Buffer));

    strcmp() enter buffer and other string

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I don't understand.

  4. #4
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    You make your edit box. <assumed you did this>

    Client_Edit_Message = CreateWindowEx(WS_EX_STATICEDGE, "Edit", "", WS_CHILD | WS_VISIBLE | ES_MULTILINE, 1, 135, 400, 20, hWnd, NULL, g_hInst, 0);
    SendMessage(Client_Edit_Message, WM_SETFONT, (WPARAM)hDefaultFont, MAKELPARAM(FALSE, 0));


    then when user enters data in Client_Edit_Message box window you use GetWindowText(Client_Edit_Message, Buffer, sizeof(Buffer));

    you declared a Buffer[] to store your data from the window and the sizeof tell the functions howmuch to store in your Buffer[] variable.

    use strcmp() to compare the string you want to compare. ie test = strcmp( buffer , teststring );

    in winpr0c typicaly when a button has been pressed with case BN_CLICKED: message sent the getwindowtext is used so the proggie knows when valid data is there. ok?
    Last edited by kryptkat; 05-10-2005 at 01:02 PM.

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Well I tried this:

    Code:
    char Sgr[2]; 
    HWND hEdit;
     
    case WM_CREATE: {
    HFONT hfDefault;
    hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT", "", 
    WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL, 
    5, 170, 386, 75, hwnd, (HMENU)IDC_MAIN_EDIT, GetModuleHandle(NULL), NULL);
    SendMessage(hEdit, WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE, 0));
    if(hEdit == NULL) {
    MessageBox(hwnd, "Could not create edit box.", "Error", MB_OK | MB_ICONERROR);}
    else { }
    break; }
     
    case WM_LBUTTONDOWN: { 
    GetWindowText(hEdit, Sgr, sizeof(Sgr));
    if (lstrcmp(Sgr,_T("w1"))==0) {
    MessageBox(hwnd, "gOOD, iT WORKS!", "wOW!", MB_OK ); }
    break; }
    No errors, but it doesn't work. What did I do wrong?

  6. #6
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    For one you are missing the switchcase() wich should belong to the winmain() or the proc.

    just started looking at it. that was the first i noticed let me look some more or get you an example.

    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    switch(msg)
    {


    then your case here:

    you also need


    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
    {


    it is not a compleat prog.

    edit:
    You need to decide what type of window you want. You have the editbox. and reg the window.

    you need a message loop

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
    TranslateMessage(&Msg);
    DispatchMessage(&Msg);
    }
    return Msg.wParam;


    and the window procedure see above code.
    Last edited by kryptkat; 05-11-2005 at 08:39 PM.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    And the handle to the edit will have lost scope (as soon as the WN_CREATE was processed).


    Use a static HWND

    Or use

    GetWindowText( GetDlgItem(hwnd , IDC_MAIN_EDIT) ,.......
    "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

  8. #8
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I got it working. Thanks, for the help guys.
    Last edited by Queatrix; 05-12-2005 at 10:06 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Bitmasking Problem
    By mike_g in forum C++ Programming
    Replies: 13
    Last Post: 11-08-2007, 12:24 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM