我登记我的类在下面的方法:BringWindowToTop甚至没有工作
BOOL CNDSClientDlg::InitInstance()
{
//Register Window Updated on 16th Nov 2010, @Subhen
// Register our unique class name that we wish to use
WNDCLASS wndcls;
memset(&wndcls, 0, sizeof(WNDCLASS));
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.hInstance = AfxGetInstanceHandle();
wndcls.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndcls.lpszMenuName = NULL;
//Class name for using FindWindow later
wndcls.lpszClassName = _T("CNDSClientDlg");
// Register new class and exit if it fails
if(!AfxRegisterClass(&wndcls)) // [C]
{
return FALSE;
}
}
,然后调用的InitInstance方法和类的构造函数创建窗口:
CNDSClientDlg::CNDSClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNDSClientDlg::IDD, pParent)
{
InitInstance();
HWND hWnd;
hInst = AfxGetInstanceHandle(); // Store instance handle in our global variable
hWnd = CreateWindow(_T("CNDSClientDlg"), "NDS", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
}
现在在我的其他应用程序我发现窗口,并试图把顶部:
编辑 能带来newlyCreated窗户用下面的代码
CWnd *pWndPrev = NULL;
CWnd *FirstChildhWnd = NULL;
pWndPrev = CWnd::FindWindow(_T("CNDSClientDlg"),NULL);
if(pWndPrev != NULL)
{
//pWndPrev->BringWindowToTop();
WINDOWPLACEMENT wndplacement;
pWndPrev->GetWindowPlacement(&wndplacement);
wndplacement.showCmd = SW_RESTORE;
pWndPrev->SetWindowPlacement(&wndplacement);
pWndPrev->SetForegroundWindow();
FirstChildhWnd = pWndPrev->GetLastActivePopup();
if (pWndPrev != FirstChildhWnd)
{
// a pop-up window is active, bring it to the top too
FirstChildhWnd->GetWindowPlacement(&wndplacement);
wndplacement.showCmd = SW_RESTORE;
FirstChildhWnd->SetWindowPlacement(&wndplacement);
FirstChildhWnd->SetForegroundWindow();
}
我能找到窗口pWndPrev
不为空,但它不是把我的应用程序前。我需要注册任何其他类而不是CNDSClientDlg。我想把我的MFC应用程序置顶。
@cbranch,@FrédéricHamidi,感谢这是Workinng。但是这会产生一个新的空白窗口,而不是我的跑窗。我认为这是因为创建窗口。我需要显示我的应用程序不是新窗口 – Simsons 2010-11-17 07:25:54
@Subhen,你的意思是你在其他应用程序中创建了一个具有相同类名的窗口? – 2010-11-17 07:28:48
我不太确定什么是相同的类名。但是,我的MFC应用程序中有多个类(对话框),我正在使用其中的一个,CNDSClientDlg – Simsons 2010-11-17 07:32:05