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.

405 lines
13 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998
  4. *
  5. * TITLE: COMFIRST.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 9/28/1999
  12. *
  13. * DESCRIPTION: First wizard page for cameras
  14. *
  15. *******************************************************************************/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. #include "comfirst.h"
  19. #include <shlobj.h>
  20. #include "resource.h"
  21. #include "shellext.h"
  22. #include "wiatextc.h"
  23. #include "simcrack.h"
  24. #include "gwiaevnt.h"
  25. static int c_nMaxThumbnailWidth = 120;
  26. static int c_nMaxThumbnailHeight = 120;
  27. CCommonFirstPage::CCommonFirstPage( HWND hWnd )
  28. : m_hWnd(hWnd),
  29. m_pControllerWindow(NULL),
  30. m_bThumbnailsRequested(false),
  31. m_hBigTitleFont(NULL),
  32. m_nWiaEventMessage(RegisterWindowMessage(STR_WIAEVENT_NOTIFICATION_MESSAGE))
  33. {
  34. }
  35. CCommonFirstPage::~CCommonFirstPage(void)
  36. {
  37. m_hWnd = NULL;
  38. m_pControllerWindow = NULL;
  39. }
  40. LRESULT CCommonFirstPage::OnWizNext( WPARAM, LPARAM )
  41. {
  42. return 0;
  43. }
  44. LRESULT CCommonFirstPage::OnActivate( WPARAM wParam, LPARAM )
  45. {
  46. //
  47. // We also update on activate messages, because we can't set
  48. // wizard buttons when we are not the active process
  49. //
  50. if (WA_INACTIVE != wParam)
  51. {
  52. HandleImageCountChange(true);
  53. }
  54. return 0;
  55. }
  56. void CCommonFirstPage::HandleImageCountChange( bool bUpdateWizButtons )
  57. {
  58. //
  59. // How many items are available?
  60. //
  61. int nCount = m_pControllerWindow->m_WiaItemList.Count();
  62. //
  63. // Figure out which message and buttons to display
  64. //
  65. int nMessageResourceId = 0;
  66. int nButtons = 0;
  67. switch (m_pControllerWindow->m_DeviceTypeMode)
  68. {
  69. case CAcquisitionManagerControllerWindow::ScannerMode:
  70. nMessageResourceId = nCount ? IDS_FIRST_PAGE_INSTRUCTIONS_SCANNER : IDS_SCANNER_NO_IMAGES;
  71. nButtons = nCount ? PSWIZB_NEXT : 0;
  72. break;
  73. case CAcquisitionManagerControllerWindow::CameraMode:
  74. //
  75. // If we can take pictures, enable the next button and don't tell the user there are no images.
  76. //
  77. if (m_pControllerWindow->m_bTakePictureIsSupported)
  78. {
  79. nButtons = PSWIZB_NEXT;
  80. nMessageResourceId = IDS_FIRST_PAGE_INSTRUCTIONS_CAMERA;
  81. }
  82. else
  83. {
  84. nButtons = nCount ? PSWIZB_NEXT : 0;
  85. nMessageResourceId = nCount ? IDS_FIRST_PAGE_INSTRUCTIONS_CAMERA : IDS_CAMERA_NO_IMAGES;
  86. }
  87. break;
  88. case CAcquisitionManagerControllerWindow::VideoMode:
  89. nMessageResourceId = IDS_FIRST_PAGE_INSTRUCTIONS_VIDEO;
  90. nButtons = PSWIZB_NEXT;
  91. break;
  92. };
  93. //
  94. // Set the buttons
  95. //
  96. if (bUpdateWizButtons)
  97. {
  98. PropSheet_SetWizButtons( GetParent(m_hWnd), nButtons );
  99. }
  100. //
  101. // Set the message
  102. //
  103. CSimpleString( nMessageResourceId, g_hInstance ).SetWindowText( GetDlgItem( m_hWnd, IDC_FIRST_INSTRUCTIONS ) );
  104. }
  105. LRESULT CCommonFirstPage::OnSetActive( WPARAM, LPARAM )
  106. {
  107. WIA_PUSHFUNCTION(TEXT("CCommonFirstPage::OnSetActive"));
  108. //
  109. // Make sure we have a valid controller window
  110. //
  111. if (!m_pControllerWindow)
  112. {
  113. return -1;
  114. }
  115. HandleImageCountChange(true);
  116. //
  117. // We do want to exit on disconnect if we are on this page
  118. //
  119. m_pControllerWindow->m_OnDisconnect = CAcquisitionManagerControllerWindow::OnDisconnectGotoLastpage|CAcquisitionManagerControllerWindow::OnDisconnectFailDownload|CAcquisitionManagerControllerWindow::OnDisconnectFailUpload|CAcquisitionManagerControllerWindow::OnDisconnectFailDelete;
  120. //
  121. // Get the focus off the hyperlink control
  122. //
  123. if (GetDlgItem( m_hWnd, IDC_CAMFIRST_EXPLORE ))
  124. {
  125. PostMessage( m_hWnd, WM_NEXTDLGCTL, 0, 0 );
  126. }
  127. return 0;
  128. }
  129. LRESULT CCommonFirstPage::OnShowWindow( WPARAM, LPARAM )
  130. {
  131. if (!m_bThumbnailsRequested)
  132. {
  133. //
  134. // Request the thumbnails
  135. //
  136. m_pControllerWindow->DownloadAllThumbnails();
  137. //
  138. // Make sure we don't ask for the thumbnails again
  139. //
  140. m_bThumbnailsRequested = true;
  141. }
  142. return 0;
  143. }
  144. LRESULT CCommonFirstPage::OnInitDialog( WPARAM, LPARAM lParam )
  145. {
  146. WIA_PUSHFUNCTION(TEXT("CCommonFirstPage::OnInitDialog"));
  147. //
  148. // Make sure this starts out NULL
  149. //
  150. m_pControllerWindow = NULL;
  151. //
  152. // Get the PROPSHEETPAGE.lParam
  153. //
  154. PROPSHEETPAGE *pPropSheetPage = reinterpret_cast<PROPSHEETPAGE*>(lParam);
  155. if (pPropSheetPage)
  156. {
  157. m_pControllerWindow = reinterpret_cast<CAcquisitionManagerControllerWindow*>(pPropSheetPage->lParam);
  158. if (m_pControllerWindow)
  159. {
  160. m_pControllerWindow->m_WindowList.Add(m_hWnd);
  161. }
  162. }
  163. //
  164. // Bail out
  165. //
  166. if (!m_pControllerWindow)
  167. {
  168. EndDialog(m_hWnd,IDCANCEL);
  169. return -1;
  170. }
  171. //
  172. // Hide the explore camera link and label if this is one of those icky serial cameras or dv cameras
  173. //
  174. if (m_pControllerWindow->IsSerialCamera() || m_pControllerWindow->m_DeviceTypeMode==CAcquisitionManagerControllerWindow::VideoMode)
  175. {
  176. //
  177. // Hide the link
  178. //
  179. if (GetDlgItem( m_hWnd, IDC_CAMFIRST_EXPLORE ))
  180. {
  181. ShowWindow( GetDlgItem( m_hWnd, IDC_CAMFIRST_EXPLORE ), SW_HIDE );
  182. EnableWindow( GetDlgItem( m_hWnd, IDC_CAMFIRST_EXPLORE ), FALSE );
  183. }
  184. }
  185. //
  186. // Set the font size for the title and device name
  187. //
  188. m_hBigTitleFont = WiaUiUtil::CreateFontWithPointSizeFromWindow( GetDlgItem(m_hWnd,IDC_FIRST_TITLE), 14, false, false );
  189. if (m_hBigTitleFont)
  190. {
  191. SendDlgItemMessage( m_hWnd, IDC_FIRST_TITLE, WM_SETFONT, reinterpret_cast<WPARAM>(m_hBigTitleFont), MAKELPARAM(TRUE,0));
  192. }
  193. m_hBigDeviceFont = WiaUiUtil::ChangeFontFromWindow( GetDlgItem(m_hWnd,IDC_FIRST_DEVICE_NAME), 2 );
  194. if (m_hBigDeviceFont)
  195. {
  196. SendDlgItemMessage( m_hWnd, IDC_FIRST_DEVICE_NAME, WM_SETFONT, reinterpret_cast<WPARAM>(m_hBigDeviceFont), MAKELPARAM(TRUE,0));
  197. }
  198. WiaUiUtil::CenterWindow( GetParent(m_hWnd), NULL );
  199. //
  200. // Set the wizard's icon
  201. //
  202. if (m_pControllerWindow->m_hWizardIconSmall && m_pControllerWindow->m_hWizardIconBig)
  203. {
  204. SendMessage( GetParent(m_hWnd), WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(m_pControllerWindow->m_hWizardIconSmall) );
  205. SendMessage( GetParent(m_hWnd), WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(m_pControllerWindow->m_hWizardIconBig) );
  206. }
  207. //
  208. // Get the device name and truncate it to fit in the static control
  209. //
  210. CSimpleString strDeviceName = CSimpleStringConvert::NaturalString(m_pControllerWindow->m_strwDeviceName);
  211. strDeviceName = WiaUiUtil::FitTextInStaticWithEllipsis( strDeviceName, GetDlgItem( m_hWnd, IDC_FIRST_DEVICE_NAME ), DT_END_ELLIPSIS|DT_NOPREFIX );
  212. //
  213. // Set the text in the "device name" box
  214. //
  215. strDeviceName.SetWindowText( GetDlgItem( m_hWnd, IDC_FIRST_DEVICE_NAME ) );
  216. //
  217. // This only has to be done in one page.
  218. //
  219. m_pControllerWindow->SetMainWindowInSharedMemory( GetParent(m_hWnd) );
  220. //
  221. // If we have a parent window, center the wizard on it.
  222. //
  223. if (m_pControllerWindow->m_pEventParameters->hwndParent)
  224. {
  225. WiaUiUtil::CenterWindow( GetParent(m_hWnd), m_pControllerWindow->m_pEventParameters->hwndParent );
  226. }
  227. return 0;
  228. }
  229. LRESULT CCommonFirstPage::OnEventNotification( WPARAM, LPARAM lParam )
  230. {
  231. WIA_PUSHFUNCTION(TEXT("CCommonFirstPage::OnEventNotification"));
  232. CGenericWiaEventHandler::CEventMessage *pEventMessage = reinterpret_cast<CGenericWiaEventHandler::CEventMessage *>(lParam);
  233. if (pEventMessage)
  234. {
  235. if (pEventMessage->EventId() == WIA_EVENT_ITEM_CREATED || pEventMessage->EventId() == WIA_EVENT_ITEM_DELETED)
  236. {
  237. //
  238. // Only update controls if we are the active page
  239. //
  240. if (PropSheet_GetCurrentPageHwnd(GetParent(m_hWnd)) == m_hWnd)
  241. {
  242. //
  243. // Because of some weirdness in prsht.c when calling PSM_SETWIZBUTTONS,
  244. // we only want to call PSM_SETWIZBUTTONS when we are the foreground app,
  245. // so I try to figure out if our process owns the foreground window.
  246. // Assume we won't be updating the buttons
  247. //
  248. bool bUpdateWizButtons = false;
  249. //
  250. // Get the foreground window
  251. //
  252. HWND hForegroundWnd = GetForegroundWindow();
  253. if (hForegroundWnd)
  254. {
  255. //
  256. // Get the process id of the foreground window. If it is the
  257. // same process ID as ours, we will update the wizard buttons
  258. //
  259. DWORD dwProcessId = 0;
  260. GetWindowThreadProcessId(hForegroundWnd,&dwProcessId);
  261. if (dwProcessId == GetCurrentProcessId())
  262. {
  263. bUpdateWizButtons = true;
  264. }
  265. }
  266. //
  267. // Update the controls
  268. //
  269. HandleImageCountChange(bUpdateWizButtons);
  270. }
  271. }
  272. //
  273. // Don't delete the message, it is deleted in the controller window
  274. //
  275. }
  276. return 0;
  277. }
  278. LRESULT CCommonFirstPage::OnDestroy( WPARAM, LPARAM )
  279. {
  280. if (m_hBigTitleFont)
  281. {
  282. DeleteObject(m_hBigTitleFont);
  283. m_hBigTitleFont = NULL;
  284. }
  285. if (m_hBigDeviceFont)
  286. {
  287. DeleteObject(m_hBigDeviceFont);
  288. m_hBigDeviceFont = NULL;
  289. }
  290. return 0;
  291. }
  292. LRESULT CCommonFirstPage::OnHyperlinkClick( WPARAM, LPARAM lParam )
  293. {
  294. LRESULT lResult = FALSE;
  295. NMLINK *pNmLink = reinterpret_cast<NMLINK*>(lParam);
  296. if (pNmLink)
  297. {
  298. CWaitCursor wc;
  299. HRESULT hr = E_FAIL;
  300. CSimpleStringWide strwShellLocation;
  301. if (PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DPF_MOUNT_POINT, strwShellLocation ))
  302. {
  303. CSimpleString strShellLocation = CSimpleStringConvert::NaturalString(strwShellLocation);
  304. if (strShellLocation.Length())
  305. {
  306. SHELLEXECUTEINFO ShellExecuteInfo = {0};
  307. ShellExecuteInfo.cbSize = sizeof(ShellExecuteInfo);
  308. ShellExecuteInfo.hwnd = m_hWnd;
  309. ShellExecuteInfo.nShow = SW_SHOW;
  310. ShellExecuteInfo.lpVerb = TEXT("open");
  311. ShellExecuteInfo.lpFile = const_cast<LPTSTR>(strShellLocation.String());
  312. if (ShellExecuteEx( &ShellExecuteInfo ))
  313. {
  314. hr = S_OK;
  315. }
  316. else
  317. {
  318. hr = HRESULT_FROM_WIN32(GetLastError());
  319. WIA_PRINTHRESULT((hr,TEXT("ShellExecuteEx failed")));
  320. }
  321. }
  322. }
  323. else if (PropStorageHelpers::GetProperty( m_pControllerWindow->m_pWiaItemRoot, WIA_DIP_DEV_ID, strwShellLocation ) && strwShellLocation.Length())
  324. {
  325. hr = WiaUiUtil::ExploreWiaDevice(strwShellLocation);
  326. }
  327. if (!SUCCEEDED(hr))
  328. {
  329. MessageBox( m_hWnd, CSimpleString( IDS_UNABLE_OPEN_EXPLORER, g_hInstance ), CSimpleString( IDS_ERROR_TITLE, g_hInstance ), MB_ICONHAND );
  330. }
  331. }
  332. return lResult;
  333. }
  334. LRESULT CCommonFirstPage::OnNotify( WPARAM wParam, LPARAM lParam )
  335. {
  336. SC_BEGIN_NOTIFY_MESSAGE_HANDLERS()
  337. {
  338. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_WIZNEXT,OnWizNext);
  339. SC_HANDLE_NOTIFY_MESSAGE_CODE(PSN_SETACTIVE,OnSetActive);
  340. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(NM_RETURN,IDC_CAMFIRST_EXPLORE,OnHyperlinkClick);
  341. SC_HANDLE_NOTIFY_MESSAGE_CONTROL(NM_CLICK,IDC_CAMFIRST_EXPLORE,OnHyperlinkClick);
  342. }
  343. SC_END_NOTIFY_MESSAGE_HANDLERS();
  344. }
  345. INT_PTR CALLBACK CCommonFirstPage::DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  346. {
  347. SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CCommonFirstPage)
  348. {
  349. SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog );
  350. SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify );
  351. SC_HANDLE_DIALOG_MESSAGE( WM_SHOWWINDOW, OnShowWindow );
  352. SC_HANDLE_DIALOG_MESSAGE( WM_DESTROY, OnDestroy );
  353. SC_HANDLE_DIALOG_MESSAGE( WM_ACTIVATE, OnActivate );
  354. }
  355. SC_HANDLE_REGISTERED_DIALOG_MESSAGE( m_nWiaEventMessage, OnEventNotification );
  356. SC_END_DIALOG_MESSAGE_HANDLERS();
  357. }