对CWnd类的模拟

来源:互联网 发布:mac mysql可视化界面 编辑:程序博客网 时间:2024/05/17 09:27

孙鑫用模拟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);
.....
} 

 

原创粉丝点击