[RESOLVED] SendMessage for a game - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: [RESOLVED] SendMessage for a game

  1. #16
    Join Date
    Feb 2011
    Posts
    11

    Re: SendMessage for a game

    Quote Originally Posted by Austin.Soucy View Post
    Try passing your child windows to this before the click.

    Code:
    ScreenToClient(handles[i], &pt);
    You can also use ShowWindow() to maximize your window and then work with screen coords(probably not the best way, but it works).


    EDIT: How do you find hMU?

    if you are using this like in your previous post it might be a source for error.
    Code:
    HWND hMU = FindWindow(NULL, "Untitled - Notepad");
    hMU = FindWindowEx(hMU, NULL, "EDIT", NULL);
    you should only need
    Code:
    HWND hMU = FindWindow(NULL, "APP TITLE");
    and then find the child windows normally with EnumChildWindow
    I'm sorry, I forgot to change the first parameter of ScreenToClient, as you mentioned. Now the same popup menu appears at 100:100 of Desktop window.

    This is how I find hMU:

    Code:
    HWND hMU = FindWindow("MU", "Mu Online");
    I used Spy++ and my code on the game window, and they both detected same handle value for the game. When I change class name to NULL, it works too. Could the anticheat prevent my attempts to click, probably with a global mouse hook?

  2. #17
    Join Date
    Oct 2010
    Posts
    68

    Re: SendMessage for a game

    Unfortunately I am stumped at this point...I tried

    If you are using the correct HWND and passing correct client coords I see no reason that it should not work. Maybe if you post your full code we can defer to someone that has more knowledge than I do. Also, perhaps a screenshot of the game? Is this a full-screen game or windowed?

  3. #18
    Join Date
    Feb 2011
    Posts
    11

    Re: SendMessage for a game

    Quote Originally Posted by Austin.Soucy View Post
    Unfortunately I am stumped at this point...I tried

    If you are using the correct HWND and passing correct client coords I see no reason that it should not work. Maybe if you post your full code we can defer to someone that has more knowledge than I do. Also, perhaps a screenshot of the game? Is this a full-screen game or windowed?
    Thank you for efforts! This is the full code of how I test Send/PostMessage. If you want to take a look at the whole project (I mean, everything except this PostMessage), I can post it too, because the code is compact.

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (Msg)
    	{
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    			
    		case WM_KEYDOWN:
    		{
    			HWND hMU = FindWindow("MU", "InsaniaMU");
    			
    			if (wParam == VK_F11)
    			{
    				PostMessage(hMU, WM_RBUTTONDOWN, 0, MAKELPARAM(200, 200));
    			}
    			else if (wParam == VK_F12)
    			{
    				
    				PostMessage(hMU, WM_RBUTTONUP, 0, MAKELPARAM(200, 200));
    			}
    			break;
    		}
    		
    		default:
    			return DefWindowProc(hWnd, Msg, wParam, lParam);
    	}
    	
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
    {
    	WNDCLASSEX wndclass;
    	wndclass.cbSize        = sizeof(WNDCLASSEX);
            wndclass.style         = 0;
            wndclass.lpfnWndProc   = WndProc;
            wndclass.cbClsExtra    = 0;
            wndclass.cbWndExtra    = 0;
            wndclass.hInstance     = hInstance;
            wndclass.hIcon         = NULL;
            wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
            wndclass.hbrBackground = (HBRUSH)COLOR_3DSHADOW;
            wndclass.lpszMenuName  = NULL;
            wndclass.lpszClassName = "WINDOWCLASS";
            wndclass.hIconSm       = NULL;
    	RegisterClassEx(&wndclass);
    	
    	CreateWindow("WINDOWCLASS", "123", WS_CAPTION | WS_SYSMENU | WS_VISIBLE, 10, 10, 100, 100, NULL, NULL, hInstance, NULL);
    	
    	MSG Msg;
            while(GetMessage(&Msg, NULL, 0, 0) > 0)
            {
                    TranslateMessage(&Msg);
                    DispatchMessage(&Msg);
            }
    
    	return 0;
    }
    The game can be full-screen or windowed, it depends on the setting. I was testing the code above with a windowed game. It said the game screenshot is too large, so there's the link to photobucket, hopefully it won't be treated as an advertisement: http://i1135.photobucket.com/albums/...ttozero/mu.jpg

    Thanks!

  4. #19
    Join Date
    Feb 2011
    Posts
    11

    Re: SendMessage for a game

    So, yesterday I found the solution. Maybe it's ugly now, but that's only because I don't know yet what exactly each of my SendMessages do. I just used Spy++ on the game window and caught all the messages it received when I hovered the mouse over it and pressed and released the right mouse button. I tried to send the caught messages into the game window from my program, and finally got my program working.

    Code:
    void OnRMouseButtonDown(void)
    {
    	WINDOWPOS wp = {hMU, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE};
    
    	SendMessage(hMU, WM_SETCURSOR, (WPARAM)hMU, MAKELPARAM(HTCLIENT, WM_MOUSEMOVE));
    	SendMessage(hMU, WM_MOUSEACTIVATE, (WPARAM)hMU, MAKELPARAM(HTCLIENT, WM_RBUTTONDOWN));
    	SendMessage(hMU, WM_WINDOWPOSCHANGING, 0, (LPARAM)&wp);
    	SendMessage(hMU, WM_NCPAINT, 1, 0);
    	SendMessage(hMU, WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
    	SendMessage(hMU, WM_ACTIVATEAPP, 1, 0);
    	SendMessage(hMU, WM_NCACTIVATE, 1, 0);
    	SendMessage(hMU, WM_ACTIVATE, WA_CLICKACTIVE, 0);
    	SendMessage(hMU, WM_SETFOCUS, 0, 0);
    	SendMessage(hMU, WM_SETCURSOR, (WPARAM)hMU, MAKELPARAM(1, WM_RBUTTONDOWN));
    
    	PostMessage(hMU, WM_RBUTTONDOWN, 2, 0x1530279);
    }
    
    void OnRMouseButtonUp(void)
    {
    	PostMessage(hMU, WM_RBUTTONUP, 0, 0x1530279);
    
    	SendMessage(hMU, WM_CAPTURECHANGED, 0, 0);
    }
    Therefore, if you have a task similar to what I had, use Spy++ and repeat all the messages you caught with it.

    Thank you all!
    Last edited by PointToZero; April 20th, 2011 at 08:58 AM.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center