iBinx Corp.
contact usshisen-sho

Source listing: wndcore.h. Return to the main page

/* -*- C++ -*-
 *******************************************************************
 *
 *
 * wndcore.h - core window class declarations
 *
 *
 *******************************************************************
 *
 * General purpose window classes for Win32
 *
 *******************************************************************
 *
 * Created 2001-02-20 by Jim Mason <jmason@sirius.com>
 *
 * Copyright (C) 2001 Jim Mason.
 *
 *******************************************************************
 *
 * This file is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This file is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this file; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *******************************************************************
 */


#ifndef _WNDCORE_H_
#define _WNDCORE_H_

/////////////////////////////////////////////////////////////////////////////
// Window superclass

class Window {
// Construction
public:
    Window();
    virtual ~Window();

// Access
public:
    void SubclassWindow(HWND hWnd);
    void SubclassDlgItem(UINT nID, Window* pParent);
    virtual BOOL Create(DWORD dwStyleEx, LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
                        DWORD dwStyle, const RECT& rect, HWND hParentWnd, UINT nID);
    inline HWND GetHWnd()  { return m_hWnd; }

// Win32 API encapsulation methods
public:
    inline HDC GetDC()  { return ::GetDC(m_hWnd); }
    inline int ReleaseDC(HDC hDC)  { return ::ReleaseDC(m_hWnd, hDC); }
    inline HDC BeginPaint(LPPAINTSTRUCT ps)  { return ::BeginPaint(m_hWnd, ps); }
    inline BOOL EndPaint(CONST PAINTSTRUCT* ps)  { return ::EndPaint(m_hWnd, ps); }
    inline BOOL GetUpdateRect(LPRECT lpRect, BOOL bErase) {
        return ::GetUpdateRect(m_hWnd, lpRect, bErase); }
    inline BOOL GetWindowRect(LPRECT rc)  { return ::GetWindowRect(m_hWnd, rc); }
    inline BOOL GetClientRect(LPRECT rc)  { return ::GetClientRect(m_hWnd, rc); }
    inline BOOL MoveWindow(int x, int y, int cx, int cy, BOOL bRepaint) {
        return ::MoveWindow(m_hWnd, x, y, cx, cy, bRepaint); }
    inline BOOL MoveWindow(const RECT& rc, BOOL bRepaint) {
        return MoveWindow(rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, bRepaint); }
    inline BOOL ShowWindow(int nCmdShow)  { return ::ShowWindow(m_hWnd, nCmdShow); }
    inline BOOL InvalidateRect(const RECT* lpRect, BOOL bErase) {
        return ::InvalidateRect(m_hWnd, lpRect, bErase); }
    inline BOOL UpdateWindow()  { return ::UpdateWindow(m_hWnd); }
    inline HWND GetDlgItem(UINT nID)  { return ::GetDlgItem(m_hWnd, nID); }

// Overrides
protected:
    virtual LRESULT WndProc(UINT nMsg, WPARAM wParam, LPARAM lParam);
    virtual BOOL PreCreateWindow(CREATESTRUCT &cs);
    virtual void PreSubclassWindow();
    virtual void PostNcDestroy();
    virtual int OnCreate(LPCREATESTRUCT lpCreateStruct);
    virtual void OnDestroy();
    virtual BOOL OnCommand(UINT nID, UINT nEvent, HWND hSource);

protected:
    ATOM RegisterClass(WNDCLASS* pwc);
    ATOM RegisterClassEx(WNDCLASSEX* pwcex);

protected:
    static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT nMsg,
                                             WPARAM wParam, LPARAM lParam);

protected:
    WNDPROC m_oldWndProc;
    HWND m_hWnd;
};

/////////////////////////////////////////////////////////////////////////////
// Dialog superclass

class Dialog : public Window {
// Construction
public:
    Dialog(LPCTSTR szTemplateName, Window* pParent=NULL);
    Dialog(UINT nTempateID, Window* pParent=NULL);

// Access
public:
    int DoModal();

// Overrides
protected:
    LRESULT WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
    BOOL OnCommand(UINT nID, UINT nEvent, HWND hSource);
    virtual BOOL OnInitDialog();

protected:
    Window* m_pParent;
    LPCTSTR m_szTemplateName;
};

#endif // ndef _WNDCORE_H_
<< Back to Shisen-Sho