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.

274 lines
7.0 KiB

  1. /******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 2000
  4. *
  5. * TITLE: Nameit.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: KeisukeT
  10. *
  11. * DATE: 27 Mar, 2000
  12. *
  13. * DESCRIPTION:
  14. * Device naming page of WIA class installer.
  15. *
  16. *
  17. *******************************************************************************/
  18. //
  19. // Precompiled header
  20. //
  21. #include "precomp.h"
  22. #pragma hdrstop
  23. //
  24. // Include
  25. //
  26. #include "nameit.h"
  27. //
  28. // Function
  29. //
  30. CNameDevicePage::CNameDevicePage(PINSTALLER_CONTEXT pInstallerContext) :
  31. CInstallWizardPage(pInstallerContext, NameTheDevice)
  32. {
  33. //
  34. // Set link to previous/next page. This page should show up.
  35. //
  36. m_uPreviousPage = IDD_DYNAWIZ_SELECT_NEXTPAGE;
  37. m_uNextPage = EmeraldCity;
  38. //
  39. // Initialize member.
  40. //
  41. m_pInstallerContext = pInstallerContext;
  42. }
  43. CNameDevicePage::~CNameDevicePage() {
  44. } // CNameDevicePage()
  45. BOOL
  46. CNameDevicePage::OnNotify(
  47. LPNMHDR lpnmh
  48. )
  49. {
  50. BOOL bRet;
  51. DWORD dwMessageId;
  52. DebugTrace(TRACE_PROC_ENTER,(("CNameDevicePage::OnNotify: Enter... \r\n")));
  53. //
  54. // Initialize local.
  55. //
  56. bRet = FALSE;
  57. dwMessageId = 0;
  58. //
  59. // Dispatch message.
  60. //
  61. switch(lpnmh->code){
  62. case PSN_KILLACTIVE:
  63. {
  64. CString csFriendlyName;
  65. DebugTrace(TRACE_STATUS,(("CNameDevicePage::OnNotify: PSN_KILLACTIVE.\r\n")));
  66. //
  67. // Dialog is about to disappear. Set FriendlyName.
  68. //
  69. if(NULL == m_pCDevice){
  70. DebugTrace(TRACE_WARNING,(("CNameDevicePage::OnNotify: WARNING!! CDevice doesn't exist.\r\n")));
  71. bRet = FALSE;
  72. goto OnNotify_return;
  73. }
  74. //
  75. // Get FriendlyName from text box.
  76. //
  77. csFriendlyName.GetContents(GetDlgItem(m_hwnd, DeviceFriendlyName));
  78. //
  79. // Check the FriendlyName only when user push 'NEXT'.
  80. //
  81. if(m_bNextButtonPushed){
  82. DWORD dwLength;
  83. //
  84. // Check length.
  85. //
  86. dwLength = lstrlen((LPCTSTR)csFriendlyName);
  87. if(0 == dwLength){
  88. dwMessageId = NoDeviceName;
  89. }
  90. if(dwLength > MAX_FRIENDLYNAME){
  91. dwMessageId = DeviceNameTooLong;
  92. }
  93. //
  94. // Check if it's unique.
  95. //
  96. if(!csFriendlyName.IsEmpty()){
  97. //
  98. // Acquire mutex to access name store.
  99. //
  100. if(ERROR_SUCCESS != m_pCDevice->AcquireInstallerMutex(MAX_MUTEXTIMEOUT)){ // it must be done at least in 60 sec.
  101. DebugTrace(TRACE_ERROR,("CNameDevicePage::OnNotify: ERROR!! Unable to acquire mutex in 60 sec.\r\n"));
  102. } // if(ERROR_SUCCESS != AcquireInstallerMutex(60000))
  103. //
  104. // Refresh current device list.
  105. //
  106. m_pCDevice->CollectNames();
  107. //
  108. // See if Friendly is unique.
  109. //
  110. if(!(m_pCDevice->IsFriendlyNameUnique((LPTSTR)csFriendlyName))){
  111. dwMessageId = DuplicateDeviceName;
  112. } // if(!(m_pCDevice->IsFriendlyNameUnique((LPTSTR)csFriendlyName)))
  113. } // if(!csFriendlyName.IsEmpty())
  114. //
  115. // If FriendlyName is invalid, show error MessageBox.
  116. //
  117. if(0 != dwMessageId){
  118. //
  119. // Select text box.
  120. //
  121. SendDlgItemMessage(m_hwnd,
  122. DeviceFriendlyName,
  123. EM_SETSEL,
  124. 0,
  125. MAKELPARAM(0, -1));
  126. SetFocus(GetDlgItem(m_hwnd, DeviceFriendlyName));
  127. //
  128. // Show error message box.
  129. //
  130. ShowInstallerMessage(dwMessageId);
  131. //
  132. // Don't leave this page.
  133. //
  134. SetWindowLongPtr(m_hwnd, DWLP_MSGRESULT, TRUE);
  135. bRet = TRUE;
  136. goto OnNotify_return;
  137. } else { // if(0 != dwMessageId)
  138. //
  139. // Set FriendlyName.
  140. //
  141. m_pCDevice->SetFriendlyName((LPTSTR)csFriendlyName);
  142. } // // if(0 != dwMessageId)
  143. } // else (m_bNextButtonPushed)
  144. //
  145. // Release mutex.
  146. //
  147. m_pCDevice->ReleaseInstallerMutex();
  148. //
  149. // Reset pCDevice.
  150. //
  151. m_pCDevice = NULL;
  152. bRet = TRUE;
  153. goto OnNotify_return;
  154. } // case PSN_KILLACTIVE
  155. case PSN_SETACTIVE:
  156. {
  157. DebugTrace(TRACE_STATUS,(("CNameDevicePage::OnNotify: PSN_SETACTIVE.\r\n")));
  158. //
  159. // Get current CDevice object;
  160. //
  161. m_pCDevice = (CDevice *)m_pInstallerContext->pDevice;
  162. if(NULL == m_pCDevice){
  163. DebugTrace(TRACE_ERROR, (("CNameDevicePage::OnNotify: ERROR!! CDevice is not created.\r\n")));
  164. }
  165. //
  166. // Show current friendly name.
  167. //
  168. SetDlgItemText(m_hwnd, DeviceFriendlyName, m_pCDevice->GetFriendlyName());
  169. //
  170. // Limit the text upto MAX_FRIENDLYNAME. (=64)
  171. //
  172. SendDlgItemMessage(m_hwnd, DeviceFriendlyName, EM_LIMITTEXT, MAX_FRIENDLYNAME, 0);
  173. //
  174. // If "PortSelect = no", then set previous page to device selection page.
  175. //
  176. if(PORTSELMODE_NORMAL != m_pCDevice->GetPortSelectMode())
  177. {
  178. m_uPreviousPage = IDD_DYNAWIZ_SELECTDEV_PAGE;
  179. } else {
  180. m_uPreviousPage = IDD_DYNAWIZ_SELECT_NEXTPAGE;
  181. }
  182. goto OnNotify_return;
  183. } // case PSN_SETACTIVE:
  184. } // switch(lpnmh->code)
  185. OnNotify_return:
  186. //
  187. // Release mutex. ReleaseInstallerMutex() will handle invalid handle also, so we can call anyway.
  188. //
  189. if(NULL != m_pCDevice){
  190. m_pCDevice->ReleaseInstallerMutex();
  191. } // if(NULL != m_pCDevice)
  192. DebugTrace(TRACE_PROC_LEAVE,(("CNameDevicePage::OnNotify: Leaving... Ret=0x%x.\r\n"), bRet));
  193. return bRet;
  194. } // CNameDevicePage::OnNotify()
  195. BOOL
  196. IsValidFriendlyName(
  197. LPSTR szFriendlyName
  198. )
  199. {
  200. return TRUE;
  201. } // IsValidFriendlyName()