3b60edb167115393798327b1655b6ffb11a5f1d8
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
42 //#include <winspool.h>
46 HINSTANCE hInst
; // current instance
48 HWND hMainWnd
; // Main Window
49 HWND hStatusWnd
; // Status Bar Window
51 HWND hTreeWnd
; // Tree Control Window
52 HWND hListWnd
; // List Control Window
53 HWND hSplitWnd
; // Splitter Bar Control Window
55 int nMinimumWidth
; // Minimum width of the dialog (OnSize()'s cx)
56 int nMinimumHeight
; // Minimum height of the dialog (OnSize()'s cy)
58 int nOldWidth
; // Holds the previous client area width
59 int nOldHeight
; // Holds the previous client area height
61 BOOL bInMenuLoop
= FALSE
; // Tells us if we are in the menu loop
63 TCHAR szTitle
[MAX_LOADSTRING
]; // The title bar text
64 TCHAR szWindowClass
[MAX_LOADSTRING
]; // The title bar text
65 TCHAR szFrameClass
[MAX_LOADSTRING
]; // The title bar text
67 // Foward declarations of functions included in this code module:
68 ATOM
MyRegisterClass(HINSTANCE hInstance
);
69 ATOM
MyRegisterClass2(HINSTANCE hInstance
);
70 BOOL
InitInstance(HINSTANCE
, int);
71 LRESULT CALLBACK
WndProc(HWND
, UINT
, WPARAM
, LPARAM
);
72 LRESULT CALLBACK
FrameWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
74 int APIENTRY
WinMain(HINSTANCE hInstance
,
75 HINSTANCE hPrevInstance
,
82 // Initialize global strings
83 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
84 LoadString(hInstance
, IDC_REGEDIT
, szWindowClass
, MAX_LOADSTRING
);
85 LoadString(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
87 MyRegisterClass(hInstance
);
88 MyRegisterClass2(hInstance
);
90 // Perform application initialization:
91 if (!InitInstance(hInstance
, nCmdShow
)) {
94 hAccelTable
= LoadAccelerators(hInstance
, (LPCTSTR
)IDC_REGEDIT
);
97 while (GetMessage(&msg
, NULL
, 0, 0)) {
98 if (!TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
)) {
99 TranslateMessage(&msg
);
100 DispatchMessage(&msg
);
109 // FUNCTION: MyRegisterClass()
111 // PURPOSE: Registers the window class.
115 // This function and its usage is only necessary if you want this code
116 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
117 // function that was added to Windows 95. It is important to call this function
118 // so that the application will get 'well formed' small icons associated
121 ATOM
MyRegisterClass(HINSTANCE hInstance
)
125 wcex
.cbSize
= sizeof(WNDCLASSEX
);
126 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
127 wcex
.lpfnWndProc
= (WNDPROC
)WndProc
;
130 wcex
.hInstance
= hInstance
;
131 wcex
.hIcon
= LoadIcon(hInstance
, (LPCTSTR
)IDI_REGEDIT
);
132 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
133 wcex
.hbrBackground
= (HBRUSH
)SS_BLACKRECT
/*(COLOR_WINDOW+1)*/;
134 // wcex.lpszMenuName = (LPCSTR)IDC_REGEDIT;
135 wcex
.lpszMenuName
= (LPCSTR
)IDR_REGEDIT_MENU
;
136 wcex
.lpszClassName
= szWindowClass
;
137 wcex
.hIconSm
= LoadIcon((HINSTANCE
)wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
138 return RegisterClassEx(&wcex
);
141 ATOM
MyRegisterClass2(HINSTANCE hInstance
)
145 wcex
.cbSize
= sizeof(WNDCLASSEX
);
146 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
147 wcex
.lpfnWndProc
= (WNDPROC
)FrameWndProc
;
150 wcex
.hInstance
= hInstance
;
151 wcex
.hIcon
= LoadIcon(hInstance
, (LPCTSTR
)IDI_REGEDIT
);
152 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
153 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
154 wcex
.lpszMenuName
= (LPCSTR
)IDR_REGEDIT_MENU
;
155 wcex
.lpszClassName
= szFrameClass
;
156 wcex
.hIconSm
= LoadIcon((HINSTANCE
)wcex
.hInstance
, (LPCTSTR
)IDI_SMALL
);
157 return RegisterClassEx(&wcex
);
162 // FUNCTION: InitInstance(HANDLE, int)
164 // PURPOSE: Saves instance handle and creates main window
168 // In this function, we save the instance handle in a global variable and
169 // create and display the main program window.
171 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
175 // Initialize the Windows Common Controls DLL
176 InitCommonControls();
178 hInst
= hInstance
; // Store instance handle in our global variable
179 hMainWnd
= CreateWindow(szWindowClass
, szTitle
, WS_OVERLAPPEDWINDOW
,
180 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0, NULL
, NULL
, hInstance
, NULL
);
185 // Get the minimum window sizes
186 // GetWindowRect(hMainWnd, &rc);
187 // nMinimumWidth = (rc.right - rc.left);
188 // nMinimumHeight = (rc.bottom - rc.top);
190 // Create the status bar
191 hStatusWnd
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
192 "", hMainWnd
, STATUS_WINDOW
);
196 // Create the status bar panes
200 SendMessage(hStatusWnd
, SB_SETPARTS
, 3, (long)nParts
);
203 hSplitWnd = CreateWindow(szFrameClass, "splitter window", WS_VISIBLE|WS_CHILD,
204 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
205 hMainWnd, (HMENU)SPLIT_WINDOW, hInstance, NULL);
209 hTreeWnd
= CreateTreeView(hMainWnd
, "c:\\foobar.txt");
213 hListWnd
= CreateListView(hMainWnd
, "");
217 ShowWindow(hMainWnd
, nCmdShow
);
218 UpdateWindow(hMainWnd
);
224 // This function handles all the sizing events for the application
225 // It re-sizes every window, and child window that needs re-sizing
226 void OnSize(UINT nType
, int cx
, int cy
)
233 if (nType
== SIZE_MINIMIZED
)
236 nXDifference
= cx
- nOldWidth
;
237 nYDifference
= cy
- nOldHeight
;
241 // Update the status bar size
242 GetWindowRect(hStatusWnd
, &rc
);
243 SendMessage(hStatusWnd
, WM_SIZE
, nType
, MAKELPARAM(cx
, cy
+ (rc
.bottom
- rc
.top
)));
245 // Update the status bar pane sizes
246 nParts
[0] = bInMenuLoop
? -1 : 100;
249 SendMessage(hStatusWnd
, SB_SETPARTS
, bInMenuLoop
? 1 : 3, (long)nParts
);
251 GetWindowRect(hStatusWnd
, &rc
);
253 MoveWindow(hTreeWnd
,0,0,cx
/2,cy
-(rc
.bottom
- rc
.top
),TRUE
);
254 MoveWindow(hListWnd
,cx
/2,0,cx
,cy
-(rc
.bottom
- rc
.top
),TRUE
);
258 void OnEnterMenuLoop(HWND hWnd
)
262 // Update the status bar pane sizes
264 SendMessage(hStatusWnd
, SB_SETPARTS
, 1, (long)&nParts
);
266 SendMessage(hStatusWnd
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)_T(""));
269 void OnExitMenuLoop(HWND hWnd
)
276 // Update the status bar pane sizes
277 GetClientRect(hWnd
, &rc
);
280 nParts
[2] = rc
.right
;
281 SendMessage(hStatusWnd
, SB_SETPARTS
, 3, (long)nParts
);
282 SendMessage(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)_T(""));
283 // wsprintf(text, _T("CPU Usage: %3d%%"), PerfDataGetProcessorUsage());
284 // SendMessage(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
285 // wsprintf(text, _T("Processes: %d"), PerfDataGetProcessCount());
286 // SendMessage(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
289 void OnMenuSelect(HWND hWnd
, UINT nItemID
, UINT nFlags
, HMENU hSysMenu
)
293 strcpy(str
, TEXT(""));
294 if (nFlags
& MF_POPUP
) {
295 if (hSysMenu
!= GetMenu(hWnd
)) {
296 if (nItemID
== 2) nItemID
= 5;
299 if (LoadString(hInst
, nItemID
, str
, 100)) {
300 // load appropriate string
302 // first newline terminates actual string
303 lpsz
= _tcschr(lpsz
, '\n');
307 SendMessage(hStatusWnd
, SB_SETTEXT
, 0, (LPARAM
)str
);
311 LRESULT CALLBACK
FrameWndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
316 TCHAR szHello
[MAX_LOADSTRING
];
317 LoadString(hInst
, IDS_HELLO
, szHello
, MAX_LOADSTRING
);
321 wmId
= LOWORD(wParam
);
322 wmEvent
= HIWORD(wParam
);
323 // Parse the menu selections:
326 // ShowAboutBox(hWnd);
328 HICON hIcon
= LoadIcon(hInst
, (LPCTSTR
)IDI_REGEDIT
);
329 ShellAbout(hWnd
, szTitle
, "FrameWndProc", hIcon
);
330 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
337 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
341 hdc
= BeginPaint(hWnd
, &ps
);
342 // TODO: Add any drawing code here...
344 GetClientRect(hWnd
, &rt
);
345 DrawText(hdc
, szHello
, strlen(szHello
), &rt
, DT_CENTER
);
352 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
359 // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
361 // PURPOSE: Processes messages for the main window.
363 // WM_COMMAND - process the application menu
364 // WM_PAINT - Paint the main window
365 // WM_DESTROY - post a quit message and return
368 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
373 //TCHAR szHello[MAX_LOADSTRING];
374 //LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
378 wmId
= LOWORD(wParam
);
379 wmEvent
= HIWORD(wParam
);
380 // Parse the menu selections:
382 case ID_REGISTRY_PRINTERSETUP
:
386 //PageSetupDlg(&psd);
388 case ID_REGISTRY_OPENLOCAL
:
391 // hChildWnd = CreateWindow(szFrameClass, szTitle, WS_OVERLAPPEDWINDOW | WS_CHILD,
392 // CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, hWnd, NULL, hInst, NULL);
393 hChildWnd
= CreateWindow(szFrameClass
, szTitle
, WS_OVERLAPPEDWINDOW
| WS_CHILD
,
394 0, 0, 150, 170, hWnd
, NULL
, hInst
, NULL
);
396 ShowWindow(hChildWnd
, 1);
397 UpdateWindow(hChildWnd
);
402 // ShowAboutBox(hWnd);
404 HICON hIcon
= LoadIcon(hInst
, (LPCTSTR
)IDI_REGEDIT
);
405 ShellAbout(hWnd
, szTitle
, "", hIcon
);
406 //if (hIcon) DestroyIcon(hIcon); // NOT REQUIRED
413 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
417 // Handle the window sizing in it's own function
418 OnSize(wParam
, LOWORD(lParam
), HIWORD(lParam
));
421 hdc
= BeginPaint(hWnd
, &ps
);
422 // TODO: Add any drawing code here...
424 GetClientRect(hWnd
, &rt
);
425 //DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
434 case WM_ENTERMENULOOP
:
435 OnEnterMenuLoop(hWnd
);
437 case WM_EXITMENULOOP
:
438 OnExitMenuLoop(hWnd
);
441 OnMenuSelect(hWnd
, LOWORD(wParam
), HIWORD(wParam
), (HMENU
)lParam
);
444 return DefWindowProc(hWnd
, message
, wParam
, lParam
);