Code:
#include<windows.h>
#include<math.h>
#include<time.h>
#include<process.h>
#include<queue>
#include<commctrl.h>
#include "resource.h"
#include <stdio.h>
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "comctl32.lib")
using namespace std;
TCHAR szAppName[]=TEXT("Assessment Runner");
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT APIENTRY ViewQueueProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL CALLBACK MainDialogProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
HMENU hMenu;
srand(time(NULL));
HWND hwnd; // handle to a window
MSG msg; // message
WNDCLASS wndclass; // window class we are declaring
INITCOMMONCONTROLSEX icc = { 0 };
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icc);
// 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;
}
void Thread (PVOID pvoid)
{
char child1[] = "c:\\debug\\test.exe";
MessageBox(NULL, TEXT("Before executing program Thread!"), szAppName, MB_ICONERROR);
system(child1);
MessageBox(NULL, TEXT("After executing program Thread!"), szAppName, MB_ICONERROR);
_endthread();
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndViewQueue;
static HINSTANCE hInstance;
WNDCLASS wndclass;
switch (message)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT) lParam)->hInstance;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_TEST_TEST:
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, MainDialogProc);
break;
case RUN_QUEUE:
MessageBox(NULL, TEXT("Before Thread!"), szAppName, MB_ICONERROR);
_beginthread(Thread, 0, NULL);
break;
case VIEW_QUEUE:
wndclass.style=CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc=ViewQueueProc;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hInstance=hInstance;
wndclass.hIcon=NULL;
wndclass.hCursor=LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground=(HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName=NULL;
wndclass.lpszClassName=WC_LISTVIEW;
RegisterClass(&wndclass);
hwndViewQueue=CreateWindow(WC_LISTVIEW, NULL, WS_OVERLAPPEDWINDOW ,
200, 200, 300, 300, hwnd, 0, hInstance, NULL);
ShowWindow(hwndViewQueue, SW_SHOWNORMAL); // now show the window!
UpdateWindow(hwnd); // update it
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)
{
static HWND hwndCombo, hwndList;
switch (message)
{
case WM_INITDIALOG:
hwndCombo=GetDlgItem(hDlg, IDC_COMBO1);
SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test");
SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test2");
SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test3");
SendMessage(hwndCombo, CB_ADDSTRING,0,(LPARAM) "Test4");
return TRUE;
case WM_COMMAND:
switch (LOWORD (wParam))
{
case IDC_COMBO1:
return TRUE;
case IDOK:
EndDialog(hDlg, TRUE);
return TRUE;
}
break;
}
return FALSE;
}
LRESULT APIENTRY ViewQueueProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hListView;
static HINSTANCE hInstance;
LVCOLUMN lvc = { 0 };
LVITEM lv = { 0 };
switch (message)
{
case WM_CREATE:
hInstance=((LPCREATESTRUCT) lParam)->hInstance;
hListView = CreateWindow(WC_LISTVIEW,
NULL,
WS_CHILD | WS_VISIBLE | LVS_REPORT,
10,
10,
500,
500,
hwnd,
(HMENU) 500,
hInstance,
NULL);
ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_FMT;
lvc.fmt = LVCFMT_LEFT;
/* Add four columns to the list-view (first column contains check box). */
lvc.iSubItem = 0;
lvc.cx = 50;
lvc.pszText = TEXT("Record");
ListView_InsertColumn(hListView, 0, &lvc);
lvc.iSubItem = 1;
lvc.cx = 100;
lvc.pszText = TEXT("Name");
ListView_InsertColumn(hListView, 1, &lvc);
lvc.iSubItem = 2;
lvc.cx = 70;
lvc.pszText = TEXT("Episodes");
ListView_InsertColumn(hListView, 2, &lvc);
lvc.iSubItem = 3;
lvc.cx = 150;
lvc.pszText = TEXT("Any Good?");
ListView_InsertColumn(hListView, 3, &lvc);
/* Add some rows. */
lv.iItem = 0;
ListView_InsertItem(hListView, &lv);
ListView_SetItemText(hListView, 0, 0, TEXT("Duh"));
ListView_SetItemText(hListView, 0, 1, TEXT("Friends"));
ListView_SetItemText(hListView, 0, 2, TEXT("500"));
ListView_SetItemText(hListView, 0, 3, TEXT("Alright"));
lv.iItem = 1;
ListView_InsertItem(hListView, &lv);
ListView_SetItemText(hListView, 1, 0, TEXT("Duh again"));
ListView_SetItemText(hListView, 1, 1, TEXT("Survivor"));
ListView_SetItemText(hListView, 1, 2, TEXT("970,000"));
ListView_SetItemText(hListView, 1, 3, TEXT("Please, not again"));
break;
case WM_DESTROY:
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}