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++] Explaining PostMessage (need help)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Sep 07, 2008 12:46 pm    Post subject: [C++] Explaining PostMessage (need help) Reply with quote

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
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sun Sep 07, 2008 1:01 pm    Post subject: Reply with quote

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

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Sep 07, 2008 1:26 pm    Post subject: Reply with quote

FindWindowEx works just fine, FindWindowA returns error (FindWindowA does not take 4 arguments).


Care to explain?

_________________
Back to top
View user's profile Send private message
Overload
Master Cheater
Reputation: 0

Joined: 08 Feb 2008
Posts: 293

PostPosted: Sun Sep 07, 2008 1:27 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sun Sep 07, 2008 1:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hieroglyphics
I post too much
Reputation: 0

Joined: 06 Dec 2007
Posts: 2007
Location: Your bedroom

PostPosted: Sun Sep 07, 2008 2:05 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Sep 07, 2008 2:16 pm    Post subject: Reply with quote

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

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Sep 07, 2008 2:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
Hieroglyphics
I post too much
Reputation: 0

Joined: 06 Dec 2007
Posts: 2007
Location: Your bedroom

PostPosted: Sun Sep 07, 2008 3:38 pm    Post subject: Reply with quote

LOL sorry I'm so off topic, but DAMN lurc you just own everyone
_________________

Back to top
View user's profile Send private message AIM Address MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sun Sep 07, 2008 3:56 pm    Post subject: Reply with quote

Thanks once again lurc xD
And yup that is your code, it hella helped Surprised

_________________
Back to top
View user's profile Send private message
sphere90
Grandmaster Cheater
Reputation: 0

Joined: 24 Jun 2006
Posts: 912

PostPosted: Tue Sep 09, 2008 5:06 am    Post subject: Reply with quote

Hieroglyphics wrote:
LOL sorry I'm so off topic, but DAMN lurc you just own everyone


Oh really?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Sep 09, 2008 1:19 pm    Post subject: Reply with quote

We had this conversation over IRC Laughing

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

Joined: 12 Nov 2006
Posts: 531

PostPosted: Tue Sep 09, 2008 3:48 pm    Post subject: Reply with quote

lurc wrote:
We had this conversation over IRC Laughing

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. Neutral

_________________
Back to top
View user's profile Send private message AIM Address
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Tue Sep 09, 2008 4:24 pm    Post subject: Reply with quote

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

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Sep 09, 2008 4:50 pm    Post subject: Reply with quote

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
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
Goto page 1, 2  Next
Page 1 of 2

 
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