-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUIDemo.cpp
More file actions
131 lines (104 loc) · 4.69 KB
/
UIDemo.cpp
File metadata and controls
131 lines (104 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Test.cpp : 定义应用程序的类行为。
//
#include "stdafx.h"
#include "UIDemo.h"
#include "UIDemoDlg.h"
#include "CommonStruct.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTestApp
BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// CTestApp 构造
CTestApp::CTestApp()
{
// 支持重新启动管理器
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的一个 CTestApp 对象
CTestApp theApp;
// CTestApp 初始化
BOOL CTestApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
if (!RunOnlyOneApp())
{
return FALSE;
}
AfxEnableControlContainer();
// 创建 shell 管理器,以防对话框包含
// 任何 shell 树视图控件或 shell 列表视图控件。
CShellManager *pShellManager = new CShellManager;
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
CTestDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置处理何时用
// “确定”来关闭对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用
// “取消”来关闭对话框的代码
}
// 删除上面创建的 shell 管理器。
if (pShellManager != NULL)
{
delete pShellManager;
}
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
// 而不是启动应用程序的消息泵。
return FALSE;
}
BOOL CTestApp::RunOnlyOneApp()
{
HANDLE hMutex = CreateMutex(NULL, FALSE, _T("UIDemo"));
// 检查错误代码
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(hMutex);
HWND hWndPrevious = ::GetWindow( ::GetDesktopWindow(), GW_CHILD );
while(::IsWindow(hWndPrevious))
{
if (::GetProp(hWndPrevious, WINDOW_TAG))
{
if (::IsIconic(hWndPrevious))
{
::ShowWindow(hWndPrevious, SW_RESTORE);
::SetForegroundWindow(hWndPrevious);
}
else
{
::SetForegroundWindow(::GetLastActivePopup(hWndPrevious));
}
return FALSE;
}
hWndPrevious = ::GetWindow( hWndPrevious, GW_HWNDNEXT );
}
return FALSE;
}
return TRUE;
}