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.

290 lines
7.2 KiB

  1. // Mqapitest.cpp : Defines the class behaviors for the application.
  2. //
  3. //=--------------------------------------------------------------------------=
  4. // Copyright 1997-1999 Microsoft Corporation. All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. #include "stdafx.h"
  12. #include "MQApitst.h"
  13. #include "MainFrm.h"
  14. #include "testDoc.h"
  15. #include "testView.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CTestApp
  23. BEGIN_MESSAGE_MAP(CTestApp, CWinApp)
  24. //{{AFX_MSG_MAP(CTestApp)
  25. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  26. // NOTE - the ClassWizard will add and remove mapping macros here.
  27. // DO NOT EDIT what you see in these blocks of generated code!
  28. //}}AFX_MSG_MAP
  29. // Standard file based document commands
  30. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  31. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CTestApp construction
  35. CTestApp::CTestApp()
  36. {
  37. // TODO: add construction code here,
  38. // Place all significant initialization in InitInstance
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // The one and only CTestApp object
  42. CTestApp theApp;
  43. /////////////////////////////////////////////////////////////////////////////
  44. // CTestApp initialization
  45. BOOL CTestApp::InitInstance()
  46. {
  47. //
  48. // This application should only be used when DS is enabled.
  49. // if we are in DS-disabled mode we should stop execution.
  50. //
  51. if (!IsDsEnabledLocaly())
  52. {
  53. ::MessageBox(NULL,"This application is not designed to run on DS-disabled mode configuration",NULL,MB_OK);
  54. exit(0);
  55. }
  56. //
  57. // Standard initialization
  58. // If you are not using these features and wish to reduce the size
  59. // of your final executable, you should remove from the following
  60. // the specific initialization routines you do not need.
  61. #ifdef _AFXDLL
  62. Enable3dControls(); // Call this when using MFC in a shared DLL
  63. #else
  64. Enable3dControlsStatic(); // Call this when linking to MFC statically
  65. #endif
  66. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  67. // Register the application's document templates. Document templates
  68. // serve as the connection between documents, frame windows and views.
  69. CSingleDocTemplate* pDocTemplate;
  70. pDocTemplate = new CSingleDocTemplate(
  71. IDR_MAINFRAME,
  72. RUNTIME_CLASS(CTestDoc),
  73. RUNTIME_CLASS(CMainFrame), // main SDI frame window
  74. RUNTIME_CLASS(CTestView));
  75. AddDocTemplate(pDocTemplate);
  76. // Parse command line for standard shell commands, DDE, file open
  77. CCommandLineInfo cmdInfo;
  78. ParseCommandLine(cmdInfo);
  79. // Dispatch commands specified on the command line
  80. if (!ProcessShellCommand(cmdInfo))
  81. return FALSE;
  82. return TRUE;
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CAboutDlg dialog used for App About
  86. class CAboutDlg : public CDialog
  87. {
  88. public:
  89. CAboutDlg();
  90. // Dialog Data
  91. //{{AFX_DATA(CAboutDlg)
  92. enum { IDD = IDD_ABOUTBOX };
  93. //}}AFX_DATA
  94. // ClassWizard generated virtual function overrides
  95. //{{AFX_VIRTUAL(CAboutDlg)
  96. protected:
  97. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  98. //}}AFX_VIRTUAL
  99. // Implementation
  100. protected:
  101. //{{AFX_MSG(CAboutDlg)
  102. // No message handlers
  103. //}}AFX_MSG
  104. DECLARE_MESSAGE_MAP()
  105. };
  106. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  107. {
  108. //{{AFX_DATA_INIT(CAboutDlg)
  109. //}}AFX_DATA_INIT
  110. }
  111. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  112. {
  113. CDialog::DoDataExchange(pDX);
  114. //{{AFX_DATA_MAP(CAboutDlg)
  115. //}}AFX_DATA_MAP
  116. }
  117. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  118. //{{AFX_MSG_MAP(CAboutDlg)
  119. // No message handlers
  120. //}}AFX_MSG_MAP
  121. END_MESSAGE_MAP()
  122. // App command to run the dialog
  123. void CTestApp::OnAppAbout()
  124. {
  125. CAboutDlg aboutDlg;
  126. aboutDlg.DoModal();
  127. }
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CTestApp commands
  130. //
  131. // Pointer to hold the main window pointer.
  132. //
  133. CWnd* pMainView;
  134. extern "C" void PrintToScreen(const TCHAR * Format, ...)
  135. {
  136. TCHAR szText[500];
  137. va_list l;
  138. static len = 0;
  139. //Format the string
  140. va_start(l, Format);
  141. #ifdef UNICODE
  142. vswprintf(szText, Format, l);
  143. #else
  144. vsprintf(szText, Format, l);
  145. #endif
  146. CEdit& rfMainEdit = ((CTestView*)pMainView)->GetEditCtrl();
  147. int i = rfMainEdit.GetLineCount();
  148. ((CTestView*)pMainView)->GetEditCtrl().SetSel(INT_MAX,INT_MAX);
  149. ((CTestView*)pMainView)->GetEditCtrl().ReplaceSel(szText);
  150. ((CTestView*)pMainView)->GetEditCtrl().ReplaceSel(TEXT("\r\n"));
  151. len += lstrlen(szText) + 2;
  152. ((CTestView*)pMainView)->GetDocument()->SetModifiedFlag(FALSE);
  153. }
  154. BOOL CTestApp::IsDsEnabledLocaly()
  155. /*++
  156. Routine Description:
  157. The rutine checked if the coomputer is DS -enabled/disabled
  158. Arguments:
  159. None
  160. Return Value:
  161. TRUE - DS - enabled.
  162. FALSE - DS - disabled.
  163. --*/
  164. {
  165. MQPRIVATEPROPS PrivateProps;
  166. QMPROPID aPropId[MAX_VAR];
  167. MQPROPVARIANT aPropVar[MAX_VAR];
  168. DWORD cProp;
  169. HRESULT hr;
  170. //
  171. // Prepare DS-enabled property.
  172. //
  173. cProp = 0;
  174. aPropId[cProp] = PROPID_PC_DS_ENABLED;
  175. aPropVar[cProp].vt = VT_NULL;
  176. ++cProp;
  177. //
  178. // Create a PRIVATEPROPS structure.
  179. //
  180. PrivateProps.cProp = cProp;
  181. PrivateProps.aPropID = aPropId;
  182. PrivateProps.aPropVar = aPropVar;
  183. PrivateProps.aStatus = NULL;
  184. //
  185. // Retrieve the information.
  186. //
  187. //
  188. // This code detect DS connection.
  189. // This code is designed to allow the sample to compile both on NT4 and Windows 2000.
  190. // The MQGetPrivateComputerInformation() function can be called directly
  191. // on Windows 2000.
  192. //
  193. HINSTANCE hMqrtLibrary = GetModuleHandle(TEXT("mqrt.dll"));
  194. ASSERT(hMqrtLibrary != NULL);
  195. typedef HRESULT (APIENTRY *MQGetPrivateComputerInformation_ROUTINE)(LPCWSTR , MQPRIVATEPROPS*);
  196. MQGetPrivateComputerInformation_ROUTINE pfMQGetPrivateComputerInformation =
  197. (MQGetPrivateComputerInformation_ROUTINE)GetProcAddress(hMqrtLibrary,
  198. "MQGetPrivateComputerInformation");
  199. if(pfMQGetPrivateComputerInformation == NULL)
  200. {
  201. //
  202. // There is no entry point in the dll matching to this routine
  203. // it must be an old version of mqrt.dll -> product one.
  204. // It will be OK to handle this case as a case of DS-enabled mode.
  205. //
  206. return TRUE;
  207. }
  208. hr = pfMQGetPrivateComputerInformation(
  209. NULL,
  210. &PrivateProps);
  211. if(FAILED(hr))
  212. {
  213. //
  214. // we were not able to determine if DS is enabled or disabled
  215. // notify the user and assume the worst case - (i.e. we are DS-disasbled).
  216. //
  217. AfxMessageBox("Unable to detect DS connection");
  218. return FALSE;
  219. }
  220. if(PrivateProps.aPropVar[0].boolVal == 0)
  221. {
  222. //
  223. // DS-disabled.
  224. //
  225. return FALSE;
  226. }
  227. return TRUE;
  228. }