首页 > 编程语言 > 详细

MFC 中 CreateEx() 函数

时间:2019-10-17 09:24:57      阅读:81      评论:0      收藏:0      [点我收藏+]

    1. 主要创建主窗口或父窗口
    BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
        LPCTSTR lpszWindowName, DWORD dwStyle,
        int x, int y, int nWidth, int nHeight,
        HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL);
    2. 主要创建子窗口
    BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
        LPCTSTR lpszWindowName, DWORD dwStyle,
        const RECT& rect,
        CWnd* pParentWnd, UINT nID,
        LPVOID lpParam = NULL);

BOOL CtestDialogApp::InitInstance()
{
     //自己用 CreateEx() 创建主窗口,需要自己注册窗口类
    CWnd* pWnd = new CWnd();//要想接收消息,则需要新建一个类继承 CWnd,像 CMyMainWnd
    //CWnd* pWnd = new CMyMainWnd();
    WNDCLASS wc = { 0 };
    wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
    wc.lpfnWndProc = ::DefWindowProc;
    wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
    wc.hCursor = (HCURSOR)::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));//加载系统的标准的光标
    //wc.hIcon=...
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);// 也可以用 (LPCTSTR)IDR_MENU1;
    wc.lpszClassName = _T("myWindow");
    RegisterClass(&wc);

    m_pMainWnd = pWnd; // 必不可少
    pWnd->CreateEx(0, wc.lpszClassName, _T("xxx窗口名"), WS_VISIBLE|WS_OVERLAPPEDWINDOW, 20, 20, 600, 400, NULL, NULL);
    return TRUE; // 必不可少
}

 

// WNDCLASS
typedef struct  _WNDCLASS { 
    UINT       style; 
    WNDPROC    lpfnWndProc; 
    int        cbClsExtra; 
    int        cbWndExtra; 
    HINSTANCE  hInstance; 
    HICON      hIcon; 
    HCURSOR    hCursor; 
    HBRUSH     hbrBackground; 
    LPCTSTR    lpszMenuName; 
    LPCTSTR    lpszClassName; 
} WNDCLASS, *PWNDCLASS; 

//
MSG
The MSG structure contains message information from a threads message queue. 

typedef struct tagMSG {
  HWND   hwnd; 
  UINT   message; 
  WPARAM wParam; 
  LPARAM lParam; 
  DWORD  time; 
  POINT  pt; 
} MSG, *PMSG; 

//Members
hwnd :Handle to the window whose window procedure receives the message. 
message :Specifies the message identifier. Applications can only use the low word; the high word is reserved by the system. 
wParam :Specifies additional information about the message. The exact meaning depends on the value of the message member. 
lParam :Specifies additional information about the message. The exact meaning depends on the value of the message member. 
time :Specifies the time at which the message was posted. 
pt :Specifies the cursor position, in screen coordinates, when the message was posted. 

 

MFC 中 CreateEx() 函数

原文:https://www.cnblogs.com/htj10/p/11688697.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!