Opening a running process programmatically
-
I am a beginner who wants to restore the main window of a clock program that resides in the System Tray when running. What I want to do programatically is done normally by right clicking on the clock program's icon in the System Tray, then selecting "Restore Main Window" from the context menu. I have tried many things, and the closest I can get is using SetForegroundWindow, which will only work when I have already selected "Restore Main Window" from the context menu and then minimized the restored main window. I think I must be missing some fundamental concept about what I am trying to do. Consider the pseudocode below...
void MyApp::OnLaunchSysTrayApp { CWnd*m_hWnd = FindWindow(NULL, "System Tray Application Name") if (m_hWnd) { m_hWnd->SetForegroundWindow(); //Displays restored main window if not on top //m_hWnd->GetWindow(NULL); //Fails //m_hWnd->ShowWindow(SW_RESTORE); //Fails //m_hWnd->SetActiveWindow(); //Fails BOOL m_bIconic; m_bIconic=m_hWnd->IsIconic() if (m_bIconic) { //m_hWnd->GetWindow(NULL); //Fails //m_hWnd->ShowWindow(SW_RESTORE); //Fails //m_hWnd->SetActiveWindow(); //Fails } etc. } }
I would appreciate any suggestions about how I might achieve my goal, or information about whatever basic concept I (probably) currently fail to understand. Thank you."For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
I am a beginner who wants to restore the main window of a clock program that resides in the System Tray when running. What I want to do programatically is done normally by right clicking on the clock program's icon in the System Tray, then selecting "Restore Main Window" from the context menu. I have tried many things, and the closest I can get is using SetForegroundWindow, which will only work when I have already selected "Restore Main Window" from the context menu and then minimized the restored main window. I think I must be missing some fundamental concept about what I am trying to do. Consider the pseudocode below...
void MyApp::OnLaunchSysTrayApp { CWnd*m_hWnd = FindWindow(NULL, "System Tray Application Name") if (m_hWnd) { m_hWnd->SetForegroundWindow(); //Displays restored main window if not on top //m_hWnd->GetWindow(NULL); //Fails //m_hWnd->ShowWindow(SW_RESTORE); //Fails //m_hWnd->SetActiveWindow(); //Fails BOOL m_bIconic; m_bIconic=m_hWnd->IsIconic() if (m_bIconic) { //m_hWnd->GetWindow(NULL); //Fails //m_hWnd->ShowWindow(SW_RESTORE); //Fails //m_hWnd->SetActiveWindow(); //Fails } etc. } }
I would appreciate any suggestions about how I might achieve my goal, or information about whatever basic concept I (probably) currently fail to understand. Thank you."For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
Too much of this depends on the particular application to usefully answer. Maybe the clock window is destroyed, or maybe it is the main window for the application but is hidden. Maybe, maybe... In short, I don;t think there is a generic way of doing this. Iain.
-
I am a beginner who wants to restore the main window of a clock program that resides in the System Tray when running. What I want to do programatically is done normally by right clicking on the clock program's icon in the System Tray, then selecting "Restore Main Window" from the context menu. I have tried many things, and the closest I can get is using SetForegroundWindow, which will only work when I have already selected "Restore Main Window" from the context menu and then minimized the restored main window. I think I must be missing some fundamental concept about what I am trying to do. Consider the pseudocode below...
void MyApp::OnLaunchSysTrayApp { CWnd*m_hWnd = FindWindow(NULL, "System Tray Application Name") if (m_hWnd) { m_hWnd->SetForegroundWindow(); //Displays restored main window if not on top //m_hWnd->GetWindow(NULL); //Fails //m_hWnd->ShowWindow(SW_RESTORE); //Fails //m_hWnd->SetActiveWindow(); //Fails BOOL m_bIconic; m_bIconic=m_hWnd->IsIconic() if (m_bIconic) { //m_hWnd->GetWindow(NULL); //Fails //m_hWnd->ShowWindow(SW_RESTORE); //Fails //m_hWnd->SetActiveWindow(); //Fails } etc. } }
I would appreciate any suggestions about how I might achieve my goal, or information about whatever basic concept I (probably) currently fail to understand. Thank you."For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
Try posting the SW_RESTORE command to the application.