孙鑫MFC笔记(7)--对话框编程

孙鑫MFC笔记(7)--对话框编程

 

1. Insert -->Resource --->Dialog------>New 新建一个对话框

2.在VC++ 中,一个窗口与一个C++ 类进行关联,对话框的基类为CDialog 类,对话框分为模态对话框与非模态对话框,模态对话框在应用程序能进行其它操作之前必须关闭,非模态的对话框允许不关闭对话框而进行应用程序操作.

MSDN的说明:

This class is the base class used for displaying dialog boxes on the screen. Dialog boxes are of two types: modal and modeless. A modal dialog box must be closed by the user before the application continues. A modeless dialog box allows the user to display the dialog box and return to another task without canceling or removing the dialog box.

3.确定选中新学添加的对话框,View ---> ClassWizard 创建一个基于CDialog 的类与本对话框关联,输入类名,文件名,基类名,对话框ID , 此时,我们在工程中添加了一个类

4.对话框的创建

a.模态对话框:DoModal()  //Calls a modal dialog box and returns when done.

//Return Value:An int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred, in which case the Output window will contain error information from GetLastError.

b.非模态对话框:

CTestDialog *pDlg=new CTestDialog();
 pDlg->Create(IDD_DIALOG1,this);
 pDlg->ShowWindow(SW_SHOW);

virtual BOOL Create(
   UINT nIDTemplate,  //对话框ID号
   CWnd* pParentWnd = NULL   //对话框父窗口C++对象指针
); //Initializes the CDialog object. Creates a modeless dialog box and attaches it to the CDialog object.

BOOL ShowWindow(int nCmdShow ); //Sets the visibility state of the window

NOTE:

非模态对话框要覆盖其基类的OnOk()函数 ,在MSDN中的说明: If you implement the OK button in a modeless dialog box, you must override the OnOK member function and call DestroyWindow from within it. Don't call the base-class member function, because it calls EndDialog, which makes the dialog box invisible but does not destroy it.

5.创建动态按钮:

CButton m_btn;
...........
if(!m_btn.m_hWnd)  //如果没有创建
 {
  m_btn.Create("Mickor.Guo",BS_DEFPUSHBUTTON |WS_CHILD|WS_VISIBLE,
   CRect(0,10,100,30),this,123);
 }
 else
 {
  m_btn.DestroyWindow();  //消毁窗口
 }

NOTE:

virtual BOOL CButton::Create(
   LPCTSTR lpszCaption,    //Specifies the button control's text.  按钮文本
   DWORD dwStyle,  //按钮样式  Specifies the button control's style. Apply any combination of button styles to the button.
   const RECT& rect,  //按钮位置与大小  Specifies the button control's size and position.
   CWnd* pParentWnd,  //父窗口指针
   UINT nID   //按钮ID
);  //Creates the Windows button control and attaches it to the CButton object.

6.静态文本框编程:

CString str;
 if(GetDlgItem(IDC_NUMBER1)->GetWindowText(str),str=="Number1")
 {
  GetDlgItem(IDC_NUMBER1)->SetWindowText("数字1");
 }

NOTE:

a.   CWnd* GetDlgItem ( int nID ) const; //This method retrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID. //通过控件ID 获得控件C++对象指针
b.   void GetWindowText(CString& rString )const;  //This method copies the CWnd caption title into the buffer pointed to by lpszStringBuf or into the destination string rString. If the CWnd object is a control, the GetWindowText method copies the text within the control instead of copying the caption.   //获得窗口文本
C.   void SetWindowText( LPCTSTR lpszString );  //This method sets the window title to the specified text. If the window is a control, the text within the control is set. This method causes a WM_SETTEXT message to be sent to this window.   //设置窗口文本
D.   逗号(",")运算符的应用
E. 在此之前,要设置静态文本控件的Notify 属性为真

7.EditBox 输入框编程:

int GetDlgItemText( int nID,  // 控件ID
LPTSTR lpStr,  //字符串数组
int nMaxCount  //最大的字符数
) const; //在一个窗口控件中读取文本到字符数组中
//This method retrieves the title or text associated with a control in a dialog box. This method copies the text to the location pointed to by lpStr and returns a count of the number of bytes it copies.

