请教一个窗口置顶的问题?
我的程序是别人程序调用的。假设别人的程序为A,我的程序为B。
A在运行时是全屏的,点击A上的一个按钮会运行我的程序。这时我的程序会覆盖在他的上面,当不用时客户只需要点击A的任意地方(即此时没有点击我的程序B,窗体转移了焦点),这时A又将全屏,而我的程序B被A遮挡住,放在A的后面。
当客户想要再次调用我的程序时,还是点击那个按钮(此时我的程序已经运行,并且没有关闭),这时我的程序将显示到前面。
BOOL CSyxPosApp::InitInstance(){ CreateMutex(NULL, TRUE, "SyxPosApp"); if(GetLastError()==ERROR_ALREADY_EXISTS) { if( AfxGetMainWnd() != NULL ) SetWindowPos( AfxGetMainWnd()->m_hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE ); return false; } ...}BOOL CALLBACK EnumWindowsProc( HWND hwnd, // handle to parent window LPARAM lParam // application-defined value ){ char chTitle[256]; GetWindowText(hwnd,chTitle,256); CString strTtile=chTitle; if(strTtile.Find("我的软件")!=-1) { HWND* pWnd=(HWND*)lParam; *pWnd=hwnd; return FALSE; } return TRUE;}/////////////////////////////////////////////////////////////////////////////// CMagStudio initializationBOOL CMagStudio::InitInstance(){ CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); //////////////////////////////////////////////////////////////////////// // 确保程序只运行一个实例,可以增加环境参数决定是否采取这种方式 char* chMutexName="我的软件"; HANDLE hMutex= OpenMutex(MUTEX_ALL_ACCESS,true,chMutexName); if(hMutex){ //Have other instance HWND FirstWnd=NULL,FirstChildWnd=NULL; EnumWindows(EnumWindowsProc,(LPARAM)(&FirstWnd)); if(FirstWnd){ ShowWindow(FirstWnd,SW_SHOW); ShowWindow(FirstWnd, SW_RESTORE ); BringWindowToTop( FirstWnd ); SetForegroundWindow( FirstWnd ); FirstChildWnd=GetLastActivePopup(FirstWnd); if(FirstChildWnd!=FirstWnd){ ShowWindow(FirstChildWnd,SW_SHOW); BringWindowToTop( FirstChildWnd ); SetForegroundWindow( FirstChildWnd ); }// else if( ! cmdInfo.m_strFileName.IsEmpty() ){ //PostMessage(FirstWnd,)// } return FALSE; } return FALSE; } else //The first instance CreateMutex(NULL,true,chMutexName);