SkinListDlg.cpp
上传用户:sgmlaoniu
上传日期:2022-06-15
资源大小:28k
文件大小:6k
源码类别:

ListView/ListBox

开发平台:

Visual C++

  1. // SkinListDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SkinList.h"
  5. #include "SkinListDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CAboutDlg dialog used for App About
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // Dialog Data
  18. //{{AFX_DATA(CAboutDlg)
  19. enum { IDD = IDD_ABOUTBOX };
  20. //}}AFX_DATA
  21. // ClassWizard generated virtual function overrides
  22. //{{AFX_VIRTUAL(CAboutDlg)
  23. protected:
  24. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  25. //}}AFX_VIRTUAL
  26. // Implementation
  27. protected:
  28. //{{AFX_MSG(CAboutDlg)
  29. //}}AFX_MSG
  30. DECLARE_MESSAGE_MAP()
  31. };
  32. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  33. {
  34. //{{AFX_DATA_INIT(CAboutDlg)
  35. //}}AFX_DATA_INIT
  36. }
  37. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CAboutDlg)
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  44. //{{AFX_MSG_MAP(CAboutDlg)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CSkinListDlg dialog
  49. CSkinListDlg::CSkinListDlg(CWnd* pParent /*=NULL*/)
  50. : CDialog(CSkinListDlg::IDD, pParent)
  51. {
  52. //{{AFX_DATA_INIT(CSkinListDlg)
  53. //}}AFX_DATA_INIT
  54. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  55. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  56. }
  57. void CSkinListDlg::DoDataExchange(CDataExchange* pDX)
  58. {
  59. CDialog::DoDataExchange(pDX);
  60. //{{AFX_DATA_MAP(CSkinListDlg)
  61. DDX_Control(pDX, IDC_SKIN_LIST, m_SkinList);
  62. //}}AFX_DATA_MAP
  63. }
  64. BEGIN_MESSAGE_MAP(CSkinListDlg, CDialog)
  65. //{{AFX_MSG_MAP(CSkinListDlg)
  66. ON_WM_SYSCOMMAND()
  67. ON_WM_PAINT()
  68. ON_WM_QUERYDRAGICON()
  69. ON_NOTIFY(HDN_ENDTRACK, 0, OnEndtrackSkinList)
  70. ON_WM_SIZE()
  71. //}}AFX_MSG_MAP
  72. END_MESSAGE_MAP()
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CSkinListDlg message handlers
  75. BOOL CSkinListDlg::OnInitDialog()
  76. {
  77. CDialog::OnInitDialog();
  78. // Add "About..." menu item to system menu.
  79. // IDM_ABOUTBOX must be in the system command range.
  80. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  81. ASSERT(IDM_ABOUTBOX < 0xF000);
  82. CMenu* pSysMenu = GetSystemMenu(FALSE);
  83. if (pSysMenu != NULL)
  84. {
  85. CString strAboutMenu;
  86. strAboutMenu.LoadString(IDS_ABOUTBOX);
  87. if (!strAboutMenu.IsEmpty())
  88. {
  89. pSysMenu->AppendMenu(MF_SEPARATOR);
  90. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  91. }
  92. }
  93. // Set the icon for this dialog.  The framework does this automatically
  94. //  when the application's main window is not a dialog
  95. SetIcon(m_hIcon, TRUE); // Set big icon
  96. SetIcon(m_hIcon, FALSE); // Set small icon
  97. m_SkinList.Init();
  98. m_SkinList.SetBkColor(RGB(76,85,118));
  99. m_SkinList.SetTextColor(RGB(222,222,222));
  100. LOGFONT lf;
  101. memset(&lf, 0, sizeof(LOGFONT));
  102. lf.lfHeight = 12;
  103. strcpy(lf.lfFaceName, "Verdana");
  104. font.CreateFontIndirect(&lf);
  105. m_SkinList.SetFont(&font, TRUE);
  106. m_SkinList.InsertColumn(0, "BLANK", LVCFMT_LEFT, 0);
  107. m_SkinList.InsertColumn(1, "SONG", LVCFMT_LEFT, 100);
  108. m_SkinList.InsertColumn(2, "ARTIST", LVCFMT_LEFT, 100);
  109. m_SkinList.InsertColumn(3, "GENRE", LVCFMT_LEFT, 100);
  110. m_SkinList.SetRedraw(FALSE);
  111. CString cszItem;
  112. for(int i=0; i<8000; i++)
  113. {
  114. cszItem.Format("%d - %s", i, "Matthew Good - Near Fantastica");
  115. m_SkinList.InsertItem(i, cszItem);
  116. m_SkinList.SetItemText(i, 1, cszItem);
  117. m_SkinList.SetItemText(i, 2, "Matthew Good");
  118. m_SkinList.SetItemText(i, 3, "Rock");
  119. }
  120. m_SkinList.SetRedraw(TRUE);
  121. ListView_SetExtendedListViewStyle(m_SkinList.m_hWnd, LVS_EX_FULLROWSELECT  | LVS_EX_HEADERDRAGDROP);
  122. return TRUE;  // return TRUE  unless you set the focus to a control
  123. }
  124. void CSkinListDlg::OnSysCommand(UINT nID, LPARAM lParam)
  125. {
  126. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  127. {
  128. CAboutDlg dlgAbout;
  129. dlgAbout.DoModal();
  130. }
  131. else
  132. {
  133. CDialog::OnSysCommand(nID, lParam);
  134. }
  135. }
  136. // If you add a minimize button to your dialog, you will need the code below
  137. //  to draw the icon.  For MFC applications using the document/view model,
  138. //  this is automatically done for you by the framework.
  139. void CSkinListDlg::OnPaint() 
  140. {
  141. if (IsIconic())
  142. {
  143. CPaintDC dc(this); // device context for painting
  144. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  145. // Center icon in client rectangle
  146. int cxIcon = GetSystemMetrics(SM_CXICON);
  147. int cyIcon = GetSystemMetrics(SM_CYICON);
  148. CRect rect;
  149. GetClientRect(&rect);
  150. int x = (rect.Width() - cxIcon + 1) / 2;
  151. int y = (rect.Height() - cyIcon + 1) / 2;
  152. // Draw the icon
  153. dc.DrawIcon(x, y, m_hIcon);
  154. }
  155. else
  156. {
  157. CDialog::OnPaint();
  158. }
  159. }
  160. // The system calls this to obtain the cursor to display while the user drags
  161. //  the minimized window.
  162. HCURSOR CSkinListDlg::OnQueryDragIcon()
  163. {
  164. return (HCURSOR) m_hIcon;
  165. }
  166. void CSkinListDlg::OnEndtrackSkinList(NMHDR* pNMHDR, LRESULT* pResult) 
  167. {
  168. HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
  169. m_SkinList.m_SkinHorizontalScrollbar.UpdateThumbPosition();
  170. *pResult = 0;
  171. }
  172. void CSkinListDlg::OnSize(UINT nType, int cx, int cy) 
  173. {
  174. CDialog::OnSize(nType, cx, cy);
  175. CRect rect;
  176. GetClientRect(&rect);
  177. rect.DeflateRect(50,50,50,50);
  178. if(m_SkinList)
  179. {
  180. if(rect.Width() > 100 && rect.Height() > 100)
  181. {
  182. m_SkinList.SetWindowPos(NULL, 0,0, rect.Width(), rect.Height(), SWP_NOMOVE);
  183. m_SkinList.PositionScrollBars();
  184. }
  185. }
  186. }