Thread: edit box's content

  1. #1
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161

    edit box's content

    i've created a window with an edit box and a button key. I want the window to do different things when the user types something in the edit box and press's the button. The edit box is called chapter and the button is called hFind. The problem is that my code doesn't work. In wm_command: i'm trying to make it so that if the user types test and clicks find a message box will appear but on my attempt at it there was an error.

    Code:
    case WM_COMMAND:
             if (HIWORD(wParam) == BN_CLICKED);
             {
                 if (LOWORD(wParam) == 1 )
                 {
                      if (hChapter == "test")
                      {
                                   MessageBox("Your input", "You typed test.", NULL, NULL);
                                   }
    This brings up an compilation error but does anybody know the proper way to do this.
    I started out with nothing and I still have most of it left.

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    what is hChapter defined as? Also I don't see you reading in the text there. This doesn't call a message box but it does read text and saves it.
    Code:
    case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case nameDialogEnter:
                    {
                        int nameLength = GetWindowTextLength(GetDlgItem(hwnd,nameDialogText));
                        if(nameLength > 0)
                        {
                            char *getName = new char[nameLength + 1];
                            GetDlgItemText(hwnd,nameDialogText,getName,nameLength + 1);
                            mainPlayer.setName(getName);
                            delete [] getName;
                            EndDialog(hwnd,nameDialogEnter);
                        }
                        else
                        {
                            MessageBox(hwnd,TEXT("Invalid Input"),TEXT("Error"),MB_ICONERROR);
                        }
                    }
                    break;
                }
                return TRUE;
                break;
    nameDialogEnter is a button.
    Woop?

  3. #3
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    hChapter is a single line text box that i want the user to type in then press the button which is hFind. The if the edit field value is "test" to show a message box.
    I started out with nothing and I still have most of it left.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by algi
    hChapter is a single line text box that i want the user to type in then press the button which is hFind. The if the edit field value is "test" to show a message box.
    You work with edit controls by using handles to them like in prog-bman's example. If you have a window handle as aposed to a dialog handle then send WM_GETTEXTLENGTH/WM_GETTEXT thru SendMessage.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    A combobox, not an edit, is the usual control to do this kind of thing (give user limited number of choices)......
    "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

  6. #6
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    wait i'm confused. Below is my wm_create, and wm_command.

    Code:
    case WM_CREATE:
             hChapter = CreateWindow ( "EDIT", "Search Here",
                                       WS_CHILD | WS_VISIBLE |
                                       WS_BORDER | ES_AUTOHSCROLL,
                                       20, 180, 120, 20,
                                       hWnd, (HMENU) 1,
                                       hInstGlobal, NULL);
                                       
             hFind = CreateWindow ( "BUTTON", "Find",
                                    WS_CHILD | WS_VISIBLE |
                                    BS_PUSHBUTTON,
                                    150, 180, 140, 20,
                                    hWnd, (HMENU) 1,
                                    hInstGlobal, NULL);
             return 0;
        // If the user wants to close the application
        
        case WM_COMMAND:
             if (HIWORD(wParam) == BN_CLICKED);
             {
                 if (LOWORD(wParam) == 1 )
                 {
                      if (hChapter == test)
                      {
                                   MessageBox("Your input", "You typed test.", NULL, NULL);
                                   }
                      else
                      {
                      }
                      }
                      }
                      return 0;
    I'm trying to get the value for hChapter and make the computer do different inputs for it. Like if i type in "test" in the edit box and press find, the message box comes up saying "You typed test".
    I started out with nothing and I still have most of it left.

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Quote Originally Posted by Quantum1024
    You work with edit controls by using handles to them like in prog-bman's example. If you have a window handle as aposed to a dialog handle then send WM_GETTEXTLENGTH/WM_GETTEXT thru SendMessage.
    so instead of this
    Code:
    if (hChapter == test)
    you would do something like this
    Code:
    char TextBuffer[256];
    SendMessage(hChapter, WM_GETTEXT, 255, TextBuffer);
    MessageBox(NULL, Buffer, NULL, MB_OK);

  8. #8
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    so how do i use wm_gettext?
    I started out with nothing and I still have most of it left.

  9. #9
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    I think this is what you are looking for.
    Code:
    case WM_COMMAND:
        switch(HIWORD(wParam))
        {
            case BN_CLICKED:
                switch(LOWORD(wParam))
                {
                    case 1:
                        {
                            char inputText[100];
                            GetWindowText(hChapter,inputText,99);
                            if(strcmp(inputText,"Test") == 0)
                            {
                                MessageBox(NULL,TEXT("You entered test"),TEXT("Your input was:"),MB_OK);
                            }
                        }
                        break;
                }
        }
        return 0;
        break;
    Woop?

  10. #10
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Ummmmmmmmmm.....

    If you use the WS_CHILD style the HMENU becomes the controls ID number.

    You use one (1) in both controls. Each control should have a diff number (but as the edit can't generate a click msg and you don't use GetDlgItem() this will work).
    "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

  11. #11
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    yes thank you very much progman
    I started out with nothing and I still have most of it left.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  2. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  3. Capture Enter key press in EDIT Box
    By richiev in forum Windows Programming
    Replies: 4
    Last Post: 07-14-2005, 12:03 AM
  4. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM