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 


[Question][C++] SendMessage/PostMessage

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

Joined: 16 Apr 2007
Posts: 160

PostPosted: Fri Dec 28, 2007 7:37 pm    Post subject: [Question][C++] SendMessage/PostMessage Reply with quote

Lets say I would want to make a program which types "abc" into a notepad.

hwnd is the handle.

How would I go about using SendMessage or PostMessage to input abc into notepad?


Thanks,
intheomg

_________________
To get a miss in Power Guard hack, just update the damn addresses from a Damage Control which modifies the damage taken after Power Guard has calculated the damage its supposed to deal to the monster. No clues on which Damage Control! Rolling Eyes

人生的价值是多少?
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Dec 28, 2007 7:40 pm    Post subject: Reply with quote

you don't send the message to the main notepad window, you send it to the edit child control of the window (using FindWindowEx)

also WM_CHAR

not going to write code because this has been answered many times before and you should be able to find it in a search (if search actually worked)

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

Joined: 16 Apr 2007
Posts: 160

PostPosted: Fri Dec 28, 2007 7:45 pm    Post subject: Reply with quote

Well, I still don't really understand SendMessage/PostMessage. Is there any other way to send keys to a MINIMIZED window? Confused

P.S. Google sucks Sad

Thanks,
intheomg


EDIT: Ok, ok, can someone just give me the full code to send keys to a minimized application? I will analyse it thoroughly.

*Hope for someone to pass it to me Sad

_________________
To get a miss in Power Guard hack, just update the damn addresses from a Damage Control which modifies the damage taken after Power Guard has calculated the damage its supposed to deal to the monster. No clues on which Damage Control! Rolling Eyes

人生的价值是多少?


Last edited by intheomg on Fri Dec 28, 2007 8:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Fri Dec 28, 2007 8:08 pm    Post subject: Reply with quote

FindWindowA
FindWindowExA
PostMessage Loop ('A',+1,+2)

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

Joined: 16 Apr 2007
Posts: 160

PostPosted: Fri Dec 28, 2007 8:56 pm    Post subject: Reply with quote

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

int main(){
    int locatewindow,exit;
    HWND hwnd;
    DWORD pid;
    HANDLE phandle;
   
    locatewindow:
    hwnd = FindWindow(NULL,"Untitled - Notepad");
    if(hwnd==0){
                cout << "Failed to locate notepad's window, please open window and press enter to continue." << endl << endl;
                cin.get();
                goto locatewindow;
                }else{
    GetWindowThreadProcessId(hwnd, &pid); // get the pid
    phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid); // we need a handle

    system("Title = Notepad");
    cout << "What would you like to do?" << endl;
    cout << "1. Chat." << endl;
    cout << "2. Exit notepad trainer." << endl << endl;
   
   
                                      }
                                     

    cout << "Press F2 to type." << endl;
    cout << "Press F5 to exit the trainer." << endl << endl;
    while(1==1){
    if(GetAsyncKeyState(VK_F2)){
    cout << "F2 Pressed!" << endl;
    PostMessage(hwnd,WM_KEYDOWN,97,0);
    Sleep(10);
    PostMessage(hwnd,WM_CHAR,97,0);
    Sleep(10);
    PostMessage(hwnd,WM_KEYUP,97,0);
    }
    if(GetAsyncKeyState(VK_F5)){
    goto exit;
    }
}
exit:
    return 0;
}


Can someone see what's wrong with this? =\

Help me please...

EDIT: Oops, spotted three useless declaration.

Thanks,
intheomg Sad

_________________
To get a miss in Power Guard hack, just update the damn addresses from a Damage Control which modifies the damage taken after Power Guard has calculated the damage its supposed to deal to the monster. No clues on which Damage Control! Rolling Eyes

人生的价值是多少?
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Fri Dec 28, 2007 9:16 pm    Post subject: Reply with quote

Code:

typedef void CONTEXT;
typedef void* PCONTEXT;
#include <stdlib.h>
#include <tchar.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>

int _tmain(_TINT argc, _TCHAR* argv[])
{
   HWND hwnd, hwndchild; int i;
   LPCTSTR msg = _T("penispenispenis");
   
   hwnd = FindWindow(_T("Notepad"), NULL); //Take notes, this works with any document open
   if (hwnd != NULL) {
      hwndchild = FindWindowEx(hwnd, NULL, TEXT("EDIT"), NULL);
      if (hwndchild != NULL) {
         for(i = 0; i < _tcslen(msg); i++) {
            SendMessage(hwndchild, WM_CHAR, msg[i], 0);
         }
         
         _tprintf(TEXT("success."));
         return EXIT_SUCCESS;
      }
   }   
   
   _tprintf(TEXT("fail."));   
   return EXIT_FAILURE;
}

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

