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.

338 lines
8.2 KiB

  1. // wabappDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "wabapp.h"
  5. #include "wabappDlg.h"
  6. #include "caldlg.h"
  7. #include "webbrwsr.h"
  8. #include "wabobject.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. CWAB * g_pWAB;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CAboutDlg dialog used for App About
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20. CAboutDlg();
  21. // Dialog Data
  22. //{{AFX_DATA(CAboutDlg)
  23. enum { IDD = IDD_ABOUTBOX };
  24. //}}AFX_DATA
  25. // ClassWizard generated virtual function overrides
  26. //{{AFX_VIRTUAL(CAboutDlg)
  27. protected:
  28. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  29. //}}AFX_VIRTUAL
  30. // Implementation
  31. protected:
  32. //{{AFX_MSG(CAboutDlg)
  33. //}}AFX_MSG
  34. DECLARE_MESSAGE_MAP()
  35. };
  36. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CAboutDlg)
  39. //}}AFX_DATA_INIT
  40. }
  41. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CAboutDlg)
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  48. //{{AFX_MSG_MAP(CAboutDlg)
  49. // No message handlers
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CWabappDlg dialog
  54. CWabappDlg::CWabappDlg(CWnd* pParent /*=NULL*/)
  55. : CDialog(CWabappDlg::IDD, pParent)
  56. {
  57. //{{AFX_DATA_INIT(CWabappDlg)
  58. // NOTE: the ClassWizard will add member initialization here
  59. //}}AFX_DATA_INIT
  60. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  61. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  62. }
  63. void CWabappDlg::DoDataExchange(CDataExchange* pDX)
  64. {
  65. CDialog::DoDataExchange(pDX);
  66. //{{AFX_DATA_MAP(CWabappDlg)
  67. // NOTE: the ClassWizard will add DDX and DDV calls here
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CWabappDlg, CDialog)
  71. //{{AFX_MSG_MAP(CWabappDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_BN_CLICKED(IDC_BUTTON, OnBDayButtonClicked)
  76. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnItemchangedList)
  77. ON_BN_CLICKED(IDC_RADIO_DETAILS, OnRadioDetails)
  78. ON_BN_CLICKED(IDC_RADIO_PHONELIST, OnRadioPhonelist)
  79. ON_BN_CLICKED(IDC_RADIO_EMAILLIST, OnRadioEmaillist)
  80. ON_BN_CLICKED(IDC_RADIO_BIRTHDAYS, OnRadioBirthdays)
  81. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  82. //}}AFX_MSG_MAP
  83. END_MESSAGE_MAP()
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CWabappDlg message handlers
  86. BOOL CWabappDlg::OnInitDialog()
  87. {
  88. CDialog::OnInitDialog();
  89. // Add "About..." menu item to system menu.
  90. // IDM_ABOUTBOX must be in the system command range.
  91. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  92. ASSERT(IDM_ABOUTBOX < 0xF000);
  93. CMenu* pSysMenu = GetSystemMenu(FALSE);
  94. if (pSysMenu != NULL)
  95. {
  96. CString strAboutMenu;
  97. strAboutMenu.LoadString(IDS_ABOUTBOX);
  98. if (!strAboutMenu.IsEmpty())
  99. {
  100. pSysMenu->AppendMenu(MF_SEPARATOR);
  101. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  102. }
  103. }
  104. // Set the icon for this dialog. The framework does this automatically
  105. // when the application's main window is not a dialog
  106. SetIcon(m_hIcon, TRUE); // Set big icon
  107. SetIcon(m_hIcon, FALSE); // Set small icon
  108. // TODO: Add extra initialization here
  109. InitCommonControls();
  110. g_pWAB = new CWAB;
  111. CListCtrl * pListView = (CListCtrl *) GetDlgItem(IDC_LIST);
  112. g_pWAB->LoadWABContents(pListView);
  113. // select the first item in the list view
  114. pListView->SetItem(0,0,LVIF_STATE,NULL,0,LVNI_SELECTED,LVNI_SELECTED,NULL);
  115. // turn on the details button by default
  116. CButton * pButtonDetails = (CButton *) GetDlgItem(IDC_RADIO_DETAILS);
  117. pButtonDetails->SetCheck(BST_CHECKED);
  118. SendMessage(WM_COMMAND, (WPARAM) IDC_RADIO_DETAILS, 0);
  119. return TRUE; // return TRUE unless you set the focus to a control
  120. }
  121. void CWabappDlg::OnSysCommand(UINT nID, LPARAM lParam)
  122. {
  123. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  124. {
  125. CAboutDlg dlgAbout;
  126. dlgAbout.DoModal();
  127. }
  128. else
  129. {
  130. CDialog::OnSysCommand(nID, lParam);
  131. }
  132. }
  133. // If you add a minimize button to your dialog, you will need the code below
  134. // to draw the icon. For MFC applications using the document/view model,
  135. // this is automatically done for you by the framework.
  136. void CWabappDlg::OnPaint()
  137. {
  138. if (IsIconic())
  139. {
  140. CPaintDC dc(this); // device context for painting
  141. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  142. // Center icon in client rectangle
  143. int cxIcon = GetSystemMetrics(SM_CXICON);
  144. int cyIcon = GetSystemMetrics(SM_CYICON);
  145. CRect rect;
  146. GetClientRect(&rect);
  147. int x = (rect.Width() - cxIcon + 1) / 2;
  148. int y = (rect.Height() - cyIcon + 1) / 2;
  149. // Draw the icon
  150. dc.DrawIcon(x, y, m_hIcon);
  151. }
  152. else
  153. {
  154. CDialog::OnPaint();
  155. }
  156. }
  157. // The system calls this to obtain the cursor to display while the user drags
  158. // the minimized window.
  159. HCURSOR CWabappDlg::OnQueryDragIcon()
  160. {
  161. return (HCURSOR) m_hIcon;
  162. }
  163. void CWabappDlg::OnBDayButtonClicked()
  164. {
  165. CCalDlg CalDlg;
  166. CListCtrl * pListView = (CListCtrl *) GetDlgItem(IDC_LIST);
  167. int iItem = pListView->GetNextItem(-1, LVNI_SELECTED);
  168. if(iItem == -1)
  169. return;
  170. CalDlg.SetItemName(pListView->GetItemText(iItem, 0));
  171. SYSTEMTIME st={0};
  172. if(!g_pWAB->GetSelectedItemBirthday(pListView, &st))
  173. GetSystemTime(&st);
  174. CalDlg.SetDate(st);
  175. if(IDOK == CalDlg.DoModal())
  176. {
  177. CalDlg.GetDate(&st);
  178. g_pWAB->SetSelectedItemBirthday(pListView, st);
  179. }
  180. }
  181. BOOL CWabappDlg::DestroyWindow()
  182. {
  183. CListCtrl * pListView = (CListCtrl *) GetDlgItem(IDC_LIST);
  184. g_pWAB->ClearWABLVContents(pListView);
  185. delete g_pWAB;
  186. return CDialog::DestroyWindow();
  187. }
  188. void CWabappDlg::OnItemchangedList(NMHDR* pNMHDR, LRESULT* pResult)
  189. {
  190. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  191. // TODO: Add your control notification handler code here
  192. CListCtrl * pListView = (CListCtrl *) GetDlgItem(IDC_LIST);
  193. static int oldItem;
  194. int newItem = pListView->GetNextItem(-1, LVNI_SELECTED);
  195. if(newItem != oldItem && newItem != -1)
  196. {
  197. TCHAR szFileName[MAX_PATH];
  198. g_pWAB->CreateDetailsFileFromWAB(pListView, szFileName);
  199. if(lstrlen(szFileName))
  200. {
  201. CWebBrowser * pCWB = (CWebBrowser *) GetDlgItem(IDC_EXPLORER);
  202. pCWB->Navigate(szFileName, NULL, NULL, NULL, NULL);
  203. }
  204. oldItem = newItem;
  205. }
  206. *pResult = 0;
  207. }
  208. void CWabappDlg::OnRadioDetails()
  209. {
  210. g_pWAB->SetDetailsOn(TRUE);
  211. CListCtrl * pListView = (CListCtrl *) GetDlgItem(IDC_LIST);
  212. TCHAR szFileName[MAX_PATH];
  213. g_pWAB->CreateDetailsFileFromWAB(pListView, szFileName);
  214. if(lstrlen(szFileName))
  215. {
  216. CWebBrowser * pCWB = (CWebBrowser *) GetDlgItem(IDC_EXPLORER);
  217. pCWB->Navigate(szFileName, NULL, NULL, NULL, NULL);
  218. }
  219. }
  220. void CWabappDlg::OnRadioPhonelist()
  221. {
  222. TCHAR szFileName[MAX_PATH];
  223. g_pWAB->SetDetailsOn(FALSE);
  224. g_pWAB->CreatePhoneListFileFromWAB(szFileName);
  225. if(lstrlen(szFileName))
  226. {
  227. CWebBrowser * pCWB = (CWebBrowser *) GetDlgItem(IDC_EXPLORER);
  228. pCWB->Navigate(szFileName, NULL, NULL, NULL, NULL);
  229. }
  230. }
  231. void CWabappDlg::OnRadioEmaillist()
  232. {
  233. TCHAR szFileName[MAX_PATH];
  234. g_pWAB->SetDetailsOn(FALSE);
  235. g_pWAB->CreateEmailListFileFromWAB(szFileName);
  236. if(lstrlen(szFileName))
  237. {
  238. CWebBrowser * pCWB = (CWebBrowser *) GetDlgItem(IDC_EXPLORER);
  239. pCWB->Navigate(szFileName, NULL, NULL, NULL, NULL);
  240. }
  241. }
  242. void CWabappDlg::OnRadioBirthdays()
  243. {
  244. TCHAR szFileName[MAX_PATH];
  245. g_pWAB->SetDetailsOn(FALSE);
  246. g_pWAB->CreateBirthdayFileFromWAB(szFileName);
  247. if(lstrlen(szFileName))
  248. {
  249. CWebBrowser * pCWB = (CWebBrowser *) GetDlgItem(IDC_EXPLORER);
  250. pCWB->Navigate(szFileName, NULL, NULL, NULL, NULL);
  251. }
  252. }
  253. void CWabappDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  254. {
  255. CListCtrl * pListView = (CListCtrl *) GetDlgItem(IDC_LIST);
  256. g_pWAB->ShowSelectedItemDetails(m_hWnd, pListView);
  257. *pResult = 0;
  258. }