Commit | Line | Data |
---|---|---|
f752b124 AJ |
1 | /* |
2 | * Regedit main function | |
3 | * | |
4 | * Copyright (C) 2002 Robert Dickenson <robd@reactos.org> | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | */ | |
20 | ||
21 | #define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */ | |
22 | #include <windows.h> | |
23 | #include <commctrl.h> | |
24 | #include <stdlib.h> | |
25 | #include <tchar.h> | |
f752b124 AJ |
26 | #include <stdio.h> |
27 | #include <fcntl.h> | |
28 | ||
29 | #define REGEDIT_DECLARE_FUNCTIONS | |
30 | #include "main.h" | |
31 | ||
b2d8cd3f | 32 | LPCSTR g_pszDefaultValueName = _T("(Default)"); |
f752b124 AJ |
33 | |
34 | BOOL ProcessCmdLine(LPSTR lpCmdLine); | |
35 | ||
36 | ||
37 | /******************************************************************************* | |
38 | * Global Variables: | |
39 | */ | |
40 | ||
41 | HINSTANCE hInst; | |
42 | HWND hFrameWnd; | |
43 | HWND hStatusBar; | |
44 | HMENU hMenuFrame; | |
649643aa | 45 | HMENU hPopupMenus = 0; |
f752b124 AJ |
46 | UINT nClipboardFormat; |
47 | LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT"); | |
48 | ||
49 | ||
16614538 | 50 | #define MAX_LOADSTRING 100 |
f752b124 AJ |
51 | TCHAR szTitle[MAX_LOADSTRING]; |
52 | TCHAR szFrameClass[MAX_LOADSTRING]; | |
53 | TCHAR szChildClass[MAX_LOADSTRING]; | |
54 | ||
55 | ||
f752b124 AJ |
56 | /******************************************************************************* |
57 | * | |
58 | * | |
59 | * FUNCTION: InitInstance(HANDLE, int) | |
60 | * | |
61 | * PURPOSE: Saves instance handle and creates main window | |
62 | * | |
63 | * COMMENTS: | |
64 | * | |
65 | * In this function, we save the instance handle in a global variable and | |
66 | * create and display the main program window. | |
67 | */ | |
68 | ||
d73dad66 | 69 | static BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) |
f752b124 AJ |
70 | { |
71 | WNDCLASSEX wcFrame = { | |
58c185ec DP |
72 | sizeof(WNDCLASSEX), |
73 | CS_HREDRAW | CS_VREDRAW/*style*/, | |
74 | FrameWndProc, | |
75 | 0/*cbClsExtra*/, | |
76 | 0/*cbWndExtra*/, | |
77 | hInstance, | |
78 | LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)), | |
79 | LoadCursor(0, IDC_ARROW), | |
80 | 0/*hbrBackground*/, | |
81 | 0/*lpszMenuName*/, | |
82 | szFrameClass, | |
83 | (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON, | |
84 | GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) | |
85 | }; | |
f752b124 AJ |
86 | ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */ |
87 | ||
88 | WNDCLASSEX wcChild = { | |
58c185ec DP |
89 | sizeof(WNDCLASSEX), |
90 | CS_HREDRAW | CS_VREDRAW/*style*/, | |
91 | ChildWndProc, | |
92 | 0/*cbClsExtra*/, | |
93 | sizeof(HANDLE)/*cbWndExtra*/, | |
94 | hInstance, | |
95 | LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)), | |
96 | LoadCursor(0, IDC_ARROW), | |
97 | 0/*hbrBackground*/, | |
98 | 0/*lpszMenuName*/, | |
99 | szChildClass, | |
100 | (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON, | |
101 | GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED) | |
102 | ||
103 | }; | |
f752b124 AJ |
104 | ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */ |
105 | hChildWndClass = hChildWndClass; /* warning eater */ | |
106 | ||
58c185ec | 107 | hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU)); |
649643aa | 108 | hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_POPUP_MENUS)); |
f752b124 AJ |
109 | |
110 | /* Initialize the Windows Common Controls DLL */ | |
111 | InitCommonControls(); | |
112 | ||
828aff30 RS |
113 | /* register our hex editor control */ |
114 | HexEdit_Register(); | |
115 | ||
f752b124 AJ |
116 | nClipboardFormat = RegisterClipboardFormat(strClipboardFormat); |
117 | /* if (nClipboardFormat == 0) { | |
118 | DWORD dwError = GetLastError(); | |
119 | } */ | |
120 | ||
121 | hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle, | |
58c185ec DP |
122 | WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE, |
123 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, | |
124 | NULL, hMenuFrame, hInstance, NULL/*lpParam*/); | |
f752b124 AJ |
125 | |
126 | if (!hFrameWnd) { | |
127 | return FALSE; | |
128 | } | |
129 | ||
130 | /* Create the status bar */ | |
131 | hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS, | |
132 | _T(""), hFrameWnd, STATUS_WINDOW); | |
133 | if (hStatusBar) { | |
134 | /* Create the status bar panes */ | |
135 | SetupStatusBar(hFrameWnd, FALSE); | |
136 | CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED); | |
137 | } | |
138 | ShowWindow(hFrameWnd, nCmdShow); | |
139 | UpdateWindow(hFrameWnd); | |
140 | return TRUE; | |
141 | } | |
142 | ||
143 | /******************************************************************************/ | |
144 | ||
d73dad66 | 145 | static void ExitInstance(void) |
f752b124 AJ |
146 | { |
147 | DestroyMenu(hMenuFrame); | |
148 | } | |
149 | ||
d73dad66 | 150 | static BOOL TranslateChildTabMessage(MSG *msg) |
b2d8cd3f KF |
151 | { |
152 | if (msg->message != WM_KEYDOWN) return FALSE; | |
153 | if (msg->wParam != VK_TAB) return FALSE; | |
154 | if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE; | |
155 | PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0); | |
156 | return TRUE; | |
157 | } | |
158 | ||
f752b124 AJ |
159 | int APIENTRY WinMain(HINSTANCE hInstance, |
160 | HINSTANCE hPrevInstance, | |
161 | LPSTR lpCmdLine, | |
162 | int nCmdShow) | |
163 | { | |
164 | MSG msg; | |
165 | HACCEL hAccel; | |
f752b124 AJ |
166 | |
167 | if (ProcessCmdLine(lpCmdLine)) { | |
168 | return 0; | |
169 | } | |
170 | ||
f752b124 | 171 | /* Initialize global strings */ |
eb9d0e92 DP |
172 | LoadString(hInstance, IDS_APP_TITLE, szTitle, COUNT_OF(szTitle)); |
173 | LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, COUNT_OF(szFrameClass)); | |
174 | LoadString(hInstance, IDC_REGEDIT, szChildClass, COUNT_OF(szChildClass)); | |
f752b124 AJ |
175 | |
176 | /* Store instance handle in our global variable */ | |
177 | hInst = hInstance; | |
178 | ||
179 | /* Perform application initialization */ | |
180 | if (!InitInstance(hInstance, nCmdShow)) { | |
181 | return FALSE; | |
182 | } | |
183 | hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT); | |
184 | ||
185 | /* Main message loop */ | |
ee0344a4 | 186 | while (GetMessage(&msg, NULL, 0, 0)) { |
b2d8cd3f KF |
187 | if (!TranslateAccelerator(hFrameWnd, hAccel, &msg) |
188 | && !TranslateChildTabMessage(&msg)) { | |
f752b124 AJ |
189 | TranslateMessage(&msg); |
190 | DispatchMessage(&msg); | |
191 | } | |
192 | } | |
193 | ExitInstance(); | |
194 | return msg.wParam; | |
195 | } |