* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#define WIN32_LEAN_AND_MEAN /* Exclude rarely-used stuff from Windows headers */
-#include <windows.h>
-#include <commctrl.h>
-#include <stdlib.h>
-#include <tchar.h>
-#include <process.h>
-#include <stdio.h>
-#include <fcntl.h>
-
-#define REGEDIT_DECLARE_FUNCTIONS
-#include "main.h"
-
+#include <regedit.h>
BOOL ProcessCmdLine(LPSTR lpCmdLine);
HWND hFrameWnd;
HWND hStatusBar;
HMENU hMenuFrame;
+HMENU hPopupMenus = 0;
UINT nClipboardFormat;
LPCTSTR strClipboardFormat = _T("TODO: SET CORRECT FORMAT");
+const TCHAR g_szGeneralRegKey[] = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit");
+#define MAX_LOADSTRING 100
TCHAR szTitle[MAX_LOADSTRING];
TCHAR szFrameClass[MAX_LOADSTRING];
TCHAR szChildClass[MAX_LOADSTRING];
-/*******************************************************************************
- *
- * FUNCTION: DynamicBind( void )
- *
- * PURPOSE: Binds all functions dependent on user32.dll
- */
-static BOOL DynamicBind( void )
-{
- HMODULE dll;
-
-#define d(x) \
- p##x = (typeof (x) ) GetProcAddress( dll, #x ); \
- if( ! p##x ) \
- { \
- fprintf(stderr,"failed to bind function at line %d\n",__LINE__); \
- return FALSE; \
- } \
-
-
- dll = LoadLibrary("user32");
- if( !dll )
- return FALSE;
-
- d(BeginDeferWindowPos)
- d(BeginPaint)
- d(CallWindowProcA)
- d(CheckMenuItem)
- d(CloseClipboard)
- d(CreateWindowExA)
- d(DefWindowProcA)
- d(DeferWindowPos)
- d(DestroyMenu)
- d(DestroyWindow)
- d(DialogBoxParamA)
- d(DispatchMessageA)
- d(EmptyClipboard)
- d(EndDeferWindowPos)
- d(EndDialog)
- d(EndPaint)
- d(FillRect)
- d(GetCapture)
- d(GetClientRect)
- d(GetCursorPos)
- d(GetDC)
- d(GetDlgItem)
- d(GetMenu)
- d(GetMessageA)
- d(GetSubMenu)
- d(GetSystemMetrics)
- d(InvertRect)
- d(IsWindowVisible)
- d(LoadAcceleratorsA)
- d(LoadBitmapA)
- d(LoadCursorA)
- d(LoadIconA)
- d(LoadImageA)
- d(LoadMenuA)
- d(LoadStringA)
- d(MessageBeep)
- d(MoveWindow)
- d(OpenClipboard)
- d(PostQuitMessage)
- d(RegisterClassExA)
- d(RegisterClipboardFormatA)
- d(ReleaseCapture)
- d(ReleaseDC)
- d(ScreenToClient)
- d(SendMessageA)
- d(SetCapture)
- d(SetCursor)
- d(SetFocus)
- d(SetWindowLongA)
- d(SetWindowTextA)
- d(ShowWindow)
- d(TranslateAccelerator)
- d(TranslateMessage)
- d(UpdateWindow)
- d(WinHelpA)
- d(wsprintfA)
-
- dll = LoadLibrary("gdi32");
- if( !dll )
- return FALSE;
-
- d(DeleteDC)
- d(DeleteObject)
- d(GetStockObject)
-
- dll = LoadLibrary("comctl32");
- if( !dll )
- return FALSE;
-
- d(CreateStatusWindowA)
- d(ImageList_Add)
- d(ImageList_Create)
- d(ImageList_GetImageCount)
- d(InitCommonControls)
-
- dll = LoadLibrary("comdlg32");
- if( !dll )
- return FALSE;
-
- d(CommDlgExtendedError)
- d(GetOpenFileNameA)
- d(GetSaveFileNameA)
- d(PrintDlgA)
-
- return TRUE;
-}
-
/*******************************************************************************
*
*
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
+ BOOL AclUiAvailable;
+ HMENU hEditMenu;
+ TCHAR szBuffer[256];
+
WNDCLASSEX wcFrame = {
- sizeof(WNDCLASSEX),
- CS_HREDRAW | CS_VREDRAW/*style*/,
- FrameWndProc,
- 0/*cbClsExtra*/,
- 0/*cbWndExtra*/,
- hInstance,
- LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
- LoadCursor(0, IDC_ARROW),
- 0/*hbrBackground*/,
- 0/*lpszMenuName*/,
- szFrameClass,
- (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
- GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
- };
+ sizeof(WNDCLASSEX),
+ CS_HREDRAW | CS_VREDRAW/*style*/,
+ FrameWndProc,
+ 0/*cbClsExtra*/,
+ 0/*cbWndExtra*/,
+ hInstance,
+ LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
+ LoadCursor(0, IDC_ARROW),
+ 0/*hbrBackground*/,
+ 0/*lpszMenuName*/,
+ szFrameClass,
+ (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
+ GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
+ };
ATOM hFrameWndClass = RegisterClassEx(&wcFrame); /* register frame window class */
WNDCLASSEX wcChild = {
- sizeof(WNDCLASSEX),
- CS_HREDRAW | CS_VREDRAW/*style*/,
- ChildWndProc,
- 0/*cbClsExtra*/,
- sizeof(HANDLE)/*cbWndExtra*/,
- hInstance,
- LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
- LoadCursor(0, IDC_ARROW),
- 0/*hbrBackground*/,
- 0/*lpszMenuName*/,
- szChildClass,
- (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
- GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
-
- };
+ sizeof(WNDCLASSEX),
+ CS_HREDRAW | CS_VREDRAW/*style*/,
+ ChildWndProc,
+ 0/*cbClsExtra*/,
+ sizeof(HANDLE)/*cbWndExtra*/,
+ hInstance,
+ LoadIcon(hInstance, MAKEINTRESOURCE(IDI_REGEDIT)),
+ LoadCursor(0, IDC_ARROW),
+ 0/*hbrBackground*/,
+ 0/*lpszMenuName*/,
+ szChildClass,
+ (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_REGEDIT), IMAGE_ICON,
+ GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED)
+
+ };
ATOM hChildWndClass = RegisterClassEx(&wcChild); /* register child windows class */
hChildWndClass = hChildWndClass; /* warning eater */
- hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
+ RegisterHexEditorClass(hInstance);
+
+ hMenuFrame = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_REGEDIT_MENU));
+ hPopupMenus = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_POPUP_MENUS));
/* Initialize the Windows Common Controls DLL */
InitCommonControls();
+ hEditMenu = GetSubMenu(hMenuFrame, 1);
+
+ AclUiAvailable = InitializeAclUiDll();
+ if(!AclUiAvailable)
+ {
+ /* hide the Edit/Permissions... menu entry */
+ if(hEditMenu != NULL)
+ {
+ RemoveMenu(hEditMenu, ID_EDIT_PERMISSIONS, MF_BYCOMMAND);
+ /* remove the separator after the menu item */
+ RemoveMenu(hEditMenu, 4, MF_BYPOSITION);
+ }
+ }
+
+ if(hEditMenu != NULL)
+ SetMenuDefaultItem(hEditMenu, ID_EDIT_MODIFY, MF_BYCOMMAND);
+
nClipboardFormat = RegisterClipboardFormat(strClipboardFormat);
/* if (nClipboardFormat == 0) {
DWORD dwError = GetLastError();
} */
- hFrameWnd = CreateWindowEx(0, (LPCTSTR)(int)hFrameWndClass, szTitle,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
+ hFrameWnd = CreateWindowEx(WS_EX_WINDOWEDGE, (LPCTSTR)(UlongToPtr(hFrameWndClass)), szTitle,
+ WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, hMenuFrame, hInstance, NULL/*lpParam*/);
if (!hFrameWnd) {
return FALSE;
SetupStatusBar(hFrameWnd, FALSE);
CheckMenuItem(GetSubMenu(hMenuFrame, ID_VIEW_MENU), ID_VIEW_STATUSBAR, MF_BYCOMMAND|MF_CHECKED);
}
+
+ /* Restore position */
+ if (RegQueryStringValue(HKEY_CURRENT_USER, g_szGeneralRegKey,
+ _T("LastKey"),
+ szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0])) == ERROR_SUCCESS)
+ {
+ SelectNode(g_pChildWnd->hTreeWnd, szBuffer);
+ }
+
ShowWindow(hFrameWnd, nCmdShow);
UpdateWindow(hFrameWnd);
return TRUE;
/******************************************************************************/
-void ExitInstance(void)
+/* we need to destroy the main menu before destroying the main window
+ to avoid a memory leak */
+
+void DestroyMainMenu() {
+ DestroyMenu(hMenuFrame);
+}
+
+/******************************************************************************/
+
+void ExitInstance(HINSTANCE hInstance)
+{
+ UnregisterHexEditorClass(hInstance);
+
+ DestroyMenu(hPopupMenus);
+ UnloadAclUiDll();
+}
+
+BOOL TranslateChildTabMessage(MSG *msg)
{
- DestroyMenu(hMenuFrame);
+ if (msg->message != WM_KEYDOWN) return FALSE;
+ if (msg->wParam != VK_TAB) return FALSE;
+ if (GetParent(msg->hwnd) != g_pChildWnd->hWnd) return FALSE;
+ PostMessage(g_pChildWnd->hWnd, WM_COMMAND, ID_SWITCH_PANELS, 0);
+ return TRUE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
{
MSG msg;
HACCEL hAccel;
-/*
- int hCrt;
- FILE *hf;
- AllocConsole();
- hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
- hf = _fdopen(hCrt, "w");
- *stdout = *hf;
- setvbuf(stdout, NULL, _IONBF, 0);
-
- wprintf(L"command line exit, hInstance = %d\n", hInstance);
- getch();
- FreeConsole();
- return 0;
- */
- if (ProcessCmdLine(lpCmdLine)) {
+ /*
+ int hCrt;
+ FILE *hf;
+ AllocConsole();
+ hCrt = _open_osfhandle((long)GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
+ hf = _fdopen(hCrt, "w");
+ *stdout = *hf;
+ setvbuf(stdout, NULL, _IONBF, 0);
+
+ wprintf(L"command line exit, hInstance = %d\n", hInstance);
+ getch();
+ FreeConsole();
return 0;
- }
+ */
- if (!DynamicBind()) {
+ if (ProcessCmdLine(lpCmdLine)) {
return 0;
}
if (!InitInstance(hInstance, nCmdShow)) {
return FALSE;
}
- hAccel = LoadAccelerators(hInstance, (LPCTSTR)IDC_REGEDIT);
+ hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(ID_ACCEL));
/* Main message loop */
while (GetMessage(&msg, (HWND)NULL, 0, 0)) {
- if (!TranslateAccelerator(msg.hwnd, hAccel, &msg)) {
+ if (!TranslateAccelerator(hFrameWnd, hAccel, &msg)
+ && !TranslateChildTabMessage(&msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
- ExitInstance();
+
+ ExitInstance(hInstance);
return msg.wParam;
}