]> git.saurik.com Git - wxWidgets.git/blame - src/msw/wince/hello.cpp
Added wxFrameBase::OnMenuOpen, and wxUSE_IDLEMENUUPDATES in platform.h
[wxWidgets.git] / src / msw / wince / hello.cpp
CommitLineData
2e8e834c
RR
1// -----------------------------------------------------------
2// This hello program will test wxBase for WinCE
3// -----------------------------------------------------------
4
5// Include WinCE headers
6#include <windows.h>
7#include <windowsx.h>
8#include "resource.h"
9
10// Include wxWindows headers
11#include "wx/app.h"
12#include "wx/string.h"
13
14// Do not undef DrawText, since we need it here
15#include "wx/msw/private.h"
16
17// -----------------------------------------------------------
18// Hello world code
19// -----------------------------------------------------------
20
21HINSTANCE hInst = NULL; // Local copy of hInstance
22HWND hwndMain = NULL; // Handle to Main window returned from CreateWindow
23
24TCHAR szAppName[] = TEXT("Hello Pocket PC Application");
25TCHAR szTitle[] = TEXT("Hello Pocket PC");
26
27LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
28{
29 LRESULT lResult = TRUE;
30 HDC hdc;
31 PAINTSTRUCT ps;
32 RECT rect;
33
34 switch(msg)
35 {
36 case WM_COMMAND:
37 switch (GET_WM_COMMAND_ID(wp,lp))
38 {
39 case IDOK:
40 SendMessage(hwnd,WM_CLOSE,0,0);
41 break;
42 default:
43 return DefWindowProc(hwnd, msg, wp, lp);
44 }
45 break;
46 case WM_PAINT:
47 {
48 hdc = BeginPaint (hwnd, &ps);
49 GetClientRect (hwnd, &rect);
50
51 // Test wxString
52 wxString test( wxT("Hello wxWindows!") );
53 DrawText (hdc, test.c_str(), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
54
55 EndPaint (hwnd, &ps);
56 }
57 break;
58
59 case WM_CLOSE:
60 DestroyWindow(hwnd);
61 break;
62
63 case WM_DESTROY:
64 PostQuitMessage(0);
65 break;
66
67 default:
68 lResult = DefWindowProc(hwnd, msg, wp, lp);
69 break;
70 }
71 return (lResult);
72}
73
74
75BOOL InitInstance (HINSTANCE hInstance, int CmdShow )
76{
77
78 hInst = hInstance;
79 hwndMain = CreateWindow(szAppName,
80 szTitle,
81 WS_VISIBLE,
82 CW_USEDEFAULT,
83 CW_USEDEFAULT,
84 CW_USEDEFAULT,
85 CW_USEDEFAULT,
86 NULL, NULL, hInstance, NULL );
87
88 if ( !hwndMain )
89 {
90 return FALSE;
91 }
92 ShowWindow(hwndMain, CmdShow );
93 UpdateWindow(hwndMain);
94 return TRUE;
95}
96
97BOOL InitApplication ( HINSTANCE hInstance )
98{
99 WNDCLASS wc;
100 BOOL f;
101
102 wc.style = CS_HREDRAW | CS_VREDRAW ;
103 wc.lpfnWndProc = (WNDPROC)WndProc;
104 wc.cbClsExtra = 0;
105 wc.cbWndExtra = 0;
106 wc.hIcon = NULL;
107 wc.hInstance = hInstance;
108 wc.hCursor = NULL;
109 wc.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
110 wc.lpszMenuName = NULL;
111 wc.lpszClassName = szAppName;
112
113 f = (RegisterClass(&wc));
114
115 return f;
116}
117
118
119int WINAPI WinMain(HINSTANCE hInstance,
120 HINSTANCE hPrevInstance,
121 LPWSTR lpCmdLine,
122 int CmdShow)
123
124{
125 // We use wxBase as a first test
126 wxInitialize();
127
128 MSG msg;
129 HWND hHelloWnd = NULL;
130 HACCEL hAccel = NULL;
131
132 //Check if Hello.exe is running. If it's running then focus on the window
133 hHelloWnd = FindWindow(szAppName, szTitle);
134 if (hHelloWnd)
135 {
136 SetForegroundWindow (hHelloWnd);
137 return 0;
138 }
139
140 if ( !hPrevInstance )
141 {
142 if ( !InitApplication ( hInstance ) )
143 {
144 return (FALSE);
145 }
146
147 }
148 if ( !InitInstance( hInstance, CmdShow ) )
149 {
150 return (FALSE);
151 }
152 hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));
153
154 while ( GetMessage( &msg, NULL, 0,0 ) == TRUE )
155 {
156 if (!TranslateAccelerator(hwndMain,hAccel, &msg))
157 {
158 TranslateMessage (&msg);
159 DispatchMessage(&msg);
160 }
161 }
162
163 // Quit wxBase
164 wxUninitialize();
165
166 return (msg.wParam);
167}
168
169