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

  1. //-----------------------------------------------------------------------------
  2. // File: flexlistbox.h
  3. //
  4. // Desc: Implements a list box control that can display a list of text strings,
  5. //       each can be selected by mouse.  The class CFlexListBox is derived from
  6. //       CFlexWnd.  It is used by the class CFlexComboBox when it needs to
  7. //       expand to show the list of choices.
  8. //
  9. // Copyright (C) 1999-2001 Microsoft Corporation. All Rights Reserved.
  10. //-----------------------------------------------------------------------------
  11.  
  12. #ifndef __FLEXLISTBOX_H__
  13. #define __FLEXLISTBOX_H__
  14.  
  15.  
  16. #include "flexscrollbar.h"
  17.  
  18.  
  19. #define FLBF_INTEGRALHEIGHT        0x00000001
  20.  
  21. #define FLBF_DEFAULT (FLBF_INTEGRALHEIGHT)
  22.  
  23. enum {
  24.     FLBN_SEL,
  25.     FLBN_FINALSEL,
  26.     FLBN_CANCEL
  27. };
  28.  
  29. struct FLEXLISTBOXCREATESTRUCT {
  30.     DWORD dwSize;
  31.     DWORD dwFlags;
  32.     HWND hWndParent;
  33.     HWND hWndNotify;
  34.     BOOL bVisible;
  35.     RECT rect;
  36.     HFONT hFont;
  37.     COLORREF rgbText, rgbBk, rgbSelText, rgbSelBk, rgbFill, rgbLine;
  38.     int nSBWidth;
  39. };
  40.  
  41. struct FLEXLISTBOXITEM {
  42.     FLEXLISTBOXITEM() : pszText(NULL), nID(-1), pData(NULL), bSelected(FALSE) {}
  43.     FLEXLISTBOXITEM(const FLEXLISTBOXITEM &i) {nID = i.nID; pData = i.pData; bSelected = i.bSelected; SetText(i.GetText());}
  44.     ~FLEXLISTBOXITEM() {cleartext();}
  45.     void SetText(LPCTSTR str) {cleartext(); pszText = _tcsdup(str);}
  46.     LPCTSTR GetText() const {return pszText;}
  47.     int nID;
  48.     void *pData;
  49.     BOOL bSelected;
  50. private:
  51.     void cleartext() {if (pszText) free(pszText); pszText = NULL;}
  52.     LPTSTR pszText;    // allocated
  53. };
  54.  
  55.  
  56. class CFlexListBox : public CFlexWnd
  57. {
  58. public:
  59.     CFlexListBox();
  60.     ~CFlexListBox();
  61.  
  62.     // creation
  63.     BOOL Create(FLEXLISTBOXCREATESTRUCT *);
  64.     BOOL CreateForSingleSel(FLEXLISTBOXCREATESTRUCT *);
  65.  
  66.     // cosmetics
  67.     void SetFont(HFONT hFont);
  68.     void SetColors(COLORREF text, COLORREF bk, COLORREF seltext, COLORREF selbk, COLORREF fill, COLORREF line);
  69.  
  70.     // setup
  71.     int AddString(LPCTSTR);    // returns index
  72.  
  73.     // interaction
  74.     void SelectAndShowSingleItem(int i, BOOL bScroll = TRUE);
  75.     void SetSel(int i) {SelectAndShowSingleItem(i, FALSE);}
  76.     void StartSel();
  77.  
  78.     LPCTSTR GetSelText();
  79.     int GetSel();
  80.  
  81. protected:
  82.     virtual void OnPaint(HDC hDC);
  83.     virtual LRESULT WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  84.     virtual void OnWheel(POINT point, WPARAM wParam);
  85.  
  86. private:
  87.     HWND m_hWndNotify;
  88.  
  89.     CArray<FLEXLISTBOXITEM, FLEXLISTBOXITEM &> m_ItemArray;
  90.  
  91.     COLORREF m_rgbText, m_rgbBk, m_rgbSelText, m_rgbSelBk, m_rgbFill, m_rgbLine;
  92.     HFONT m_hFont;
  93.     int m_nSBWidth;
  94.  
  95.     int m_nTextHeight;
  96.  
  97.     DWORD m_dwFlags;
  98.  
  99.     int m_nSelItem;
  100.     int m_nTopIndex;
  101.         
  102.     void Calc();
  103.     void SetVertSB(BOOL);
  104.     void SetVertSB();
  105.     void SetSBValues();
  106.  
  107.     void InternalPaint(HDC hDC);
  108.     
  109.     void Notify(int code);
  110.  
  111.     POINT m_point;
  112.     BOOL m_bOpenClick;  // True when user click the combobox to open the listbox. False after that button up msg is processed.
  113.     BOOL m_bCapture;
  114.     BOOL m_bDragging;
  115.  
  116.     CFlexScrollBar m_VertSB;
  117.     BOOL m_bVertSB;
  118. };
  119.  
  120.  
  121. CFlexListBox *CreateFlexListBox(FLEXLISTBOXCREATESTRUCT *pcs);
  122.  
  123.  
  124. #endif //__FLEXLISTBOX_H__
  125.