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.