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++] PostMessage

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

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Feb 10, 2008 11:16 am    Post subject: [C++] PostMessage Reply with quote

I've been trying like crazy to get this stupid PostMessage deal to work.

Here's my code:

Code:

int _tmain(int argc, _TCHAR* argv[])
{
   HWND hHandle = FindWindow(NULL, _T("Untitled - Notepad"));
   cout << hHandle << endl;
   int x = MapVirtualKey(0x5A, 0) << 16;
   cout << x << endl;
   cout << GetLastError() << endl;
   PostMessage(hHandle, 0x100, 0x5A, x);
   cout << GetLastError() << endl;
   Sleep(1000);
   PostMessage(hHandle, 0x101, 0x5A, x);
   return 0;
}


When it runs, it gives me a valid handle, and a valid Virtual Key, and both GetLastError()s return 0. However, when I go check notepad, the text is still the same. What am I doing wrong?

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Feb 10, 2008 11:23 am    Post subject: Reply with quote

Damn.

Is there an easy way to just send something to the selected control?

I'm trying to loop through running programs and send a key-combination to it. Notepad was just an example.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sun Feb 10, 2008 11:30 am    Post subject: Reply with quote

Code:
HWND hHandle = FindWindow(L"notepad", NULL);


^ You might want to use the class instead of the window title aswell.
Back to top
View user's profile Send private message MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Feb 10, 2008 11:36 am    Post subject: Reply with quote

Ok, now I never got this.

When using classes in FindWindow, it's referring to classes as things like when you create your own class while programming, right? If so, how do you know the class--do you just kinda know?

Edit:

GetClassName! Surprised

Edit again:

I hate the fact that C++ has no default string. -__-

Ok, so I have this:

Code:

char *cname;
int wee = GetClassName(hHandle, cname, 81);


This gives me the error that it can't convert char * to LPsomething or other.

I tried the L macro that noz mentioned, and VS said that it didn't exist. -__-

Edit once again:

Damn, that's retarded. Changed it to a TCHAR *, and it built fine. -__-

Edit:

I hate this stuff.

When using this code:

Code:

   HWND hHandle = FindWindow(NULL, _T("Untitled - Notepad"));
   cout << hHandle << endl;
   TCHAR *cname = {0};
   int wee = GetClassName(hHandle, cname, 81);
   cout << GetLastError();
   cin.get();


I get the error 998, which VS tells me is

Code:

Invalid access to memory location.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Sun Feb 10, 2008 12:22 pm    Post subject: Reply with quote

I don't know if you got it already. But here is how it worked for me:
Code:
h := FindWIndow('notepad', nil);
h := FindWindowEx(h, 0, 'edit', 0);

(ye you see delphi though)

There's a great program called WinSpy with which you can easly check for classes or other things in a window. Too bad it's german...Sad
Download: http://download.lima-city.de/crackcheck/WinSpy.zip
Got from: http://www.delphipraxis.net/topic17426,0,asc,0.html
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Feb 10, 2008 12:31 pm    Post subject: Reply with quote

Well the thing is, I'm not having trouble with the API itself, I'm having trouble with the C++. x_x

Thanks though, I'm talking to Renko about it on MSN

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
XxOsirisxX
Grandmaster Cheater Supreme
Reputation: 0

Joined: 30 Oct 2006
Posts: 1597

PostPosted: Sun Feb 10, 2008 12:34 pm    Post subject: Reply with quote

rEakW0n wrote:
I don't know if you got it already. But here is how it worked for me:
Code:
h := FindWIndow('notepad', nil);
h := FindWindowEx(h, 0, 'edit', 0);

(ye you see delphi though)

There's a great program called WinSpy with which you can easly check for classes or other things in a window. Too bad it's german...Sad
Download: http://download.lima-city.de/crackcheck/WinSpy.zip
Got from: http://www.delphipraxis.net/topic17426,0,asc,0.html


I did make one that i saw long time ago at internet.

It's like that one you just posted, just that this one have less features, just the pointer move one it's avalible. Which also tells you the Class.

I will post since i feel like i will not lose nothing.



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________

Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Sun Feb 10, 2008 12:36 pm    Post subject: Reply with quote

Well I've got it, thanks everyone.
_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
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