对CWnd类的模拟

孙鑫用模拟CWnd类来说明类对象和窗口资源的关系: 通过m_hWnd来联系.

class CWnd
{
 public:

         CWnd()

        { 

           m_hWnd=NULL;     

         }
          BOOL  CreateEx(

                                    DWORD dwExStyle,      // extended window style
                                   LPCTSTR lpClassName,  // pointer to registered class   name
                                   LPCTSTR lpWindowName, // pointer to window name
                                   DWORD dwStyle,        // window style
                                    int x,                // horizontal position of window
                                    int y,                // vertical position of window
                                    int nWidth,           // window width
                                    int nHeight,          // window height
                                    HWND hWndParent,      // handle to parent or owner window
                                    HMENU hMenu,          // handle to menu, or child-window identifier
                                    HINSTANCE hInstance,  // handle to application instance
                                    LPVOID lpParam        // pointer to window-creation data

                             );

        BOOL ShowWindow(int nCmdShow);

        BOOL UpdateWindow();

public:

         HWND   m_hWnd;

};

 

 

 BOOL  CWnd::CreateEx(

                                    DWORD dwExStyle,      // extended window style
                                   LPCTSTR lpClassName,  // pointer to registered class   name
                                   LPCTSTR lpWindowName, // pointer to window name
                                   DWORD dwStyle,        // window style
                                    int x,                // horizontal position of window
                                    int y,                // vertical position of window
                                    int nWidth,           // window width
                                    int nHeight,          // window height
                                    HWND hWndParent,      // handle to parent or owner window
                                    HMENU hMenu,          // handle to menu, or child-window identifier
                                    HINSTANCE hInstance,  // handle to application instance
                                    LPVOID lpParam        // pointer to window-creation data

                             )

{

    m_hWnd=::CreateWindowEx(dwExStyle, lpClassName,lpWindowName, dwStyle,

                                             x,y, nWidth,nHeight, hWndParent,hMenu,  hInstance, lpParam );

   if(m_hWnd)

              return TRUE;

   else

               return FALSE;

 

}

 

 

 BOOL    CWnd::ShowWindow(int nCmdShow)

{

     return  ::ShowWindow(m_hWnd,nCmdShow);

 

 

} 

 

BOOL    CWnd:: UpdateWindow()

{

    return  ::UpdateWindow(m_hWnd);

}

 

int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
   ......
    CWnd   wnd;
    wnd.CreateEx(...);
    wnd.ShowWindow(SW_SHOWNORMAL);
    wnd.UpdateWindow();
    原来利用API的调拥
    HWND   hWnd;
    hWnd=::CreateWindowEx(...);
    ::ShowWindow(hWnd,SW_SHOWNORMAL);
    ::UpdateWindow(hWnd);
.....
}
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值