ChiToLetterDlg.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // ChiToLetterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ChiToLetter.h"
  5. #include "ChiToLetterDlg.h"
  6. #include "MyChiToLetter.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CChiToLetterDlg dialog
  51. CChiToLetterDlg::CChiToLetterDlg(CWnd* pParent /*=NULL*/)
  52. : CDialog(CChiToLetterDlg::IDD, pParent)
  53. {
  54. //{{AFX_DATA_INIT(CChiToLetterDlg)
  55. // NOTE: the ClassWizard will add member initialization here
  56. //}}AFX_DATA_INIT
  57. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  58. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  59. }
  60. void CChiToLetterDlg::DoDataExchange(CDataExchange* pDX)
  61. {
  62. CDialog::DoDataExchange(pDX);
  63. //{{AFX_DATA_MAP(CChiToLetterDlg)
  64. // NOTE: the ClassWizard will add DDX and DDV calls here
  65. //}}AFX_DATA_MAP
  66. }
  67. BEGIN_MESSAGE_MAP(CChiToLetterDlg, CDialog)
  68. //{{AFX_MSG_MAP(CChiToLetterDlg)
  69. ON_WM_SYSCOMMAND()
  70. ON_WM_PAINT()
  71. ON_WM_QUERYDRAGICON()
  72. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  73. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  74. //}}AFX_MSG_MAP
  75. END_MESSAGE_MAP()
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CChiToLetterDlg message handlers
  78. BOOL CChiToLetterDlg::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. CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO1);
  102. return TRUE; // return TRUE unless you set the focus to a control
  103. }
  104. void CChiToLetterDlg::OnSysCommand(UINT nID, LPARAM lParam)
  105. {
  106. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  107. {
  108. CAboutDlg dlgAbout;
  109. dlgAbout.DoModal();
  110. }
  111. else
  112. {
  113. CDialog::OnSysCommand(nID, lParam);
  114. }
  115. }
  116. // If you add a minimize button to your dialog, you will need the code below
  117. // to draw the icon. For MFC applications using the document/view model,
  118. // this is automatically done for you by the framework.
  119. void CChiToLetterDlg::OnPaint()
  120. {
  121. if (IsIconic())
  122. {
  123. CPaintDC dc(this); // device context for painting
  124. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  125. // Center icon in client rectangle
  126. int cxIcon = GetSystemMetrics(SM_CXICON);
  127. int cyIcon = GetSystemMetrics(SM_CYICON);
  128. CRect rect;
  129. GetClientRect(&rect);
  130. int x = (rect.Width() - cxIcon + 1) / 2;
  131. int y = (rect.Height() - cyIcon + 1) / 2;
  132. // Draw the icon
  133. dc.DrawIcon(x, y, m_hIcon);
  134. }
  135. else
  136. {
  137. CDialog::OnPaint();
  138. }
  139. }
  140. // The system calls this to obtain the cursor to display while the user drags
  141. // the minimized window.
  142. HCURSOR CChiToLetterDlg::OnQueryDragIcon()
  143. {
  144. return (HCURSOR) m_hIcon;
  145. }
  146. void CChiToLetterDlg::OnOK()
  147. {
  148. if(GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2)==IDC_RADIO1)
  149. Func(TRUE);
  150. else
  151. Func(FALSE);
  152. }
  153. void CChiToLetterDlg::OnRadio1()
  154. {
  155. // TODO: Add your control notification handler code here
  156. if(GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2)==IDC_RADIO1)
  157. Func(TRUE);
  158. }
  159. void CChiToLetterDlg::OnRadio2()
  160. {
  161. // TODO: Add your control notification handler code here
  162. if(GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO2)==IDC_RADIO2)
  163. Func(FALSE);
  164. }
  165. void CChiToLetterDlg::Func(BOOL blnEnd)
  166. {
  167. // TODO: Add extra validation here
  168. CMyChiToLetter MyLetter;
  169. CString strText,strLetter;
  170. GetDlgItem(IDC_EDIT1)->GetWindowText(strText);
  171. if(strText!="")
  172. {
  173. MyLetter.m_LetterEnd=blnEnd;
  174. //默认为全部大写
  175. strLetter=MyLetter.GetLetter(strText);
  176. GetDlgItem(IDC_EDIT2)->SetWindowText(strLetter);
  177. //全部小写
  178. MyLetter.m_blnSimaple=FALSE;
  179. MyLetter.m_blnAllBiG=FALSE;
  180. MyLetter.m_blnFirstBig=FALSE;
  181. strLetter=MyLetter.GetLetter(strText);
  182. GetDlgItem(IDC_EDIT3)->SetWindowText(strLetter);
  183. //首字母大写
  184. MyLetter.m_blnSimaple=FALSE;
  185. MyLetter.m_blnAllBiG=FALSE;
  186. MyLetter.m_blnFirstBig=TRUE;
  187. strLetter=MyLetter.GetLetter(strText);
  188. GetDlgItem(IDC_EDIT4)->SetWindowText(strLetter);
  189. //只返回大写首字母
  190. MyLetter.m_blnFirstBig=TRUE;
  191. MyLetter.m_blnAllBiG=FALSE;
  192. MyLetter.m_blnSimaple=TRUE;
  193. strLetter=MyLetter.GetLetter(strText);
  194. GetDlgItem(IDC_EDIT5)->SetWindowText(strLetter);
  195. //返回小写首字母
  196. MyLetter.m_blnAllBiG=FALSE;
  197. MyLetter.m_blnSimaple=TRUE;
  198. MyLetter.m_blnFirstBig=FALSE;
  199. strLetter=MyLetter.GetLetter(strText);
  200. GetDlgItem(IDC_EDIT6)->SetWindowText(strLetter);
  201. }
  202. }