-1

I'm trying to use a hotkey to change a layered window from being transparent to allowing mouse messages to come through.

In my main function I call

// make hotkey with WM_HOTKEY messages sent to hwnd's window procedure, id 1, 
// no other keys to work, F5 as hotkey  
// while checking for errors and it completes successfully. I also do the same 
// (id of 2) for VK_F7 and it completes successfully.

RegisterHotKey (hwnd, 1, 0, VK_F5); 
RegisterHotKey (hwnd, 2, 0, VK_F7);

In my window procedure, I have

case WM_HOTKEY: 
    MessageBox (hwnd, "Got here", "Attention", MB_OK);
    // Other stuff I need to do here

I tried adding MOD_CONTROL, but to no avail.

This did actually work before. The only difference now is that I realized that two windows would solve the problems I've been having. Last time I only had one, and now I have two window procedures in my application. I made sure it's all going to the right one and everything, but I shouldn'e be limited to just 1 window... The window itself displays, as I set the transparency to 100/255 so it screens the view a bit, and I can see that screen.

Changing the key itself does nothing, and the WM_HOTKEY messages are being posted to the queue. I'm going to try manually sending them to the window.

edit: ^ with SendMessage() isn't working, going to see if it's getting any messages, and same with the other window while I'm at it.

edit: okay I feel like an idiot for saying this, but I had RegisterHotKey going to a null hwnd since I didn't actually create that window yet (I created the one not getting hotkey message first and originally had these right after that). The problem is that even though I can see this window, and if I comment it all out the view is different (no screen), it isn't receiving any messages.

edit: I changed the title to something more suitable with this extra info. If this is a generic thing anyone's experienced, I'd be glad to hear. For now, I'm assuming it's my wrapper and creating them manually.

major edit: I just tried using raw API instead of my wrapper and it had an error registering the second. I changed the class name and now the classes register and the windows get created. The message box that comes up for hotkeys shows too. I think I forgot to put the showwindow for them though, I'll say how that works in a second (edit: after I restart my computer yet again!!!). Before you ask, I didn't spend too long on my wrapper yet, and yes, it has error checking, but uses a similar system to set/get lasterror() and I didn't check the return values on them since the second one seemed to be created before.

Kev
  • 118,037
  • 53
  • 300
  • 385
chris
  • 60,560
  • 13
  • 143
  • 205
  • Did you create both windows on the same thread? Did you check for WM_HOTKEY in the message loop? – David Heffernan Oct 01 '11 at 16:22
  • I basically set one window up, created it, then set the other up and created it right after. If you mean the message loop in main() I shouldn't have to because I specified the associated window. I was going to make sure they were being posted in the first place as the next thing though. EDIT: yes they are being sent, I checked via if (msg.message == WM_HOTKEY) MessageBox(...); – chris Oct 01 '11 at 16:32
  • If they arrive in your message loop then your window proc isn't what you think it is, or you are misdelivering. What does your message loop look like? – David Heffernan Oct 01 '11 at 16:46
  • Okay, I switched the order in which I set up/created the windows and now it is getting messages. At this point I feel I should mention I'm using two instances of my own wrapper class to set up/create (not handle) these windows. I'll look into that to see if it has a problem when more than one instance is made, though I don't see how it would. @your question: `while (GetMessage (&msg,0,0,0) > 0) { //checking for WM_HOTKEY was here; TranslateMessage (&msg); DispatchMessage (&msg); }` This was put at the end of main. – chris Oct 01 '11 at 16:47
  • Sorry, time ran out, I do remember a tutorial on dialog boxes adding a section for it in there. Would this be the same even if they are both children of the desktop? Also, switching them and removing the message notifications produces the correct things (including hotkeys) for that one, but the other is just white. – chris Oct 01 '11 at 16:53
  • 3
    If you solved it yourself, you can answer your own question and accept your own answer. – Mysticial Oct 01 '11 at 17:51
  • I didn't know that, thanks. Guess it'll clear it up in the standard way. – chris Oct 01 '11 at 18:35
  • Really, answer the question yourself and revert it to its original form. Or delete it. – David Heffernan Oct 01 '11 at 19:34
  • Sorry, I had to wait 8 hours since it was posted to do so. I'm doing it in <1h since it says 7h atm. – chris Oct 02 '11 at 00:08

1 Answers1

0

The problem was that both windows had the same class name. This does confuse me a bit, as I thought they were allowed to, and I shall be adding a static instance counting member to my wrapper then. The final result is that every problem in this area is now fixed :D
EDIT: I just had to add this after learning it, but I came upon the knowledge that you can create two windows with the same class name, but they must use the same window procedure. Learning this actually strengthened my understanding of this topic a lot, so if I clear this up for even one other person I'll be happy. /EDIT

Just in case you're wondering what the purpose of this was, I'm including a little shot of it. It's hopefully going to turn into something that you can "skin" your screen with. It does stay on top and follow you around now so most of it is done. As you can see, not the nicest computer to work with

screenshot of program in action

The console window will be hidden later when I add a way to exit.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
chris
  • 60,560
  • 13
  • 143
  • 205
  • Is the "How's it going" smiley part of the solution, if not then I'd post a screenshot without it. It's distracting and not necessary. – Kev Oct 02 '11 at 13:39
  • It's just that people usually wonder exactly what you're trying to accomplish by this, and a screenshot was the best way to show it once the main part was actually working. It doesn't have to be so in-your-face, a decorative border is one use. The smiley is a product of the program, which stays on top when you switch windows etc, and that was my point, as that's what I was able to achieve upon solving this problem. In the future, I'll remember to make an answer to my own question more informative, I just had it in my original post instead. – chris Oct 02 '11 at 14:41
  • 1
    Ah ok...it looked like a MS Paint free-hand after thought :) – Kev Oct 02 '11 at 14:42
  • Yes, at this stage it's all freehand, but when I get some time I plan to add a nice floating toolbar etc, as well as a window with easily layed out options. – chris Oct 02 '11 at 14:44