#include<iostream>
#include <windows.h>
#define MY_WIN_CLASS "MyWinClass"
#define CMD_GAME_OVER 101
#define CMD_WHAT 102
#define ID_LIFE 103
#define ID_ITEM_b 301
#define CMD_level 1098
#define CMD_level_1 1034
#define CMD_level_2 1094
#define CMD_level_3 1095
int Init(HINSTANCE hInstance);
HWND CreateMainWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
void PUZZLE(int x, int y);
HWND hMainWin=NULL , hButton=NULL;
int x=0,y=0,bx=100,by=170,w=340,h=70,wX=600,wY=450;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow )
{
MSG msg;
if ( Init(hInstance) == 0 ) {
MessageBox(NULL,"Failed to initialize","Error",MB_OK);
return 0;
} else {
while (GetMessage(&msg,NULL,0,0)) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}
}
int Init(HINSTANCE hInstance)
{
WNDCLASS WinClass;
int Ok;
WinClass.style = NULL;
WinClass.lpfnWndProc = WndProc;
WinClass.cbClsExtra = 0;
WinClass.cbWndExtra = 0;
WinClass.hInstance = hInstance;
WinClass.hIcon = LoadIcon(hInstance,IDI_APPLICATION);
WinClass.hCursor = LoadCursor(NULL,IDC_ARROW);
WinClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WinClass.lpszMenuName = (LPCSTR)NULL;
WinClass.lpszClassName = (LPCSTR)MY_WIN_CLASS;
if ( Ok = RegisterClass(&WinClass) ) {
hMainWin = CreateMainWindow(hInstance);
if ( hMainWin == NULL ) Ok = 0;
}
return Ok;
}
HWND CreateMainWindow(HINSTANCE hInstance)
{
HWND hWin;
HMENU hMainMenu, hSubMenu;
hMainMenu = CreateMenu();
hSubMenu = CreateMenu();
AppendMenu(hSubMenu,MF_STRING,CMD_GAME_OVER,"&Over");
AppendMenu(hMainMenu,MF_STRING|MF_POPUP,(UINT)hSubMenu,"&Game");
AppendMenu(hSubMenu,MF_STRING,CMD_level,"&Easy");
AppendMenu(hSubMenu,MF_STRING,CMD_level,"&Medium");
AppendMenu(hSubMenu,MF_STRING,CMD_level,"&Hard");
AppendMenu(hMainMenu,MF_STRING|MF_POPUP,(UINT)hSubMenu,"&Level");
hSubMenu = CreateMenu();
AppendMenu(hMainMenu,MF_STRING,CMD_WHAT,"&About");
if (hWin = CreateWindow((LPCSTR)MY_WIN_CLASS,
" Midterm Test",
(DWORD)WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL|WS_CLIPSIBLINGS ,
60, 30,600 , 450,NULL, hMainMenu, hInstance, (LPVOID)NULL)) {
hButton=CreateWindow("BUTTON"," 1 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY|WS_GROUP,
100,5,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 2 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY|WS_GROUP,
211,5,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 3 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY,
322,5,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 4 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY|WS_GROUP,
100,116,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 5 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY|WS_GROUP,
211,116,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 6 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY,
322,116,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 7 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY|WS_GROUP,
100,227,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
hButton=CreateWindow("BUTTON"," 8 ",
WS_CHILD|WS_VISIBLE|BS_NOTIFY,
322,227,110,110,hWin,(HMENU)ID_ITEM_b,hInstance,(LPSTR)NULL);
ShowWindow(hWin, SW_SHOWNORMAL);
SetActiveWindow(hWin);
}
return hWin;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CTLCOLORSTATIC:
return (LRESULT)GetStockObject(WHITE_BRUSH);
case WM_MOUSEMOVE:
x = LOWORD(lParam);
y = HIWORD(lParam);
PUZZLE(x,y);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case CMD_WHAT:
MessageBox(NULL," PROGRAMMED BY:: OUSMAN KASSAMA ","User Interface Prototype",MB_OK);
break;
case CMD_GAME_OVER:
DestroyWindow(hMainWin);
break;
}
return 0;
}
return (DefWindowProc(hWnd, message, wParam, lParam));
}
void PUZZLE(int x, int y)
{
int x1=x,y1=y;
int x2=x1,y2=y1;
int x3=x1,y3=y1;
int posX=0,posY=0;
if((x1 >= bx-20) && (x1 <= 420) && (y1 >= by-20) && (y1 <= (by-20)+h)){
if(y1<= 225){posX=600-x1;posY=450-y1; }
else{posX=(300)-x1;posY=(225)-y1;}
if (posX <= 0)posX = 0;
if (posY <= 0)posY = 0;
if (posX >= wX-w)posX = 260;
if (posY >= wY-h)posY = 360;
SetWindowPos(hButton,NULL,posX,posY,0,0,SWP_NOSIZE|SWP_NOZORDER);
bx=posX;
by=posY;
}
}</windows.h></iostream>