Code:
#include<windows.h>
#include "resource.h"
using namespace std;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK MainDialogProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
HMENU hMenu;
static TCHAR szAppName[]=TEXT("Assessment Runner");
HWND hwnd; // handle to a window
MSG msg; // message
WNDCLASS wndclass; // window class we are declaring
// Now we set the attributes for our window
wndclass.style=CS_HREDRAW | CS_VREDRAW; // Style, in this case can be redrawn
wndclass.lpfnWndProc=WndProc; // window process name - handles message calls
wndclass.cbClsExtra=0; // Extra space for the window
wndclass.cbWndExtra=0; // ditto
wndclass.hInstance=hInstance; // program instance name passed to WinMain
wndclass.hIcon=LoadIcon(NULL, IDI_APPLICATION); // Load icon for the tray
wndclass.hCursor=LoadCursor(NULL, IDC_ARROW); // Load icon for the mouse arrow
wndclass.hbrBackground=(HBRUSH) GetStockObject(WHITE_BRUSH); // Load background color
wndclass.lpszMenuName=NULL; // Set menu - none here
wndclass.lpszClassName=szAppName; // Sets window name, taken from above
hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));
if (!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("Error running program!"), szAppName, MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName, TEXT("Assessment Runer"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenu,
hInstance, NULL); // Create the window! Name, Title, Style, x Position, y Position
// X size, Y size, parent window handle, window menu handle,
// program instance handle, creation parameters(passing variables)
ShowWindow(hwnd, iCmdShow); // now show the window
UpdateWindow(hwnd); // update it
while (GetMessage(&msg, NULL, 0, 0)) // gets message from mouse and keyboard, always non
// zero until you quit the window
{
TranslateMessage(&msg); // translates message from message queue (mouse/keyboard/etc)
DispatchMessage(&msg); // sends to WndProc to translate and tell what to do!
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HINSTANCE hInstance;
switch (message)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT) lParam)->hInstance;
return 0;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_TEST_TEST:
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, MainDialogProc);
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
BOOL CALLBACK MainDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDOK: // user clicked OK button, return
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}