Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Using SendMessage() to give myself notifications?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
hc6
How do I cheat?
Reputation: 0

Joined: 13 Nov 2009
Posts: 4

PostPosted: Fri Nov 13, 2009 12:53 am    Post subject: [C++] Using SendMessage() to give myself notifications? Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Nov 13, 2009 6:50 am    Post subject: Reply with quote

Yes you can, that is a common practice
Back to top
View user's profile Send private message
hc6
How do I cheat?
Reputation: 0

Joined: 13 Nov 2009
Posts: 4

PostPosted: Fri Nov 13, 2009 11:35 am    Post subject: Reply with quote

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
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Fri Nov 13, 2009 11:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Nov 13, 2009 2:39 pm    Post subject: Reply with quote

No sending WM_COMMAND to the same hWnd should work. You must be doing something wrong..
Back to top
View user's profile Send private message
hc6
How do I cheat?
Reputation: 0

Joined: 13 Nov 2009
Posts: 4

PostPosted: Fri Nov 13, 2009 6:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Nov 14, 2009 6:07 am    Post subject: Reply with quote

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
View user's profile Send private message
hc6
How do I cheat?
Reputation: 0

Joined: 13 Nov 2009
Posts: 4

PostPosted: Sat Nov 14, 2009 1:57 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites