home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Game Programming for Teens / VBGPFT.cdr / DirectX8 / dx8a_sdk.exe / samples / multimedia / directinput / diconfig / flexwnd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-22  |  4.1 KB  |  129 lines

  1. //-----------------------------------------------------------------------------
  2. // File: flexwnd.h
  3. //
  4. // Desc: CFlexWnd is a generic class that encapsulates the functionalities
  5. //       of a window.  All other window classes are derived from CFlexWnd.
  6. //
  7. //       Child classes can have different behavior by overriding the
  8. //       overridable message handlers (OnXXX members).
  9. //
  10. // Copyright (C) 1999-2000 Microsoft Corporation. All Rights Reserved.
  11. //-----------------------------------------------------------------------------
  12.  
  13. #ifndef __FLEXWND_H__
  14. #define __FLEXWND_H__
  15.  
  16.  
  17. #include "flexmsg.h"
  18.  
  19. class CFlexToolTip;
  20.  
  21. class CFlexWnd
  22. {
  23. public:
  24.     CFlexWnd();
  25.     ~CFlexWnd();
  26.  
  27.     // class registration
  28.     static void RegisterWndClass(HINSTANCE hInst);
  29.     static void UnregisterWndClass(HINSTANCE hInst);
  30.  
  31.     // Tooltip
  32.     static CFlexToolTip s_ToolTip;  // Shared tooltip window object
  33.     static DWORD s_dwLastMouseMove;  // Last GetTickCount() that we have a WM_MOUSEMOVE
  34.     static HWND s_hWndLastMouseMove;  // Last window handle of WM_MOUSEMOVE
  35.     static LPARAM s_PointLastMouseMove;  // Last point of WM_MOUSEMOVE
  36.  
  37.     // public read-only access to hwnd
  38.     const HWND &m_hWnd;
  39.  
  40.     // creation
  41.     int DoModal(HWND hParent, int nTemplate, HINSTANCE hInst = NULL);
  42.     int DoModal(HWND hParent, LPCTSTR lpTemplate, HINSTANCE hInst = NULL);
  43.     HWND DoModeless(HWND hParent, int nTemplate, HINSTANCE hInst = NULL);
  44.     HWND DoModeless(HWND hParent, LPCTSTR lpTemplate, HINSTANCE hInst = NULL);
  45.     HWND Create(HWND hParent, LPCTSTR tszName, DWORD dwExStyle, DWORD dwStyle, const RECT &rect, HMENU hMenu = NULL);
  46.     HWND Create(HWND hParent, const RECT &rect, BOOL bVisible);
  47.  
  48.     // destruction
  49.     void Destroy();
  50.  
  51.     // operations
  52.     void RenderInto(HDC hDC, int x = 0, int y = 0);
  53.     void Invalidate();
  54.  
  55.     // information
  56.     SIZE GetClientSize() const;
  57.     void GetClientRect(LPRECT) const;
  58.     static CFlexWnd *GetFlexWnd(HWND hWnd);
  59.     BOOL HasWnd() {return m_hWnd != NULL;}
  60.     static LPCTSTR GetDefaultClassName();
  61.     BOOL IsDialog();
  62.     BOOL InRenderMode();
  63.     void SetReadOnly(BOOL bReadOnly) { m_bReadOnly = bReadOnly; }
  64.     BOOL GetReadOnly() { return m_bReadOnly; }
  65.  
  66.     // mouse capture
  67.     void SetCapture();
  68.     void ReleaseCapture();
  69.  
  70. protected:
  71.  
  72.     // derived operations
  73.     void SetRenderMode(BOOL bRender = TRUE);
  74.     BOOL EndDialog(int);
  75.  
  76.     // overridable message handlers
  77.     virtual void OnInit() {}
  78.     virtual LRESULT OnCreate(LPCREATESTRUCT lpCreateStruct) {return 0;}
  79.     virtual BOOL OnInitDialog() {return TRUE;}
  80.     virtual void OnTimer(UINT uID) {}
  81.     virtual BOOL OnEraseBkgnd(HDC hDC);
  82.     virtual void OnPaint(HDC hDC) {}
  83.     virtual void OnRender(BOOL bInternalCall = FALSE);
  84.     virtual LRESULT OnCommand(WORD wNotifyCode, WORD wID, HWND hWnd)  {return 0;}
  85.     virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam)  {return 0;}
  86.     virtual void OnMouseOver(POINT point, WPARAM fwKeys) {}
  87.     virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft) {}
  88.     virtual void OnDoubleClick(POINT point, WPARAM fwKeys, BOOL bLeft) {}
  89.     virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  90.     virtual void OnDestroy() {}
  91.  
  92. private:
  93.  
  94.     // implementation...
  95.  
  96.     // information and initialization
  97.     int m_nID;
  98.     HWND m_privhWnd;
  99.     BOOL m_bIsDialog;
  100.     BOOL m_bReadOnly;  // Whether this window is read-only (disabled).
  101.     void SetHWND(HWND hWnd);
  102.     void InitFlexWnd();
  103.  
  104.     // paint helper (for inserting debug painting)
  105.     virtual void DoOnPaint(HDC hDC);
  106.     
  107.     // render mode
  108.     BOOL m_bRender;
  109.     HDC m_hRenderInto;
  110.     BOOL RenderIntoClipChild(HWND hChild);
  111.     BOOL RenderIntoRenderChild(HWND hChild);
  112.  
  113. friend static BOOL CALLBACK RenderIntoClipChild(HWND hWnd, LPARAM lParam);
  114. friend static BOOL CALLBACK RenderIntoRenderChild(HWND hWnd, LPARAM lParam);
  115.  
  116.     // class information
  117.     static void FillWndClass(HINSTANCE hInst);
  118.     static BOOL sm_bWndClassRegistered;
  119.     static WNDCLASSEX sm_WndClass;
  120.     static LPCTSTR sm_tszWndClassName;
  121.     static HINSTANCE sm_hInstance;
  122.  
  123. friend LRESULT CALLBACK __BaseFlexWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  124. friend LRESULT CALLBACK __BaseFlexWndDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  125. };
  126.  
  127.  
  128. #endif //__FLEXWND_H__
  129.