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);
    }

  • 相关阅读:
    通过调用C语言的库函数与在C代码中使用内联汇编两种方式来使用同一个系统调用来分析系统调用的工作机制
    解密腾讯课堂视频缓存文件
    Pycharm启动后加载anaconda一直updating indices造成Pycharm闪退甚至电脑崩溃
    Pycharm基本设置和插件安装
    Pycharm配置anaconda环境
    Anaconda管理Python环境
    Markdown介绍及工具推荐
    Android应用性能测试
    常用的adb命令
    QTP入门——玩玩小飞机
  • 原文地址:https://www.cnblogs.com/hongjiumu/p/3722498.html
Copyright © 2011-2022 走看看