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
)
81 WNDCLASSEX wcFrame
= {
83 CS_HREDRAW
| CS_VREDRAW
/*style*/,
88 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
)),
89 LoadCursor(0, IDC_ARROW
),
93 (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
), IMAGE_ICON
,
94 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
)
96 ATOM hFrameWndClass
= RegisterClassEx(&wcFrame
); /* register frame window class */
98 WNDCLASSEX wcChild
= {
100 CS_HREDRAW
| CS_VREDRAW
/*style*/,
103 sizeof(HANDLE
)/*cbWndExtra*/,
105 LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
)),
106 LoadCursor(0, IDC_ARROW
),
110 (HICON
)LoadImage(hInstance
, MAKEINTRESOURCE(IDI_REGEDIT
), IMAGE_ICON
,
111 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
)
114 ATOM hChildWndClass
= RegisterClassEx(&wcChild
); /* register child windows class */
115 hChildWndClass
= hChildWndClass
; /* warning eater */
117 RegisterHexEditorClass(hInstance
);
119 hMenuFrame
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_REGEDIT_MENU
));
120 hPopupMenus
= LoadMenu(hInstance
, MAKEINTRESOURCE(IDR_POPUP_MENUS
));
122 /* Initialize the Windows Common Controls DLL */
123 InitCommonControls();
125 hEditMenu
= GetSubMenu(hMenuFrame
, 1);
127 AclUiAvailable
= InitializeAclUiDll();
130 /* hide the Edit/Permissions... menu entry */
131 if(hEditMenu
!= NULL
)
133 RemoveMenu(hEditMenu
, ID_EDIT_PERMISSIONS
, MF_BYCOMMAND
);
134 /* remove the separator after the menu item */
135 RemoveMenu(hEditMenu
, 4, MF_BYPOSITION
);
139 if(hEditMenu
!= NULL
)
140 SetMenuDefaultItem(hEditMenu
, ID_EDIT_MODIFY
, MF_BYCOMMAND
);
142 nClipboardFormat
= RegisterClipboardFormat(strClipboardFormat
);
143 /* if (nClipboardFormat == 0) {
144 DWORD dwError = GetLastError();
147 hFrameWnd
= CreateWindowEx(WS_EX_WINDOWEDGE
, (LPCTSTR
)(int)hFrameWndClass
, szTitle
,
148 WS_OVERLAPPEDWINDOW
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
,
149 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
150 NULL
, hMenuFrame
, hInstance
, NULL
/*lpParam*/);
156 /* Create the status bar */
157 hStatusBar
= CreateStatusWindow(WS_VISIBLE
|WS_CHILD
|WS_CLIPSIBLINGS
|SBT_NOBORDERS
,
158 _T(""), hFrameWnd
, STATUS_WINDOW
);
160 /* Create the status bar panes */
161 SetupStatusBar(hFrameWnd
, FALSE
);
162 CheckMenuItem(GetSubMenu(hMenuFrame
, ID_VIEW_MENU
), ID_VIEW_STATUSBAR
, MF_BYCOMMAND
|MF_CHECKED
);
165 /* Restore position */
166 if (RegQueryStringValue(HKEY_CURRENT_USER
,
167 _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit"),
169 szBuffer
, sizeof(szBuffer
) / sizeof(szBuffer
[0])) == ERROR_SUCCESS
)
172 if (!_tcsncmp(s
, _T("My Computer\\"), 12))
174 SelectNode(g_pChildWnd
->hTreeWnd
, s
);
177 ShowWindow(hFrameWnd
, nCmdShow
);
178 UpdateWindow(hFrameWnd
);
182 /******************************************************************************/
184 void ExitInstance(HINSTANCE hInstance
)
186 UnregisterHexEditorClass(hInstance
);
187 DestroyMenu(hMenuFrame
);
188 DestroyMenu(hPopupMenus
);
192 BOOL
TranslateChildTabMessage(MSG
*msg
)
194 if (msg
->message
!= WM_KEYDOWN
) return FALSE
;
195 if (msg
->wParam
!= VK_TAB
) return FALSE
;
196 if (GetParent(msg
->hwnd
) != g_pChildWnd
->hWnd
) return FALSE
;
197 PostMessage(g_pChildWnd
->hWnd
, WM_COMMAND
, ID_SWITCH_PANELS
, 0);
201 int APIENTRY
WinMain(HINSTANCE hInstance
,
202 HINSTANCE hPrevInstance
,
213 hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
214 hf = _fdopen(hCrt, "w");
216 setvbuf(stdout, NULL, _IONBF, 0);
218 wprintf(L"command line exit, hInstance = %d\n", hInstance);
224 if (ProcessCmdLine(lpCmdLine
)) {
228 /* Initialize global strings */
229 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
230 LoadString(hInstance
, IDC_REGEDIT_FRAME
, szFrameClass
, MAX_LOADSTRING
);
231 LoadString(hInstance
, IDC_REGEDIT
, szChildClass
, MAX_LOADSTRING
);
233 /* Store instance handle in our global variable */
236 /* Perform application initialization */
237 if (!InitInstance(hInstance
, nCmdShow
)) {
240 hAccel
= LoadAccelerators(hInstance
, (LPCTSTR
)IDC_REGEDIT
);
242 /* Main message loop */
243 while (GetMessage(&msg
, (HWND
)NULL
, 0, 0)) {
244 if (!TranslateAccelerator(msg
.hwnd
, hAccel
, &msg
)
245 && !TranslateChildTabMessage(&msg
)) {
246 TranslateMessage(&msg
);
247 DispatchMessage(&msg
);
251 ExitInstance(hInstance
);