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

    效果图

  • 相关阅读:
    JavaScript学习笔记之数组(一)
    Ajax与CORS通信
    JSONP跨域
    JavaScript原型与原型链
    CSS布局套路
    爱奇艺的自制节目
    2019.3.6错误经验
    Kickdown UVA
    ASP.NET Web
    C# Windows
  • 原文地址:https://www.cnblogs.com/Malphite/p/10828926.html
Copyright © 2011-2022 走看看