The quest for the main window...

G

Guest

I need to send Maximize/Minimize/Restore messages to applications spawned trought "CreateProcess" calls from within my program (kind of what the taskbar-buttons do) so, how do I send Maximize/Minimize/Restore messages to these "user spawned" apps

It is possible to post messages to any window using its HWND, however many apps (like MS-WORD) create several windows (most of them hidden) and all of these relate to the same ProcessID. Although the "EnumWindows" function does enumerate only top level windows, it does not guarantee that the first retrieved window handle of an application will be handle of the app's main window, so... what to do

This is as far as I have gone:

//this code seems to work only for simple apps like TextPad but not for MS Word, MSIE or winzi

HWND LookForWindowHandle(NodeInfo *node

if (!EnumWindows((WNDENUMPROC)GetWinHandle,(LPARAM)node)
return node->WindowHandle()
els
return 0


BOOL CALLBACK GetWinHandle(HWND hwnd,LPARAM lParam

NodeInfo* pInfo=(NodeInfo *)lParam
DWORD dwProcessId=0
GetWindowThreadProcessId(hwnd,&dwProcessId)
if(dwProcessId==pInfo->ProcessID()&&IsWindow(hwnd)&&IsWindowVisible(hwnd))
pInfo->WindowHandle(hwnd)

return (pInfo->WindowHandle()==NULL)


// ..

//posting messages..
if(pInfo->Active()) //if the document is already ope

if(IsIconic(pInfo->WindowHandle())) //if the document is minimize
PostMessage(pInfo->WindowHandle(), WM_SYSCOMMAND, SC_RESTORE, 0)
els
BringWindowToTop(pInfo->WindowHandle())


Thanks in advance for your time and for any help you may provide

MortZ
 
G

Guest

Once again I answered my own post..

This is not a complete solution, but it might help

http://upc.pkmn.co.uk/win32/task.shtm

"Many thanks to the author...

----- MortZ wrote: ----

I need to send Maximize/Minimize/Restore messages to applications spawned trought "CreateProcess" calls from within my program (kind of what the taskbar-buttons do) so, how do I send Maximize/Minimize/Restore messages to these "user spawned" apps

It is possible to post messages to any window using its HWND, however many apps (like MS-WORD) create several windows (most of them hidden) and all of these relate to the same ProcessID. Although the "EnumWindows" function does enumerate only top level windows, it does not guarantee that the first retrieved window handle of an application will be handle of the app's main window, so... what to do

This is as far as I have gone:

//this code seems to work only for simple apps like TextPad but not for MS Word, MSIE or winzi

HWND LookForWindowHandle(NodeInfo *node

if (!EnumWindows((WNDENUMPROC)GetWinHandle,(LPARAM)node)
return node->WindowHandle()
els
return 0


BOOL CALLBACK GetWinHandle(HWND hwnd,LPARAM lParam

NodeInfo* pInfo=(NodeInfo *)lParam
DWORD dwProcessId=0
GetWindowThreadProcessId(hwnd,&dwProcessId)
if(dwProcessId==pInfo->ProcessID()&&IsWindow(hwnd)&&IsWindowVisible(hwnd))
pInfo->WindowHandle(hwnd)

return (pInfo->WindowHandle()==NULL)


// ..

//posting messages..
if(pInfo->Active()) //if the document is already ope

if(IsIconic(pInfo->WindowHandle())) //if the document is minimize
PostMessage(pInfo->WindowHandle(), WM_SYSCOMMAND, SC_RESTORE, 0)
els
BringWindowToTop(pInfo->WindowHandle())



Thanks in advance for your time and for any help you may provide

MortZ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top