Cleanup code.
Changed main "ghost" window to a message-only window.
This commit is contained in:
@@ -55,7 +55,8 @@ INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
|||||||
|
|
||||||
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
|
VOID MoveWindowToMonitorCenter(HWND hwnd, BOOL bWorkArea, BOOL bResize)
|
||||||
{
|
{
|
||||||
diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd, L"Title:", (LPWSTR)szBuffer);
|
//diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd, L"Title:", (LPWSTR)szBuffer);
|
||||||
|
diag_log(L"Entering MoveWindowToMonitorCenter(): hwnd =", hwnd);
|
||||||
|
|
||||||
RECT fgwrc = { 0 };
|
RECT fgwrc = { 0 };
|
||||||
GetWindowRect(hwnd, &fgwrc);
|
GetWindowRect(hwnd, &fgwrc);
|
||||||
@@ -136,7 +137,7 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
|||||||
}
|
}
|
||||||
|
|
||||||
MyRegisterClass(hInstance);
|
MyRegisterClass(hInstance);
|
||||||
hWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
|
hWnd = CreateWindowExW(0, szClass, szTitle, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, hInstance, NULL);
|
||||||
if (!hWnd)
|
if (!hWnd)
|
||||||
{
|
{
|
||||||
ShowError(IDS_ERR_WND);
|
ShowError(IDS_ERR_WND);
|
||||||
@@ -146,8 +147,8 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
|
|||||||
int nArgs = 0;
|
int nArgs = 0;
|
||||||
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
|
LPWSTR* szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
|
||||||
|
|
||||||
diag_log(L"Arguments:", nArgs);
|
diag_log(L"Arguments:", nArgs - 1);
|
||||||
for (int i = 0; i < nArgs; i++)
|
for (int i = 1; i < nArgs; i++)
|
||||||
{
|
{
|
||||||
diag_log(L"Argument", i, L":", szArglist[i]);
|
diag_log(L"Argument", i, L":", szArglist[i]);
|
||||||
}
|
}
|
||||||
@@ -196,108 +197,105 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
{
|
{
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
{
|
|
||||||
hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
|
|
||||||
if (!hMenu)
|
|
||||||
{
|
{
|
||||||
diag_log(L"Loading context menu failed!");
|
hMenu = LoadMenuW(hInst, MAKEINTRESOURCE(IDR_MENU));
|
||||||
ShowError(IDS_ERR_MENU);
|
if (!hMenu)
|
||||||
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
diag_log(L"Context menu successfully loaded");
|
|
||||||
|
|
||||||
hPopup = GetSubMenu(hMenu, 0);
|
|
||||||
if (!hPopup)
|
|
||||||
{
|
|
||||||
diag_log(L"Creating popup menu failed!");
|
|
||||||
ShowError(IDS_ERR_POPUP);
|
|
||||||
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
diag_log(L"Popup menu successfully created");
|
|
||||||
|
|
||||||
mii.cbSize = sizeof(MENUITEMINFO);
|
|
||||||
mii.fMask = MIIM_STATE;
|
|
||||||
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
|
||||||
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
|
||||||
|
|
||||||
//nid.cbSize = sizeof(NOTIFYICONDATAW);
|
|
||||||
nid.cbSize = sizeof(nid);
|
|
||||||
nid.hWnd = hWnd;
|
|
||||||
//nid.uVersion = NOTIFYICON_VERSION_4;
|
|
||||||
nid.uVersion = NOTIFYICON_VERSION;
|
|
||||||
nid.uCallbackMessage = WM_WCW;
|
|
||||||
nid.hIcon = hIcon;
|
|
||||||
nid.uID = IDI_TRAYICON;
|
|
||||||
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
|
||||||
nid.dwInfoFlags = NIIF_NONE;
|
|
||||||
nid.dwState = NIS_HIDDEN;
|
|
||||||
nid.dwStateMask = NIS_HIDDEN;
|
|
||||||
//StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle);
|
|
||||||
StringCchCopyW(nid.szTip, ARRAYSIZE(nid.szTip), szTitle);
|
|
||||||
|
|
||||||
hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
|
|
||||||
if (!hMouseHook)
|
|
||||||
{
|
|
||||||
diag_log(L"Creating mouse hook failed!");
|
|
||||||
ShowError(IDS_ERR_HOOK);
|
|
||||||
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
diag_log(L"Mouse hook was successfully set");
|
|
||||||
|
|
||||||
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
|
|
||||||
if (!hKbdHook)
|
|
||||||
{
|
|
||||||
diag_log(L"Creating keyboard hook failed!");
|
|
||||||
ShowError(IDS_ERR_HOOK);
|
|
||||||
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
|
||||||
}
|
|
||||||
diag_log(L"Keyboard hook was successfully set");
|
|
||||||
|
|
||||||
LoadStringW(hInst, IDS_ABOUT, szAbout, _countof(szAbout));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_WCW:
|
|
||||||
{
|
|
||||||
if ((lParam == WM_RBUTTONDOWN || lParam == WM_LBUTTONDOWN) && wParam == IDI_TRAYICON)
|
|
||||||
{
|
|
||||||
SetForegroundWindow(hWnd);
|
|
||||||
POINT pt;
|
|
||||||
GetCursorPos(&pt);
|
|
||||||
int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
|
|
||||||
if (idMenu == ID_POPUPMENU_ICON)
|
|
||||||
{
|
{
|
||||||
bShowIcon = FALSE;
|
diag_log(L"Loading context menu failed!");
|
||||||
HandlingTrayIcon();
|
ShowError(IDS_ERR_MENU);
|
||||||
|
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
}
|
}
|
||||||
if (idMenu == ID_POPUPMENU_AREA)
|
diag_log(L"Context menu successfully loaded");
|
||||||
|
|
||||||
|
hPopup = GetSubMenu(hMenu, 0);
|
||||||
|
if (!hPopup)
|
||||||
{
|
{
|
||||||
bWorkArea = !bWorkArea;
|
diag_log(L"Creating popup menu failed!");
|
||||||
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
ShowError(IDS_ERR_POPUP);
|
||||||
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
diag_log(L"Changed 'Use workarea' option to", bWorkArea);
|
|
||||||
}
|
}
|
||||||
if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed)
|
diag_log(L"Popup menu successfully created");
|
||||||
|
|
||||||
|
mii.cbSize = sizeof(MENUITEMINFO);
|
||||||
|
mii.fMask = MIIM_STATE;
|
||||||
|
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
||||||
|
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
||||||
|
|
||||||
|
nid.cbSize = sizeof(NOTIFYICONDATAW);
|
||||||
|
nid.hWnd = hWnd;
|
||||||
|
nid.uVersion = NOTIFYICON_VERSION;
|
||||||
|
nid.uCallbackMessage = WM_WCW;
|
||||||
|
nid.hIcon = hIcon;
|
||||||
|
nid.uID = IDI_TRAYICON;
|
||||||
|
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
|
||||||
|
nid.dwInfoFlags = NIIF_NONE;
|
||||||
|
nid.dwState = NIS_HIDDEN;
|
||||||
|
nid.dwStateMask = NIS_HIDDEN;
|
||||||
|
StringCchCopyW(nid.szTip, _countof(nid.szTip), szTitle);
|
||||||
|
|
||||||
|
hMouseHook = SetWindowsHookExW(WH_MOUSE_LL, MouseHookProc, hInst, NULL);
|
||||||
|
if (!hMouseHook)
|
||||||
{
|
{
|
||||||
bKPressed = TRUE;
|
diag_log(L"Creating mouse hook failed!");
|
||||||
diag_log(L"Opening 'About' dialog");
|
ShowError(IDS_ERR_HOOK);
|
||||||
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
|
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
bKPressed = FALSE;
|
|
||||||
}
|
}
|
||||||
if (idMenu == ID_POPUPMENU_EXIT) SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
diag_log(L"Mouse hook was successfully set");
|
||||||
|
|
||||||
|
hKbdHook = SetWindowsHookExW(WH_KEYBOARD_LL, KeyboardHookProc, hInst, NULL);
|
||||||
|
if (!hKbdHook)
|
||||||
|
{
|
||||||
|
diag_log(L"Creating keyboard hook failed!");
|
||||||
|
ShowError(IDS_ERR_HOOK);
|
||||||
|
SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
|
}
|
||||||
|
diag_log(L"Keyboard hook was successfully set");
|
||||||
|
|
||||||
|
LoadStringW(hInst, IDS_ABOUT, szAbout, _countof(szAbout));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case WM_DESTROY:
|
case WM_WCW:
|
||||||
{
|
{
|
||||||
PostQuitMessage(0);
|
if ((lParam == WM_RBUTTONDOWN || lParam == WM_LBUTTONDOWN) && wParam == IDI_TRAYICON)
|
||||||
}
|
{
|
||||||
break;
|
SetForegroundWindow(hWnd);
|
||||||
|
POINT pt;
|
||||||
|
GetCursorPos(&pt);
|
||||||
|
int idMenu = TrackPopupMenu(hPopup, TPM_RETURNCMD, pt.x, pt.y, 0, hWnd, NULL);
|
||||||
|
if (idMenu == ID_POPUPMENU_ICON)
|
||||||
|
{
|
||||||
|
bShowIcon = FALSE;
|
||||||
|
HandlingTrayIcon();
|
||||||
|
}
|
||||||
|
if (idMenu == ID_POPUPMENU_AREA)
|
||||||
|
{
|
||||||
|
bWorkArea = !bWorkArea;
|
||||||
|
bWorkArea ? mii.fState = MFS_CHECKED : mii.fState = MFS_UNCHECKED;
|
||||||
|
SetMenuItemInfoW(hPopup, ID_POPUPMENU_AREA, FALSE, &mii);
|
||||||
|
diag_log(L"Changed 'Use workarea' option to", bWorkArea);
|
||||||
|
}
|
||||||
|
if (idMenu == ID_POPUPMENU_ABOUT && !bKPressed)
|
||||||
|
{
|
||||||
|
bKPressed = TRUE;
|
||||||
|
diag_log(L"Opening 'About' dialog");
|
||||||
|
DialogBoxW(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, (DLGPROC)About);
|
||||||
|
bKPressed = FALSE;
|
||||||
|
}
|
||||||
|
if (idMenu == ID_POPUPMENU_EXIT) SendMessageW(hWnd, WM_CLOSE, NULL, NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
case WM_DESTROY:
|
||||||
return DefWindowProcW(hWnd, message, wParam, lParam);
|
{
|
||||||
|
PostQuitMessage(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return DefWindowProcW(hWnd, message, wParam, lParam);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -378,48 +376,48 @@ BOOL CALLBACK DlgProc(HWND hDlg, UINT dlgmsg, WPARAM wParam, LPARAM lParam)
|
|||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
switch (dlgmsg)
|
switch (dlgmsg)
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
|
||||||
SetWindowTextW(hDlg, szTitle);
|
|
||||||
GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
|
|
||||||
GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass));
|
|
||||||
GetWindowRect(hFgWnd, &rcFW);
|
|
||||||
x = rcFW.left;
|
|
||||||
y = rcFW.top;
|
|
||||||
w = rcFW.right - rcFW.left;
|
|
||||||
h = rcFW.bottom - rcFW.top;
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_X, x, TRUE);
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE);
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE);
|
|
||||||
SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE);
|
|
||||||
SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle);
|
|
||||||
SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass);
|
|
||||||
UpdateWindow(hDlg);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case WM_COMMAND:
|
|
||||||
switch (LOWORD(wParam))
|
|
||||||
{
|
{
|
||||||
case IDC_BUTTON_SET:
|
SetWindowTextW(hDlg, szTitle);
|
||||||
{
|
GetWindowTextW(hFgWnd, szWinTitle, _countof(szWinTitle));
|
||||||
x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE);
|
GetClassNameW(hFgWnd, szWinClass, _countof(szWinClass));
|
||||||
y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE);
|
GetWindowRect(hFgWnd, &rcFW);
|
||||||
w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE);
|
x = rcFW.left;
|
||||||
h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE);
|
y = rcFW.top;
|
||||||
SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL);
|
w = rcFW.right - rcFW.left;
|
||||||
MoveWindow(hFgWnd, x, y, w, h, TRUE);
|
h = rcFW.bottom - rcFW.top;
|
||||||
SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL);
|
SetDlgItemInt(hDlg, IDC_EDIT_X, x, TRUE);
|
||||||
return TRUE;
|
SetDlgItemInt(hDlg, IDC_EDIT_Y, y, TRUE);
|
||||||
|
SetDlgItemInt(hDlg, IDC_EDIT_WIDTH, w, FALSE);
|
||||||
|
SetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, h, FALSE);
|
||||||
|
SetDlgItemTextW(hDlg, IDC_EDIT_TITLE, szWinTitle);
|
||||||
|
SetDlgItemTextW(hDlg, IDC_EDIT_CLASS, szWinClass);
|
||||||
|
UpdateWindow(hDlg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IDCANCEL:
|
case WM_COMMAND:
|
||||||
case IDC_BUTTON_CLOSE:
|
switch (LOWORD(wParam))
|
||||||
{
|
{
|
||||||
EndDialog(hDlg, LOWORD(wParam));
|
case IDC_BUTTON_SET:
|
||||||
diag_log(L"Closing 'Manual editing' dialog");
|
{
|
||||||
break;
|
x = GetDlgItemInt(hDlg, IDC_EDIT_X, NULL, TRUE);
|
||||||
}
|
y = GetDlgItemInt(hDlg, IDC_EDIT_Y, NULL, TRUE);
|
||||||
}
|
w = GetDlgItemInt(hDlg, IDC_EDIT_WIDTH, NULL, FALSE);
|
||||||
|
h = GetDlgItemInt(hDlg, IDC_EDIT_HEIGHT, NULL, FALSE);
|
||||||
|
SendMessageW(hFgWnd, WM_ENTERSIZEMOVE, NULL, NULL);
|
||||||
|
MoveWindow(hFgWnd, x, y, w, h, TRUE);
|
||||||
|
SendMessageW(hFgWnd, WM_EXITSIZEMOVE, NULL, NULL);
|
||||||
|
return TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case IDCANCEL:
|
||||||
|
case IDC_BUTTON_CLOSE:
|
||||||
|
{
|
||||||
|
EndDialog(hDlg, LOWORD(wParam));
|
||||||
|
diag_log(L"Closing 'Manual editing' dialog");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@@ -488,21 +486,17 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
|
|
||||||
switch (message)
|
switch (message)
|
||||||
{
|
{
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
{
|
|
||||||
SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAbout);
|
|
||||||
return (INT_PTR)TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_NOTIFY:
|
|
||||||
{
|
|
||||||
LPNMHDR pNMHdr = (LPNMHDR)lParam;
|
|
||||||
switch (pNMHdr->code)
|
|
||||||
{
|
{
|
||||||
case NM_CLICK:
|
SetDlgItemTextW(hDlg, IDC_ABOUTHELP, szAbout);
|
||||||
case NM_RETURN:
|
return (INT_PTR)TRUE;
|
||||||
if (pNMHdr->idFrom == IDC_DONATIONLINK)
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case WM_NOTIFY:
|
||||||
|
{
|
||||||
|
LPNMHDR pNMHdr = (LPNMHDR)lParam;
|
||||||
|
if ((NM_CLICK == pNMHdr->code || NM_RETURN == pNMHdr->code) && IDC_DONATIONLINK == pNMHdr->idFrom)
|
||||||
{
|
{
|
||||||
PNMLINK pNMLink = (PNMLINK)pNMHdr;
|
PNMLINK pNMLink = (PNMLINK)pNMHdr;
|
||||||
LITEM item = pNMLink->item;
|
LITEM item = pNMLink->item;
|
||||||
@@ -512,17 +506,15 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||||
{
|
{
|
||||||
EndDialog(hDlg, LOWORD(wParam));
|
EndDialog(hDlg, LOWORD(wParam));
|
||||||
diag_log(L"Closing 'About' dialog");
|
diag_log(L"Closing 'About' dialog");
|
||||||
return (INT_PTR)TRUE;
|
return (INT_PTR)TRUE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return (INT_PTR)FALSE;
|
return (INT_PTR)FALSE;
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user