Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <winuser.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK WndProc2 (HWND, UINT, WPARAM, LPARAM);
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...);
char *titles (void);
char *names (void);
int title=2, name=1;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin");
static TCHAR szAppName2[] = TEXT ("#2 Win");
int tmp;
HWND hwnd, hwnd2, hwnd3, hwnd4;
MSG msg;
WNDCLASS wndclass, wndclass2;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass2.style = CS_HREDRAW | CS_VREDRAW;
wndclass2.lpfnWndProc = WndProc2;
wndclass2.cbClsExtra = 0;
wndclass2.cbWndExtra = 0;
wndclass2.hInstance = hInstance;
wndclass2.hIcon = LoadIcon (NULL, IDC_ARROW);
wndclass2.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass2.lpszMenuName = NULL;
wndclass2.lpszClassName = szAppName2;
wndclass2.hCursor=LoadCursor(NULL,IDC_ARROW);
if ( !RegisterClass (&wndclass))
{
tmp = GetLastError();
MessageBoxPrintf( TEXT ("Error"),
TEXT ("Error Number: %i"), tmp);
return 0;
}
if ( !RegisterClass (&wndclass2))
{
tmp = GetLastError();
MessageBoxPrintf( TEXT ("Error"),
TEXT ("Error Number: %i"), tmp);
return 0;
}
hwnd = CreateWindow (szAppName,
TEXT ("The Hello Program"),
WS_OVERLAPPEDWINDOW,
10,
10,
200,
200,
NULL,
NULL,
hInstance,
NULL);
hwnd2 = CreateWindow (szAppName2,
TEXT("POPUP"),
WS_OVERLAPPED,
500,
500,
200,
200,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
ShowWindow (hwnd2, iCmdShow);
UpdateWindow (hwnd2);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
TCHAR szBuffer[100];
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rect);
wsprintf(szBuffer, TEXT ("%s %s"), titles(), names());
DrawText ( hdc, szBuffer, -1, &rect,
DT_SINGLELINE | DT_CENTER);
EndPaint (hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProc2 (HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
TCHAR szBuffer[100];
switch (message)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint (hwnd2, &ps);
GetClientRect (hwnd2, &rect);
DrawText ( hdc, TEXT("#2"), -1, &rect,
DT_SINGLELINE | DT_CENTER);
EndPaint (hwnd2, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd2, message, wParam, lParam);
}
int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
TCHAR szBuffer [1024];
va_list pArgList;
va_start (pArgList, szFormat);
_vsntprintf (szBuffer, sizeof (szBuffer) / sizeof (TCHAR),
szFormat, pArgList);
va_end (pArgList);
return MessageBox (NULL, szBuffer, szCaption, 0);
}
char* titles(void)
{
switch (title)
{
case 0:
return ("Dirt Ball");
break;
case 1:
return ("Serf");
break;
case 2:
return ("Peasant");
break;
case 3:
return ("Adventurer");
break;
case 4:
return ("Governer");
break;
case 5:
return ("Grand Governer");
break;
case 6:
return ("Duke");
break;
case 7:
return ("King");
break;
}
}
char* names (void)
{
switch (name)
{
case 0:
return ("Gnos");
case 1:
return ("Bob");
case 2:
return ("Michael");
case 3:
return ("Shirley");
}
}