• 根据ID获取CEdit的句柄实例


    MyApp.h和MyApp.cpp

    #ifndef MY_APP_H_
    #define MY_APP_H_
    
    #include <afxwin.h>
    
    class CMyApp:public CWinApp
    {
    public:
        virtual BOOL InitInstance();
    };
    
    #endif
    
    =====================================
    
    
    #include "stdafx.h"
    #include "MyApp.h"
    
    #include "resource.h"
    #include "MyCustomCDialog.h"
    
    BOOL CMyApp::InitInstance()
    {
        /*
        CDialog dialog;
        dialog.Create(IDD_DIALOG_FIRST,NULL);
        dialog.ShowWindow(m_nCmdShow);
        */
    
        CMyCustomCDialog myDialog;
        myDialog.DoModal();
        //myDialog.ShowWindow(m_nCmdShow);
    
        /*myDialog.UpdateData(true);
    
        std::string result(myDialog.m_cstrEditFirst.GetBuffer());
        myDialog.m_cstrEditFirst.ReleaseBuffer();
        */
        ::MessageBox(NULL,"Message","Title",MB_OK);
        myDialog.DestroyWindow();
    
        return true;
    }
    
    CMyApp myApp;

    CMyCustomCDialog.h和 CMyCustomCDialog.cpp

    #ifndef MY_CUSTOM_CDIALOG_H_
    #define MY_CUSTOM_CDIALOG_H_
    
    #include <afxwin.h>
    #include "resource.h"
    #include <string>
    
    class CMyCustomCDialog:public CDialog
    {
    public:
        CMyCustomCDialog(CWnd* pParent=NULL);
    
        enum{ IDD=IDD_DIALOG_FIRST };
    
        //Overrides
    protected:
        virtual void DoDataExchange(CDataExchange* pDX);
    
        //Implement
    protected:
        afx_msg void OnDoAction();
    
        DECLARE_MESSAGE_MAP()
    
    public:
        CString m_cstrEditFirst;
    };
    
    #endif
    
    
    ======================================
    
    
    #include "stdafx.h"
    #include "MyCustomCDialog.h"
    
    CMyCustomCDialog::CMyCustomCDialog(CWnd* pParent)
        :CDialog(CMyCustomCDialog::IDD,pParent)
    {
    
    }
    
    void CMyCustomCDialog::DoDataExchange(CDataExchange* pDX)
    {
        CDialog::DoDataExchange(pDX);
        ::MessageBox(NULL,"Message_DoDataExchange","Title",MB_OK);
    
        DDX_Text(pDX,IDC_EDIT_FIRST,m_cstrEditFirst);
    }
    
    BEGIN_MESSAGE_MAP(CMyCustomCDialog,CDialog)
        ON_BN_CLICKED(IDC_BUTTON_ACTION,OnDoAction)
    END_MESSAGE_MAP()
    
    void CMyCustomCDialog::OnDoAction()
    {
        HWND hWnd=::GetDlgItem(this->m_hWnd,IDC_EDIT_FIRST);
        char* pChar=new char[100];
        memset(pChar,'',100);
        ::GetWindowText(hWnd,pChar,99);
        m_cstrEditFirst.Format("%s",pChar);
    }

    Resource很简单:

    sample edit box(CEdit)

      Action(CButton)

    关键代码是:

    void CMyCustomCDialog::OnDoAction()
    {
      HWND hWnd=::GetDlgItem(this->m_hWnd,IDC_EDIT_FIRST);
      char* pChar=new char[100];
      memset(pChar,'',100);
      ::GetWindowText(hWnd,pChar,99);
      m_cstrEditFirst.Format("%s",pChar);
    }

  • 相关阅读:
    数学符号表
    对比深度学习十大框架:TensorFlow最流行但并不是最好
    支持向量机通俗导论(理解SVM的三层境界)
    Annotation
    Struts2的拦截器
    DLL文件的引用
    JS引擎
    Windows窗口的创建
    解决构造器多参数的设计问题
    静态工厂对比构造器之优缺点
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3722498.html
Copyright © 2020-2023  润新知