| View previous topic :: View next topic |
| Author |
Message |
hc6 How do I cheat?
Reputation: 0
Joined: 13 Nov 2009 Posts: 4
|
Posted: Fri Nov 13, 2009 12:53 am Post subject: [C++] Using SendMessage() to give myself notifications? |
|
|
| Is it possible to use SendMessage() in one of my threads to notify the main getmessage loop of something? For example, one of my threads changes the value of a variable, and I want to notify the main that the variable has changed, and take certain actions that can't be carried out in the thread that sent the notification.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Nov 13, 2009 6:50 am Post subject: |
|
|
| Yes you can, that is a common practice
|
|
| Back to top |
|
 |
hc6 How do I cheat?
Reputation: 0
Joined: 13 Nov 2009 Posts: 4
|
Posted: Fri Nov 13, 2009 11:35 am Post subject: |
|
|
| I tried to send a simple WM_COMMAND message to the hwnd that is the current console, and I couldn't obtain the WM_COMMAND message with the getMessage() loop. Did I send to the wrong hwnd, or did I use the wrong message?
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Fri Nov 13, 2009 11:49 am Post subject: |
|
|
When you want to send your own messages to your own program, use your own message instead of WM_COMMAND:
(It has to be above WM_USER so it doesn't interfere with other messages)
| Code: | #define WM_MYMESSAGE WM_USER + 0
#define WM_MYOTHERMESSAGE WM_USER + 1 |
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Fri Nov 13, 2009 2:39 pm Post subject: |
|
|
| No sending WM_COMMAND to the same hWnd should work. You must be doing something wrong..
|
|
| Back to top |
|
 |
hc6 How do I cheat?
Reputation: 0
Joined: 13 Nov 2009 Posts: 4
|
Posted: Fri Nov 13, 2009 6:54 pm Post subject: |
|
|
This is what I have:
| Code: | SetConsoleTitle(L"winhk");
thisWnd = FindWindow(NULL, L"winhk");// thisWnd is not NULL after this.
SendMessage(thisWnd,WM_COMMAND,0,0);
...
MSG msg = {0};
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
if(msg.message == WM_COMMAND){
cout<<"received\n";
}
}
|
received never gets printed out.
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Sat Nov 14, 2009 6:07 am Post subject: |
|
|
Try setting the hWnd parameter of GetMessage to thisWnd
| Code: | | while (GetMessage(&msg, thisWnd, 0, 0) > 0) |
(Then it will only get the messages for that specific window, and not the messages that are send to the other windows of the thread or to the thread itself)
|
|
| Back to top |
|
 |
hc6 How do I cheat?
Reputation: 0
Joined: 13 Nov 2009 Posts: 4
|
Posted: Sat Nov 14, 2009 1:57 pm Post subject: |
|
|
| Nope, the message is still not getting received by the loop. Tried using PeekMessage as well and it wouldn't receive it either.
|
|
| Back to top |
|
 |
|