#include <windows.h>
//number of form items
#define TOTALNUM 4
//window and object defenitions
#define WINDOW1 0
#define WINDOW2 1
#define WINDOW3 2
#define WINDOW4 3
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ;
int idFocus;
TCHAR szChildClass[] = TEXT ("Checker4_Child") ;
//array of MDL child windows
static HWND hwndarray[TOTALNUM];
static HWND hwndmbuttons[2]; //two buttons that select actions
static HWND hwndwin3[12]; //Storing all the elements of window 3
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Checker4") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = 0 ;//CS_HREDRAW | CS_VREDRAW
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
wndclass.lpfnWndProc = ChildWndProc ;
wndclass.cbWndExtra = sizeof (long) ;
wndclass.hIcon = NULL;
wndclass.lpszClassName = szChildClass ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;
RegisterClass (&wndclass) ;
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
//this is our array of elements on the window
int i;
switch (message)
{
case WM_CREATE:
for(i = 0; i < TOTALNUM ; i++)
{
//putting individual paramters for each window
switch(i)
{
case 0:
hwndarray = CreateWindow (szChildClass ,
TEXT("Results"),WS_CHILDWINDOW | WS_VISIBLE |
WS_CAPTION | WS_THICKFRAME | WS_CLIPSIBLINGS | WS_VSCROLL,
i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
break;
case 1:
hwndarray = CreateWindow (szChildClass ,
TEXT("Actions"),WS_CHILDWINDOW | WS_VISIBLE |
WS_CAPTION | WS_CLIPSIBLINGS,
i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
break;
case 2:
hwndarray = CreateWindow (szChildClass ,
TEXT("window 3"),WS_CHILDWINDOW |
WS_CAPTION | WS_CLIPSIBLINGS,
i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
break;
case 3:
hwndarray = CreateWindow (szChildClass ,
TEXT("window 4"),WS_CHILDWINDOW |
WS_CAPTION | WS_CLIPSIBLINGS,
i * 100,i * 100, 200, 200, hwnd, (HMENU) i,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
break;
}
}
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
//child windows messages
LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static int iVscrollPos;
static int iHscrollPos;
int i;
int j;
//size of window
static int sizeX;
static int sizeY;
//window id
int id = GetWindowLong (hwnd, GWL_ID) ;
char* temp;
switch (message)
{
case WM_CREATE:
//drawing the second window
if(id == WINDOW2)
{
//this button would show window3
hwndmbuttons[0] = CreateWindow ( TEXT("button"),
TEXT("Show Window 3"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
5, 5,
135 , 20 ,
hwnd, (HMENU) 0,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//this button would show window 4
hwndmbuttons[1] = CreateWindow ( TEXT("button"),
TEXT("Show Window 4"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
5, 29,
135 , 20 ,
hwnd, (HMENU) 1,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
MoveWindow(hwnd,0,220,150,80,TRUE);
}
if(id == WINDOW3)
{
MoveWindow(hwnd,300,220,300,300,TRUE);
//creating items :
//big TOP GROUP BOX
hwndwin3[0] = CreateWindow ( TEXT("button"),
TEXT("Results:"),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
2, 0,
sizeX - 5 , sizeY - 50 ,
hwnd, (HMENU) 0,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//little DOWN GROUP BOX
hwndwin3[1] = CreateWindow ( TEXT("button"),
TEXT(""),
WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
2, sizeY - 50 ,
sizeX - 5 ,sizeY - (sizeY - 50) - 3 ,
hwnd, (HMENU) 0,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//CANCEL BUTTON - ID = 1
hwndwin3[2] = CreateWindow ( TEXT("button"),
TEXT("CANCEL"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
sizeX - 100, sizeY - 30 ,
85 ,20 ,
hwnd, (HMENU) 1,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//OK BUTTON - ID = 2
hwndwin3[3] = CreateWindow ( TEXT("button"),
TEXT("OK"),
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
sizeX - 190, sizeY - 30 ,
85 ,20 ,
hwnd, (HMENU) 2,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//LABEL 1
hwndwin3[4] = CreateWindow ( TEXT("STATIC"),
TEXT("Please enter first parmaters :"),
WS_CHILD | WS_VISIBLE | SS_CENTER ,
10, 14 ,
200 ,20 ,
hwnd, (HMENU) -1,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//EDIT1 - ID = 3 (Winning numbers)
hwndwin3[5] = CreateWindow ( TEXT("edit"),
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |ES_AUTOHSCROLL,
10, 35 ,
sizeX - 20 ,20 ,
hwnd, (HMENU) 3,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//LABEL 2
hwndwin3[6] = CreateWindow ( TEXT("STATIC"),
TEXT("Tour N :"),
WS_CHILD | WS_VISIBLE | SS_CENTER ,
10, 60 ,
55 ,20 ,
hwnd, (HMENU) -1,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//EDIT2 - ID = 4 (Number of tour)
hwndwin3[7] = CreateWindow ( TEXT("edit"),
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT|ES_NUMBER ,
10, 75 ,
55 ,20 ,
hwnd, (HMENU) 4,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//LABEL 3
hwndwin3[8] = CreateWindow ( TEXT("STATIC"),
TEXT("Date :"),
WS_CHILD | WS_VISIBLE | SS_CENTER ,
80, 60 ,
55 ,20 ,
hwnd, (HMENU) -1,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//EDIT3 - ID = 5 (Date of tour)
hwndwin3[9] = CreateWindow ( TEXT("edit"),
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,
80, 75 ,
80 ,20 ,
hwnd, (HMENU) 5,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//LABEL 4
hwndwin3[10] = CreateWindow ( TEXT("STATIC"),
TEXT("Time :"),
WS_CHILD | WS_VISIBLE | SS_CENTER ,
170, 60 ,
55 ,20 ,
hwnd, (HMENU) -1,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
//EDIT4 - ID = 6 (Date of tour)
hwndwin3[11] = CreateWindow ( TEXT("edit"),
NULL,
WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT ,
170, 75 ,
80 ,20 ,
hwnd, (HMENU) 6,
((LPCREATESTRUCT) lParam)->hInstance, NULL) ;
}
if(id == WINDOW4)
{
MoveWindow(hwnd,300,220,300,300,TRUE);
}
SetFocus (hwndmbuttons[0]) ;
return 0 ;
case WM_COMMAND:
//working with individual window
switch(id)
{
case WINDOW1: break;
case WINDOW2: // Showing 3 window
if(LOWORD(wParam) == 0)
{
ShowWindow(hwndarray[2],TRUE);
SetFocus (hwndarray[2]);
ShowWindow(hwndarray[3],FALSE);
}
else //showing forth window
{
ShowWindow(hwndarray[3],TRUE);
SetFocus (hwndarray[3]);
ShowWindow(hwndarray[2],FALSE);
}
break;
}
return 0;
case WM_SIZE:
sizeX = LOWORD (lParam) ;
sizeY = HIWORD (lParam) ;
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}