zoukankan      html  css  js  c++  java
  • 根据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);
    }

  • 相关阅读:
    sql server数据库中char,varchar,nvarchar字段的区别
    SQLServer 实现rownum 的功能
    web.config加密和解密
    页面命名和用户控件命名一样带来的后果
    oracle初识
    加载类成员技巧
    string.Empty与"",null的区别
    收集了一些有关网页设计的问题集
    网页最顶部转瞬即逝的巨幅广告特效
    鼠标放在图片连接上面,预览图片
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3722498.html
Copyright © 2011-2022 走看看