Skip to content

Commit

Permalink
Merge pull request #39 from OndrejPetrzilka/no_hook_option
Browse files Browse the repository at this point in the history
Added --no-hook command line option
  • Loading branch information
benbuck committed Mar 22, 2020
2 parents 9fd3316 + 3773aa1 commit d63df30
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions RBTray.cpp
Expand Up @@ -292,8 +292,10 @@ LRESULT CALLBACK HookWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
RestoreWindowFromTray(_hwndItems[i]);
}
}
UnRegisterHook();
FreeLibrary(_hLib);
if (_hLib) {
UnRegisterHook();
FreeLibrary(_hLib);
}
PostQuitMessage(0);
break;
default:
Expand All @@ -316,10 +318,14 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*
int argc;
LPWSTR * argv = CommandLineToArgvW(GetCommandLineW(), &argc);
bool shouldExit = false;
bool useHook = true;
for (int a = 0; a < argc; ++a) {
if (!wcscmp(argv[a], L"--exit")) {
shouldExit = true;
}
if (!wcscmp(argv[a], L"--no-hook")) {
useHook = false;
}
}

_hwndHook = FindWindow(NAME, NAME);
Expand All @@ -332,13 +338,15 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE /*hPrevInstance*
return 0;
}

if (!(_hLib = LoadLibrary(L"RBHook.dll"))) {
MessageBox(NULL, L"Error loading RBHook.dll.", L"RBTray", MB_OK | MB_ICONERROR);
return 0;
}
if (!RegisterHook(_hLib)) {
MessageBox(NULL, L"Error setting hook procedure.", L"RBTray", MB_OK | MB_ICONERROR);
return 0;
if (useHook) {
if (!(_hLib = LoadLibrary(L"RBHook.dll"))) {
MessageBox(NULL, L"Error loading RBHook.dll.", L"RBTray", MB_OK | MB_ICONERROR);
return 0;
}
if (!RegisterHook(_hLib)) {
MessageBox(NULL, L"Error setting hook procedure.", L"RBTray", MB_OK | MB_ICONERROR);
return 0;
}
}

WNDCLASS wc;
Expand Down

0 comments on commit d63df30

Please sign in to comment.