Joined: 16 Apr 2007
Posts: 160

PostPosted: Fri Dec 28, 2007 9:22 pm    Post subject: Reply with quote

appalsap wrote:
Code:

typedef void CONTEXT;
typedef void* PCONTEXT;
#include <stdlib.h>
#include <tchar.h>
#include <windef.h>
#include <winbase.h>
#include <winuser.h>

int _tmain(_TINT argc, _TCHAR* argv[])
{
   HWND hwnd, hwndchild; int i;
   LPCTSTR msg = _T("penispenispenis");
   
   hwnd = FindWindow(_T("Notepad"), NULL); //Take notes, this works with any document open
   if (hwnd != NULL) {
      hwndchild = FindWindowEx(hwnd, NULL, TEXT("EDIT"), NULL);
      if (hwndchild != NULL) {
         for(i = 0; i < _tcslen(msg); i++) {
            SendMessage(hwndchild, WM_CHAR, msg[i], 0);
         }
         
         _tprintf(TEXT("success."));
         return EXIT_SUCCESS;
      }
   }   
   
   _tprintf(TEXT("fail."));   
   return EXIT_FAILURE;
}



Err? 44 Errors Confused

BTW, I'm using Dev C++ compiler...


Regards,
intheomg Sad


EDIT!!!!:

Wooo, I got it, after modifying alot from your code.

Code:

#include <stdlib.h>
#include <tchar.h>
#include <windef.h>
#include <windows.h>
using namespace std;

int main()
{
   HWND hwnd, hwndchild; int i;
   LPCTSTR msg = _T("penispenispenis");
   
   hwnd = FindWindow(_T("Notepad"), NULL); //Take notes, this works with any document open
   if (hwnd != NULL) {
      hwndchild = FindWindowEx(hwnd, NULL, TEXT("EDIT"), NULL);
      if (hwndchild != NULL) {
         for(i = 0; i < _tcslen(msg); i++) {
            SendMessage(hwndchild, WM_CHAR, msg[i], 0);
         }
         
         return 0;
      }
   }   
     
   return EXIT_FAILURE;
}


Time to analyse! Thanks alot appal ^^ Very Happy



EDITTTTTTTT!!!! ATTENTION!!!

How do I stimulate clicks at a certain co-ordinates with PostMessage/SendMessage, while the targeted window is minimized? Crying or Very sad

_________________
To get a miss in Power Guard hack, just update the damn addresses from a Damage Control which modifies the damage taken after Power Guard has calculated the damage its supposed to deal to the monster. No clues on which Damage Control! Rolling Eyes

人生的价值是多少?
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Sat Dec 29, 2007 12:53 am    Post subject: Reply with quote

Quote:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK

Quote:
WM_RBUTTONDOWN
WM_RBUTTONUP
WM_RBUTTONDBLCLK

Quote:
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MBUTTONDBLCLK

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

Joined: 16 Apr 2007
Posts: 160

PostPosted: Sat Dec 29, 2007 8:48 am    Post subject: Reply with quote

sponge wrote:
Quote:
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK

Quote:
WM_RBUTTONDOWN
WM_RBUTTONUP
WM_RBUTTONDBLCLK

Quote:
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MBUTTONDBLCLK



Thanks, but, how do you go about setting the co-ords for it? It is possible?

_________________
To get a miss in Power Guard hack, just update the damn addresses from a Damage Control which modifies the damage taken after Power Guard has calculated the damage its supposed to deal to the monster. No clues on which Damage Control! Rolling Eyes

人生的价值是多少?
Back to top
View user's profile Send private message
the_undead
Expert Cheater
Reputation: 1

Joined: 12 Nov 2006
Posts: 235
Location: Johannesburg, South Africa

PostPosted: Sat Dec 29, 2007 8:51 am    Post subject: Reply with quote

lParam.

How about you just use msdn?

_________________
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
intheomg
Expert Cheater
Reputation: 0

Joined: 16 Apr 2007
Posts: 160

PostPosted: Sat Dec 29, 2007 8:54 am    Post subject: Reply with quote

the_undead wrote:
lParam.

How about you just use msdn?


I know it is supposed to be filled in lParam, but, lets say I would like the mouse co-ords - x = 40, y = 50,

how do I go about filling it in? What value do I fill in?


And I have no idea what is MSDN.


Thanks!
intheomg

_________________
To get a miss in Power Guard hack, just update the damn addresses from a Damage Control which modifies the damage taken after Power Guard has calculated the damage its supposed to deal to the monster. No clues on which Damage Control! Rolling Eyes

人生的价值是多少?
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sat Dec 29, 2007 1:33 pm    Post subject: Reply with quote

http://msdn2.microsoft.com/
_________________
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