int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd = NULL; /* Dia's window */ LPWSTR *szArglist = NULL; int nArgs; int retval; int start_at = 1; char *filename_utf8 = NULL; char *filename_utf8_down = NULL; GError *error = NULL; /** * load registry setting if it's available */ LoadRegSettings(); /** * was anything found in the registry? */ gUseRegVal = (strlen(gszDiaExe) !=0); if (__argc < 2) { MessageBox(NULL, "Usage: dia-win-remote.exe [diaw.exe|dia.exe] [--integrated] file1 file2 ...", gszVersion, MB_ICONSTOP); return -1; } szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); if( NULL == szArglist ) { MessageBox(NULL, "CommandLineToArgvW failed\n", gszVersion, MB_ICONSTOP); return -1; } /** * Check if first argument is an executable. */ filename_utf8 = g_utf16_to_utf8(szArglist[1], -1, NULL, NULL, &error); if(error) { MessageBox(NULL, "Error converting to UTF-8!", gszVersion, MB_ICONEXCLAMATION); g_free(filename_utf8); LocalFree(szArglist); return -1; } filename_utf8_down = g_utf8_strdown(filename_utf8, -1); g_free(filename_utf8); if(g_pattern_match_simple("*.exe", filename_utf8_down)) start_at = 2; g_free(filename_utf8_down); /** * Can't just look for "Dia" as other languages use * different title text. Lets do this the hard way * and examine all the windows. */ EnumWindows(FindDiaWindow, (LPARAM)&hWnd); /** * Is Dia running? */ if (hWnd != NULL) { retval = DragAndDropDia(hWnd, nArgs, szArglist, start_at); } else { retval = LaunchDia(nArgs, szArglist, start_at); } LocalFree(szArglist); return retval; }
// // Entry-point for text-editor application // int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int iShowCmd) { MSG msg; HACCEL hAccel; TCHAR **argv; int argc; //TCHAR *pszCmdlineFile = 0; TCHAR arg[MAX_PATH]; // // get the first commandline argument // TCHAR *pszCmdline = GetArg(GetCommandLineW(), arg, MAX_PATH); argv = GetArgvCommandLine(&argc); // check if we have any options if(pszCmdline && *pszCmdline == '-') { pszCmdline = GetArg(pszCmdline, arg, MAX_PATH); // do the user-account-control thing if(lstrcmpi(arg, _T("-uac")) == 0) { //return 0; } // image-file-execute-options else if(lstrcmpi(arg, _T("-ifeo")) == 0) { // skip notepad.exe pszCmdline = GetArg(pszCmdline, arg, MAX_PATH); } // unrecognised option else { } } // has a prior instance elevated us to admin in order to // modify some system-wide settings in the registry? if(argv && argc == 4 && lstrcmpi(argv[1], _T("-uac")) == 0) { g_fAddToExplorer = _ttoi(argv[2]); g_fReplaceNotepad = _ttoi(argv[3]); if(SetExplorerContextMenu(g_fAddToExplorer) && SetImageFileExecutionOptions(g_fReplaceNotepad)) { SaveRegSysSettings(); return 0; } else { return ERROR_ACCESS_DENIED; } } // default to the built-in resources g_hResourceModule = hInst; OleInitialize(0); // initialize window classes InitMainWnd(); InitTextView(); LoadRegSettings(); // create the main window! g_hwndMain = CreateMainWnd(); // open file specified on commmand line if(pszCmdline && *pszCmdline) { // check to see if it's a quoted filename if(*pszCmdline == '\"') { GetArg(pszCmdline, arg, MAX_PATH); pszCmdline = arg; } NeatpadOpenFile(g_hwndMain, pszCmdline); LoadFileData(pszCmdline, g_hwndMain); } // automatically create new document if none specified else { PostMessage(g_hwndMain, WM_COMMAND, IDM_FILE_NEW, 0); } ApplyRegSettings(); ShowWindow(g_hwndMain, iShowCmd); // // load keyboard accelerator table // hAccel = LoadAccelerators(g_hResourceModule, MAKEINTRESOURCE(IDR_ACCELERATOR1)); // // message-loop // while(GetMessage(&msg, NULL, 0, 0) > 0) { if(!TranslateAccelerator(g_hwndMain, hAccel, &msg)) { if((!IsWindow(g_hwndSearchDlg) || !IsDialogMessage(g_hwndSearchDlg, &msg))) { TranslateMessage(&msg); DispatchMessage(&msg); } } } if(g_fSaveOnExit) SaveRegSettings(); OleUninitialize(); ExitProcess(0); return 0; }