void SetDlgItemText(
int nID,  //控件ID
LPCTSTR lpszString );  //字符串
//设置控件的文本内容   This method sets the caption or text of a control owned by a window or dialog box. SetDlgItemText sends a WM_SETTEXT message to the given control


int atoi( const char *string ); // 把一个字符串转为INT 类型的数值

char *_itoa(
   int value,  //要换的数值
   char *string,  //转换成的字符串
   int radix  //数值的进制  2--36
); //把一个数值转换成字符串

UINT GetDlgItemInt(
int nID,  //控件ID
BOOL* lpTrans = NULL,  //控件文本是否有非数字字符,当设为NULL 时,不进行报错
BOOL bSigned = TRUE )  //是否为有符号数值
const; //获得控件文本,并转换成数值类型 The CWnd::GetDlgItemInt method retrieves the text of the control identified by the nID parameter. This method translates the text into an integer value by stripping any extra spaces at the beginning of the text and converting decimal digits. It stops the translation when it reaches the end of the text or encounters any nonnumeric character.

void SetDlgItemInt(
int nID,  //控件ID
UINT nValue,  //数值
BOOL bSigned = TRUE  //是否为有符号数值
); //把一个数值设置成控件文本  This method sets the text of a specified control in a dialog box to the string representation of a specified integer value. SetDlgItemInt sends a WM_SETTEXT message to the given control.

8.数据交换与较验

  A. View ---> ClassWizard ---> Member Variables 在此界面添加数据成员与控件的数据关联操作,类名,控件名,数据成员名,数据类型,数据范围等
  B. 此时,ClassWizard 在程序中添加了如下代码:
     头文件中: //{{AFX_DATA(CTestDialog)
 enum { IDD = IDD_DIALOG1 };
 int  m_num1;
 int  m_num2;
 int  m_num3;
 //}}AFX_DATA
     源文件中的DoDataExchange 函数中:
 DDX_Text(pDX, IDC_EDIT1, m_num1);
 DDV_MinMaxInt(pDX, m_num1, 0, 100);
 DDX_Text(pDX, IDC_EDIT2, m_num2);
 DDX_Text(pDX, IDC_EDIT3, m_num3);
 //}}AFX_DATA_MAP
     在DoDataExchange 函数中进行了数据交换与较验的设置.
   
     MSDN中NOTE:
       virtual void DoDataExchange( CDataExchange* pDX );
     //This method is called by the framework to exchange and validate dialog data
  C. 想要在程序中进行数据交互,必须调用 UpdateData() 函数
       BOOL UpdateData(BOOL bSaveAndValidate = TRUE );
     //NOTE:This method initializes data in a dialog box, or retrieves and validates dialog data.Specifies a flag that indicates whether dialog box is being initialized (FALSE) or data is being retrieved (TRUE).

9.通过控件对象进行数据交互与关联
 
  A. 如同上面(7) 一样,在 Add Member Variables 界面的Category 下拉列表框中,选择Control ,进行控件关联操作
  B. 此时,添加的控件对象就如同窗口控件的一个COPY ,直接对此对象进行操作即可.

10.通过Windows 消息进行数据交互

  A. 想要获得一个控件文本,可以有以下四种方式:
       ::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);
       ::SendMessage(m_edit1.m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);
       GetDlgItem(IDC_EDIT1)->SendMessage(WM_GETTEXT,10,(LPARAM)ch1);
       m_edit1.SendMessage(WM_GETTEXT,10,(LPARAM)ch1);

  B. 设置文本:
     m_edit1.SendMessage(WM_SETTEXT,0,(LPARAM)ch1);
     ::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_SETTEXT,0,(LPARAM)ch1);

  C. CWnd::SendDlgItemMessage(IDC_EDIT1,WM_GETTEXT,10,(LPARAM)ch1);

     NOTE:
      LRESULT SendMessage(
        HWND hWnd,    //控件句柄
        UINT Msg,     //Windows 消息 , 这里为WM_GETTEXT 获得文本/WM_SETTEXT 设置文本
        WPARAM wParam, //WM_GETTEXT 时,为最大字符数量 ,WM_SETTEXT 时,要设为0
        LPARAM lParam  //要获得或设置的文本
      ); //发送一个Windows 消息

      LRESULT SendDlgItemMessage(
        int nID,  //控件ID
        UINT message,
        WPARAM wParam = 0,
        LPARAM lParam = 0
     ); //This method sends a message to a control. 参数同上

