zoukankan      html  css  js  c++  java
  • 024.讲MFC_窗口指针

    窗口指针
    通过HWND获得CWnd指针        //如何通过窗口句柄获得窗口指针
    获得应用程序主窗口的指针      //如何获得应用程序主窗口的指针
    一、建立名为dialogPoint的mfc工程,添加两个button 
    双击button1
    进入dialogPointDlg.cpp
    添加
    void CdialogPointDlg::OnBnClickedButton1()
    {
    // TODO: 在此添加控件通知处理程序代码
    HWND hWnd = GetSafeHwnd(); //获取当前窗口句柄
    CWnd *pWnd = CWnd::FromHandle(hWnd); //通过句柄得到指针
    CString s;
    s.Format(_T("pWnd = 0x%X this = 0x%X"),pWnd,this);
    AfxMessageBox(s);
    }

    同理双击button2
    添加
    void CdialogPointDlg::OnBnClickedButton2()
    {
    // TODO: 在此添加控件通知处理程序代码
    CdialogPointApp *pApp = (CdialogPointApp *)AfxGetApp();//应用程序指针
    CWnd *pMainWnd = pApp->m_pMainWnd;
    CString s;
    s.Format(_T("pMainWnd = 0x%X this = 0x%X"),pMainWnd,this);
    AfxMessageBox(s);
    }

    效果图

  • 相关阅读:
    嵌入式系统引导和启动的流程
    microblaze以太网程序
    机试题
    共模差分 对比
    xilinx XPS无法启动的问题
    FPGA开发流程
    Mel-Frequency-Warping
    微软-黄学东-清华大学FIT楼报告-20170407
    Matlab
    Anaconda安装
  • 原文地址:https://www.cnblogs.com/Malphite/p/10828926.html
Copyright © 2011-2022 走看看