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 


PostMessage Function

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
DarkxStorm
Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 46

PostPosted: Sat Aug 16, 2008 11:40 pm    Post subject: PostMessage Function Reply with quote

I'm currently learning C++ and would like to know how the PostMessage function works. It'll be great if someone can explain it to me, thanks.
Back to top
View user's profile Send private message
Estraik
Expert Cheater
Reputation: 0

Joined: 05 Feb 2008
Posts: 128

PostPosted: Sun Aug 17, 2008 12:35 am    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/ms644944(VS.85).aspx

Try that page, it explains postmessage() function.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Sun Aug 17, 2008 12:47 am    Post subject: Reply with quote

example by reakwon:
Code:
#include <windows.h>
#include <iostream>
using namespace std;

int main(){
   HWND notepad;
   HWND textfield;
   notepad = FindWindow(L"notepad", NULL);  // Getting notepad-handle
   if(notepad != 0){ // Checking if the handle is correct
      textfield = FindWindowEx(notepad, 0, L"Edit", NULL); // Getting notepad's memo-handle
      if(textfield != 0){ // Checking if memo-handle is correct
         char * text = "lol"; // text to send
         for(int i=0; i<strlen(text); i++) // Loop
            PostMessageA(textfield, WM_CHAR, text[i], 0); // sending every single char of text.
         cout << "Done sent :>" << endl;
      } else {
         cout << "Could not get Edit-Handle" << endl; // if incorrect memo-handle
      }
   } else {
         cout << "Could not get Notepad-Handle" << endl; // if incorrect notepad-handle
   }
}


For many programs (such as MapleStory) the FindWindowEx aint needed Smile
Back to top
View user's profile Send private message
DarkxStorm
Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 46

PostPosted: Sun Aug 17, 2008 5:23 pm    Post subject: Reply with quote

I can get the function working now, but what about creating mouseclicks?
I'm attempting to make a bot for Mabinogi.


Last edited by DarkxStorm on Sun Aug 17, 2008 8:02 pm; edited 1 time in total
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Sun Aug 17, 2008 5:47 pm    Post subject: Reply with quote

This is my best description ( of course i may be wrong on certain things ):

Code:


Function Name : PostMessage
Dll Import : User32.dll
Parameters :
1: HWND;
2: UINT;
3: WPARAM;
4: LPARAM;
Description :
PostMessage sends messages to the handle of a window and tells the window to process the WPARAM & LPARAM.

Explainations:

WPARAM is mainly 'looks'
LPARAM is the 'functioning'
For example, used on MapleStory, WPARAM would print out the text, but it wouldn't loot sucessfully, and LPARAM wouldn't print out the text, but loot.
HWND is a var type that holds the handle of a window and or component.
You can get the HWND of a window with FindWindow and the HWND of a component using FindWindowEx.
UINT is just like a Unsigned Int. It holds the Virtual Key Code to be sent,
VK_SHIFT and of 0x5A( 'Z' ).


Back to top
View user's profile Send private message AIM Address MSN Messenger
DarkxStorm
Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 46

PostPosted: Sun Aug 17, 2008 8:10 pm    Post subject: Reply with quote

slippppppppp wrote:
This is my best description ( of course i may be wrong on certain things ):

Code:


Function Name : PostMessage
Dll Import : User32.dll
Parameters :
1: HWND;
2: UINT;
3: WPARAM;
4: LPARAM;
Description :
PostMessage sends messages to the handle of a window and tells the window to process the WPARAM & LPARAM.

Explainations:

WPARAM is mainly 'looks'
LPARAM is the 'functioning'
For example, used on MapleStory, WPARAM would print out the text, but it wouldn't loot sucessfully, and LPARAM wouldn't print out the text, but loot.
HWND is a var type that holds the handle of a window and or component.
You can get the HWND of a window with FindWindow and the HWND of a component using FindWindowEx.
UINT is just like a Unsigned Int. It holds the Virtual Key Code to be sent,
VK_SHIFT and of 0x5A( 'Z' ).




That helped me understand better, thanks.
I tried to use:

PostMessage(Mabinogi, WM_KEYDOWN, 0, 0x72);

to press F3 in Mabinogi (meant to say that instead of MapleStory earlier), but that results in nothing happening.

Like you said, WPARAM prints out text , which works, changing LPARAM doesn't do anything..
What am I doing wrong here?
Back to top
View user's profile Send private message
WafflesFTW
Expert Cheater
Reputation: 0

Joined: 21 Mar 2008
Posts: 131

PostPosted: Sun Aug 17, 2008 8:12 pm    Post subject: Reply with quote

Did you define Mabinogi to be the HWND of the program? If not, you need to do FindWindow on the windowclass to attain Mabinogi's HWND to postmessages to it.
Back to top
View user's profile Send private message AIM Address
DarkxStorm
Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 46

PostPosted: Sun Aug 17, 2008 8:19 pm    Post subject: Reply with quote

This is a bit of what I have so far, I followed the example that was posted above:


HWND Mabinogi;
Mabinogi = FindWindow((LPCTSTR)"Mabinogi", NULL);
if(Mabinogi != 0)
{
PostMessageA(Mabinogi, WM_KEYDOWN, 0, 0x72);
Sleep(50);
PostMessageA(Mabinogi, WM_KEYUP, 0, 0x72);
Sleep(100);
}

The thing is I am able to print text in Mabinogi by switching the WPARAM and the LPARAM around. (0x72 , 0)
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Sun Aug 17, 2008 9:01 pm    Post subject: Reply with quote

no shit. VKs are suppose to go in WPARAM.
_________________
Back to top
View user's profile Send private message
DarkxStorm
Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 46

PostPosted: Sun Aug 17, 2008 9:17 pm    Post subject: Reply with quote

Well, WPARAM only prints text for me.
As in sending the key "i" would type "i" in the chatbox, but not open up the inventory.
What should I do instead? (Sorry, I'm not too good with C++)

Edit: Oh, and what would I put in LPARAM?
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Sun Aug 17, 2008 9:19 pm    Post subject: Reply with quote

each message has its own settings. MSDN > WM_KEYDOWN.
_________________
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Mon Aug 18, 2008 8:56 am    Post subject: Reply with quote

Fail. You need a bypass like HookHop.dll for Mabinogi because it has GameGuard.
Back to top
View user's profile Send private message
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Mon Aug 18, 2008 10:52 am    Post subject: Reply with quote

DarkxStorm wrote:
This is a bit of what I have so far, I followed the example that was posted above:


HWND Mabinogi;
Mabinogi = FindWindow((LPCTSTR)"Mabinogi", NULL);
if(Mabinogi != 0)
{
PostMessageA(Mabinogi, WM_KEYDOWN, 0, 0x72);
Sleep(50);
PostMessageA(Mabinogi, WM_KEYUP, 0, 0x72);
Sleep(100);
}

The thing is I am able to print text in Mabinogi by switching the WPARAM and the LPARAM around. (0x72 , 0)


DarkxStorm. First of all FindWindows' Parameters are
1: CLASS
2: WINDOW

So you need to put Mabinogi on the second paramter not the 1st.

And like i say, LParam holds most of the functionality.
Back to top
View user's profile Send private message AIM Address MSN Messenger
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