TESTDlg.cpp
上传用户:weisheen
上传日期:2022-07-09
资源大小:19390k
文件大小:6k
源码类别:

ActiveX/DCOM/ATL

开发平台:

Visual C++

  1. // TESTDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "TEST.h"
  5. #include "TESTDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. // No message handlers
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CTESTDlg dialog
  50. CTESTDlg::CTESTDlg(CWnd* pParent /*=NULL*/)
  51. : CDialog(CTESTDlg::IDD, pParent)
  52. {
  53. //{{AFX_DATA_INIT(CTESTDlg)
  54. // NOTE: the ClassWizard will add member initialization here
  55. //}}AFX_DATA_INIT
  56. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  57. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  58. }
  59. void CTESTDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialog::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CTESTDlg)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CTESTDlg, CDialog)
  67. //{{AFX_MSG_MAP(CTESTDlg)
  68. ON_WM_SYSCOMMAND()
  69. ON_WM_PAINT()
  70. ON_WM_QUERYDRAGICON()
  71. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  72. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  73. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CTESTDlg message handlers
  78. BOOL CTESTDlg::OnInitDialog()
  79. {
  80. CDialog::OnInitDialog();
  81. // Add "About..." menu item to system menu.
  82. // IDM_ABOUTBOX must be in the system command range.
  83. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  84. ASSERT(IDM_ABOUTBOX < 0xF000);
  85. CMenu* pSysMenu = GetSystemMenu(FALSE);
  86. if (pSysMenu != NULL)
  87. {
  88. CString strAboutMenu;
  89. strAboutMenu.LoadString(IDS_ABOUTBOX);
  90. if (!strAboutMenu.IsEmpty())
  91. {
  92. pSysMenu->AppendMenu(MF_SEPARATOR);
  93. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  94. }
  95. }
  96. // Set the icon for this dialog.  The framework does this automatically
  97. //  when the application's main window is not a dialog
  98. SetIcon(m_hIcon, TRUE); // Set big icon
  99. SetIcon(m_hIcon, FALSE); // Set small icon
  100. // TODO: Add extra initialization here
  101. return TRUE;  // return TRUE  unless you set the focus to a control
  102. }
  103. void CTESTDlg::OnSysCommand(UINT nID, LPARAM lParam)
  104. {
  105. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  106. {
  107. CAboutDlg dlgAbout;
  108. dlgAbout.DoModal();
  109. }
  110. else
  111. {
  112. CDialog::OnSysCommand(nID, lParam);
  113. }
  114. }
  115. // If you add a minimize button to your dialog, you will need the code below
  116. //  to draw the icon.  For MFC applications using the document/view model,
  117. //  this is automatically done for you by the framework.
  118. void CTESTDlg::OnPaint() 
  119. {
  120. if (IsIconic())
  121. {
  122. CPaintDC dc(this); // device context for painting
  123. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  124. // Center icon in client rectangle
  125. int cxIcon = GetSystemMetrics(SM_CXICON);
  126. int cyIcon = GetSystemMetrics(SM_CYICON);
  127. CRect rect;
  128. GetClientRect(&rect);
  129. int x = (rect.Width() - cxIcon + 1) / 2;
  130. int y = (rect.Height() - cyIcon + 1) / 2;
  131. // Draw the icon
  132. dc.DrawIcon(x, y, m_hIcon);
  133. }
  134. else
  135. {
  136. CDialog::OnPaint();
  137. }
  138. }
  139. // The system calls this to obtain the cursor to display while the user drags
  140. //  the minimized window.
  141. HCURSOR CTESTDlg::OnQueryDragIcon()
  142. {
  143. return (HCURSOR) m_hIcon;
  144. }
  145. #include "../BooksDAL.h"
  146. #include "../BooksDAL_i.c"
  147. #include <atlbase.h>
  148. #include <comdef.h>
  149. void CTESTDlg::OnButton1() 
  150. {
  151. // TODO: Add your control notification handler code here
  152. ::CoInitialize(NULL);
  153. CComPtr<IDALMyBools> mytools;
  154. mytools.CoCreateInstance(CLSID_DALMyBools);
  155. DTOBook* pData=NULL;
  156. mytools->put_PWD(_bstr_t("csd0910"));
  157. mytools->put_UID(_bstr_t("csd0910"));
  158. mytools->put_DataSource(_bstr_t("lisongtao"));
  159. mytools->GetBookByIsbn(123457,&pData);
  160. UINT iResult=0;
  161. mytools->DeleteBookById(123457,&iResult);
  162. }
  163. void CTESTDlg::OnButton2() 
  164. {
  165. // TODO: Add your control notification handler code here
  166. DTOBook* bt=new DTOBook();
  167. bt->BookAuthor=::SysAllocString(L"wangwu");
  168. bt->BookName=::SysAllocString(L"asp");
  169. bt->BookIsnb=123468;
  170. ::CoInitialize(NULL);
  171. CComPtr<IDALMyBools> mytools;
  172. mytools.CoCreateInstance(CLSID_DALMyBools);
  173. mytools->put_PWD(_bstr_t("csd0910"));
  174. mytools->put_UID(_bstr_t("csd0910"));
  175. mytools->put_DataSource(_bstr_t("lisongtao"));
  176. UINT iResult=0;
  177. mytools->SaveBook(bt,&iResult);
  178. }
  179. void CTESTDlg::OnButton3() 
  180. {
  181. // TODO: Add your control notification handler code here
  182. ::CoInitialize(NULL);
  183. CComPtr<IDALMyBools> mytools;
  184. mytools.CoCreateInstance(CLSID_DALMyBools);
  185. mytools->put_PWD(_bstr_t("tiger"));
  186. mytools->put_UID(_bstr_t("scott"));
  187. mytools->put_DataSource(_bstr_t("tarena"));
  188. DTOBook* pData=NULL;
  189. UINT iSize=0;
  190. mytools->QueryAllBook(&pData,&iSize);
  191. for(int i=0;i<iSize;i++)
  192. {
  193. MessageBox(CString((pData+i)->BookName));
  194. }
  195. ::CoTaskMemFree(pData);
  196. }