Reputation: 2842
I'm working on a little program to make my life easier when using Microsoft Remote Assistance (msra.exe). Using c++, I'm able to open msra.exe, then find the window handle. I then want to find the child windows(buttons), and interact with them. The problem seems to be though, that I cannot find the button that I want. Spy++ shows that the buttons have this text:
Window 004902F4 "Invite someone you trust to help you" Button.
My program returns that when searching for this string, the button does not exist. Anyone have any ideas? Here's the code:
#include "stdafx.h"
#include <windows.h>
#include <string>
#include <sys/types.h>
#include <stdlib.h>
#include <Windows.h>
#include <process.h>
using std::string;
void openRA(void * dummy);
int _tmain(int argc, _TCHAR* argv[])
{
_beginthread(openRA, 0, NULL);
Sleep(1000);
HWND handle = NULL;
handle = FindWindow(NULL, TEXT("Windows Remote Assistance"));
if(handle == NULL){
printf("handle was null\n");
}
else{
printf("handle was not null\n");
}
HWND button1 = NULL;
Sleep(1000);
button1 = FindWindowEx(handle, 0, 0, TEXT("Invite someone you trust to help you"));
if(button1 == NULL){
printf("Button1 was null");
}
else{
printf("I found he button!");
}
fflush(stdout);
return 0;
}
void openRA( void * dummy){
printf("I'm inside this function\n");
system("msra.exe &");
}
Edit:
Here's an image of what spy++ shows.
Upvotes: 2
Views: 7425
Reputation: 652
I made this code here, so didn't tryied it(I'm running my linux right now)
EnumChildWindows(FindWindow(NULL, TEXT("Windows Remote Assistance), (WNDENUMPROC)&EnumProc, 0);
//------------------------------------------------------------------------
BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam);
{
LPTSTR szBuff;
if (GetWindowText(hwnd, szBuff, sizeof(szBuff)
{
if (!strcmp("Invite someone you trust to help you", szBuff)
{
//We found the button!
}
}
//No button was found
}
Upvotes: -1
Reputation: 16896
The top-level window has the caption "Windows Remote Assistance". This is the window returned by FindWindow
.
This contains an embedded dialog, which also has the caption "Windows Remote Assistance" and contains the button you are interested in.
The button is not a direct child of the top-level window, so FindWindowEx
doesn't find it.
Use EnumChildWindows
to recursively enumerate all the children of the top-level window and check the captions yourself.
Upvotes: 5