11.设置文本复选
  
   SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,0,-1);
   m_edit3.SetFocus();  //获得焦点

   NOTE:
     SendMessage(      // 设置复选     
        (HWND) hWndControl,      // handle to destination control    
        (UINT) EM_SETSEL,      // message ID    
        (WPARAM) wParam,      // = (WPARAM) () wParam;    //开始位置
        (LPARAM) lParam      // = (LPARAM) () lParam;     //结束位置
     ); //The EM_SETSEL message selects a range of characters in an edit control. You can send this message to either an edit control or a rich edit control.

     SendMessage(      // 获得复选内容  
        (HWND) hWndControl,      // handle to destination control    
        (UINT) EM_GETSEL,      // message ID    
        (WPARAM) wParam,      // = (WPARAM) () wParam;    //开始位置
        (LPARAM) lParam      // = (LPARAM) () lParam;     //结束位置
     ); //The EM_GETSEL message retrieves the starting and ending character positions of the current selection in an edit control. You can send this message to either an edit control or a rich edit control.

12.对话框控件的七种访问方式:

A.   GetDlgItem()->Get(Set)WindowText()
B.   GetDlgItemText()/SetDlgItemText()
C.   GetDlgItemInt()/SetDlgItemInt()
D.   将控件和整型变量相关联
E.    将控件和控件变量相关联
F.    SendMessage()
G.   SendDlgItemMessage()

13.扩展窗口

   A. 实现
     SetWindowPos(NULL,0,0,rectSmall.Width(),rectSmall.Height(),
   SWP_NOMOVE|SWP_NOZORDER);

     void GetWindowRect(LPRECT lpRect )const;  //获得窗口大小
     BOOL SetWindowPos (const CWnd* pWndInsertAfter,int x,int y,int cx,int cy,UINT nFlags ); //设置窗口大小与位置

     NOTE:
      void GetWindowRect(LPRECT lpRect )const;  //获得窗口大小
         //This method copies the dimensions of the bounding rectangle of the CWnd object into the structure pointed to by lpRect. The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.
    
      BOOL SetWindowPos (
         const CWnd* pWndInsertAfter,//指定此窗口Z-order 位置的前一窗口指针,也可以用NULL 或预设值
         int x,  //left
         int y,  //top
         int cx, //Width
         int cy, //Height
         UINT nFlags  //指定窗口的配置选项  //Specifies sizing and positioning options
      );

   B. Z-order 说明:
      窗口的Z次序表明了重叠窗口堆中窗口的位置,这个窗口堆是按一个假想的轴定位的,这个轴就是从屏幕向外伸展的Z轴。Z次序最上面的窗口覆盖所有其它的窗口,Z次序最底层的窗口被所有其它的窗口覆盖。应用程序设置窗口在Z次序中的位置是通过把它放在一个给定窗口的后面,或是放在窗口堆的顶部或底部。Windows系统管理三个独立的Z次序——一个用于顶层窗口、一个用于兄弟窗口,还有一个是用于最顶层窗口。最顶层窗口覆盖所有其它非最顶层窗口,而不管它是不是活动窗口或是前台窗口。应用程序通过设置WS_EX_TOPMOST风格创建最顶层窗口。一般情况下,Windows系统把刚刚创建的窗口放在Z次序的顶部,用户可通过激活另外一个窗口来改变Z次序;Windows系统总是把活动的窗口放在Z次序的顶部,应用程序可用函数BringWindowToTop把一个窗口放置到Z次序的顶部。函数SetWindowPos和DeferWindowPos用来重排Z次序。

      a.兄弟窗口
         共享同一个父窗口的多个子窗口叫兄弟窗口。
      b.活动窗口
         活动窗口是应用程序的顶层窗口,也就是当前使用的窗口。只有一个顶层窗口可以是活动窗口,如果用户使用的是一个子窗口,Windows系统就激活与这个子窗口相应的顶层窗口。任何时候系统中只能有一个顶层窗口是活动的。用户通过单击窗口(或其中的一个子窗口)、使用ALT+TAB或ALT+ESC组合键来激活一个顶层窗口,应用程序则调用函数SetActiveWindow来激活一个顶层窗口。
      c.前台窗口和后台窗口
         在Windows系统中,每一个进程可运行多个线程,每个线程都能创建窗口。创建正在使用窗口的线程称之为前台线程,这个窗口就称之为前台窗口。所有其它的线程都是后台线程,由后台线程所创建的窗口叫后台窗口。用户通过单击一个窗口、使用ALT+TAB或ALT+ESC组合键来设置前台窗口,应用程序则用函数SetForegroundWindow设置前台窗口。如果新的前台窗口是一个顶层窗口,那么Windows系统就激活它,换句话说,Windows系统激活相应的顶层窗口。
    
