Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.6 KiB

  1. #include <windows.h>
  2. #include <shellapi.h>
  3. #include <shlobj.h>
  4. #include <shlwapi.h>
  5. #include "resource.h"
  6. #define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
  7. HMODULE g_hInstance = NULL;
  8. LPTSTR g_pszFile = NULL;
  9. BOOL FormatMessageString(UINT idTemplate, LPTSTR pszStrOut, DWORD cchSize, ...)
  10. {
  11. BOOL fResult = FALSE;
  12. va_list vaParamList;
  13. TCHAR szFormat[512];
  14. if (LoadString(g_hInstance, idTemplate, szFormat, ARRAYSIZE(szFormat)))
  15. {
  16. va_start(vaParamList, cchSize);
  17. fResult = FormatMessage(FORMAT_MESSAGE_FROM_STRING, szFormat, 0, 0, pszStrOut, cchSize, &vaParamList);
  18. va_end(vaParamList);
  19. }
  20. return fResult;
  21. }
  22. INT_PTR QuickviewHackDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  23. {
  24. INT_PTR fReturn = FALSE;
  25. switch (uMsg)
  26. {
  27. case WM_INITDIALOG:
  28. {
  29. // Set the message
  30. TCHAR szMessage[512];
  31. BOOL fFormat = FormatMessageString(IDS_QUESTION, szMessage, ARRAYSIZE(szMessage), StrRChr(g_pszFile, NULL, TEXT('\\')) + 1);
  32. if (fFormat)
  33. {
  34. SetWindowText(GetDlgItem(hwnd, IDC_MESSAGE), szMessage);
  35. }
  36. // default focus
  37. fReturn = FALSE;
  38. }
  39. break;
  40. case WM_PAINT:
  41. {
  42. HDC hdcPaint = GetDC(hwnd);
  43. // Set the icon
  44. HICON hQuestionIcon = (HICON) LoadIcon(NULL, MAKEINTRESOURCE(IDI_QUESTION));
  45. DrawIcon(hdcPaint, 7, 7, hQuestionIcon);
  46. // Don't free the icon, its shared.
  47. ReleaseDC(hwnd, hdcPaint);
  48. }
  49. break;
  50. case WM_COMMAND:
  51. {
  52. switch ((UINT) LOWORD(wParam))
  53. {
  54. case IDYES:
  55. {
  56. SHELLEXECUTEINFO shexecinfo = {0};
  57. shexecinfo.cbSize = sizeof(shexecinfo);
  58. shexecinfo.lpVerb = TEXT("openas");
  59. shexecinfo.lpClass = TEXT("unknown");
  60. shexecinfo.nShow = SW_SHOWNORMAL;
  61. shexecinfo.fMask = SEE_MASK_CLASSNAME;
  62. shexecinfo.lpFile = g_pszFile;
  63. // This may take a while
  64. SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT)));
  65. ShellExecuteEx(&shexecinfo);
  66. }
  67. // Fall through
  68. case IDNO:
  69. EndDialog(hwnd, LOWORD(wParam));
  70. fReturn = TRUE;
  71. break;
  72. }
  73. break;
  74. }
  75. break;
  76. default:
  77. break;
  78. }
  79. return fReturn;
  80. }
  81. int _stdcall ModuleEntry(void)
  82. {
  83. UINT uiExit = 0;
  84. g_hInstance = GetModuleHandle(NULL);
  85. // The command-line looks like:
  86. // "quikview.exe" -v -f:"c:\blah\foo\doc.jpg"
  87. // We want to take the stuff between the two quotes at the end
  88. TCHAR szFile[MAX_PATH + 1];
  89. LPTSTR pszLastQuote = StrRChr(GetCommandLine(), NULL, TEXT('\"'));
  90. if (pszLastQuote)
  91. {
  92. LPTSTR pszSecondLastQuote = StrRChr(GetCommandLine(), pszLastQuote - 1, TEXT('\"'));
  93. if (pszSecondLastQuote)
  94. {
  95. StrCpyN(szFile, pszSecondLastQuote + 1, ARRAYSIZE(szFile));
  96. // Now find our last quote again
  97. pszLastQuote = StrRChr(szFile, NULL, TEXT('\"'));
  98. if (pszLastQuote)
  99. {
  100. *pszLastQuote = 0;
  101. // szFile now has what we want
  102. g_pszFile = szFile;
  103. DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_QVHACK), NULL,
  104. QuickviewHackDialogProc, 0);
  105. }
  106. }
  107. }
  108. ExitProcess(uiExit);
  109. return 0; // We never come here.
  110. }