Repository navigation
Expand file tree
/
Copy pathCWndApp_Ext.cpp
More file actions
194 lines (182 loc) · 6.1 KB
/
Copy pathCWndApp_Ext.cpp
File metadata and controls
194 lines (182 loc) · 6.1 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// Copyright © 2013, 2018, 2026 Ivyware Pty Ltd, Khrustal & Mann
// MELBOURNE, VICTORIA, AUSTRALIA, 3000
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.
//
//
// Implementation for CWnd extensions
//
#include "StdAfx.h"
#include "CWndApp_Ext.h"
#include "CString_Ext.h"
#define SECURITY_WIN32
#include "security.h"
#include "Msgexception.h"
//
// Run message pump to completion
// NOTES: Periodically we need to run the message pump to completion to
// implement transitory actions locked in the windows message queue.
//
DWORD_PTR
g_dwRunMsgPump2Completion = 1;
MsgcoreMFC_EXT void
RunMsgPump2Completion ( ) noexcept
{
// Run the message loop. It will run until GetMessage() returns 0
MSG messages;
while ( g_dwRunMsgPump2Completion &&
PeekMessage(&messages,NULL,0,0,PM_REMOVE) > 0 )
{
// Translate virtual-key messages into character messages
TranslateMessage ( &messages );
// Send message to WindowProcedure
DispatchMessage ( &messages );
}
}
//
// CWndApp application file helpers
// NOTES: Static functions are just simpler
//
// Parameters: LPCTSTR lpszDataFileName
// Folder/file path to be appended to FOLDERID_LocalAppData
//
// Returns: CString
// Constructed FOLDERID_LocalAppData file path
MsgcoreMFC_EXT CString
CWinApp_LocalAppDataFilePath( LPCTSTR lpszDataFileName )
{
USES_CONVERSION;
WCHAR *pwszPathname;
SHGetKnownFolderPath ( FOLDERID_LocalAppData, 0, NULL, &pwszPathname);
CString strLocalAppDataFile((W2A(pwszPathname)));
CoTaskMemFree(pwszPathname);
strLocalAppDataFile += _T("\\");
strLocalAppDataFile += lpszDataFileName;
return strLocalAppDataFile;
}
//
// CWndApp application file helpers
// NOTES: Static functions are just simpler
//
// Parameters: LPCTSTR lpszDataFileName
// Folder/file path to be appended to FOLDERID_ProgramData
//
// Returns: CString
// Constructed FOLDERID_ProgramData file path
MsgcoreMFC_EXT CString
CWinApp_ProgramDataFilePath( LPCTSTR lpszDataFileName )
{
USES_CONVERSION;
WCHAR *pwszPathname;
SHGetKnownFolderPath ( FOLDERID_ProgramData, 0, NULL, &pwszPathname);
CString strProgramDataFile((W2A(pwszPathname)));
CoTaskMemFree(pwszPathname);
strProgramDataFile += _T("\\");
strProgramDataFile += lpszDataFileName;
return strProgramDataFile;
}
//
// CWndApp application file helpers
// NOTES: Static functions are just simpler
//
// Returns: CString
// Path to folder from which module is executing
CString
CWinApp_ModuleFolderPath ( )
{
USES_CONVERSION;
// Build name of sample workspace
// NOTES: Relative to installation directory
TCHAR tcsModulePathname[_MAX_PATH+1];
DWORD dwSize = GetModuleFileName ( NULL, tcsModulePathname, ARRAYSIZE(tcsModulePathname) );
if ( dwSize < 0 )
EVERR->MODULE
->Message ( L"GetModuleFileName() failed" )
->HResult(0)
->Throw ( );
#ifdef _DEBUG // Because in debug we don't run from install directory
#ifdef _WIN64
dwSize = swprintf_s ( &tcsModulePathname[0], ARRAYSIZE(tcsModulePathname)
, L"C:\\Program Files\\Chartboard\\bin\\Chartboard.exe" );
#else
dwSize = swprintf_s ( &tcsModulePathname[0], ARRAYSIZE(tcsModulePathname)
, L"C:\\Program Files (x86)\\Chartboard\\bin\\Chartboard.exe");
#endif
#endif
TCHAR tcsDrive [_MAX_DRIVE];
TCHAR tcsDirectory[_MAX_DIR];
TCHAR tcsFilename [_MAX_FNAME];
TCHAR tcsExtension[_MAX_EXT];
_tsplitpath_s( tcsModulePathname
, tcsDrive, tcsDirectory, tcsFilename, tcsExtension );
CString strModuleFolderPath;
strModuleFolderPath = tcsDrive;
strModuleFolderPath += tcsDirectory;
// Tidy up, and
return strModuleFolderPath;
}
//
// Fetches active CView for CWndApp application
// NOTES: Static functions are just simpler
//
MsgcoreMFC_EXT CView*
CWndApp_GetActiveView ( )
{
CMDIFrameWnd *pFrame = (CMDIFrameWnd *)AfxGetApp()->GetMainWnd();
// Get the active MDI child window.
CMDIChildWnd *pChild = (CMDIChildWnd *)pFrame->GetActiveFrame();
// or CMDIChildWnd *pChild = pFrame->MDIGetActive();
// Get the active view attached to the active MDI child window.
return pChild->GetActiveView();
}
//
// Post URL message to CWinApp
// NOTES: WM_PostHtmlURL setting requirement
//
// Parameters: LPCTSTR lpszURL
// URL to be activated
//
// BOOL bExternalOverride
// External override flag.
MsgcoreMFC_EXT
UINT g_uiWM_PostHtmlURL = 0; // PostHtmlURL notification message
MsgcoreMFC_EXT BOOL
CWndApp_PostHtmlURL ( LPCTSTR lpszURL, BOOL bExternalOverride )
{
ASSERT(g_uiWM_PostHtmlURL);
if ( g_uiWM_PostHtmlURL )
{
CString *pstrURL = new CString ( lpszURL );
return AfxGetApp()->PostThreadMessage ( g_uiWM_PostHtmlURL, (WPARAM)pstrURL, (LPARAM)bExternalOverride );
}
return FALSE;
}
//
// Retreives username under which application is running.
// NOTES: Not suitable for use from a Windows Service
//
// Returns: CString
// Username under which application is running
//
CString
CWndApp_GetUsername ( )
{
TCHAR szUsername[UNLEN+1];
DWORD szUsernameSize = ARRAYSIZE(szUsername);
GetUserNameEx ( NameSamCompatible, &szUsername[0], &szUsernameSize );
CString strUsername = &szUsername[0];
int nIdx = strUsername.ReverseFind ( L'\\' );
if ( nIdx >= 0 )
strUsername = strUsername.Right ( strUsername.GetLength() - nIdx - 1 );
return strUsername;
}