14.焦点事件(回车)

   WNDPROC prevProc;
   LRESULT CALLBACK WinSunProc(
      HWND hwnd,      // handle to window
      UINT uMsg,      // message identifier
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
   )
   {
 if(uMsg==WM_CHAR && wParam==0x0d)
 {
  //::SetFocus(::GetNextWindow(hwnd,GW_HWNDNEXT));
  //SetFocus(::GetWindow(hwnd,GW_HWNDNEXT));
  SetFocus(::GetNextDlgTabItem(::GetParent(hwnd),hwnd,FALSE));  
return 1;
 }
 else
  return prevProc(hwnd,uMsg,wParam,lParam);
   }
   BOOL CTestDialog::OnInitDialog()
   {
 CDialog::OnInitDialog();

 prevProc=(WNDPROC)SetWindowLong(GetDlgItem(IDC_EDIT1)->m_hWnd,GWL_WNDPROC,
  (LONG)WinSunProc);
 return TRUE;
   }

   A.操作过程:
    1). 屏蔽掉OnOk() 函数
    2). 重载 WM_INITDIALOG 消息处理 OnInitDialog()
    3). 用 SetWindowLong 函数指定特定的窗口过程处理函数
    4). 在特定的窗口过程函数中写入处理代码
    5). 注意:输入文本框的Multiline 属性 设为真

   B.NOTE:
     LONG SetWindowLong(
       HWND hWnd,   //窗口句柄
       int nIndex,  //指定要修改的属性  GWL_WNDPROC 为窗口处理过程函数
       LONG dwNewLong //处理函数地址
     ); //设置窗口指定的属性  This function changes an attribute of the specified window.The function also sets the 32-bit (long) value at the specified offset into the extra window memory.
     //If the function succeeds, the return value is the previous value of the specified 32-bit integer.

     HWND GetNextWindow(         
        HWND hWnd,   //本窗口句柄
        UINT wCmd    //方向  GW_HWNDNEXT 或   GW_HWNDPREV
     ); //按指定方向取得本窗口下一窗口句柄

     HWND GetWindow(HWND hWnd,UINT uCmd);  //参数同上设置 

     HWND GetNextDlgTabItem(         
        HWND hDlg,   //Dialog Handle
        HWND hCtl,   //This Handle
        BOOL bPrevious  //Specifies how the function is to search the dialog box. If this parameter is TRUE, the function searches for the previous control in the dialog box. If this parameter is FALSE, the function searches for the next control in the dialog box.
     );//The GetNextDlgTabItem function searches controls in the order (or reverse order) they were created in the dialog box template. The function returns the first control it locates that is visible, not disabled, and has the WS_TABSTOP style. If no such control exists, the function returns hCtl.

15.焦点事件(Tab Stop)
    GetFocus()->GetNextWindow()->SetFocus();
    GetFocus()->GetWindow(GW_HWNDNEXT)->SetFocus();
    GetNextDlgTabItem(GetFocus())->SetFocus();

    NOTE:
      static CWnd* PASCAL GetFocus( );  //This method obtains a pointer to the CWnd that currently has the input focus
    
      CWnd* GetNextDlgTabItem(
        CWnd* pWndCtl,
        BOOL bPrevious = FALSE )
      const; //This method obtains a pointer to the first control that was created with the WS_TABSTOP style, that precedes, or follows the specified control.
        //pWndCtl:Identifies the control to be used as the starting point for the search
        //bPrevious:Specifies how the function is to search the dialog box. If TRUE, the function searches for the previous control in the dialog box; if FALSE, it searches for the next control.

以上转载自:http://vzzllblog.bokee.com/4951893.html


