Page 53 - DCAP408_WEB_PROGRAMMING
P. 53
Unit 4: Windows Controls
if (!hwndMain) Notes
return FALSE;
ShowWindow(hwndMain, SW_SHOW);
UpdateWindow(hwndMain);
HWND hwndSt;
hwndSt = CreateWindowEx(0, "STATIC", "First Name", WS_CHILD, 100, 100,
100, 20, hwndMain, (HMENU)1, hinstance, NULL);
ShowWindow(hwndSt, SW_SHOW);
UpdateWindow(hwndSt);
HWND hwndEd = CreateWindowEx(0, "EDIT", NULL, WS_CHILD, 100, 122, 100,
20, hwndMain, (HMENU)2, hinstance, NULL);
ShowWindow(hwndEd, SW_SHOW);
UpdateWindow(hwndEd);
MSG msg;
BOOL bRet;
while( (bRet = GetMessage( &msg, hwndMain, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit the application
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
You can utilize the following command at the command prompt to compile the code:
g++ winst.cpp -mwindows -o winst.exe
There are two controls in the code. Let us see at the static one. The class is, STATIC; this is the
second argument of the CreateWindowEx function. The name of the static control is, “First
Name”; this is the third argument of the function; this name occurs as the content display of the
static control. You have the WS_CHILD style signifying that it is a child window. The rest of the
arguments to the CreateWindowEx function are like those for the EDIT control. Keep in mind,
LOVELY PROFESSIONAL UNIVERSITY 47