#define WIN31 #include #include "RegEdit.h" #include "SDKRegEd.h" /*********************************************************/ /******************* Globals *****************************/ /*********************************************************/ char szAppName[] = "Registration Editor" ; char szSDKRegEd[] = "SDKRegEd"; char *pszLongName; char *pszOutOfMemory; extern char szNull[]; HANDLE hInstance; HWND hWndMain, hWndDlg = NULL, hWndHelp; LPSTR lpCmdLine; WORD wCmdFlags, wHelpMenuItem, wHelpId, wHelpMain; LONG (FAR PASCAL *lpfnEditor)(HWND, WORD, WORD, LONG); FARPROC lpOldHook; FARPROC lpMainWndDlg = NULL; WORD wHelpIndex; HANDLE hAcc; BOOL fOpenError = FALSE; /*********************************************************/ /******************* Functions ***************************/ /*********************************************************/ unsigned long NEAR PASCAL RetSetValue(HKEY hKey, PSTR pSubKey, PSTR pVal) { return(RegSetValue(hKey, pSubKey, REG_SZ, pVal, 0L)); } #ifndef REGLOAD unsigned long NEAR PASCAL WriteThroughSetValue(HKEY hKey, PSTR pSubKey, PSTR pVal) { long lRet; if (!(lRet=RegSetValue(hKey, pSubKey, REG_SZ, pVal, 0L))) lRet = SDKSetValue(hKey, pSubKey, pVal); return(lRet); } #endif unsigned long (NEAR PASCAL *lpfnSetValue)(HKEY, PSTR, PSTR) = RetSetValue; unsigned long NEAR PASCAL MySetValue(HKEY hKey, PSTR pSubKey, PSTR pVal) { return((*lpfnSetValue)(hKey, pSubKey, pVal)); } VOID NEAR PASCAL GetCommandFlags(void) { wCmdFlags = 0; while(1) { /* skip spaces */ while(*lpCmdLine == ' ') ++lpCmdLine; /* check if this is a command line switch */ if(*lpCmdLine!='/' && *lpCmdLine!='-') break; ++lpCmdLine; /* set known flags */ while(*lpCmdLine && *lpCmdLine!=' ') { switch(*lpCmdLine) { case('s'): /* for silent */ case('S'): /* for silent */ wCmdFlags |= FLAG_SILENT; break; case('v'): /* use tree editor */ case('V'): /* use tree editor */ wCmdFlags |= FLAG_VERBOSE; break; case('u'): /* update, don't overwrite existing path entries */ case('U'): /* in shell\open\command or shell\open\print */ wCmdFlags |= FLAG_LEAVECOMMAND; break; } lpCmdLine = AnsiNext(lpCmdLine); } } } #ifndef REGLOAD long FAR PASCAL WndProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam) { static HANDLE hCustRegs = NULL; HCURSOR oldCursor; switch(wMessage) { case WM_ACTIVATE: if(wParam) { hWndHelp = hWnd; SetFocus(hWndDlg); } break; case WM_CREATE: { RECT rcWnd, rcClt; DragAcceptFiles(hWnd, TRUE); lpfnEditor(hWnd, wMessage, wParam, lParam); if((rcWnd.right=MyGetProfileInt(IDS_SHORTNAME, IDS_WIDTH, 0))<=0 || (rcWnd.bottom=MyGetProfileInt(IDS_SHORTNAME, IDS_HEIGHT, 0))<=0) { GetWindowRect(hWndDlg, &rcWnd); rcWnd.right -= rcWnd.left; rcWnd.bottom -= rcWnd.top; } GetClientRect(hWnd, &rcClt); rcClt.right -= rcWnd.right; rcClt.bottom -= rcWnd.bottom; GetWindowRect(hWnd, &rcWnd); SetWindowPos(hWnd, NULL, 0, 0, rcWnd.right-rcWnd.left-rcClt.right, rcWnd.bottom-rcWnd.top-rcClt.bottom, SWP_NOMOVE | SWP_NOZORDER); return(DefWindowProc(hWnd, wMessage, wParam, lParam)); } case WM_CLOSE: case WM_QUERYENDSESSION: { HKEY hKeyRoot; WORD wErrMsg; int nReturn; if(!fOpenError) { if(!lpfnEditor(hWnd, wMessage, wParam, lParam)) return(0L); if(RegOpenKey(HKEY_CLASSES_ROOT, NULL, &hKeyRoot) == ERROR_SUCCESS) { if(wErrMsg=GetErrMsg((WORD)RegCloseKey(hKeyRoot))) { PSTR pError; if(pError=(PSTR)MyLoadString(wErrMsg, NULL, LMEM_FIXED)) { nReturn = MyMessageBox(hWnd, IDS_ENDERROR, MB_YESNO|MB_ICONHAND|MB_SYSTEMMODAL, lstrlen(pError), (LPSTR)pError); LocalFree((HANDLE)pError); } else /* Notice the flags are ignored for OOM */ nReturn = MyMessageBox(hWnd, IDS_OUTOFMEMORY, MB_OK|MB_ICONHAND|MB_SYSTEMMODAL, 0); if(nReturn != IDYES) return(0L); } } } return(DefWindowProc(hWnd, wMessage, wParam, lParam)); } case WM_DESTROY: if(hWndDlg) DestroyWindow(hWndDlg); if(lpMainWndDlg) FreeProcInstance(lpMainWndDlg); #ifndef NOHELP WinHelp(hWnd, NULL, HELP_QUIT, 0L); #endif DragAcceptFiles(hWnd, FALSE); PostQuitMessage(0); break; case WM_SIZE: { RECT rcDlg, rcWnd; int hgt; if(wParam == SIZEICONIC) break; if(!hWndDlg) { /* This should only happen during the create message */ PostMessage(hWnd, wMessage, wParam, lParam); break; } if(wParam == SIZENORMAL) { WriteProfileInt(IDS_SHORTNAME, IDS_WIDTH, LOWORD(lParam)); WriteProfileInt(IDS_SHORTNAME, IDS_HEIGHT, HIWORD(lParam)); } hgt = HIWORD(lParam); SetWindowPos(hWndDlg, NULL, 0, 0, LOWORD(lParam), hgt, SWP_NOZORDER); GetWindowRect(hWndDlg, &rcDlg); ScreenToClient(hWnd, (POINT *)(&rcDlg) + 1); if((WORD)rcDlg.bottom != HIWORD(lParam)) { GetWindowRect(hWnd, &rcWnd); SetWindowPos(hWnd, NULL, 0, 0, rcWnd.right-rcWnd.left, rcWnd.bottom-rcWnd.top-HIWORD(lParam)+rcDlg.bottom, SWP_NOMOVE | SWP_NOZORDER); } break; } case WM_DROPFILES: { int result, i, nFileName; HANDLE hFileName; WORD wFlags; wFlags = (GetKeyState(VK_CONTROL)&0x8000) ? FLAG_SILENT : 0; lpfnEditor(hWnd, wMessage, wParam, lParam); for(result=DragQueryFile(wParam, (UINT)-1, NULL, 0), i=0; i 1) { PSTR pLocal; WORD wFileLen = 130; WORD wCmdLen = lstrlen(lpCmdLine) + 1; while(1) { if(!(pLocal=(PSTR)LocalAlloc(LMEM_FIXED, wFileLen+wCmdLen))) { MyMessageBox(NULL, IDS_OUTOFMEMORY, MB_OK|MB_ICONHAND|MB_SYSTEMMODAL, 0); return(FALSE); } if(GetModuleFileName(hTemp, pLocal, wFileLen) < (int)wFileLen-5) break; LocalFree((HANDLE)pLocal); wFileLen += 130; } lstrcat(pLocal, " "); lstrcat(pLocal, lpCmdLine); return(WinExec(pLocal, SW_SHOWNORMAL) > 32); } #else if(hPrevInstance) { GetInstanceData(hPrevInstance, (PSTR)&hWndMain, sizeof(hWndMain)); if(hCmd) PostMessage(hWndMain, WM_COMMAND, ID_FINISHMERGE, MAKELONG(hCmd, wCmdFlags | FLAG_WRITETHROUGH)); else { SetWindowPos(hWndMain, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); if(IsIconic(hWndMain)) ShowWindow(hWndMain, SW_RESTORE); else SetActiveWindow(GetLastActivePopup(hWndMain)); } return(TRUE); } #endif if(hCmd) { ProcessFiles(NULL, hCmd, wCmdFlags); return(TRUE); } #ifdef REGLOAD return(TRUE); #else if(!CreateMainWindow()) return(FALSE); if(fOpenError) PostMessage(hWndMain, WM_COMMAND, ID_EXIT, 0L); else { ShowWindow(hWndMain, nCmdShow); UpdateWindow(hWndMain); } if(lpMessageFilter=MakeProcInstance(MessageFilter, hInstance)) lpOldHook = SetWindowsHook(WH_MSGFILTER, lpMessageFilter); hAcc = LoadAccelerators(hInstance, wCmdFlags&FLAG_VERBOSE ? szSDKRegEd : "RegEdit"); if (lpfnRegisterPenApp = (VOID (FAR PASCAL *)(WORD, BOOL))GetProcAddress(GetSystemMetrics(SM_PENWINDOWS), "RegisterPenApp")) (*lpfnRegisterPenApp)(1, TRUE); while(GetMessage(&msg, NULL, 0, 0)) { if(!hAcc || !TranslateAccelerator(hWndMain, hAcc, &msg)) { if(!hWndDlg || !IsDialogMessage(hWndDlg, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } if (lpfnRegisterPenApp) (*lpfnRegisterPenApp)(1, FALSE); if(lpMessageFilter) { UnhookWindowsHook(WH_MSGFILTER, lpMessageFilter); FreeProcInstance(lpMessageFilter); } return(msg.wParam); #endif }