MFC click to change the text addition timer scaling form, mfc Timer
1. Add the required control, Set ID: labNum1, txtNum1, txtNum2, txtNum3, and btnAdd, and convert labNum1 property to Y-> true (the control can send messages when clicked or double-clicked)
2. Double-click the labNum1 control and add the response function of labNum1. Click the text and switch the text.
Void CMFCTestDlg: OnStnClickedlabnum1 () {// TODO: add the control notification handler code CString labNum1Str; GetDlgItem (labNum1)-> GetWindowText (labNum1Str ); if (labNum1Str = TEXT ("Num1") {GetDlgItem (labNum1)-> SetWindowText (TEXT ("Number 1");} else {GetDlgItem (labNum1) -> SetWindowText (TEXT ("Num1 "));}}
3. Implement the addition Timer
① Add the variables m_num1, m_num2, and m_num3 for the controls respectively (you can set constraints if needed)
② Add a response function for btnAdd
Void CMFCTestDlg: OnBnClickedbtnadd () {// TODO: add the control notification handler code UpdateData () here; // call the environment variable m_num3 = m_num1 + m_num2; UpdateData (FALSE ); // update environment variable}
4. Form Scaling
① Add the control btnFlex and set the text to "Open> ". Add the control picSplit, set visible to false, and sunken to true (change the control style to a concave edge)
② Add Global static variables rectBig, rectSmall, rectSplit
static CRect rectBig;static CRect rectSmall;static CRect rectSlit;
③ Add the response code in OnInitDialog () in order to make the form appear after loading.
// TODO: add the additional initialization code GetWindowRect (& rectBig); GetDlgItem (picSplit)-> GetWindowRect (& rectSlit); rectSmall. top = rectBig. top; rectSmall. bottom = rectBig. bottom; rectSmall. left = rectBig. left; rectSmall. right = rectSlit. right; SetWindowPos (NULL, 0, 0, rectSmall. width (), rectSmall. height (), SWP_NOMOVE | SWP_NOZORDER );
④ Add a response function for btnSplit
Void CMFCTestDlg: OnBnClickedbtnflex () {// TODO: add the control notification handler code CString btnFlexStr; GetDlgItemText (btnFlex, btnFlexStr) here ); if (btnFlexStr = TEXT ("contract <") {SetDlgItemText (btnFlex, TEXT ("Open>"); SetWindowPos (NULL, 0, 0, rectSmall. width (), rectSmall. height (), SWP_NOMOVE | SWP_NOZORDER);} else {SetDlgItemText (btnFlex, TEXT ("contract <"); SetWindowPos (NULL, rectBig. width (), rectBig. height (), SWP_NOMOVE | SWP_NOZORDER );}}