Subscribe to Bodom's Universe        RSS Feed
-----

Windows GUI messages are making my head spin!

Icon Leave Comment
And I Like it!

Code::blocks is officially my favorite code editor. It does everything I would ever need to do in VS without the extra baggage, and the customizability is GREAT! I created a Win32 app project, and my basic window code was already implemented!

But thats not what I am here to talk about... ON TO MESSAGES!

So I suddenly realized what this damn message loop was for inside the LRESULT CALLBACK WindowProcedure function. It handles everything! Key presses, mouse clicks, mouse movement... it's all so very simple to track...

Getting specific is another issue, but that is also another blog post...

example:
I found a cool windows message that will detect mouse movement. So, I decided to have a message box pop up whenever the user moves the mouse:

case WM_MOUSEMOVE:
MessageBox(hwnd, "DON'T MOVE THAT MOUSE", "Error 002", MB_OK, MB_ICONEXCLAMATION);
break;



This was great and all. I would get a box on my screen, and whenever I moved my mouse in it I would get a message box yellin' at me not to move it. Now... how to make this more annoying...

I moved up to my CreateWindow function in win main, and changed the length and width to my native screen size (1440x900 for my external monitor)

    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "MY New Cool App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           1440,                 /* The programs width */
           900,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );



And then... you guessed it, ran the program.
I got a screen the size of my native resolution, and whenever I moved the mouse, an infinite amount of diolouge boxes would pop up, one after another. Wonderful! So I can't exit out of my program. Thank God for code blocks, as there was still a CMD window in the back, and exiting that exited out of the program.

*whew* that was fun... Pointless but fun, and I got to see proof that this event works.

I did something similar with WM_KEYDOWN:
case WM_KEYDOWN:
if(GetAsyncKeyState(VK_DOWN) != 0)
        PostQuitMessage (0);
else
	MessageBox(hwnd, "Wrong Key", "Error: 001", MB_OK);
break;



Basically, if the user presses a key and it isn't the down arrow, they get a nice error box. GetAsyncKeyState returns zero unless the key specified in the parameter is pushed. For a full list, do a google search on Virtual Keys. its on there somewhere.

I know a lot of you seasoned programmers are going "well damn, Bodom, thats 5 minutes I'm not gonna get back."
Please understand, this is all new to me, this GUI stuff, and messing around with these messages are all the rage for me right now!

If anyone has any other unique or interesting messages and code as i have here (well, mine is interesting to ME) please, feel free to comment them here. I am always looking for more ways to spread my knowledge of C++ in general. Why know only one aspect when I can learn everything there is to know, eh?

Peace Out
~Bodom

0 Comments On This Entry

 

January 2022

S M T W T F S
      1
2345678
9101112131415
161718192021 22
23242526272829
3031     

Recent Comments

Search My Blog

14 user(s) viewing

14 Guests
0 member(s)
0 anonymous member(s)