home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / flexwnd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  4.3 KB  |  133 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-2001 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.     // Unhighlight callouts when a click is made elsewhere besides the callouts
  32.     static HWND s_CurrPageHwnd;
  33.  
  34.     // Tooltip
  35.     static CFlexToolTip s_ToolTip;  // Shared tooltip window object
  36.     static DWORD s_dwLastMouseMove;  // Last GetTickCount() that we have a WM_MOUSEMOVE
  37.     static HWND s_hWndLastMouseMove;  // Last window handle of WM_MOUSEMOVE
  38.     static LPARAM s_PointLastMouseMove;  // Last point of WM_MOUSEMOVE
  39.  
  40.     // public read-only access to hwnd
  41.     const HWND &m_hWnd;
  42.  
  43.     // creation
  44.     int DoModal(HWND hParent, int nTemplate, HINSTANCE hInst = NULL);
  45.     int DoModal(HWND hParent, LPCTSTR lpTemplate, HINSTANCE hInst = NULL);
  46.     HWND DoModeless(HWND hParent, int nTemplate, HINSTANCE hInst = NULL);
  47.     HWND DoModeless(HWND hParent, LPCTSTR lpTemplate, HINSTANCE hInst = NULL);
  48.     HWND Create(HWND hParent, LPCTSTR tszName, DWORD dwExStyle, DWORD dwStyle, const RECT &rect, HMENU hMenu = NULL);
  49.     HWND Create(HWND hParent, const RECT &rect, BOOL bVisible);
  50.  
  51.     // destruction
  52.     void Destroy();
  53.  
  54.     // operations
  55.     void RenderInto(HDC hDC, int x = 0, int y = 0);
  56.     void Invalidate();
  57.  
  58.     // information
  59.     SIZE GetClientSize() const;
  60.     void GetClientRect(LPRECT) const;
  61.     static CFlexWnd *GetFlexWnd(HWND hWnd);
  62.     BOOL HasWnd() {return m_hWnd != NULL;}
  63.     static LPCTSTR GetDefaultClassName();
  64.     BOOL IsDialog();
  65.     BOOL InRenderMode();
  66.     void SetReadOnly(BOOL bReadOnly) { m_bReadOnly = bReadOnly; }
  67.     BOOL GetReadOnly() { return m_bReadOnly; }
  68.  
  69.     // mouse capture
  70.     void SetCapture();
  71.     void ReleaseCapture();
  72.  
  73. protected:
  74.  
  75.     // derived operations
  76.     void SetRenderMode(BOOL bRender = TRUE);
  77.     BOOL EndDialog(int);
  78.  
  79.     // overridable message handlers
  80.     virtual void OnInit() {}
  81.     virtual LRESULT OnCreate(LPCREATESTRUCT lpCreateStruct) {return 0;}
  82.     virtual BOOL OnInitDialog() {return TRUE;}
  83.     virtual void OnTimer(UINT uID) {}
  84.     virtual BOOL OnEraseBkgnd(HDC hDC);
  85.     virtual void OnPaint(HDC hDC) {}
  86.     virtual void OnRender(BOOL bInternalCall = FALSE);
  87.     virtual LRESULT OnCommand(WORD wNotifyCode, WORD wID, HWND hWnd)  {return 0;}
  88.     virtual LRESULT OnNotify(WPARAM wParam, LPARAM lParam)  {return 0;}
  89.     virtual void OnMouseOver(POINT point, WPARAM fwKeys) {}
  90.     virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft) {}
  91.     virtual void OnWheel(POINT point, WPARAM wParam) {}
  92.     virtual void OnDoubleClick(POINT point, WPARAM fwKeys, BOOL bLeft) {}
  93.     virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  94.     virtual void OnDestroy() {}
  95.  
  96. private:
  97.  
  98.     // implementation...
  99.  
  100.     // information and initialization
  101.     int m_nID;
  102.     HWND m_privhWnd;
  103.     BOOL m_bIsDialog;
  104.     BOOL m_bReadOnly;  // Whether this window is read-only (disabled).
  105.     void SetHWND(HWND hWnd);
  106.     void InitFlexWnd();
  107.  
  108.     // paint helper (for inserting debug painting)
  109.     virtual void DoOnPaint(HDC hDC);
  110.     
  111.     // render mode
  112.     BOOL m_bRender;
  113.     HDC m_hRenderInto;
  114.     BOOL RenderIntoClipChild(HWND hChild);
  115.     BOOL RenderIntoRenderChild(HWND hChild);
  116.  
  117. friend static BOOL CALLBACK RenderIntoClipChild(HWND hWnd, LPARAM lParam);
  118. friend static BOOL CALLBACK RenderIntoRenderChild(HWND hWnd, LPARAM lParam);
  119.  
  120.     // class information
  121.     static void FillWndClass(HINSTANCE hInst);
  122.     static BOOL sm_bWndClassRegistered;
  123.     static WNDCLASSEX sm_WndClass;
  124.     static LPCTSTR sm_tszWndClassName;
  125.     static HINSTANCE sm_hInstance;
  126.  
  127. friend LRESULT CALLBACK __BaseFlexWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  128. friend LRESULT CALLBACK __BaseFlexWndDialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  129. };
  130.  
  131.  
  132. #endif //__FLEXWND_H__
  133.