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 */
39 BOOL
ProcessCmdLine(LPSTR lpCmdLine
);
42 /*******************************************************************************
50 HMENU hPopupMenus
= 0;
51 UINT nClipboardFormat
;
52 LPCTSTR strClipboardFormat
= _T("TODO: SET CORRECT FORMAT");
55 #define MAX_LOADSTRING 100
56 TCHAR szTitle
[MAX_LOADSTRING
];
57 TCHAR szFrameClass
[MAX_LOADSTRING
];
58 TCHAR szChildClass
[MAX_LOADSTRING
];
61 /*******************************************************************************
64 * FUNCTION: InitInstance(HANDLE, int)
66 * PURPOSE: Saves instance handle and creates main window
70 * In this function, we save the instance handle in a global variable and
71 * create and display the main program window.
74 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
78 WNDCLASSEX wcFrame
= {
80 CS_HREDRAW
| CS_VREDRAW
/*style*/,
85 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
)),
86 LoadCursor(0, IDC_ARROW
),
90 (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
), IMAGE_ICON
,
91 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
)
93 ATOM hFrameWndClass
= RegisterClassEx(&wcFrame
); /* register frame window class */
95 WNDCLASSEX wcChild
= {
97 CS_HREDRAW
| CS_VREDRAW
/*style*/,
100 sizeof(HANDLE
)/*cbWndExtra*/,
102 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
)),
103 LoadCursor(0, IDC_ARROW
),
107 (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
), IMAGE_ICON
,
108 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
)
111 ATOM hChildWndClass
= RegisterClassEx(&wcChild
); /* register child windows class */
112 hChildWndClass
= hChildWndClass
; /* warning eater */
114 RegisterHexEditorClass(hInstance
);
116 hMenuFrame
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_REGEDIT_MENU
));
117 hPopupMenus
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_POPUP_MENUS
));
119 /* Initialize the Windows Common Controls DLL */
120 InitCommonControls();
123 hEditMenu
= GetSubMenu(hMenuFrame
, 1);
125 AclUiAvailable
= InitializeAclUiDll();
128 /* hide the Edit/Permissions... menu entry */
129 if(hEditMenu
!= NULL
)
131 RemoveMenu(hEditMenu
, ID_EDIT_PERMISSIONS
, MF_BYCOMMAND
);
132 /* remove the separator after the menu item */
133 RemoveMenu(hEditMenu
, 4, MF_BYPOSITION
);
137 if(hEditMenu
!= NULL
)
138 SetMenuDefaultItem(hEditMenu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
140 nClipboardFormat
= RegisterClipboardFormat(strClipboardFormat
);
141 /* if (nClipboardFormat == 0) {
142 DWORD dwError = GetLastError();
145 hFrameWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
, (LPCTSTR
)(int)hFrameWndClass
, szTitle
,
146 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
147 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
148 NULL
, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
154 /* Create the status bar */
155 hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
156 _T(""), hFrameWnd
, STATUS_WINDOW
);
158 /* Create the status bar panes */
159 SetupStatusBar(hFrameWnd
, FALSE
);
160 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
162 ShowWindow(hFrameWnd
, nCmdShow
);
163 UpdateWindow(hFrameWnd
);
167 /******************************************************************************/
169 void ExitInstance(HINSTANCE hInstance
)
171 UnregisterHexEditorClass(hInstance
);
172 DestroyMenu(hMenuFrame
);
173 DestroyMenu(hPopupMenus
);
177 BOOL
TranslateChildTabMessage(MSG
*msg
)
179 if (msg
->message
!= WM_KEYDOWN
) return FALSE
;
180 if (msg
->wParam
!= VK_TAB
) return FALSE
;
181 if (GetParent(msg
->hwnd
) != g_pChildWnd
->hWnd
) return FALSE
;
182 PostMessage(g_pChildWnd
->hWnd
, WM_COMMAND
, ID_SWITCH_PANELS
, 0);
186 int APIENTRY
WinMain(HINSTANCE hInstance
,
187 HINSTANCE hPrevInstance
,
198 hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
199 hf = _fdopen(hCrt, "w");
201 setvbuf(stdout, NULL, _IONBF, 0);
203 wprintf(L"command line exit, hInstance = %d\n", hInstance);
209 if (ProcessCmdLine(lpCmdLine
)) {
213 /* Initialize global strings */
214 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
215 LoadString(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
216 LoadString(hInstance
, IDC_REGEDIT
, szChildClass
, MAX_LOADSTRING
);
218 /* Store instance handle in our global variable */
221 /* Perform application initialization */
222 if (!InitInstance(hInstance
, nCmdShow
)) {
225 hAccel
= LoadAccelerators(hInstance
, (LPCTSTR
)IDC_REGEDIT
);
227 /* initialize the COM library for the remote registry object picker dialog */
228 hComInit
= CoInitialize(NULL
);
230 /* Main message loop */
231 while (GetMessage(&msg
, (HWND
)NULL
, 0, 0)) {
232 if (!TranslateAccelerator(msg
.hwnd
, hAccel
, &msg
)
233 && !TranslateChildTabMessage(&msg
)) {
234 TranslateMessage(&msg
);
235 DispatchMessage(&msg
);
239 if (SUCCEEDED(hComInit
))
244 ExitInstance(hInstance
);