========================================================================================
1.模态对话框 显示一个模态对话框的时候应用程序被暂停,只有关闭才可以执行其他任务
非模态对话框反之
2.MFC中资源都和一个类相关,对于一个对话框就要创建一个类与之相关
void CMyboleView::OnDoalog()
{
 // TODO: Add your command handler code here

 CTestDlg dlg;
 dlg.DoModal();//创建一个模态对话框(点击ok窗口被销毁了)
 
 /*
 //非模态对话框 (点击ok窗口是被隐藏了)
 //CTestDlg dlg;//局部变量不不行 1.定义为成员变量2.定义一个指针在堆上分配内存
 CTestDlg * pDlg = new CTestDlg();
 pDlg->Create(IDD_DIALOG1,this);//创建
 pDlg->ShowWindow(SW_SHOW);//显示
 */
}
========================================================================================
对于一个从CWnd派生的类来说,其内部都有一个成员变量m_hWnd保存了和这个C++对象相关的一个窗口的句柄
,MFC的对象和一个窗口相关联的时候,这个句柄就有值了,当这个对象没有和任何窗口相关联的时候,那么
这个句柄是为空的,所以我们可以去判断一下m_btn的句柄是否为空,如果说句柄为空我们就可以创建一个button
否则的话就销毁这个窗口
void CTestDlg::OnBtnAdd()
{
 // TODO: Add your control notification handler code here
/*
 //动态创建一个Button
 //staic BOOL blsCreat=FALSE;(两种)或者 成员变量
 
 if (m_blsCreate==FALSE)
 {
  m_btn.Create("liufei",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
   CRect(0,0,100,100),this, 123);
  m_blsCreate=TRUE;
 }
 else
 {
  m_btn.DestroyWindow();
  m_blsCreate=FALSE;
 }
*/
/*简单方法
 if (!m_btn.m_hWnd)
 {
  m_btn.Create("liufei",WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
   CRect(0,0,100,100),this, 123);
 }
 else
 {
  m_btn.DestroyWindow();
 }
*/
}
========================================================================================静态文本框一般不允许修改,若修改单击控件右击属性
1.修改其ID号
2.在样式中选择 通告一栏(即接收通告消息)

void CTestDlg::OnNumber1()
{
 // TODO: Add your control notification handler code here
 //改变静态文本框文字
 /*
 1.静态文本框也是一个窗口,我们要获得该窗口的文本
    2.GetDlgItem()获得子控件的指针,GetWindowText()获得该窗口的文本,即静态文本框文字
 SetWindowText()设置静态文本框文字
 3.逗号表达式的值为逗号后面的最后那一个
 */
 CString str;
 if(GetDlgItem(IDC_NUMBER1)->GetWindowText(str),str=="Number1")
 {
  GetDlgItem(IDC_NUMBER1)->SetWindowText("数字1");
 }
 else
 {
  GetDlgItem(IDC_NUMBER1)->SetWindowText("Number1");
 }
}

========================================================================================
1.atof, atoi, _atoi64, atol用法char==>int
2._itoa, _i64toa, _ui64toa, _itow, _i64tow用法int==>char

 /*功能:实现两个数相加
 访问控件方式
 输入框编程1
    int num1,num2,num3;
    char ch1[10],ch2[10],ch3[10];
    GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
 GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,10);
 num1=atoi(ch1);//char==>int
 num2=atoi(ch2);
 num3=num1+num2;
 
 itoa(num3,ch3,10);//int==>char
 GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
 */

 /*
 输入框编程2
    int num1,num2,num3;
    char ch1[10],ch2[10],ch3[10];

 GetDlgItemText(IDC_EDIT1,ch1,10);//GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);集成了这两个函数
 GetDlgItemText(IDC_EDIT2,ch2,10);

 num1=atoi(ch1);//char==>int
 num2=atoi(ch2);
 num3=num1+num2;

 itoa(num3,ch3,10);
 SetDlgItemText(IDC_EDIT3,ch3);//注意参数
 */

 /*
 //输入框编程3
 int num1,num2,num3;
 num1=GetDlgItemInt(IDC_EDIT1);//三个参数后面两个为缺省值,详见MSDN
 num2=GetDlgItemInt(IDC_EDIT2);
 num3=num1+num2;

 SetDlgItemInt(IDC_EDIT3,num3);//三个参数最后一个为缺省值,详见MSDN
 */
 
 /*
 访问控件方式4
 1.控件和一个变量相关联 建立类向导-->成员变量-->设置即可
 2.DDX_Text(pDX, IDC_EDIT1, m_num1);//此函数的作用是使一个控件和一个成员变量相关联
 3.从来不会被调用,是通过成员函数UpdateData被调用 初始化一个控件或者得到一个数据
 对话框是一个模态对话框的时候,框架类直接调用Updatedata(FALSE)
 4.m_num1,m_num2,m_num3,可以设置取值范围 DDV_MinMaxInt(pDX, m_num1, 0, 100);来实现
 */
 /*
 UpdateData(TRUE);//对话框-->数据
 m_num3=m_num1+m_num2;
 UpdateData(FALSE);//数据-->对话框
 */
