Sim*_*ons 2 c++ windows mfc registerclass createwindow
我正在使用以下方法注册我的班级:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
然后调用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);
}
Run Code Online (Sandbox Code Playgroud)
现在,在我的其他应用程序中,我找到了窗口,并尝试将其置于顶部:
编辑 能够使用以下代码带来新修复的Windows
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();
}
Run Code Online (Sandbox Code Playgroud)
我能够找到窗口,因为pWndPrev 它不是NULL,但它没有提出我的应用程序到前面.我是否需要注册任何其他类而不是CNDSClientDlg.我想把我的MFC应用程序放在首位.
cbr*_*nch 12
一些要看的东西......
1)尝试使用SetForegroundWindow()而不是BringWindowToTop().自从我完成Win32编程以来已经有一段时间了,但我似乎记得BringWindowToTop()有一些限制(特别是在不同进程中使用windows时).
2)微软针对从Windows 2000开始的SetForegroundWindow()实施了一些规则.简短版本是只有最前面的应用程序可以更改前台窗口.我们的想法是,不是最前面的应用程序不能"跳到"活动应用程序的前面.如果后台应用程序调用SetForegroundWindow(),Windows将闪烁应用程序的任务栏按钮,但实际上不会将应用程序带到前面.用户必须这样做.我过分简化规则,但根据您的具体情况,这可能需要考虑.
| 归档时间: |
|
| 查看次数: |
7849 次 |
| 最近记录: |