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.

237 lines
6.8 KiB

  1. ///////////////////
  2. // (C) COPYRIGHT MICROSOFT CORP., 1998-1999
  3. //
  4. // FILE: SHELLEXT.CPP
  5. //
  6. // DESCRIPTION: Implements IContextMenu and IShellPropSheetExt interfaces for
  7. // the WIA Sample Scanner device
  8. //
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. // Define a language-independent name for our menu verb
  12. static const CHAR g_PathVerbA[] = "Press Scan Button";
  13. static const WCHAR g_PathVerbW[] = L"Press Scan Button";
  14. CShellExt :: CShellExt ()
  15. {
  16. Trace(TEXT("CShellExt Constructor"));
  17. }
  18. CShellExt::~CShellExt ()
  19. {
  20. Trace(TEXT("CShellExt Destructor"));
  21. }
  22. /*****************************************************************************
  23. CShellExt::Initialize
  24. Called by the shell when the user invokes context menu or property sheet for
  25. one of our items. For context menus the dataobject may include more than one
  26. selected item.
  27. ******************************************************************************/
  28. STDMETHODIMP CShellExt::Initialize (LPCITEMIDLIST pidlFolder,
  29. LPDATAOBJECT lpdobj,
  30. HKEY hkeyProgID)
  31. {
  32. Trace(TEXT("CShellExt::Initialize Called"));
  33. LONG lType = 0;
  34. HRESULT hr = NOERROR;
  35. if (!lpdobj) {
  36. return E_INVALIDARG;
  37. }
  38. // For singular selections, the WIA namespace should always provide a
  39. // dataobject that also supports IWiaItem
  40. if (FAILED(lpdobj->QueryInterface (IID_IWiaItem, reinterpret_cast<LPVOID*>(&m_pItem)))) {
  41. // failing that, get the list of selected items from the data object
  42. UINT uItems = 0;
  43. LPWSTR szName = NULL;
  44. LPWSTR szToken = NULL;
  45. szName = GetNamesFromDataObject (lpdobj, &uItems);
  46. //
  47. // we only support singular objects
  48. //
  49. if (uItems != 1) {
  50. hr = E_FAIL;
  51. } else {
  52. //
  53. // The name is of this format: <device id>::<item name>
  54. //
  55. LPWSTR szToken = wcstok (szName, L":");
  56. if (!szToken) {
  57. hr = E_FAIL;
  58. }
  59. //
  60. // Our extension only supports root items, so make sure there's no item
  61. // name
  62. //
  63. else if (wcstok (NULL, L":")) {
  64. hr = E_FAIL;
  65. } else {
  66. hr = CreateDeviceFromId (szToken, &m_pItem);
  67. }
  68. }
  69. if (szName) {
  70. delete [] szName;
  71. }
  72. }
  73. if (SUCCEEDED(hr)) {
  74. m_pItem->GetItemType (&lType);
  75. if (!(lType & WiaItemTypeRoot)) {
  76. hr = E_FAIL; // we only support changing the property on the root item
  77. }
  78. }
  79. return hr;
  80. }
  81. /*****************************************************************************
  82. CShellExt::QueryContextMenu
  83. Called by the shell to get our context menu strings for the selected item.
  84. ******************************************************************************/
  85. STDMETHODIMP CShellExt::QueryContextMenu (HMENU hmenu,UINT indexMenu,UINT idCmdFirst,UINT idCmdLast,UINT uFlags)
  86. {
  87. Trace(TEXT("CShellExt::QueryContextMenu Called"));
  88. Trace(TEXT("indexMenu = %d"),indexMenu);
  89. Trace(TEXT("idCmdFirst = %d"),idCmdFirst);
  90. Trace(TEXT("idCmdLast = %d"),idCmdLast);
  91. Trace(TEXT("uFlags = %d"),uFlags);
  92. HRESULT hr = S_OK;
  93. MENUITEMINFO mii;
  94. TCHAR szMenuItemName[MAX_PATH];
  95. memset(&mii,0,sizeof(mii));
  96. LoadString (g_hInst,IDS_PRESS_FAXBUTTON, szMenuItemName, MAX_PATH);
  97. mii.cbSize = sizeof(mii);
  98. mii.fMask = MIIM_STRING | MIIM_ID;
  99. mii.fState = MFS_ENABLED;
  100. mii.wID = idCmdFirst;
  101. mii.dwTypeData = szMenuItemName;
  102. if (InsertMenuItem (hmenu, indexMenu, TRUE, &mii)) {
  103. m_FaxButtonidCmd = 0;
  104. memset(&mii,0,sizeof(mii));
  105. LoadString (g_hInst, IDS_PRESS_COPYBUTTON, szMenuItemName, MAX_PATH);
  106. mii.cbSize = sizeof(mii);
  107. mii.fMask = MIIM_STRING | MIIM_ID;
  108. mii.fState = MFS_ENABLED;
  109. mii.wID = idCmdFirst;
  110. mii.dwTypeData = szMenuItemName;
  111. if (InsertMenuItem (hmenu, indexMenu, TRUE, &mii)) {
  112. m_CopyButtonidCmd = 1;
  113. memset(&mii,0,sizeof(mii));
  114. LoadString (g_hInst, IDS_PRESS_SCANBUTTON, szMenuItemName, MAX_PATH);
  115. mii.cbSize = sizeof(mii);
  116. mii.fMask = MIIM_STRING | MIIM_ID;
  117. mii.fState = MFS_ENABLED;
  118. mii.wID = idCmdFirst;
  119. mii.dwTypeData = szMenuItemName;
  120. if (InsertMenuItem (hmenu, indexMenu, TRUE, &mii)) {
  121. m_ScanButtonidCmd = 2;
  122. return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 1);
  123. }
  124. }
  125. }
  126. return hr;
  127. }
  128. /*****************************************************************************
  129. CShellExt::InvokeCommand
  130. Called by the shell when the user clicks one of our menu items
  131. ******************************************************************************/
  132. STDMETHODIMP CShellExt::InvokeCommand (LPCMINVOKECOMMANDINFO lpici)
  133. {
  134. Trace(TEXT("CShellExt::InvokeCommand Called"));
  135. HRESULT hr = S_OK;
  136. UINT_PTR idCmd = reinterpret_cast<UINT_PTR>(lpici->lpVerb);
  137. if(idCmd == 0){
  138. //
  139. // it's one of ours
  140. //
  141. MessageBox(NULL,TEXT("Context menu is Selected"),TEXT("Context Menu Verb Alert!"),MB_OK);
  142. } else {
  143. hr = E_FAIL;
  144. }
  145. return hr;
  146. }
  147. /*****************************************************************************
  148. CShellExt::GetCommandString
  149. Called by the shell to get our language independent verb name.
  150. ******************************************************************************/
  151. STDMETHODIMP CShellExt::GetCommandString (UINT_PTR idCmd, UINT uType,UINT* pwReserved,LPSTR pszName,UINT cchMax)
  152. {
  153. Trace(TEXT("CShellExt::GetCommandString Called"));
  154. HRESULT hr = S_OK;
  155. if(idCmd == m_ScanButtonidCmd){
  156. } else if(idCmd == m_CopyButtonidCmd){
  157. } else if(idCmd == m_FaxButtonidCmd){
  158. } else {
  159. hr = E_FAIL;
  160. }
  161. if(FAILED(hr)){
  162. return hr;
  163. }
  164. switch (uType) {
  165. case GCS_VALIDATEA:
  166. if (pszName) {
  167. lstrcpyA (pszName, g_PathVerbA);
  168. }
  169. break;
  170. case GCS_VALIDATEW:
  171. if (pszName) {
  172. lstrcpyW (reinterpret_cast<LPWSTR>(pszName), g_PathVerbW);
  173. }
  174. break;
  175. case GCS_VERBA:
  176. lstrcpyA (pszName, g_PathVerbA);
  177. break;
  178. case GCS_VERBW:
  179. lstrcpyW (reinterpret_cast<LPWSTR>(pszName), g_PathVerbW);
  180. break;
  181. default:
  182. hr = E_FAIL;
  183. break;
  184. }
  185. return hr;
  186. }