MFC对话框操作及数据结构的巧妙运用

来源:互联网 发布:js只能输入正负整数 编辑:程序博客网 时间:2024/04/28 19:14

链表的巧妙用法:定义两个CButton类对象,类包含一个指向自己的指针,然后两个对象的指针分别指向对方,这样就行了一个CButton对象的链表。用心去观察你会发现MFC还多处用的数据结构的知识,你也会更加深入的了解它的工作机制。

属性表单程序源码下载地址:http://download.csdn.net/detail/weiyong1999/5163600

地址:MFC/WINDOW访问(设置)控件内容及句柄的常用的方法和自定义消息方法


void CTestdialog::OnAdd() {// TODO: Add your control notification handler code here/*if (m_flag==FALSE){m_btn.Create("新增按钮",BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD,CRect(0,0,100,100),this,123);m_flag=TRUE;}else{m_flag=FALSE;m_btn.DestroyWindow();}*/if (!m_btn.m_hWnd){m_btn.Create("新增按钮",BS_DEFPUSHBUTTON|WS_VISIBLE|WS_CHILD,CRect(0,0,100,100),this,123);}else{m_btn.DestroyWindow();}char ch[10]="dd";GetDlgItem(IDC_EDIT1)->SendMessage(WM_SETTEXT,10,(LPARAM)ch);//m_edit=99;//UpdateData(FALSE);}void CTestdialog::OnSet() {// TODO: Add your control notification handler code herestatic BOOL m_static=FALSE;static CRect largerect;static CRect smallrect;if (largerect.IsRectNull()){CRect tmp;GetWindowRect(&largerect);GetDlgItem(IDC_SEPARATOR)->GetWindowRect(tmp);smallrect.top=largerect.top;smallrect.left=largerect.left;smallrect.right=largerect.right;smallrect.bottom=tmp.bottom;}if(m_static==FALSE){SetWindowPos(NULL,0,0,smallrect.Width(),smallrect.Height(),SWP_NOMOVE|SWP_NOZORDER);m_static=TRUE;}else{SetWindowPos(NULL,0,0,largerect.Width(),largerect.Height(),SWP_NOMOVE|SWP_NOZORDER);m_static=FALSE;}}WNDPROC  wndproc;LRESULT CALLBACK WinEditproc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam){if (uMsg==WM_CHAR && wParam==0x0d){SetFocus(::GetNextWindow(hWnd,GW_HWNDNEXT));return 1;}else{return wndproc(hWnd,uMsg,wParam,lParam);}}BOOL CTestdialog::OnInitDialog() {CDialog::OnInitDialog();wndproc=(WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd,GWL_WNDPROC,(LONG)WinEditproc);// TODO: Add extra initialization herereturn TRUE;  // return TRUE unless you set the focus to a control              // EXCEPTION: OCX Property Pages should return FALSE}void CTestdialog::OnOK() {// TODO: Add extra validation here//GetNextDlgTabItem(GetFocus())->SetFocus();CDialog::OnOK();}


定义两个CButton类对象,类包含一个指向自己的指针,然后两个对象的指针分别指向对方,这样就行了一个CButton对象的链表。用心去观察你会发现MFC还多处用的数据结构的知识,你也会更加深入的了解它的工作机制。