Re: Problem with EnumDesktopWindows
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 03 Feb 2007 23:02:51 -0500
SendMessage, PostMessage, and other messgae-related APIs are defined NOT to work across
desktops. In fact, inter-desktop communication is, as far as I know, impossible. You
can't use shared-memory DLLs, you can't send messages, and so on. You could consider
starting up a second program in the same desktop, let IT find an manipulate the windows,
and communicate to it via a valid communication mechanism, where the typical first choice
is to use a named pipe (named pipe communication does not care about desktops). There is
a problem if two or more instances of the program are running in two or more desktops,
because the named pipe name would pose a problem unless you included the desktop name as
part of the name, e.g., if the desired pipe name was "Controller" then you might create a
pipe called Desktop1-Controller for a desktop called Desktop1. Then you could send
messages via the named pipe to Desktop1-Controller, and it in turn would do a SendMessage
or PostMessage to the app which was also running in Desktop1. This would remove the
ambiguity problem..
joe
On Sat, 3 Feb 2007 17:59:00 -0800, ThaMubber <ThaMubber@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Hi,Joseph M. Newcomer [MVP]
I have here a foreign MFC application A which I have to control with my own
program B.
The user has to start B which creates a second Desktop, because A must run
hidden.
[cpp]
...
secDesk.nLength = sizeof(secDesk);
secDesk.lpSecurityDescriptor = NULL;
secDesk.bInheritHandle = true;
...
hdesk =
CreateDesktopW(desktop,NULL,NULL,DF_ALLOWOTHERACCOUNTHOOK,GENERIC_ALL,&secDesk);
[/cpp]
After creating the Desktop, B must run the method LogonUser, because the
foreign application A needs admin privileges to run.
[cpp]
LogonUser(L"Administrator",L".",L"password",LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,&hToken)
[/cpp]
Now I have to run the foreign application (as Admin):
[cpp]
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWNORMAL;
securProc.nLength = sizeof(securProc);
securProc.lpSecurityDescriptor = NULL;
securProc.bInheritHandle = true;
if(CreateProcessAsUser(hToken,NULL,file,&securProc,NULL,TRUE,0,NULL,dir,&si,&piProc))
{
WaitForInputIdle(piProc.hProcess,INFINITE);
wi.dwProcessID = piProc.dwProcessId;
wi.hWnd = 0;
}
[/cpp]
Everything works well till here (i think).
But now the problem, my program B must control the foreign program A.
So I have to do this to get a handle of the running window
[cpp]
EnumDesktopWindows(hdesk,EnumWindowsProc,(LPARAM) &wi);
....
BOOL CALLBACK MyProg::EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
WNDINFO* pWndInfo = (WNDINFO*)(lParam);
DWORD dwProcessID;
::GetWindowThreadProcessId(hwnd, &dwProcessID);
if (dwProcessID == pWndInfo->dwProcessID)
{
pWndInfo->hWnd = hwnd;
return false;
}
return true;
}
[/cpp]
With controlling I mean that I search for some text on the foreign MFC
Dialog and do
some PostMessage for clicking on the existing Buttons on it.
Thats the whole thing. But my problem is that i don't get a handle to work
with.
Where is my mistake?
PS.: If something is unclear, please let me know.
Thanks
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Problem with EnumDesktopWindows
- From: ThaMubber
- Re: Problem with EnumDesktopWindows
- References:
- Problem with EnumDesktopWindows
- From: ThaMubber
- Problem with EnumDesktopWindows
- Prev by Date: Re: OnCommand
- Next by Date: Re: Recommend a debugger
- Previous by thread: Problem with EnumDesktopWindows
- Next by thread: Re: Problem with EnumDesktopWindows
- Index(es):
Relevant Pages
|