-
Notifications
You must be signed in to change notification settings - Fork 21
/
WTLBuilder.cpp
209 lines (171 loc) · 5.49 KB
/
WTLBuilder.cpp
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright (C) FlatGlobus([email protected]) All rights reserved.
//
// This file is a part of the WTLBuilder.
// The use and distribution terms for this software are covered by the
// Microsoft Public License (http://opensource.org/licenses/MS-PL)
// which can be found in the file MS-PL.txt at the root folder.
#include "stdafx.h"
#include "resource.h"
#include "WTLBuilderView.h"
#include "aboutdlg.h"
#include "MainFrm.h"
#include "ModuleLoader.h"
#include "Path.h"
#include "cgfiltyp.h"
CAppModule _Module;
BOOL isMSXMLInstalled();
void RegisterWFF();
static CModuleLoader modules;
LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
{
while (p1 != NULL && *p1 != NULL)
{
LPCTSTR p = p2;
while (p != NULL && *p != NULL)
{
if (*p1 == *p)
return CharNext(p1);
p = CharNext(p);
}
p1 = CharNext(p1);
}
return NULL;
}
int Run(LPTSTR lpstrCmdLine, int nCmdShow = SW_SHOWDEFAULT)
{
CMessageLoop theLoop;
_Module.AddMessageLoop(&theLoop);
CMainFrame wndMain;
CRect rc(0,0,GetSystemMetrics(SM_CXSCREEN),wndMain.CalcWindowSize());//127
if(wndMain.CreateEx(NULL,rc) == NULL)
{
ATLTRACE(_T("Main window creation failed!\n"));
return 0;
}
CreateBridge();
StartCommandTimer();
_Module.Lock();
wndMain.ShowWindow(nCmdShow);
modules.Load();
SendEvent(evLoadPackages);
//Package->LoadPackages();
SendEvent(evStartingUp);
SendEvent(evGetComponentInfo,TypeComponent);//get only controls
CPath initFileName(CPath::GetAppPath());
initFileName.SetTitle(_T("WTLbuilder"));
initFileName.SetExt(_T("js"));
if(lpstrCmdLine != NULL && strlen(lpstrCmdLine) != 0)
wndMain.LoadFormFromFile(lpstrCmdLine);
int nRet = theLoop.Run();
DestroyBridge();
_Module.RemoveMessageLoop();
modules.Free();
return nRet;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
//if(isMSXMLInstalled()==FALSE)
// return FALSE;
HRESULT hRes = ::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED /*COINIT_MULTITHREADED*/);
// If you are running on NT 4.0 or higher you can use the following call instead to
// make the EXE free threaded. This means that calls come in on a random RPC thread.
// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));
// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
::DefWindowProc(NULL, 0, 0, 0L);
AtlInitCommonControls(ICC_WIN95_CLASSES|ICC_COOL_CLASSES|ICC_DATE_CLASSES|
ICC_INTERNET_CLASSES|ICC_PAGESCROLLER_CLASS|ICC_NATIVEFNTCTL_CLASS|ICC_USEREX_CLASSES| ICC_TAB_CLASSES); // add flags to support other controls
hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));
ULONG uToken = 0;
Gdiplus::GdiplusStartupInput gsi;
Gdiplus::GdiplusStartupOutput gso;
Gdiplus::GdiplusStartup(&uToken, &gsi, &gso);
TCHAR szTokens[] = _T("-/");
int nRet = 0;
BOOL bRun = TRUE;
LPCTSTR lpszToken = FindOneOf(lpstrCmdLine, szTokens);
while (lpszToken != NULL)
{
if (lstrcmpi(lpszToken, _T("unreg"))==0)
{
bRun = FALSE;
break;
}
if (lstrcmpi(lpszToken, _T("reg"))==0)
{
bRun = FALSE;
RegisterWFF();
break;
}
lpszToken = FindOneOf(lpszToken, szTokens);
}
if(bRun)
nRet = Run(lpstrCmdLine, nCmdShow);
_Module.Term();
Gdiplus::GdiplusShutdown(uToken);
::CoUninitialize();
return nRet;
}
BOOL isMSXMLInstalled()
{
try
{
HKEY hKey;
DWORD retCode;
_TCHAR szTemp[MAX_PATH];
DWORD dwLen;
retCode = RegOpenKeyEx(HKEY_CLASSES_ROOT,
_T("CLSID\\{88d969c0-f192-11d4-a65f-0040963251e5}\\InProcServer32"),
0,
KEY_QUERY_VALUE,
&hKey);
if (retCode != ERROR_SUCCESS)
return FALSE;
retCode = RegQueryValueEx(hKey, _T(""), NULL, NULL,
(LPBYTE)szTemp, &(dwLen = sizeof(szTemp)));
if (retCode != ERROR_SUCCESS)
return FALSE;
RegCloseKey(hKey);
double dVer;
int i;
for (i = (int)_tcslen(szTemp); i >= 0; --i)
{
if (szTemp[i] ==_T('\\'))
break;
}
if (_stscanf_s(szTemp + i + 1, _T("msxml%lf"), &dVer) == 0 || dVer< 4.0)
{
MessageBox(NULL,_T("Error: MSXML 4.0 is not installed."),_T("WTLBuilder"),MB_OK|MB_ICONSTOP);
return FALSE;
}
else
return TRUE;
}
catch(...)
{
}
return FALSE;
}
void RegisterWFF()
{
CGCFileTypeAccess fta;
// get full file path to program executable file
TCHAR szProgPath[MAX_PATH * 2];
::GetModuleFileName(NULL, szProgPath, sizeof(szProgPath)/sizeof(TCHAR));
CString csTempText;
fta.SetExtension(_T("wff"));
// just pass file path in quotes on command line
csTempText = szProgPath;
csTempText += _T(" \"%1\"");
fta.SetShellOpenCommand(csTempText);
fta.SetDocumentShellOpenCommand(csTempText);
fta.SetDocumentClassName(_T("WTLBuilder.Document"));
fta.SetDocumentDescription(_T("WTLBuilder Form File"));
// use first icon in program
csTempText = szProgPath;
csTempText += ",0";
fta.SetDocumentDefaultIcon(csTempText);
// set the necessary registry entries
fta.RegSetAllInfo();
}