========================================================================================

 访问控件方式5
 1.控件和一个控件变量相关联 建立类向导-->成员变量-->contrl

 */
 /*
 int num1,num2,num3;
    char ch1[10],ch2[10],ch3[10];

 m_edit1.GetWindowText(ch1,10);
 m_edit2.GetWindowText(ch2,10);
 num1=atoi(ch1);
 num2=atoi(ch2);
 num3=num1+num2;
 itoa(num3,ch3,10);
 m_edit3.SetWindowText(ch3);
 */

        /*
 访问控件方式6 通过Windows 消息进行数据交互
 window程序都是基于消息的程序系统,因此我们要获取一个窗口的文本,可以通过发送一个消息来获取
 ,我们只要知道获取窗口文本的消息是一个什么样的消息,我们就可以通过SendMessage来发送这个消息
 从而来获取文本WM_GETTEXT,WM_SETTEXT
 */
 /*
    int num1,num2,num3;
    char ch1[10],ch2[10],ch3[10];
 
 //四种方式
 //::SendMessage(GetDlgItem(IDC_EDIT1)->m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);//平台SDK
 ::SendMessage(m_edit1.m_hWnd,WM_GETTEXT,10,(LPARAM)ch1);//如果控件和一个控件变量相关联
 //GetDlgItem(IDC_EDIT1)->SendMessage(WM_GETTEXT,10,(LPARAM)ch1);//CWnd的成员函数
 //m_edit1.SendMessage(WM_GETTEXT,10,(LPARAM)ch1);//如果控件和一个控件变量相关联

 ::SendMessage(m_edit2.m_hWnd,WM_GETTEXT,10,(LPARAM)ch2);
 num1=atoi(ch1);
 num2=atoi(ch2);
 num3=num1+num2;
 itoa(num3,ch3,10);

 m_edit3.SendMessage(WM_SETTEXT,0,(LPARAM)ch3);
 */

    /*
 访问控件方式7 通过Windows消息进行数据交互,直接给一个对话框的子控件发送消息
    */ 
 
    int num1,num2,num3;
    char ch1[10],ch2[10],ch3[10];
 SendDlgItemMessage(IDC_EDIT1,WM_GETTEXT,10,(LPARAM)ch1);
 SendDlgItemMessage(IDC_EDIT2,WM_GETTEXT,10,(LPARAM)ch2);

 num1=atoi(ch1);
 num2=atoi(ch2);
 num3=num1+num2;
 itoa(num3,ch3,10);
 SendDlgItemMessage(IDC_EDIT3,WM_SETTEXT,0,(LPARAM)ch3)

设置文本复选
 //SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,1,3);
 SendDlgItemMessage(IDC_EDIT3,EM_SETSEL,0,-1);//复选全部内容 EM_SETSEL
 m_edit3.SetFocus();//设置焦点(比如点击那个按钮焦点就在它上)

