-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
It works like this, but some code review would be good.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,30 @@ | |
|
||
#include <iostream> | ||
#include <windows.h> | ||
using namespace std; | ||
|
||
/* This is our message callback */ | ||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); | ||
|
||
int main() | ||
{ | ||
SetConsoleTitle( TEXT( "Hotkey Blocker" )); | ||
/* Create window class */ | ||
WNDCLASSEX wc; | ||
memset(&wc, 0, sizeof(wc)); | ||
wc.cbSize = sizeof(wc); | ||
wc.lpfnWndProc = WndProc; | ||
wc.lpszClassName = TEXT("MessageWindowClass"); | ||
RegisterClassEx(&wc); | ||
|
||
/* Create window (uses HWND_MESSAGE as the parent window to create message only window) */ | ||
HWND window = CreateWindow(LPCWSTR(wc.lpszClassName), LPCWSTR("HotkeyMesageWindow"), 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
if(!window) | ||
{ | ||
cerr<< "Can't create a window for messaging!" <<endl; | ||
exit(1); | ||
} | ||
|
||
SetConsoleTitle(TEXT("Hotkey Blocker")); | ||
bool keepGoing = true; | ||
|
||
int cappedKeys[] = | ||
|
@@ -19,7 +39,7 @@ int main() | |
VK_F4 | ||
}; | ||
const static int arraySize = sizeof(cappedKeys) / sizeof(int); | ||
printf( "To exit press Num Pad Divide.\n" ); /* Why doesn't this get passed? */ | ||
printf( "To exit press Num Pad Divide.\n" ); /* Why doesn't this key get passed? */ | ||
|
||
bool errorKey = false; | ||
for( int i = 0; i < arraySize; i++ ) | ||
|
@@ -33,6 +53,7 @@ int main() | |
if( !errorKey ) | ||
printf( "Ready to rock and roll!\n" ); | ||
|
||
/* Main message loop */ | ||
MSG msg = {0}; | ||
while (( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) != 0 ) || keepGoing ) | ||
This comment has been minimized.
Sorry, something went wrong.
aroxby
Collaborator
|
||
{ | ||
|
4 comments
on commit ab30c96
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The multi-byte thing is great. I'll have to come back to the rest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can solve the first half of comment number 2 by either using a nested loop or:
Remove keepGoing
from your while condition and insert if(!keepGoing) break;
at the end of your loop.
Just a couple of ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like your saying that I should move my message logic to the other function. Then main will be looped with a dumb while(keepGoing) sleep();
and keepGoing would have to be global?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No you still have things in the main loop. Yes, keepGoing will need to be global.
Something like:
do
{
if(PeekMessage(...))
{
TranslateMessage(&msg);
//This will call your WndProc
DispatchMessage(&msg);
}
Sleep(0);
} while(keepGoing);
The use of the
LPCWSTR
macro tells me you have your app set to unicode in the project properites. I think using 'multi-byte character set' or whatever the alternative is will make your life easier.