A first stab at wcstod().
[wine/hacks.git] / programs / regedit / main.c
blobd0357946fb3c260507b07bd27c23a100eb1ef1bd
1 /*
2 * Regedit main function
4 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
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.
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.
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
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>
26 #include <process.h>
27 #include <stdio.h>
28 #include <fcntl.h>
30 #define REGEDIT_DECLARE_FUNCTIONS
31 #include "main.h"
34 BOOL ProcessCmdLine(LPSTR lpCmdLine);
37 /*******************************************************************************
38 * Global Variables:
41 HINSTANCE hInst;
42 HWND hFrameWnd;
43 HWND hStatusBar;
44 HMENU hMenuFrame;
45 UINT nClipboardFormat;
46 LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
49 TCHAR szTitle[MAX_LOADSTRING];
50 TCHAR szFrameClass[MAX_LOADSTRING];
51 TCHAR szChildClass[MAX_LOADSTRING];
54 /*******************************************************************************
56 * FUNCTION: DynamicBind( void )
58 * PURPOSE: Binds all functions dependent on user32.dll
60 static BOOL DynamicBind( void )
62 HMODULE dll;
64 #define d(x) \
65 p##x = (typeof (x) ) GetProcAddress( dll, #x ); \
66 if( ! p##x ) \
67 { \
68 fprintf(stderr,"failed to bind function at line %d\n",__LINE__); \
69 return FALSE; \
70 } \
73 dll = LoadLibrary("user32");
74 if( !dll )
75 return FALSE;
77 d(BeginDeferWindowPos)
78 d(BeginPaint)
79 d(CallWindowProcA)
80 d(CheckMenuItem)
81 d(CloseClipboard)
82 d(CreateWindowExA)
83 d(DefWindowProcA)
84 d(DeferWindowPos)
85 d(DestroyMenu)
86 d(DestroyWindow)
87 d(DialogBoxParamA)
88 d(DispatchMessageA)
89 d(EmptyClipboard)
90 d(EndDeferWindowPos)
91 d(EndDialog)
92 d(EndPaint)
93 d(FillRect)
94 d(GetCapture)
95 d(GetClientRect)
96 d(GetCursorPos)
97 d(GetDC)
98 d(GetDlgItem)
99 d(GetMenu)
100 d(GetMessageA)
101 d(GetSubMenu)
102 d(GetSystemMetrics)
103 d(InvertRect)
104 d(IsWindowVisible)
105 d(LoadAcceleratorsA)
106 d(LoadBitmapA)
107 d(LoadCursorA)
108 d(LoadIconA)
109 d(LoadImageA)
110 d(LoadMenuA)
111 d(LoadStringA)
112 d(MessageBeep)
113 d(MoveWindow)
114 d(OpenClipboard)
115 d(PostQuitMessage)
116 d(RegisterClassExA)
117 d(RegisterClipboardFormatA)
118 d(ReleaseCapture)
119 d(ReleaseDC)
120 d(ScreenToClient)
121 d(SendMessageA)
122 d(SetCapture)
123 d(SetCursor)
124 d(SetFocus)
125 d(SetWindowLongA)
126 d(SetWindowTextA)
127 d(ShowWindow)
128 d(TranslateAccelerator)
129 d(TranslateMessage)
130 d(UpdateWindow)
131 d(WinHelpA)
132 d(wsprintfA)
134 dll = LoadLibrary("gdi32");
135 if( !dll )
136 return FALSE;
138 d(DeleteDC)
139 d(DeleteObject)
140 d(GetStockObject)
142 dll = LoadLibrary("comctl32");
143 if( !dll )
144 return FALSE;
146 d(CreateStatusWindowA)
147 d(ImageList_Add)
148 d(ImageList_Create)
149 d(ImageList_GetImageCount)
150 d(InitCommonControls)
152 dll = LoadLibrary("comdlg32");
153 if( !dll )
154 return FALSE;
156 d(CommDlgExtendedError)
157 d(GetOpenFileNameA)
158 d(GetSaveFileNameA)
159 d(PrintDlgA)
161 return TRUE;
164 /*******************************************************************************
167 * FUNCTION: InitInstance(HANDLE, int)
169 * PURPOSE: Saves instance handle and creates main window
171 * COMMENTS:
173 * In this function, we save the instance handle in a global variable and
174 * create and display the main program window.
177 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
179 WNDCLASSEX wcFrame = {
180 sizeof(WNDCLASSEX),
181 CS_HREDRAW | CS_VREDRAW/*style*/,
182 FrameWndProc,
183 0/*cbClsExtra*/,
184 0/*cbWndExtra*/,
185 hInstance,
186 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
187 LoadCursor(0, IDC_ARROW),
188 0/*hbrBackground*/,
189 0/*lpszMenuName*/,
190 szFrameClass,
191 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
192 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
194 ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
196 WNDCLASSEX wcChild = {
197 sizeof(WNDCLASSEX),
198 CS_HREDRAW | CS_VREDRAW/*style*/,
199 ChildWndProc,
200 0/*cbClsExtra*/,
201 sizeof(HANDLE)/*cbWndExtra*/,
202 hInstance,
203 LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
204 LoadCursor(0, IDC_ARROW),
205 0/*hbrBackground*/,
206 0/*lpszMenuName*/,
207 szChildClass,
208 (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
209 GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
212 ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */
213 hChildWndClass = hChildWndClass; /* warning eater */
215 hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
217 /* Initialize the Windows Common Controls DLL */
218 InitCommonControls();
220 nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
221 /* if (nClipboardFormat == 0) {
222 DWORD dwError = GetLastError();
223 } */
225 hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
226 WS_OVERLAPPEDWINDOW | WS_EX_CLIENTEDGE,
227 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
228 NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
230 if (!hFrameWnd) {
231 return FALSE;
234 /* Create the status bar */
235 hStatusBar = CreateStatusWindow(WS_VISIBLE|WS_CHILD|WS_CLIPSIBLINGS|SBT_NOBORDERS,
236 _T(""), hFrameWnd, STATUS_WINDOW);
237 if (hStatusBar) {
238 /* Create the status bar panes */
239 SetupStatusBar(hFrameWnd, FALSE);
240 CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
242 ShowWindow(hFrameWnd, nCmdShow);
243 UpdateWindow(hFrameWnd);
244 return TRUE;
247 /******************************************************************************/
249 void ExitInstance(void)
251 DestroyMenu(hMenuFrame);
254 int APIENTRY WinMain(HINSTANCE hInstance,
255 HINSTANCE hPrevInstance,
256 LPSTR lpCmdLine,
257 int nCmdShow)
259 MSG msg;
260 HACCEL hAccel;
262 int hCrt;
263 FILE *hf;
264 AllocConsole();
265 hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
266 hf = _fdopen(hCrt, "w");
267 *stdout = *hf;
268 setvbuf(stdout, NULL, _IONBF, 0);
270 wprintf(L"command line exit, hInstance = %d\n", hInstance);
271 getch();
272 FreeConsole();
273 return 0;
276 if (ProcessCmdLine(lpCmdLine)) {
277 return 0;
280 if (!DynamicBind()) {
281 return 0;
284 /* Initialize global strings */
285 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
286 LoadString(hInstance, IDC_REGEDIT_FRAME, szFrameClass, MAX_LOADSTRING);
287 LoadString(hInstance, IDC_REGEDIT, szChildClass, MAX_LOADSTRING);
289 /* Store instance handle in our global variable */
290 hInst = hInstance;
292 /* Perform application initialization */
293 if (!InitInstance(hInstance, nCmdShow)) {
294 return FALSE;
296 hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
298 /* Main message loop */
299 while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
300 if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)) {
301 TranslateMessage(&msg);
302 DispatchMessage(&msg);
305 ExitInstance();
306 return msg.wParam;