| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Sep 07, 2008 12:46 pm Post subject: [C++] Explaining PostMessage (need help) |
|
|
| Code: | #include <windows.h>
#include <tchar.h>
#include <commctrl.h>
BOOL APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd )
{
UNREFERENCED_PARAMETER( hInstance );
UNREFERENCED_PARAMETER( hPrevInstance );
UNREFERENCED_PARAMETER( lpCmdLine );
UNREFERENCED_PARAMETER( nShowCmd );
if ( hWnd != NULL )
{
HWND hChild = FindWindowEx( hWnd, NULL, WC_EDIT, NULL );
if ( hChild != NULL )
PostMessage( hChild, WM_CHAR, (WPARAM)'Z', 0 );
}
return 0;
} |
My question is what does this section do:
| Code: | HWND hChild = FindWindowEx( hWnd, NULL, WC_EDIT, NULL );
if ( hChild != NULL )
PostMessage( hChild, WM_CHAR, (WPARAM)'Z', 0 ); |
I know what the PostMessage line does obviously, but what is the condition in which PostMessage is executed?
Lastly, are the UNREFERENCED_PARAMETER's needed?
_________________
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Sep 07, 2008 1:01 pm Post subject: |
|
|
LOL........................
That line is to see if the handle returned by FindWindowA is null or not. If it is null then pma does't work.
Use FindWIndowA not FindWindowEx.
And you dont need those unref things.
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Sep 07, 2008 1:26 pm Post subject: |
|
|
FindWindowEx works just fine, FindWindowA returns error (FindWindowA does not take 4 arguments).
Care to explain?
_________________
|
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Sun Sep 07, 2008 1:27 pm Post subject: |
|
|
uh, i am pretty sure you're wrong dnis0. FindWindowEx allows you to find a control within a window. In this case, it looks like he is trying to find an edit box (text box) then sending the WM_CHAR message with the letter Z.
So, overall:
First line: Gets a handle on the edit box itself.
Second line: Checks to make sure you have the handle.
Third line: Sending the "Z" character to the box. (Just like typing the letter "Z")
But, I may be wrong, its just my guess.
_________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
dnsi0 I post too much
Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Sun Sep 07, 2008 1:27 pm Post subject: |
|
|
FindWindowA only needs 2 parameters
WindowClass and WindowName
Leave one null if u only want 1.
Oh... Sorry didn't see that u were trying to find a control >.>
|
|
| Back to top |
|
 |
Hieroglyphics I post too much
Reputation: 0
Joined: 06 Dec 2007 Posts: 2007 Location: Your bedroom
|
Posted: Sun Sep 07, 2008 2:05 pm Post subject: |
|
|
I love how everybody is learning to use PostMessage ever since that one guy posted like a half done code for an MS Bot lmfao and they all doin [c++] with lowercaps but this guy did uppercase O.O
_________________
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Sep 07, 2008 2:16 pm Post subject: |
|
|
| Hieroglyphics wrote: | | I love how everybody is learning to use PostMessage ever since that one guy posted like a half done code for an MS Bot lmfao and they all doin [c++] with lowercaps but this guy did uppercase O.O |
It may seem so, but i wouldn't be so quick to generalize. I had another post pertaining to the PostMessage function before the post was even made.
_________________
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Sep 07, 2008 2:58 pm Post subject: |
|
|
LOL Thats my code snippet too!!! ahaha
dnsi0, just stop posting, you're an idiot.
Anyways, back to your questions.
UNREFERENCED_PARAMETER is used to just label a parameter that is unused. The reason you use it is because while compiling on Visual Studio 2008 C++ Win32 Project with Level 4 warnings, parameters that aren't used give warnings. It is good coding practice to compile at level 4 warnings and get rid of as many warnings as you can.
There should be a
| Code: | | HWND hWnd = FindWindow(_T("Notepad"), NULL); |
Above the first check.
After this line is executed, the program makes a call to FindWindow, looking for the window with the class "Notepad". Once you have the handle to that window, its stored in hWnd.
Next, if the handle to the window is not invalid, then it executes the next line, which gets the handle to the child control in the window Notepad. The FindWindowEx there specifies, it wants to find a Edit control. Once it gets the edit control, it stores it in hChild.
Finally if hChild isn't invalid either, it makes its final call to PostMessage, where your sending a character, specified as 'Z'.
_________________
|
|
| Back to top |
|
 |
Hieroglyphics I post too much
Reputation: 0
Joined: 06 Dec 2007 Posts: 2007 Location: Your bedroom
|
Posted: Sun Sep 07, 2008 3:38 pm Post subject: |
|
|
LOL sorry I'm so off topic, but DAMN lurc you just own everyone
_________________
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sun Sep 07, 2008 3:56 pm Post subject: |
|
|
Thanks once again lurc xD
And yup that is your code, it hella helped
_________________
|
|
| Back to top |
|
 |
sphere90 Grandmaster Cheater
Reputation: 0
Joined: 24 Jun 2006 Posts: 912
|
Posted: Tue Sep 09, 2008 5:06 am Post subject: |
|
|
| Hieroglyphics wrote: | | LOL sorry I'm so off topic, but DAMN lurc you just own everyone |
Oh really?
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Sep 09, 2008 1:19 pm Post subject: |
|
|
We had this conversation over IRC
I don't own everyone.
Hieroglyphics just has lower expectations.. thinks Dark_Walk is a pro hax0r and I'm a godly programmer..
_________________
|
|
| Back to top |
|
 |
Fuzz Grandmaster Cheater
Reputation: 0
Joined: 12 Nov 2006 Posts: 531
|
Posted: Tue Sep 09, 2008 3:48 pm Post subject: |
|
|
| lurc wrote: | We had this conversation over IRC
I don't own everyone.
Hieroglyphics just has lower expectations.. thinks Dark_Walk is a pro hax0r and I'm a godly programmer.. |
Yeah, i saw that.
_________________
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Tue Sep 09, 2008 4:24 pm Post subject: |
|
|
| Code: | | HWND hChild = FindWindowEx( hWnd, NULL, WC_EDIT, NULL ); |
There is probably another piece of code before this, like...
| Code: | | HWND hWnd = FindWindow("NotePad", NULL); |
All that does is find the text box part of the notepad, the part you write with.
| Code: | if ( hChild != NULL ) //Not really important
PostMessage( hChild, WM_CHAR, (WPARAM)'Z', 0 ); |
This looks like like you pare going to type the 'z' character into that child window.
| Code: | PostMessage(
hChild, //Handle to window you want to postmessage to
WM_CHAR, //...let lurc answer this one, don't feel like looknig it up
(WPARAM)'Z',//The Z character
0//Nothing
) |
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue Sep 09, 2008 4:50 pm Post subject: |
|
|
Lol... I answered all the questions already but:
WM_CHAR is a message obviously to send a single character (WPARAM) along with its scan code/repeat count/etc. (LPARAM)
_________________
|
|
| Back to top |
|
 |
|