home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / configwnd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  7.0 KB  |  249 lines

  1. //-----------------------------------------------------------------------------
  2. // File: configwnd.h
  3. //
  4. // Desc: CConfigWnd is derived from CFlexWnd. It implements the top-level
  5. //       UI window which all other windows are descendents of.
  6. //
  7. //       Functionalities handled by CConfigWnd are device tabs, Reset, Ok,
  8. //       and Cancel buttons.
  9. //
  10. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  11. //-----------------------------------------------------------------------------
  12.  
  13. #ifndef __CONFIGWND_H__
  14. #define __CONFIGWND_H__
  15.  
  16.  
  17. #define PAGETYPE IDIDeviceActionConfigPage
  18. #define NUMBUTTONS 3
  19.  
  20.  
  21. class CMouseTrap : public CFlexWnd
  22. {
  23.     HWND m_hParent;
  24.  
  25. public:
  26.     CMouseTrap() : m_hParent(NULL) { }
  27.     HWND Create(HWND hParent = NULL, BOOL bInRenderMode = TRUE);
  28.  
  29. protected:
  30.     virtual BOOL OnEraseBkgnd(HDC hDC) {return TRUE;}
  31.     virtual void OnPaint(HDC hDC)    {}
  32.     virtual void OnRender(BOOL bInternalCall = FALSE) {}
  33. };
  34.  
  35. // Each device is represented by an ELEMENT object that is managed by
  36. // CConfigWnd.
  37. struct ELEMENT {
  38.     ELEMENT() : nCurUser(-1), pPage(NULL), lpDID(NULL) {tszCaption[0] = 0;}
  39.     // everything's cleaned up in CConfigWnd::ClearElement();
  40.     DIDEVICEINSTANCEW didi;
  41.     PAGETYPE *pPage;
  42.     HWND hWnd;
  43.     BOOL bCalc;
  44.     RECT rect, textrect;
  45.     TCHAR tszCaption[MAX_PATH];
  46.     LPDIRECTINPUTDEVICE8W lpDID;
  47.  
  48.     // the map of acfors contains an acfor for each genre/username
  49.     // that has been used so far on this device.  the dword represents
  50.     // the genre username as follows:  the hiword is the index of the
  51.     // genre per uiglobals.  the loword is the index of the username
  52.     // per uiglobals.
  53.     CMap<DWORD, DWORD &, LPDIACTIONFORMATW, LPDIACTIONFORMATW &> AcForMap;
  54.  
  55. #define MAP2GENRE(m) (int(((m) & 0xffff0000) >> 16))
  56. #define MAP2USER(m) (int((m) & 0x0000ffff))
  57. #define GENREUSER2MAP(g,u) \
  58.     ( \
  59.         ((((DWORD)(nGenre)) & 0xffff) << 16) | \
  60.         (((DWORD)(nUser)) & 0xffff) \
  61.     )
  62.  
  63.     // this function simply returns the corresponding entry in the
  64.     // map if it already exists.  otherwise, it creates a copy for
  65.     // this entry from the masteracfor and calls buildactionmap on
  66.     // it with the appropriate username.
  67.  
  68.     // bHwDefault flag is added to properly support Reset button.  BuildActionMap must be
  69.     // called with the flag to get hardware default mapping, so we need this parameter.
  70.     LPDIACTIONFORMATW GetAcFor(int nGenre, int nUser, BOOL bHwDefault = FALSE);
  71.  
  72.     // we need to keep track of the current user per-element
  73.     int nCurUser;
  74.  
  75.     // we need a pointer to the uiglobals in order to correspond
  76.     // user indexes to the actual string
  77.     CUIGlobals *pUIGlobals;
  78.  
  79.     // this function will be called in CConfigWnd::ClearElement to
  80.     // free all the actionformats from the map
  81.     void FreeMap();
  82.  
  83.     // Applies all the acfor's in the map
  84.     void Apply();
  85. };
  86.  
  87. typedef CArray<ELEMENT, ELEMENT &> ELEMENTARRAY;
  88.  
  89. // CConfigWnd needs to expose methods for child windows to notify it.
  90. class CConfigWnd : public CFlexWnd, public IDIConfigUIFrameWindow
  91. {
  92. public:
  93.     CConfigWnd(CUIGlobals &uig);
  94.     ~CConfigWnd();
  95.  
  96.     BOOL Create(HWND hParent);
  97.     static void SetForegroundWindow();
  98.     LPDIRECTINPUTDEVICE8W RenewDevice(GUID &GuidInstance);
  99.  
  100.     BOOL EnumDeviceCallback(const DIDEVICEINSTANCEW *lpdidi);
  101.     void EnumDeviceCallbackAssignUser(const DIDEVICEINSTANCEW *lpdidi, DWORD *pdwOwner);
  102.  
  103.     CUIGlobals &m_uig;
  104.  
  105.     // IDIConfigUIFrameWindow implementation...
  106.  
  107.     // Reset Entire Configuration
  108.     STDMETHOD (Reset) ();
  109.  
  110.     // Assignment Querying. GuidInstance is the guid of the device initiating the query.
  111.     STDMETHOD (QueryActionAssignedAnywhere) (GUID GuidInstance, int i);
  112.  
  113.     // Genre Control
  114.     STDMETHOD_(int, GetNumGenres) ();
  115.     STDMETHOD (SetCurGenre) (int i);
  116.     STDMETHOD_(int, GetCurGenre) ();
  117.  
  118.     // User Control
  119.     STDMETHOD_(int, GetNumUsers) ();
  120.     STDMETHOD (SetCurUser) (int nPage, int nUser);
  121.     STDMETHOD_(int, GetCurUser) (int nPage);
  122.  
  123.     // ActionFormat Access
  124.     STDMETHOD (GetActionFormatFromInstanceGuid) (LPDIACTIONFORMATW *lplpAcFor, REFGUID);
  125.  
  126.     // Main HWND Access
  127.     STDMETHOD_(HWND, GetMainHWND) ();
  128.  
  129.  
  130. protected:
  131.     // overrides
  132.     virtual void OnRender(BOOL bInternalCall = FALSE);
  133.     virtual LRESULT OnCreate(LPCREATESTRUCT lpCreateStruct);
  134.     virtual void OnPaint(HDC hDC);
  135.     virtual void OnMouseOver(POINT point, WPARAM fwKeys);
  136.     virtual void OnClick(POINT point, WPARAM fwKeys, BOOL bLeft);
  137.     virtual void OnDestroy();
  138.     virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  139.  
  140. private:
  141.  
  142. #define CFGWND_INIT_REINIT 1
  143. #define CFGWND_INIT_RESET 2
  144.  
  145.     BOOL Init(DWORD dwInitFlags = 0);
  146.     DWORD m_dwInitFlags;
  147.     BOOL m_bCreated;
  148.     int AddToList(const DIDEVICEINSTANCEW *lpdidi, BOOL bReset = FALSE);
  149.     void ClearList();
  150.     void PlacePages();
  151.     void GetPageRect(RECT &rect, BOOL bTemp = FALSE);
  152.     void Render(BOOL bInternalCall = FALSE);
  153.  
  154.     ELEMENTARRAY m_Element;
  155.     ELEMENT m_InvalidElement;
  156.     int m_CurSel;
  157.     int GetNumElements();
  158.     ELEMENT &GetElement(int i);
  159.     void ClearElement(int i, BOOL bReset = FALSE);
  160.     void ClearElement(ELEMENT &e, BOOL bReset = FALSE);
  161.     BOOL m_bScrollTabs, m_bScrollTabsLeft, m_bScrollTabsRight;
  162.     int m_nLeftTab;
  163.     RECT m_rectSTLeft, m_rectSTRight;
  164.     void ScrollTabs(int);
  165.     LPDIRECTINPUTDEVICE8W CreateDevice(GUID &guid);
  166.     BOOL m_bNeedRedraw;
  167.     CFlexMsgBox m_MsgBox;
  168.  
  169.     LPDIACTIONFORMATW GetCurAcFor(ELEMENT &e);
  170.  
  171.     int m_nCurGenre;
  172.  
  173.     IClassFactory *m_pPageFactory;
  174.     HINSTANCE m_hPageFactoryInst;
  175.     PAGETYPE *CreatePageObject(int nPage, const ELEMENT &e, HWND &refhChildWnd);
  176.     void DestroyPageObject(PAGETYPE *&pPage);
  177.  
  178.     LPDIRECTINPUT8W m_lpDI;
  179.  
  180.     RECT m_rectTopGradient, m_rectBottomGradient;
  181.     CBitmap *m_pbmTopGradient, *m_pbmBottomGradient;
  182.     BOOL m_bHourGlass;  // Set when the cursor should be an hourglass
  183.  
  184.     typedef struct BUTTON {
  185.         BUTTON() {CopyStr(tszCaption, _T(""), MAX_PATH);}
  186.         RECT rect;
  187.         TCHAR tszCaption[MAX_PATH];
  188.         SIZE textsize;
  189.         RECT textrect;
  190.     } BUTTON;
  191.     BUTTON m_Button[NUMBUTTONS];
  192.     enum {
  193.         BUTTON_RESET = 0,
  194.         BUTTON_CANCEL,
  195.         BUTTON_OK,
  196.     };
  197.  
  198.     SIZE GetTextSize(LPCTSTR tszText);
  199.  
  200.     void CalcTabs();
  201.     void CalcButtons();
  202.     void InitGradients();
  203.  
  204.     void SelTab(int);
  205.     void FireButton(int);
  206.     void ShowPage(int);
  207.     void HidePage(int);
  208.  
  209.     HDC GetRenderDC();
  210.     void ReleaseRenderDC(HDC &phDC);
  211.     void Create3DBitmap();
  212.     void Copy3DBitmapToSurface3D();
  213.     void CallRenderCallback();
  214.  
  215.     IDirectDrawSurface *m_pSurface;
  216.     IDirect3DSurface8 *m_pSurface3D;
  217.     D3DFORMAT m_SurfFormat;
  218.     UINT m_uiPixelSize;  // Size of a pixel in byte for the format we are using
  219.     CBitmap *m_pbmPointerEraser;
  220.     CBitmap *m_pbm3D;
  221.     LPVOID m_p3DBits;
  222.     BOOL m_bRender3D;
  223.  
  224.     POINT m_ptTest;
  225.  
  226.     void MapBitmaps(HDC);
  227.     BOOL m_bBitmapsMapped;
  228.  
  229.     BOOL m_bAllowEditLayout;
  230.     BOOL m_bEditLayout;
  231.     void ToggleLayoutEditting();
  232.  
  233.     CMouseTrap m_MouseTrap;
  234.  
  235.     // Timer
  236.     static void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
  237.  
  238.     HRESULT Apply();
  239.  
  240.     // GuidInstance is the guid of the device initiating the query.
  241.     BOOL IsActionAssignedAnywhere(GUID GuidInstance, int nActionIndex);
  242.  
  243.     void Unacquire();
  244.     void Reacquire();
  245. };
  246.  
  247.  
  248. #endif //__CONFIGWND_H__
  249.