zoukankan      html  css  js  c++  java
  • 实例1.1:通过HWND获得CWnd指针

     
    	//获得当前窗口的句柄
    	HWND hWnd = GetSafeHwnd();
    	//通过HWND获得CWnd指针
    	CWnd *pWnd = CWnd::FromHandle(hWnd);
    	CString strText = _T("");
    	strText.Format("pWnd = 0x%X\nthis = 0x%X\n", pWnd, this);
    	AfxMessageBox(strText);
    

    1、GetSafeHwnd方法:该函数获得窗口对象的窗口句柄。

    Returns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer。

    这个函数用途很广,很多函数的参数要求是HWND,这时就需要使用GetSafeHwnd函数了。如:

      HWND hwnd; 
      CWnd* pWnd; 
      pWnd=((CFrameWnd*)(AfxGetApp()->m_pMainWnd))->GetActiveView(); 
      hwnd=pWnd->GetDlgItem(IDC_EDIT2)->GetSafeHwnd(); 
      ::SetWindowText(hwnd,m_strResult);
    

      其它的一些情况:

    AfxWinInit         被WinMain调用的一个函数,用做MFC GUI程序初始化的一部份

    AfxBeginThread     开始一个新的执行线程

    AfxEndThread       结束一个旧的执行线程

    AfxMessageBox      类似Windows API 函数MessageBox

    AfxGetApp          取得application object(CWinApp衍生对象)的指针

    AfxGetMainWnd      取得程序主窗口的指针

    AfxGetInstance     取得程序的instance handle

    AfxRegisterClass   以自定的WNDCLASS 注册窗口类别

    2、FromHandle方法:FromHandle(HANDLE h) 先查找由用户定义的内核对象对象的封装类, 如果找到直接返回,没有找到构造一个临时对象返回.

  • 相关阅读:
    第三章感想
    第二章感想
    第一章感想
    第9章 硬件抽象层:HAL
    第10章 嵌入式linux的调试技术
    第8章 蜂鸣器驱动
    第七章 I/O
    第六章 编写Linux驱动程序
    第五章 S3C6410
    源代码的下载和编译
  • 原文地址:https://www.cnblogs.com/mars9/p/2327941.html
Copyright © 2011-2022 走看看