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 */
30 #define REGEDIT_DECLARE_FUNCTIONS
34 BOOL
ProcessCmdLine(LPSTR lpCmdLine
);
37 /*******************************************************************************
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 )
65 p##x = (typeof (x) ) GetProcAddress( dll, #x ); \
68 fprintf(stderr,"failed to bind function at line %d\n",__LINE__); \
73 dll = LoadLibrary("user32");
77 d(BeginDeferWindowPos
)
117 d(RegisterClipboardFormatA
)
128 d(TranslateAccelerator
)
134 dll
= LoadLibrary("gdi32");
142 dll
= LoadLibrary("comctl32");
146 d(CreateStatusWindowA
)
149 d(ImageList_GetImageCount
)
150 d(InitCommonControls
)
152 dll
= LoadLibrary("comdlg32");
156 d(CommDlgExtendedError
)
164 /*******************************************************************************
167 * FUNCTION: InitInstance(HANDLE, int)
169 * PURPOSE: Saves instance handle and creates main window
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
= {
181 CS_HREDRAW
| CS_VREDRAW
/*style*/,
186 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
)),
187 LoadCursor(0, IDC_ARROW
),
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
= {
198 CS_HREDRAW
| CS_VREDRAW
/*style*/,
201 sizeof(HANDLE
)/*cbWndExtra*/,
203 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
)),
204 LoadCursor(0, IDC_ARROW
),
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();
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*/);
234 /* Create the status bar */
235 hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
236 _T(""), hFrameWnd
, STATUS_WINDOW
);
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
);
247 /******************************************************************************/
249 void ExitInstance(void)
251 DestroyMenu(hMenuFrame
);
254 int APIENTRY
WinMain(HINSTANCE hInstance
,
255 HINSTANCE hPrevInstance
,
265 hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
266 hf = _fdopen(hCrt, "w");
268 setvbuf(stdout, NULL, _IONBF, 0);
270 wprintf(L"command line exit, hInstance = %d\n", hInstance);
276 if (ProcessCmdLine(lpCmdLine
)) {
280 if (!DynamicBind()) {
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 */
292 /* Perform application initialization */
293 if (!InitInstance(hInstance
, nCmdShow
)) {
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
);