| View previous topic :: View next topic |
| Author |
Message |
DarkxStorm Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 46
|
Posted: Sat Aug 16, 2008 11:40 pm Post subject: PostMessage Function |
|
|
| 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 |
|
 |
Estraik Expert Cheater
Reputation: 0
Joined: 05 Feb 2008 Posts: 128
|
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Sun Aug 17, 2008 12:47 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
DarkxStorm Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 46
|
Posted: Sun Aug 17, 2008 5:23 pm Post subject: |
|
|
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 |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Sun Aug 17, 2008 5:47 pm Post subject: |
|
|
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 |
|
 |
DarkxStorm Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 46
|
Posted: Sun Aug 17, 2008 8:10 pm Post subject: |
|
|
| 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 |
|
 |
WafflesFTW Expert Cheater
Reputation: 0
Joined: 21 Mar 2008 Posts: 131
|
Posted: Sun Aug 17, 2008 8:12 pm Post subject: |
|
|
| 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 |
|
 |
DarkxStorm Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 46
|
Posted: Sun Aug 17, 2008 8:19 pm Post subject: |
|
|
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 |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Sun Aug 17, 2008 9:01 pm Post subject: |
|
|
no shit. VKs are suppose to go in WPARAM. _________________
|
|
| Back to top |
|
 |
DarkxStorm Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 46
|
Posted: Sun Aug 17, 2008 9:17 pm Post subject: |
|
|
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 |
|
 |
sponge I'm a spammer
Reputation: 1
Joined: 07 Nov 2006 Posts: 6009
|
Posted: Sun Aug 17, 2008 9:19 pm Post subject: |
|
|
each message has its own settings. MSDN > WM_KEYDOWN. _________________
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Mon Aug 18, 2008 8:56 am Post subject: |
|
|
| Fail. You need a bypass like HookHop.dll for Mabinogi because it has GameGuard. |
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Mon Aug 18, 2008 10:52 am Post subject: |
|
|
| 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 |
|
 |
|