disable lcd controller when booting linux, this prevents ghost-lines while
[linexec-j720] / tester1.cpp
1 // tester1.cpp : Defines the entry point for the application.
2 //
3
4 #include "stdafx.h"
5 #include "tester1.h"
6 #include <commctrl.h>
7 //#include <aygshell.h>
8 #include <sipapi.h>
9 #include "setup.h"
10
11 #define MAX_LOADSTRING 100
12
13 // Global Variables:
14 HINSTANCE                       hInst;                                  // The current instance
15 HWND                            hwndCB;                                 // The command bar handle
16
17 //static SHACTIVATEINFO s_sai;
18
19 ATOM                            MyRegisterClass (HINSTANCE, LPTSTR);
20 BOOL                            InitInstance    (HINSTANCE, int);
21 LRESULT CALLBACK        WndProc                 (HWND, UINT, WPARAM, LPARAM);
22 LRESULT CALLBACK        About                   (HWND, UINT, WPARAM, LPARAM);
23 HWND                            CreateRpCommandBar(HWND);
24
25
26 #pragma warning(disable: 4100 4710 4189; error: 4701)
27 /* who cares?! 
28         4100: whining about parameters not being used.
29         4710: whining about screwing up inlining.
30         4189: initialized but not used. make that an error: later.
31         4701: usage w/o initialization.
32         */
33
34 int WINAPI WinMain(     HINSTANCE hInstance,
35                                         HINSTANCE hPrevInstance,
36                                         LPTSTR    lpCmdLine,
37                                         int       nCmdShow)
38 {
39         MSG msg;
40         HACCEL hAccelTable;
41
42         // Perform application initialization:
43         if (!InitInstance (hInstance, nCmdShow)) 
44         {
45                 return FALSE;
46         }
47
48         hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TESTER1);
49
50         // Main message loop:
51         while (GetMessage(&msg, NULL, 0, 0)) 
52         {
53                 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
54                 {
55                         TranslateMessage(&msg);
56                         DispatchMessage(&msg);
57                 }
58         }
59
60         return msg.wParam;
61 }
62
63 //
64 //  FUNCTION: MyRegisterClass()
65 //
66 //  PURPOSE: Registers the window class.
67 //
68 //  COMMENTS:
69 //
70 //    It is important to call this function so that the application 
71 //    will get 'well formed' small icons associated with it.
72 //
73 ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
74 {
75         WNDCLASS        wc;
76
77     wc.style                    = CS_HREDRAW | CS_VREDRAW;
78     wc.lpfnWndProc              = (WNDPROC) WndProc;
79     wc.cbClsExtra               = 0;
80     wc.cbWndExtra               = 0;
81     wc.hInstance                = hInstance;
82     wc.hIcon                    = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TESTER1));
83     wc.hCursor                  = 0;
84     wc.hbrBackground    = (HBRUSH) GetStockObject(WHITE_BRUSH);
85     wc.lpszMenuName             = 0;
86     wc.lpszClassName    = szWindowClass;
87
88         return RegisterClass(&wc);
89 }
90
91 HANDLE OpenCOM1() {
92
93         static HANDLE COM1handle = INVALID_HANDLE_VALUE;
94         const char msg[] = "\r\n--------linexec--------\r\n";
95         unsigned long wrote;
96         int speed = CBR_115200;
97         HANDLE h;
98
99         if (COM1handle != INVALID_HANDLE_VALUE)
100                 return (COM1handle);
101
102         h = CreateFile(TEXT("COM1:"),
103             GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0,
104             NULL);
105         if (h == INVALID_HANDLE_VALUE)
106                 return (h);
107
108         DCB dcb;
109         if (!GetCommState(h, &dcb))
110                 goto bad;
111
112         dcb.BaudRate = speed;
113         if (!SetCommState(h, &dcb))
114                 goto bad;
115
116         // Print banner on serial console.
117         WriteFile(h, msg, sizeof msg, &wrote, 0);
118
119         COM1handle = h;
120
121         return (h);
122  bad:
123         CloseHandle(h);
124         return (INVALID_HANDLE_VALUE);
125 }
126
127 //
128 //  FUNCTION: InitInstance(HANDLE, int)
129 //
130 //  PURPOSE: Saves instance handle and creates main window
131 //
132 //  COMMENTS:
133 //
134 //    In this function, we save the instance handle in a global variable and
135 //    create and display the main program window.
136 //
137
138 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
139 {
140         HWND    hWnd = NULL;
141         TCHAR   szTitle[MAX_LOADSTRING];                        // The title bar text
142         TCHAR   szWindowClass[MAX_LOADSTRING];          // The window class name
143
144         hInst = hInstance;              // Store instance handle in our global variable
145         // Initialize global string
146         LoadString(hInstance, IDC_TESTER1, szWindowClass, MAX_LOADSTRING);
147         LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
148
149         //If it is already running, then focus on the window
150         hWnd = FindWindow(szWindowClass, szTitle);      
151         if (hWnd) 
152         {
153                 SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));    
154                 return 0;
155         } 
156
157         MyRegisterClass(hInstance, szWindowClass);
158         
159         RECT    rect;
160         GetClientRect(hWnd, &rect);
161
162         OpenCOM1();
163         load_boot("\\My Documents\\params.txt");
164         load_boot("\\Storage Card\\params.txt");
165         load_boot("\\Speicherkarte\\params.txt");
166         load_boot("\\Carte de stockage\\params.txt");
167         load_boot("\\Mes documents\\params.txt");
168         load_boot("\\My Handheld PC\\Storage Card\\params.txt");
169         load_boot("\\ÒÓØ ¶°ÄÞ\\params.txt");
170
171         hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
172                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
173         if (!hWnd)
174         {       
175                 return FALSE;
176         }
177
178         
179         
180         //When the main window is created using CW_USEDEFAULT the height of the menubar (if one
181         // is created is not taken into account). So we resize the window after creating it
182         // if a menubar is present
183         {
184                 RECT rc;
185                 GetWindowRect(hWnd, &rc);
186                 rc.bottom -= MENU_HEIGHT;
187                 if (hwndCB)
188                         MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);
189         }
190
191
192         ShowWindow(hWnd, nCmdShow);
193         UpdateWindow(hWnd);
194
195         return TRUE;
196 }
197
198 //
199 //  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
200 //
201 //  PURPOSE:  Processes messages for the main window.
202 //
203 //  WM_COMMAND  - process the application menu
204 //  WM_PAINT    - Paint the main window
205 //  WM_DESTROY  - post a quit message and return
206 //
207 //
208 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
209 {
210
211         HDC hdc;
212
213         int wmId, wmEvent;
214
215         PAINTSTRUCT ps;
216
217         TCHAR szHello[MAX_LOADSTRING];
218
219
220
221         switch (message) 
222
223         {
224
225                 case WM_COMMAND:
226
227                         wmId    = LOWORD(wParam); 
228
229                         wmEvent = HIWORD(wParam); 
230
231                         // Parse the menu selections:
232
233                         switch (wmId)
234
235                         {       
236
237                                 case IDM_HELP_ABOUT:
238
239                                         DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
240
241                                     break;
242
243                                 case IDOK:
244
245                                         SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
246
247                                         SendMessage (hWnd, WM_CLOSE, 0, 0);
248
249                                         break;
250
251                                 default:
252
253                                    return DefWindowProc(hWnd, message, wParam, lParam);
254
255                         }
256
257                         break;
258
259                 case WM_CREATE:
260
261                         hwndCB = CreateRpCommandBar(hWnd);
262
263                         break;
264
265                 case WM_PAINT:
266
267                         RECT rt;
268
269                         hdc = BeginPaint(hWnd, &ps);
270
271                         GetClientRect(hWnd, &rt);
272
273                         LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
274
275                         DrawText(hdc, szHello, _tcslen(szHello), &rt, 
276
277                                 DT_SINGLELINE | DT_VCENTER | DT_CENTER);
278
279                         EndPaint(hWnd, &ps);
280
281                         break; 
282
283                 case WM_DESTROY:
284
285                         CommandBar_Destroy(hwndCB);
286
287                         PostQuitMessage(0);
288
289                         break;
290
291                 case WM_SETTINGCHANGE:
292
293 //                      SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
294
295                 break;
296
297                 default:
298
299                         return DefWindowProc(hWnd, message, wParam, lParam);
300
301    }
302
303    return 0;
304
305 }
306
307
308
309 HWND CreateRpCommandBar(HWND hwnd)
310
311 {
312 /*
313         SHMENUBARINFO mbi;
314
315
316
317         memset(&mbi, 0, sizeof(SHMENUBARINFO));
318
319         mbi.cbSize     = sizeof(SHMENUBARINFO);
320
321         mbi.hwndParent = hwnd;
322
323         mbi.nToolBarId = IDM_MENU;
324
325         mbi.hInstRes   = hInst;
326
327         mbi.nBmpId     = 0;
328
329         mbi.cBmpImages = 0;
330
331
332
333         if (!SHCreateMenuBar(&mbi)) 
334
335                 return NULL;
336
337
338
339         return mbi.hwndMB;
340 */
341         return NULL;
342 }
343
344
345
346 // Mesage handler for the About box.
347
348 LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
349
350 {
351
352 //      SHINITDLGINFO shidi;
353
354
355
356         switch (message)
357
358         {
359
360                 case WM_INITDIALOG:
361
362                         // Create a Done button and size it.  
363
364 //                      shidi.dwMask = SHIDIM_FLAGS;
365
366 //                       shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
367
368 //                      shidi.hDlg = hDlg;
369
370 //                      SHInitDialog(&shidi);
371
372                         return TRUE; 
373
374
375
376                 case WM_COMMAND:
377
378                         if (LOWORD(wParam) == IDOK) {
379
380                                 EndDialog(hDlg, LOWORD(wParam));
381
382                                 return TRUE;
383
384                         }
385
386                         break;
387
388         }
389
390     return FALSE;
391
392 }
393