Edit Control Notification

This is a discussion on Edit Control Notification within the Windows Programming forums, part of the Platform Specific Boards category; I have a dialog box with 5 edit controls. I must be certain that all 5 controls have text before ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059

    Edit Control Notification

    I have a dialog box with 5 edit controls. I must be certain that all 5 controls have text before I enable an UPDATE button. Therefore, is there any way to monitor all 5 edit controls to verify that text has been entered in all 5 controls?

    I was thinking along the lines of EN_SELCHANGE but I'm not sure on how to approach the problem. A "google" on the internet provides a couple examples but they're all in MFC which I don't really care for or totally understand.

    Thanx

    Bob

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Possibilites include checking for an EN_CHANGE notification and then either:

    Here's a quick example demonstrating the latter:
    Code:
    #include <windows.h>
    #include <tchar.h>
    
    #define NUM_EDITS 5
    
    enum {
      IDC_EDIT1=100,
      IDC_EDIT2,
      IDC_EDIT3,
      IDC_EDIT4,
      IDC_EDIT5,
      IDC_BTN
    };
    
    BOOL SetButtonState(HWND *hwnds)
    {
    int i;
    
    for (i=0;i<NUM_EDITS;++i)
      {
      if (GetWindowTextLength(hwnds[i])==0)
        {
        return FALSE;
        }
      }
    return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
    static HWND hEdits[NUM_EDITS];
    static HWND hBtn;
    
    switch (uMsg)
      {
      case WM_COMMAND:
        {
        HWND hCntrl;
        WORD wID,wNotify;
        
        hCntrl=(HWND)lParam;
        wID=LOWORD(wParam);
        wNotify=HIWORD(wParam);
        
        if (hCntrl && wNotify==EN_CHANGE)
          {
          EnableWindow(hBtn,SetButtonState(hEdits));
          }
          
        return 0;
        }
      case WM_CREATE:
        {
        CREATESTRUCT *cs=(CREATESTRUCT*)lParam;
        int i;
        
        for (i=0;i<NUM_EDITS;++i)
          {
          hEdits[i]=CreateWindowEx(WS_EX_CLIENTEDGE,_T("edit"),_T(""),
                                   WS_CHILD|WS_VISIBLE|WS_TABSTOP,
                                   10,32*(i+1),200,30,hwnd,(HMENU)(IDC_EDIT1+i),
                                   cs->hInstance,0);
          }
        hBtn=CreateWindowEx(0,_T("button"),_T("Enabled"),
                            WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_DISABLED,
                            10,40*(i+1),200,30,hwnd,(HMENU)(IDC_EDIT1*100),
                            cs->hInstance,0);
        
        SetFocus(hEdits[0]);
        return 0;
        }
      case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
      default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
      }
    }
    
    int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR pStr,int nCmd)
    {
    HWND       hwnd;
    MSG        msg;
    TCHAR      classname[]=_T("kenf's_wnd");
    WNDCLASSEX wcx={0};
    
    wcx.cbSize       =sizeof(wcx); 
    wcx.lpfnWndProc  =WndProc; 
    wcx.hInstance    =hInst; 
    wcx.hIcon        =(HICON)LoadImage(0,IDI_APPLICATION,IMAGE_ICON,0, 0,LR_SHARED); 
    wcx.hCursor      =(HCURSOR)LoadImage(0,IDC_ARROW,IMAGE_CURSOR,0,0, LR_SHARED);
    wcx.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1); 
    wcx.lpszClassName=classname; 
    
    if (RegisterClassEx(&wcx))
      {
      hwnd=CreateWindowEx(0,classname,
                          _T("5 Edits and a Button"),
                          WS_OVERLAPPEDWINDOW,
                          GetSystemMetrics(SM_CXSCREEN)/4,
                          GetSystemMetrics(SM_CYSCREEN)/4,
                          GetSystemMetrics(SM_CXSCREEN)/2,
                          GetSystemMetrics(SM_CYSCREEN)/2,
                          0,0,hInst,0);
      if (hwnd)
        {
        ShowWindow(hwnd,nCmd);
        UpdateWindow(hwnd);
        
        while (GetMessage(&msg,0,0,0)>0)
          {
          if (!IsDialogMessage(hwnd,&msg))
            {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            }
          }
        return msg.wParam;
        }
      else
        {
        MessageBox(0,_T("Wnd creation failure"),_T("Error"),MB_OK|MB_ICONERROR);
        return 0;
        }
      }
    MessageBox(0,_T("Wnd registration failure"),_T("Error"),MB_OK|MB_ICONERROR);
    return 0;
    }
    There are very probably other ways of doing this but I hope that will be of some use to you.
    Last edited by Ken Fitlike; 03-30-2005 at 01:42 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Ken,

    That's EXACTLY what I need.

    Thanx

    Bob

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't disable ctrl-V on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2008, 08:37 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 06:49 PM
  3. edit control - entering only numbers
    By Micko in forum Windows Programming
    Replies: 2
    Last Post: 08-20-2004, 12:31 PM
  4. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 10:52 PM
  5. endless edit control
    By ZerOrDie in forum Windows Programming
    Replies: 3
    Last Post: 03-21-2003, 02:51 AM

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