Leaked source code of windows server 2003
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.

273 lines
7.1 KiB

  1. #include <windows.h>
  2. #include <commdlg.h>
  3. #include <stdio.h>
  4. #include <tchar.h>
  5. #include <shlobj.h>
  6. #include <shlobjp.h>
  7. #include <objbase.h>
  8. #include "prwiziid.h"
  9. #include "resource.h"
  10. #include <strsafe.h>
  11. const GUID CLSID_PrintPhotosWizard = {0x4c649c49, 0xc48f, 0x4222, {0x9a, 0x0d, 0xcb, 0xbf, 0x42, 0x31, 0x22, 0x1d}};
  12. const GUID CLSID_PrintPhotosDropTarget = {0x60fd46de, 0xf830, 0x4894, {0xa6, 0x28, 0x6f, 0xa8, 0x1b, 0xc0, 0x19, 0x0d}};
  13. const GUID IID_ISetWaitEventForTesting = {0xd61e2fe1, 0x4af8, 0x4dbd, {0xb8, 0xad, 0xe7, 0xe0, 0x7a, 0xdc, 0xf9, 0x0f}};
  14. #define ARRAYSIZE(x) (sizeof((x))/sizeof((x)[0]))
  15. HINSTANCE g_hInstance = NULL;
  16. INT CountItems( LPTSTR pString )
  17. {
  18. INT iCount = 0;
  19. if (pString && *pString)
  20. {
  21. do
  22. {
  23. do
  24. {
  25. pString++;
  26. }
  27. while ( *pString );
  28. pString++;
  29. iCount++;
  30. }
  31. while ( *pString );
  32. }
  33. return iCount;
  34. }
  35. void RunWizard(HWND hwndOwner)
  36. {
  37. #define BUFFER_SIZE 65535
  38. TCHAR szBuffer[BUFFER_SIZE];
  39. TCHAR szParent[MAX_PATH];
  40. TCHAR szChild[MAX_PATH];
  41. LPCITEMIDLIST aPidl[ 512 ];
  42. OPENFILENAME ofn;
  43. LPITEMIDLIST pidlParent = NULL, pidlFull = NULL, pidlItem = NULL;
  44. HRESULT hr;
  45. IDataObject *pdo = NULL;
  46. INT index = 0;
  47. ZeroMemory(szBuffer,BUFFER_SIZE);
  48. ZeroMemory(&ofn, sizeof(ofn));
  49. ZeroMemory(aPidl, sizeof(aPidl));
  50. //
  51. // launch the file common dialog so the user
  52. // can select what files to pre-populate the
  53. // the wizard with...
  54. //
  55. ofn.lStructSize = sizeof(ofn);
  56. ofn.hInstance = g_hInstance;
  57. ofn.hwndOwner = hwndOwner;
  58. ofn.lpstrFilter = TEXT("All Files\0*.*\0JPEG Files\0*.jpg;*.jpeg\0TIFF Files\0*.tif;*.tiff\0GIF Files\0*.gif\0Bitmap Files\0*.bmp\0PNG Files\0*.png\0DIB Files\0*.DIB\0EMF Files\0*.EMF\0WMF Files\0*.WMF\0Icon Files\0*.ICO\0\0\0\0");
  59. ofn.nFilterIndex = 1;
  60. ofn.lpstrFile = szBuffer;
  61. ofn.nMaxFile = BUFFER_SIZE;
  62. ofn.lpstrTitle = TEXT("Select files to populate Print Photos Wizard with!");
  63. ofn.Flags = OFN_ALLOWMULTISELECT | OFN_EXPLORER | OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST;
  64. if (GetOpenFileName( &ofn ))
  65. {
  66. INT iCount = CountItems( ofn.lpstrFile );
  67. if (iCount == 1)
  68. {
  69. hr = SHILCreateFromPath( ofn.lpstrFile, &pidlFull, NULL );
  70. if (SUCCEEDED(hr))
  71. {
  72. pidlItem = ILFindLastID( pidlFull );
  73. aPidl[index++] = ILClone( pidlItem );
  74. ILRemoveLastID( pidlFull );
  75. pidlParent = ILClone( pidlFull );
  76. ILFree( pidlFull );
  77. }
  78. }
  79. else if (iCount > 1)
  80. {
  81. LPTSTR pCur = ofn.lpstrFile;
  82. LPITEMIDLIST pidlTemp = NULL;
  83. LPITEMIDLIST pidlRel = NULL;
  84. StringCchCopy( szParent, ARRAYSIZE(szParent), pCur );
  85. pCur += (lstrlen(pCur) + 1);
  86. //
  87. // Create parent idlist
  88. //
  89. hr = SHILCreateFromPath( szParent, &pidlParent, NULL );
  90. //
  91. // move to first file...
  92. if (SUCCEEDED(hr) && pidlParent)
  93. {
  94. for ( ; pCur && (*pCur); pCur += (lstrlen(pCur)+1))
  95. {
  96. //
  97. // Now, walk through and create each child item...
  98. //
  99. StringCchCopy( szChild, ARRAYSIZE(szChild), szParent );
  100. StringCchCat( szChild, ARRAYSIZE(szChild), TEXT("\\") );
  101. StringCchCat( szChild, ARRAYSIZE(szChild), pCur );
  102. //
  103. // Create a pidl
  104. //
  105. hr = SHILCreateFromPath( szChild, &pidlTemp, NULL );
  106. if (SUCCEEDED(hr))
  107. {
  108. pidlRel = ILFindLastID( pidlTemp );
  109. aPidl[index++] = ILClone( pidlRel );
  110. ILFree( pidlTemp );
  111. }
  112. }
  113. }
  114. }
  115. else
  116. {
  117. TCHAR szError[1024];
  118. StringCchPrintf( szError, ARRAYSIZE(szError), TEXT("GetOpenFileName failed, Err=%d"), CommDlgExtendedError() );
  119. MessageBox( hwndOwner, szError, TEXT("Unit Test Error"), MB_OK | MB_ICONWARNING );
  120. }
  121. if (index)
  122. {
  123. //
  124. // If there's anything in the pidl array, then create dataobject
  125. //
  126. hr = SHCreateFileDataObject( pidlParent, index, aPidl, NULL, &pdo );
  127. if (SUCCEEDED(hr) && pdo)
  128. {
  129. IDropTarget * pdt = NULL;
  130. //
  131. // Got a data object, now start the wizard & do drop operation...
  132. //
  133. hr = CoCreateInstance( CLSID_PrintPhotosDropTarget, NULL, CLSCTX_INPROC_SERVER, IID_IDropTarget, (LPVOID *)&pdt );
  134. if (SUCCEEDED(hr) && pdt)
  135. {
  136. DWORD pdwEffect = DROPEFFECT_NONE;
  137. POINTL pt;
  138. pt.x = 0;
  139. pt.y = 0;
  140. hr = pdt->Drop( pdo, 0, pt, &pdwEffect );
  141. pdt->Release();
  142. }
  143. pdo->Release();
  144. }
  145. //
  146. // Free pidls from aPidl
  147. //
  148. if (pidlParent)
  149. {
  150. ILFree( pidlParent );
  151. }
  152. for (INT i=0; i<index; i++)
  153. {
  154. if (aPidl[i])
  155. {
  156. ILFree( (LPITEMIDLIST)aPidl[i] );
  157. }
  158. }
  159. }
  160. }
  161. else
  162. {
  163. TCHAR szError[1024];
  164. StringCchPrintf( szError, ARRAYSIZE(szError), TEXT("GetOpenFileName failed, Err=%d"), CommDlgExtendedError() );
  165. MessageBox( hwndOwner, szError, TEXT("Unit Test Error"), MB_OK | MB_ICONWARNING );
  166. }
  167. }
  168. INT_PTR CALLBACK TestDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  169. {
  170. switch( uMsg )
  171. {
  172. case WM_INITDIALOG:
  173. return TRUE;
  174. case WM_COMMAND:
  175. switch (LOWORD(wParam))
  176. {
  177. case IDOK:
  178. EndDialog( hDlg, 0 );
  179. break;
  180. case IDC_RUN_WIZARD:
  181. RunWizard(hDlg);
  182. break;
  183. }
  184. }
  185. return FALSE;
  186. }
  187. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  188. {
  189. TCHAR sz[ MAX_PATH ];
  190. INT_PTR res;
  191. CoInitializeEx( NULL, COINIT_APARTMENTTHREADED );
  192. g_hInstance = hInstance;
  193. res = DialogBox( hInstance, MAKEINTRESOURCE(IDD_PHOTOTST_DIALOG), NULL, TestDlgProc );
  194. if (res == -1)
  195. {
  196. StringCchPrintf( sz, ARRAYSIZE(sz), TEXT("DialogBox failed with GLE=%d"), GetLastError() );
  197. MessageBox( NULL, sz, TEXT("Unit Test Error"), MB_OK | MB_ICONWARNING );
  198. }
  199. CoUninitialize();
  200. }