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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 BOOL
ProcessCmdLine(LPSTR lpCmdLine
);
26 /*******************************************************************************
34 HMENU hPopupMenus
= 0;
35 UINT nClipboardFormat
;
36 LPCTSTR strClipboardFormat
= _T("TODO: SET CORRECT FORMAT");
37 const TCHAR g_szGeneralRegKey
[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit");
40 #define MAX_LOADSTRING 100
41 TCHAR szTitle
[MAX_LOADSTRING
];
42 TCHAR szFrameClass
[MAX_LOADSTRING
];
43 TCHAR szChildClass
[MAX_LOADSTRING
];
46 /*******************************************************************************
49 * FUNCTION: InitInstance(HANDLE, int)
51 * PURPOSE: Saves instance handle and creates main window
55 * In this function, we save the instance handle in a global variable and
56 * create and display the main program window.
59 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
69 ZeroMemory(&wcFrame
, sizeof(WNDCLASSEX
));
70 wcFrame
.cbSize
= sizeof(WNDCLASSEX
);
71 wcFrame
.style
= CS_HREDRAW
| CS_VREDRAW
;
72 wcFrame
.lpfnWndProc
= FrameWndProc
;
73 wcFrame
.hInstance
= hInstance
;
74 wcFrame
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
));
75 wcFrame
.hIconSm
= (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
),
76 IMAGE_ICON
, GetSystemMetrics(SM_CXSMICON
),
77 GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
78 wcFrame
.hCursor
= LoadCursor(0, IDC_ARROW
);
79 wcFrame
.lpszClassName
= szFrameClass
;
81 hFrameWndClass
= RegisterClassEx(&wcFrame
); /* register frame window class */
83 ZeroMemory(&wcChild
, sizeof(WNDCLASSEX
));
84 wcChild
.cbSize
= sizeof(WNDCLASSEX
);
85 wcChild
.style
= CS_HREDRAW
| CS_VREDRAW
;
86 wcChild
.lpfnWndProc
= ChildWndProc
;
87 wcChild
.cbWndExtra
= sizeof(HANDLE
);
88 wcChild
.hInstance
= hInstance
;
89 wcChild
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
));
90 wcChild
.hCursor
= LoadCursor(0, IDC_ARROW
),
91 wcChild
.lpszClassName
= szChildClass
,
92 wcChild
.hIconSm
= (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
), IMAGE_ICON
,
93 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
95 RegisterClassEx(&wcChild
); /* register child windows class */
97 RegisterHexEditorClass(hInstance
);
99 hMenuFrame
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_REGEDIT_MENU
));
100 hPopupMenus
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_POPUP_MENUS
));
102 /* Initialize the Windows Common Controls DLL */
103 InitCommonControls();
105 hEditMenu
= GetSubMenu(hMenuFrame
, 1);
107 AclUiAvailable
= InitializeAclUiDll();
110 /* hide the Edit/Permissions... menu entry */
111 if(hEditMenu
!= NULL
)
113 RemoveMenu(hEditMenu
, ID_EDIT_PERMISSIONS
, MF_BYCOMMAND
);
114 /* remove the separator after the menu item */
115 RemoveMenu(hEditMenu
, 4, MF_BYPOSITION
);
119 if(hEditMenu
!= NULL
)
120 SetMenuDefaultItem(hEditMenu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
122 nClipboardFormat
= RegisterClipboardFormat(strClipboardFormat
);
123 /* if (nClipboardFormat == 0) {
124 DWORD dwError = GetLastError();
127 hFrameWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
, (LPCTSTR
)(UlongToPtr(hFrameWndClass
)), szTitle
,
128 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
129 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
130 NULL
, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
136 /* Create the status bar */
137 hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
138 _T(""), hFrameWnd
, STATUS_WINDOW
);
140 /* Create the status bar panes */
141 SetupStatusBar(hFrameWnd
, FALSE
);
142 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
145 /* Restore position */
146 if (RegQueryStringValue(HKEY_CURRENT_USER
, g_szGeneralRegKey
,
148 szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0])) == ERROR_SUCCESS
)
150 SelectNode(g_pChildWnd
->hTreeWnd
, szBuffer
);
153 ShowWindow(hFrameWnd
, nCmdShow
);
154 UpdateWindow(hFrameWnd
);
158 /******************************************************************************/
160 /* we need to destroy the main menu before destroying the main window
161 to avoid a memory leak */
163 void DestroyMainMenu() {
164 DestroyMenu(hMenuFrame
);
167 /******************************************************************************/
169 void ExitInstance(HINSTANCE hInstance
)
171 UnregisterHexEditorClass(hInstance
);
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
,
194 UNREFERENCED_PARAMETER(hPrevInstance
);
200 hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
201 hf = _fdopen(hCrt, "w");
203 setvbuf(stdout, NULL, _IONBF, 0);
205 wprintf(L"command line exit, hInstance = %d\n", hInstance);
211 if (ProcessCmdLine(lpCmdLine
)) {
215 /* Initialize global strings */
216 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
217 LoadString(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
218 LoadString(hInstance
, IDC_REGEDIT
, szChildClass
, MAX_LOADSTRING
);
220 /* Store instance handle in our global variable */
223 /* Perform application initialization */
224 if (!InitInstance(hInstance
, nCmdShow
)) {
227 hAccel
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(ID_ACCEL
));
229 /* Main message loop */
230 while (GetMessage(&msg
, (HWND
)NULL
, 0, 0)) {
231 if (!TranslateAccelerator(hFrameWnd
, hAccel
, &msg
)
232 && !TranslateChildTabMessage(&msg
)) {
233 TranslateMessage(&msg
);
234 DispatchMessage(&msg
);
238 ExitInstance(hInstance
);
239 return (int) msg
.wParam
;