Re: Maximise from another applications



If you are trying to find a program you have control over, a standard Windows program (like Explorer), or something that will only run once you can try FindWindow(). The problem is that if there is more than one instance running with the same classname or title you may find a different one than you wanted. I've done this sort of thing successfully with Explorer using code like what I pasted below. It was from a long time ago with previous version of the compiler so you may have to adjust it (I haven't compiled this for a while, but it may give you some ideas). I don't have any idea why I did this in the document and I wouldn't advocate that as a practice and certainly would do it again. I do know this code still works as some of our customers are still using the program that uses these functions. It basically splits the screen between my program and the Windows Explorer.

BOOL CMyDoc::StartExplorer()
{
CWnd *pWndExplorer;
BOOL bExplorerStarted = FALSE;

// Find an Explorer window that is open. If none are found then open one.
if ((pWndExplorer = CWnd::FindWindow("ExploreWClass",NULL)) == NULL) {
HINSTANCE hExplorer = ::ShellExecute(NULL,"explore",NULL,NULL,NULL,SW_SHOWNORMAL);
bExplorerStarted = TRUE;
}
else {
// Make the one that is open normal size
pWndExplorer->ShowWindow(SW_SHOWNORMAL);
}

// Pop Explorer to the front
if ((pWndExplorer = CWnd::FindWindow("ExploreWClass",NULL)) != NULL)
pWndExplorer->SetForegroundWindow();

RestoreCursor();
return bExplorerStarted;
}

void CMyDoc::AdjustExplorer()
{

CWnd *pWndExplorer;
if ((pWndExplorer = CWnd::FindWindow("ExploreWClass",NULL)) != NULL) {
// Make our application's window normal size
AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL);

CRect rect;
AfxGetMainWnd()->GetWindowRect(&rect);
UINT nHeight = rect.Height();
UINT nWidth = ::GetSystemMetrics(SM_CXSCREEN);

// First lets move us
AfxGetMainWnd()->MoveWindow(0,0,nWidth/2,nHeight,TRUE);
AfxGetMainWnd()->SetForegroundWindow();

// Now Move Explorer
pWndExplorer->ShowWindow(SW_SHOWNORMAL);
pWndExplorer->MoveWindow(nWidth/2,0,nWidth/2,nHeight,TRUE);
pWndExplorer->SetForegroundWindow();
}
else
AfxMessageBox("No Window's Explorer Found");
}

HTH,

Tom

"jmarc" <jmarc@xxxxxxxxxxxxxxxxxxxxx> wrote in message news:x4g6j.41421$Zn.32932@xxxxxxxxxxx
Maybe ShellExecuteEx() might not the right
tool I need.

I would just find a process 'already' running
for a long time, then, on an appropriate cue,
just getting em not minimized. The user
will put back minimized at will.

Assume the process who will do this job,
is surely not the one who start the target
process.

jmarc...



"Tom Serface" <tom.nospam@xxxxxxxxxxxxx> wrote in message news:016DAC42-F89C-4A3D-964B-AABFCA0F9E27@xxxxxxxxxxxxxxxx
Is the program already running and perhaps doesn't allow a second instance? ShellExecuteEx() is trying to start the program.

Tom

"jmarc" <jmarc@xxxxxxxxxxxxxxxxxxxxx> wrote in message news:fie6j.20404$Ji6.7364@xxxxxxxxxxx
So, I'm unable to get the process handle..

I did this
...fMask = SEE_MASK_NOCLOSEPROCESS;
...lpFile = "FilenameToFind.exe";
...lpParameters = "";
...nothing set for lpVerb, but even set to "find"
doesn't change anyting..

I always got the same thing.
..hProcess always return NULL
..hInstApp always return SE_ERR_ACCESSDENIED

What I'm doing wrong. I'm not too familiar with ShellExecuteEx..
Thnaks..

jmarc...

"Tom Serface" <tom.nospam@xxxxxxxxxxxxx> wrote in message news:FCF77A8E-AF55-4285-A5CB-22D968623B98@xxxxxxxxxxxxxxxx
Yeah, I seldom use FindWindow any more either. You're right that is can find windows you didn't intend for it to. If you can start the process the ShellExecuteEx method is better. Thanks for listing the rest of the process. This should work for OP.

Tom

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:jhihl3duc70itm6ol5dviehlvh765l8jdk@xxxxxxxxxx
FindWindow is usually a bit dangerous to use, because it is so sensitive to things like
incidental aspects of the class name or even worse, the caption.

Typically, I would use ShellExecuteEx (which gives me a process handle), EnumWindows to
find all the top-level windows, GetWindowThreadProcessId to get the ID of each window, and
when I found one that matched the GetProcessId() of the process handle. This would not be
sensitive to either the class name of the window or the caption text.

Having found the window, ShowWindow(SW_MAXIMIZE) should do what is needed.
joe


On Thu, 6 Dec 2007 14:45:10 -0800, "Tom Serface" <tom.nospam@xxxxxxxxxxxxx> wrote:

You can use FindWindow() to get a window pointer to the application and use MoveWindow() or ShowWindow() to change it. if you use ShellExecuteEx() I think you can get instance handle returned as part of the structure.

Tom
"jmarc" <jmarc@xxxxxxxxxxxxxxxxxxxxx> wrote in message news:uz_5j.20203$Ji6.11822@xxxxxxxxxxx
I would turn back viewable a
Minimized application from
another app!

An app will have to put back
viewable, an application that
have been minimised by the
user for too long...

I used ShellExecute.., but no
options can be used to do it.

Where to look..? Any hint!
Thanks..

jmarc...
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm







.



Relevant Pages

  • Explorer weirdness
    ... I have a whole shopping list here of Windows Explorer oddities. ... Closing an open Explorer window ... - Select several files to move, drag them to another folder (window ...
    (microsoft.public.windowsxp.general)
  • Re: Annoying desktop "reset"
    ... >>>Why does XP think it is necessary to reload all the desktop icons every ... >> A window will repaint in response to something changing in it. ... If you bind File and Print Sharing to the Internet, ... describe of repaining desktop and Explorer windows. ...
    (microsoft.public.windowsxp.configuration_manage)
  • RE: Controlling when a toolbar button is enabled/visible?
    ... and being visible in any window. ... But again as I stated this fires everytime you click on anything in Outlook, ... > using Explorer object using the same concepts (if you don't want to download ... > opens – which is exactly where you want to instantiate (or create for the ...
    (microsoft.public.outlook.program_vba)
  • Re: Explorer weirdness
    ... Shift-click selection behavior is buggy. ... Dragging a file from window A to window B sometimes hangs both ... Explorer recovers from these in maybe 10-20 seconds, ...
    (microsoft.public.windowsxp.general)
  • Re: Desktop Still Crashing
    ... > To restart Explorer, Not sure why I needed to restart Explorer, not having a ... > command prompt window ... Then using Task Manager, end the Explorer ... > Rainy ps. didn't have anything to do with the registry.. ...
    (microsoft.public.windowsxp.basics)

Quantcast