How to bring an App to front, from another App
-
Hello , I'm programing in VC++ 6, and the entire project runs in a computer without keyboard but with touch screen. The thing is that a have two app runnig at the same time, and I want the user to be able to switch between these apps by touching in a third app (called "Switcher",wich is always on top), this third app is a dialog based app, dialog's size is small and it has only two buttons, one for bring the first app to front and the other button to bring to the second app. The project has to run over win 98 an over win XP. How can i do to get wich app is The "Switcher" and bring the other to front but under the "switcher"?
-
Hello , I'm programing in VC++ 6, and the entire project runs in a computer without keyboard but with touch screen. The thing is that a have two app runnig at the same time, and I want the user to be able to switch between these apps by touching in a third app (called "Switcher",wich is always on top), this third app is a dialog based app, dialog's size is small and it has only two buttons, one for bring the first app to front and the other button to bring to the second app. The project has to run over win 98 an over win XP. How can i do to get wich app is The "Switcher" and bring the other to front but under the "switcher"?
Have you considered
SetWindowPos()
?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Hello , I'm programing in VC++ 6, and the entire project runs in a computer without keyboard but with touch screen. The thing is that a have two app runnig at the same time, and I want the user to be able to switch between these apps by touching in a third app (called "Switcher",wich is always on top), this third app is a dialog based app, dialog's size is small and it has only two buttons, one for bring the first app to front and the other button to bring to the second app. The project has to run over win 98 an over win XP. How can i do to get wich app is The "Switcher" and bring the other to front but under the "switcher"?
You can use SetWindowPos to move, resize and change the z-index of a window, SetWindowPos[^] So you could use this:
SetWindowPos(targetWindow, switcherHandle, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
To bring the window to the front, by passing the handle to your switcher window as the second parameter the target application should appear just behind it. Rather than at the front of all windows.My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
-
You can use SetWindowPos to move, resize and change the z-index of a window, SetWindowPos[^] So you could use this:
SetWindowPos(targetWindow, switcherHandle, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
To bring the window to the front, by passing the handle to your switcher window as the second parameter the target application should appear just behind it. Rather than at the front of all windows.My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
-
Thanks, So I have to use this instruccion SetWindowPos(targetWindow, switcherHandle, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); on my "Switcher" dialog, ok, my last doubt is how can I get the handler to the target window from the "Switcher" dialog?
If you know the title of the window, or its class name then you can use FindWindow[^]. If you don't have the name of the window, but do have a HINSTANCE then you can search through all of the windows until you find the one you need:
HWND tmpWnd;
bool foundWindow = false;
//Get topmost window (which would probably be switcher in this case but it doesn't really matter)
tepWnd = FindWindow(NULL, NULL)while(tmpWnd != NULL)
{
HINSTANCE hInstance = ProcIDFromWnd(tmpWnd);
if(hInstance == windowInst)
{
foundWindow = true;
break;
}
else
{
tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT);
}
}Without either a HINSTANCE the class name, or the window name then I don't think there's much you could do.
My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
-
If you know the title of the window, or its class name then you can use FindWindow[^]. If you don't have the name of the window, but do have a HINSTANCE then you can search through all of the windows until you find the one you need:
HWND tmpWnd;
bool foundWindow = false;
//Get topmost window (which would probably be switcher in this case but it doesn't really matter)
tepWnd = FindWindow(NULL, NULL)while(tmpWnd != NULL)
{
HINSTANCE hInstance = ProcIDFromWnd(tmpWnd);
if(hInstance == windowInst)
{
foundWindow = true;
break;
}
else
{
tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT);
}
}Without either a HINSTANCE the class name, or the window name then I don't think there's much you could do.
My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
Ok, it's working for the app1 that I know his title, let say from the "Switcher" app it's possible bring the other app1(the one i know his title) behind the Switcher, but with the other app2 , (wich is no-modal dialog) it doesn't work , i do not know the name of his class and the dialog it has not title, so i went whith the code that you wrote, but compiler complains with ProcIDFromWnd, it says that is undeclared identifier, it seems that is not a valid intruction for VC++ 6 , ?? Anyway , since in the final projet will be runnig only these three apps, i thoth that the Switcher can bring the app 1(the one working) behind it and send it to bottom when the user wants to see the app2, mfc library says that it's possible to use the parameter HWND_BOTTOM instead hWndSwitcher in
SetWindowPos(hWndTarget, hWndSwitcher, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
to do that, but it's doesn't work neither. What do you think? -
Ok, it's working for the app1 that I know his title, let say from the "Switcher" app it's possible bring the other app1(the one i know his title) behind the Switcher, but with the other app2 , (wich is no-modal dialog) it doesn't work , i do not know the name of his class and the dialog it has not title, so i went whith the code that you wrote, but compiler complains with ProcIDFromWnd, it says that is undeclared identifier, it seems that is not a valid intruction for VC++ 6 , ?? Anyway , since in the final projet will be runnig only these three apps, i thoth that the Switcher can bring the app 1(the one working) behind it and send it to bottom when the user wants to see the app2, mfc library says that it's possible to use the parameter HWND_BOTTOM instead hWndSwitcher in
SetWindowPos(hWndTarget, hWndSwitcher, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
to do that, but it's doesn't work neither. What do you think?I'm not sure why SetWindowPos wouldn't work, unless you have the wrong hWnd, but as for finding a window by its HINSTANCE this code should actually work. The sample I originally found was in VB so I guess that ProcIDFromWnd is specific to that, GetWindowThreadProcessId seems to be what we really need.
HWND tmpWnd;
bool foundWindow = false;
//Get topmost window (which would probably be switcher in this case but it doesn't really matter)
tepWnd = FindWindow(NULL, NULL)
DWORD procID = GetProcessId(hInstace);while(tmpWnd != NULL)
{
DWORD id = 0;
GetWindowThreadProcessId(tmpWnd, &id);
if(id == procID)
{
foundWindow = true;
break;
}
else
{
tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT);
}
}Bear in mind that this code would find all windows that a process owns, so if it has more than one then you'll have to try and figure out which one you really need.
My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
-
I'm not sure why SetWindowPos wouldn't work, unless you have the wrong hWnd, but as for finding a window by its HINSTANCE this code should actually work. The sample I originally found was in VB so I guess that ProcIDFromWnd is specific to that, GetWindowThreadProcessId seems to be what we really need.
HWND tmpWnd;
bool foundWindow = false;
//Get topmost window (which would probably be switcher in this case but it doesn't really matter)
tepWnd = FindWindow(NULL, NULL)
DWORD procID = GetProcessId(hInstace);while(tmpWnd != NULL)
{
DWORD id = 0;
GetWindowThreadProcessId(tmpWnd, &id);
if(id == procID)
{
foundWindow = true;
break;
}
else
{
tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT);
}
}Bear in mind that this code would find all windows that a process owns, so if it has more than one then you'll have to try and figure out which one you really need.
My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works
-
Now i get these error messages from compiler:
error C2065: 'GetProcessID' : undeclared identifier
error C2065: 'hInstace' : undeclared identifierI can't find a the equivalent instruction in VC++6 for
GetProcessID
Well, the function does exist MSDN[^] hInstace is just the handle for the process that started the window that you want to move, if you don't have that and want to find and move a window that has no title that you don't have a class name for, then your last option would be to look through all of the running processes and find the one you need, only then would you be able to look through all of the windows in search of the one the process opened.
My current favourite phrase: I've seen better!
-SK Genius
Source Indexing and Symbol Servers Vehicle Simulation Demo - Mostly Works