Develop and Download Open Source Software

Browse CVS Repository

Contents of /tombo/Tombo/Src/main.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.17 - (show annotations) (download) (as text)
Sun Aug 27 11:11:36 2006 UTC (17 years, 7 months ago) by hirami
Branch: MAIN
CVS Tags: Tombo_2_0b2, Tombo_2_0b3, Tombo_2_0b1, Tombo_2_0b4, B228, B229, B226, B227, B224, B225, B231, B230, HEAD
Changes since 1.16: +3 -3 lines
File MIME type: text/x-c++src
- Create new project for WM5 platform.
	In current version, feature is same as PocketPC.

1 #include <windows.h>
2 #include <commctrl.h>
3 #include <tchar.h>
4 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
5 #include <aygshell.h>
6 #endif
7
8 #include "Tombo.h"
9 #include "Message.h"
10 #include "UniConv.h"
11 #include "VarBuffer.h"
12 #include "MainFrame.h"
13 #include "Property.h"
14 #include "Logger.h"
15 #include "PasswordManager.h"
16 #include "Message.h"
17
18 //////////////////////////////////////
19 // Global variables
20 //////////////////////////////////////
21
22 Property g_Property;
23 HINSTANCE g_hInstance;
24 Logger *g_pLogger;
25
26 BOOL bDisableHotKey;
27
28 PasswordManager *g_pPasswordManager = NULL;
29
30 TomboMessage g_mMsgRes;
31
32 //////////////////////////////////////
33 // Declarations
34 //////////////////////////////////////
35
36 BOOL CheckAndRaiseAnotherTombo();
37 BOOL ParseCmdLine(LPTSTR pCmdLine);
38
39 extern "C" {
40 const char *CheckBlowFish();
41 };
42
43 //////////////////////////////////////
44 // WinMain
45 //////////////////////////////////////
46 #ifndef UNIT_TEST
47 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR pCmdLine, int nCmdShow)
48 {
49 // initialize random seed
50 srand(GetTickCount());
51
52 // load message resources.
53 g_mMsgRes.Init();
54
55 // Check other Tombo.exe is executed
56 if (CheckAndRaiseAnotherTombo()) {
57 return 0;
58 }
59
60 // Check BLOWFISH library
61 const char *p = CheckBlowFish();
62 if (p != NULL) {
63 TCHAR buf[1024];
64 LPTSTR pMsg = ConvSJIS2Unicode(p);
65 if (pMsg) {
66 wsprintf(buf, MSG_CHECKBF_FAILED, pMsg);
67 } else {
68 wsprintf(buf, MSG_CHECKBF_FAILED, TEXT("unknown"));
69 }
70 MessageBox(NULL, buf, MSG_CHECKBF_TTL, MB_ICONWARNING | MB_OK);
71 delete [] pMsg;
72 }
73
74 // Check command line strings
75 ParseCmdLine(pCmdLine);
76
77 // initialize logger
78 g_pLogger = &g_Logger;
79 // if write debug log, comment out two lines:
80 // g_Logger.Init(TEXT("C:\\temp\\TomboLog.txt"));
81 // TomboMessageBox(NULL, TEXT("Log mode is ON"), TEXT("DEBUG"), MB_OK);
82
83 bDisableHotKey = FALSE;
84
85 #if defined(PLATFORM_PSPC) || defined(PLATFORM_PKTPC) || defined(PLATFORM_BE500) || defined(PLATFORM_WM5)
86 InitCommonControls();
87 #endif
88 #if defined(PLATFORM_WIN32) || defined(PLATFORM_HPC)
89 // initialize rebar control
90 INITCOMMONCONTROLSEX icex;
91 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
92 icex.dwICC = ICC_COOL_CLASSES|ICC_BAR_CLASSES;
93 InitCommonControlsEx(&icex);
94 #endif
95
96 #if defined(PLATFORM_PKTPC) || defined(PLATFORM_WM5)
97 SHInitExtraControls();
98 #endif
99
100 // create MainFrame instance
101 MainFrame frmMain;
102 MainFrame::RegisterClass(hInst);
103
104 g_hInstance = hInst;
105
106 // load properties
107 BOOL bResult;
108 bResult = g_Property.Load();
109 if (!bResult || g_Property.IsNeedAskUser()) {
110 BOOL bPrev = bDisableHotKey;
111 bDisableHotKey = TRUE;
112 DWORD nResult = g_Property.Popup(hInst, NULL, NULL);
113 bDisableHotKey = bPrev;
114 if (nResult == IDCANCEL) {
115 return 1;
116 }
117 }
118 frmMain.Create(TOMBO_APP_NAME, hInst, nCmdShow);
119
120 // go message loop
121 int res = frmMain.MainLoop();
122
123 g_Logger.Close();
124 return res;
125 }
126 #endif
127
128 //////////////////////////////////////
129 // Mutial execute check function
130 //////////////////////////////////////
131
132 static BOOL CALLBACK EnumProc(HWND hWnd, LPARAM lParam)
133 {
134 TCHAR buf[1024];
135 GetClassName(hWnd, buf, 1024);
136 if (_tcscmp(buf, TOMBO_MAIN_FRAME_WINDOW_CLSS) == 0) {
137
138 // send message to elder instanse
139 SendMessage(hWnd, MWM_RAISE_MAINFRAME, 0, 0);
140 *(BOOL*)lParam = TRUE;
141 }
142 return TRUE;
143 }
144
145 //////////////////////////////////////
146 // Check mutual execution
147 //////////////////////////////////////
148 //
149 // Enum window and check Tombo's window.
150 // Raise window and exit if exists.
151 //
152 // statically say, we should use Mutex but...
153
154 static BOOL CheckAndRaiseAnotherTombo()
155 {
156 BOOL bExist = FALSE;
157 EnumWindows((WNDENUMPROC)EnumProc, (WPARAM)&bExist);
158 return bExist;
159 }
160
161 //////////////////////////////////////
162 // Message box
163 //////////////////////////////////////
164 //
165 // Disable hotkey version
166
167 int TomboMessageBox(HWND hWnd, LPCTSTR pText, LPCTSTR pCaption, UINT uType)
168 {
169 BOOL bPrev = bDisableHotKey;
170 bDisableHotKey = TRUE;
171 int nResult = MessageBox(hWnd, pText, pCaption, uType);
172 bDisableHotKey = bPrev;
173 return nResult;
174 }
175
176 //////////////////////////////////////
177 // Parse command line string
178 //////////////////////////////////////
179 BOOL GetDefaultFolder(LPTSTR pCmdLine, LPDWORD pStart, LPDWORD pEnd, LPTSTR *ppNext);
180
181 BOOL ParseCmdLine(LPTSTR pCmdLine)
182 {
183 LPTSTR p = pCmdLine;
184 while (*p) {
185 if (*p == TEXT('-')) {
186 if (_tcsnicmp(p+1, TEXT("root="), 5) == 0) {
187 DWORD nStart, nEnd;
188 LPTSTR pNext;
189 if (GetDefaultFolder(p + 6, &nStart, &nEnd, &pNext)) {
190 g_Property.SetCmdLineAssignedTomboRoot(p + 6 + nStart, nEnd - nStart);
191 }
192 p = pNext;
193 // } else if (_tcsnicmp(p+1, TEXT("ro"), 2) == 0) {
194 // g_Property.SetDefaultROMode(TRUE);
195 }
196 }
197 p = CharNext(p);
198 }
199 return TRUE;
200 }
201
202 BOOL GetDefaultFolder(LPTSTR pCmdLine, LPDWORD pStart, LPDWORD pEnd, LPTSTR *ppNext)
203 {
204 LPTSTR p = pCmdLine;
205 BOOL bQuoted = FALSE;
206
207 // Is quoted?
208 if (*p == TEXT('"')) {
209 bQuoted = TRUE;
210 p++;
211 }
212 *pStart = p - pCmdLine;
213
214 BOOL bBreak = FALSE;
215 while(*p) {
216 if (!bQuoted && *p == TEXT(' ')) {
217 bBreak = TRUE;
218 break;
219 }
220 if (bQuoted && *p == TEXT('"')) {
221 bBreak = TRUE;
222 break;
223 }
224 p = CharNext(p);
225 }
226 if (bQuoted) {
227 if (*p != TEXT('"')) {
228 *ppNext = p; // may be EOL
229 return FALSE;
230 }
231 *ppNext = p + 1;
232 *pEnd = p - pCmdLine;
233 return TRUE;
234 } else {
235 *ppNext = p;
236 *pEnd = p - pCmdLine;
237 return TRUE;
238 }
239
240
241 return TRUE;
242 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26