目 录 译者序 前言 第一部分 基础知识 第1章 窗口 2 1.1 窗口和API环境 2 1.1.1 三种类型窗口 2 1.1.2 客户区和非客户区 3 1.2 窗口和MFC环境 4 1.3 怎样应用MFC创建一个窗口 5 1.4 怎样使用MFC销毁一个窗口 9 1.4.1 捆绑到一个已有的窗口 9 1.4.2 窗口类 10 1.4.3 窗口进程 10 1.5 怎样使用MFC创建一个窗口类 11 1.5.1 使用AfxRegisterWndClass () 函数注册一个窗口类 11 1.5.2 使用AfxRegisterClass ()函数 创建一个窗口类 12 1.6 怎样销毁一个MFC窗口类 14 1.7 厂商安装的窗口类 14 1.8 其他类型窗口 15 1.9 桌面窗口 16 1.10 小结 16 第2章 类 18 2.1 基类 18 2.1.1 CObject 18 2.1.2 CCmdTarget 19 2.1.3 CWnd 19 2.2 应用程序、框架、文档和视图类 19 2.2.1 CWinApp(O/C/W) 20 2.2.2 CView (O/C/W) 21 2.3 其他用户界面类 22 2.3.1 通用控件类 23 2.3.2 菜单类 23 2.3.3 对话框类 24 2.3.4 控制条类 24 2.3.5 属性类 25 2.4 绘图类 25 2.4.1 设备环境类 25 2.4.2 图形对象类 25 2.5 文件类 26 2.6 数据库类 26 2.6.1 ODBC类 26 2.6.2 DAO类 27 2.7 数据集类 27 2.8 其他数据类 27 2.9 通信类 28 2.10 其他类 29 2.11 小结 31 第3章 消息处理 32 3.1 发送或寄送一个消息 32 3.1.1 发送一个消息 32 3.1.2 寄送一个消息 32 3.1.3 发送一个消息与寄送一个消息 的比较 32 3.2 怎样使用MFC发送一个消息 33 3.3 怎样用MFC寄送一个消息 33 3.4 三种类型的消息 34 3.4.1 窗口消息 34 3.4.2 命令消息 34 3.4.3 控件通知 34 3.5 MFC怎样接收一个寄送的消息 36 3.6 MFC怎样处理一个接收到的消息 36 3.7 处理用户界面的对象 44 3.8 创建自定义窗口消息 45 3.8.1 静态分配的窗口消息 45 3.8.2 动态分配的窗口消息 46 3.9 重定向消息 47 3.9.1 子分类和超分类 47 3.9.2 用MFC子分类窗口 48 3.9.3 重载OnCmdMsg ( ) 49 3.9.4 使用SetWindowsHookEx ( ) 49 3.9.5 使用SetCapture ( ) 49 3.9.6 专有的消息泵 50 3.10 小结 50 第4章 绘图 51 4.1 设备环境 51 4.2 在MFC环境中创建一个设备环境 52 4.2.1 屏幕 52 4.2.2 打印机 53 4.2.3 内存 54 4.2.4 信息 54 4.3 绘图例程 55 4.3.1 画点 55 4.3.2 画线 55 4.3.3 画形状 55 4.3.4 形状填充和翻转 55 4.3.5 滚动 56 4.3.6 绘制文本 56 4.3.7 绘制位图和图标 56 4.4 绘图属性 56 4.4.1 设备环境属性 57 4.4.2 画线属性 58 4.4.3 形状填充属性 58 4.4.4 文本绘制属性 58 4.4.5 映像模式 59 4.4.6 调色板属性 62 4.4.7 混合属性 62 4.4.8 剪裁属性 63 4.4.9 位图绘制属性 64 4.5 元文件和路径 65 4.5.1 元文件 65 4.5.2 路径 66 4.6 颜色和调色板 66 4.6.1 抖动色 67 4.6.2 未经抖动色 67 4.6.3 系统调色板 67 4.6.4 使用系统调色板 68 4.6.5 动画色 71 4.7 控制什么时候在哪里绘图 71 4.7.1 处理WM_PAINT 71 4.7.2 只绘制被无效化的区域 72 4.7.3 处理WM_DRAWITEM 72 4.7.4 在其他时间绘图 73 4.8 小结 74 第二部分 用户界面实例 第5章 应用程序与环境 76 5.1 例1 规划MFC应用程序 76 5.2 例2 用AppWizard创建一个MFC 应用程序 79 5.3 例3 用ClassWizard创建一个类 83 5.4 例4 初始化应用程序屏幕 84 5.5 例5 保存应用程序屏幕 86 5.6 例6 处理命令行选项 88 5.7 例7 动态改变应用程序图标 91 5.8 例8 提示用户优先选项 93 5.9 例9 保存和恢复用户优先选项 97 5.10 例10 终止应用程序 100 5.11 例11 创建一个启动窗口 101 第6章 菜单 107 6.1 例12 使用菜单编辑器 107 6.2 例13 添加一个菜单命令处理函数 109 6.3 例14 根据当前可视文档动态改 变菜单 110 6.4 例15 启用和禁用菜单命令 111 6.5 例16 复选标记菜单命令 112 6.6 例17 单选标记菜单命令 113 6.7 例18 动态修改菜单 114 6.8 例19 动态修改系统菜单 116 6.9 例20 触发一个菜单命令 117 6.10 例21 创建弹出式菜单 117 第7章 工具栏和状态栏 120 7.1 例22 使用工具栏编辑器 120 7.2 例23 启用和禁用工具栏按钮 122 7.3 例24 为工具栏按钮添加字 123 7.4 例25 非标准工具栏大小 128 7.5 例26 保持工具栏按钮按下 129 7.6 例27 保持工具栏按钮组中 一个按钮按下 130 7.7 例28 为工具栏添加非按钮控件 131 7.8 例29 修改应用程序的状态栏 136 7.9 例30 更新状态栏窗格 138 7.10 例31 为状态栏添加其他控件 139 第8章 视图 145 8.1 例32 滚动视图 145 8.2 例33 改变鼠标光标形状 147 8.3 例34 沙漏光标 148 8.4 例35 窗体视图 149 8.5 例36 列表视图 152 8.6 例37 动态分割一个视图 163 第9章 对话框和对话条 166 9.1 例38 使用对话框编辑器 166 9.2 例39 创建一个对话框类 168 9.3 例40 模式对话框 170 9.4 例41 无模式对话框 171 9.5 例42 在无模式对话框的控件间 切换焦点 172 9.6 例43 对话框中的动画 173 9.7 例44 消息框 174 9.8 例45 对话条 176 第10章 控件窗口 182 10.1 例46 在任意位置创建一个控 件窗口 182 10.2 例47 用子分类定制一个通用 控件窗口 183 10.3 例48 用超分类定制一个通用 控件窗口 188 10.4 例49 在按钮上放置位图 190 10.5 例50 动态填充一个组合框 192 10.6 例51 排序一个列表控件 194 10.7 例52 分隔线控件 196 第11章 绘图 198 11.1 例53 绘制图形 198 11.2 例54 绘制文本 201 11.3 例55 从任意位置装入一个图 标并绘制 203 11.4 例56 从任意位置装入一个位 图和绘制一个位图 204 11.5 例57 从文件中创建一个位图 206 11.6 例58 创建一个自绘位图 211 第三部分 内部处理实例 第12章 消息 215 12.1 例59 添加消息处理函数或重 载MFC类 216 12.2 例60 添加命令范围消息处理函数 219 12.3 例61 重定向命令消息 221 12.4 例62 创建自己的窗口消息 222 第13章 文件、串行化和数据库 225 13.1 例63 访问二进制文件 225 13.2 例64 访问标准I/O文件 227 13.3 例65 访问内存文件 228 13.4 例66 在数据类中实现串行化 229 13.5 例67 串行化SDI或MDI文档 235 13.6 例68 按要求串行化 240 13.7 例69 透明地更新串行化的文档 242 13.8 例70 串行化多态类 246 13.9 例71 串行化数据集 248 13.10 例72 访问ODBC数据库 252 13.11 例73 访问DAO数据库 257 第14章 杂类 263 14.1 例74 剪切、拷贝和粘贴文本 数据 263 14.2 例75 剪切、拷贝、粘贴多信 息文本数据 268 14.3 例76 剪切、拷贝和粘贴二进制 数据 273 14.4 例77 数组函数 280 14.5 例78 列表函数 281 14.6 例79 映像函数 283 14.7 例80 系统键盘输入 285 14.8 例81 时间 288 第四部分 打包实例 第15章 库 291 15.1 例82 静态链接C/C++库 291 15.2 例83 动态链接C/C++库 295 15.3 例84 动态链接MFC扩展类库 300 15.4 例85 资源库 303 第五部分 附录 附录A 控件窗口风格 305 附录B 消息、控件通知和消息映像宏 323 附录C 访问其他应用程序类 328 附录D 开发中注意事项 330 附录E MFC快速参考指南 339
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值