1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
LRESULT wndproc::WndProcWrapper()
{
wndproc *pThis;
vector<string> vec;
pThis->select(vec);
}
void wndproc::select(vector<string>& return)
{
HINSTANCE hInstance = GetModuleHandle(NULL);
WNDCLASSW wc = { 0 };
MSG msg;
wc.lpszClassName = L"Selection1";
wc.hInstance = hInstance;
wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 255));
wc.lpfnWndProc = WndProcWrapper;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.style = CS_DBLCLKS;
RegisterClassW(&wc);
CreateWindowW(wc.lpszClassName, L"Selection",
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, &return);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
LRESULT CALLBACK wndproc::WndProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
bool checked = true;
HWND text, button, selection1;
switch (msg) {
case WM_CREATE: {
text = CreateWindow("STATIC", "Please select options from below:", WS_VISIBLE | WS_CHILD, 20, 20, 300, 25, hwnd, NULL, NULL, NULL);
button = CreateWindow("BUTTON", "Submit", WS_VISIBLE | WS_CHILD | WS_BORDER, 500, 500, 80, 25, hwnd, (HMENU)0, NULL, NULL);
selection1 = CreateWindow("button", "Scan?", WS_VISIBLE | WS_CHILD | BS_CHECKBOX | WS_OVERLAPPED, 500, 460, 350, 20, hwnd, (HMENU)1001, NULL, NULL);
CheckDlgButton(hwnd, 1001, BST_CHECKED);
LPCREATESTRUCT lpcs = reinterpret_cast<LPCREATESTRUCT>(lParam);
vector<string> *strings = reinterpret_cast<vector<string>*>(lpcs->lpCreateParams);
int j = 40;
checkVectorSize = strings->size();
for (int i = 1; i != strings->size() + 1; i++)
{
CreateWindowA("button", (*strings)[i - 1].c_str(),
WS_VISIBLE | WS_CHILD | BS_CHECKBOX | WS_OVERLAPPED,
20, j, 185, 35, hwnd, (HMENU)i,
NULL, NULL);
CheckDlgButton(hwnd, 0, BST_UNCHECKED);
j = j + 30;
}
break;
}
case WM_COMMAND: {
int i = wParam;
if (i == 0)
{
for (int j = 0; j != checkVectorSize; j++)
{
if (IsDlgButtonChecked(hwnd, j + 1) == true)
{
check.push_back(j);//check is a member variable
}
}
if (IsDlgButtonChecked(hwnd, 1001) == true)
{
scan = true; //scan is a boolean member variable
}
else
{
scan = false;
}
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
}
checked = IsDlgButtonChecked(hwnd, i);
if (checked) {
CheckDlgButton(hwnd, i, BST_UNCHECKED);
}
else {
CheckDlgButton(hwnd, i, BST_CHECKED);
}
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
}
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
|