SkinSBDemoDlg.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // SkinSBDemoDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SkinSBDemo.h"
  5. #include "SkinSBDemoDlg.h"
  6. #include "..\lib\skinsb.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // CAboutDlg dialog used for App About
  11. class CAboutDlg : public CDialog
  12. {
  13. public:
  14. CAboutDlg();
  15. // Dialog Data
  16. enum { IDD = IDD_ABOUTBOX };
  17. protected:
  18. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  19. // Implementation
  20. protected:
  21. DECLARE_MESSAGE_MAP()
  22. };
  23. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  24. {
  25. }
  26. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. }
  30. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  31. END_MESSAGE_MAP()
  32. // CSkinSBDemoDlg dialog
  33. CSkinSBDemoDlg::CSkinSBDemoDlg(CWnd* pParent /*=NULL*/)
  34. : CDialog(CSkinSBDemoDlg::IDD, pParent)
  35. {
  36. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  37. m_bmScroll.LoadBitmap(IDB_SCROLL);
  38. }
  39. void CSkinSBDemoDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
  43. }
  44. BEGIN_MESSAGE_MAP(CSkinSBDemoDlg, CDialog)
  45. ON_WM_SYSCOMMAND()
  46. ON_WM_PAINT()
  47. ON_WM_QUERYDRAGICON()
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. // CSkinSBDemoDlg message handlers
  51. BOOL CSkinSBDemoDlg::OnInitDialog()
  52. {
  53. CDialog::OnInitDialog();
  54. // Add "About..." menu item to system menu.
  55. // IDM_ABOUTBOX must be in the system command range.
  56. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  57. ASSERT(IDM_ABOUTBOX < 0xF000);
  58. CMenu* pSysMenu = GetSystemMenu(FALSE);
  59. if (pSysMenu != NULL)
  60. {
  61. CString strAboutMenu;
  62. strAboutMenu.LoadString(IDS_ABOUTBOX);
  63. if (!strAboutMenu.IsEmpty())
  64. {
  65. pSysMenu->AppendMenu(MF_SEPARATOR);
  66. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  67. }
  68. }
  69. // Set the icon for this dialog. The framework does this automatically
  70. // when the application's main window is not a dialog
  71. SetIcon(m_hIcon, TRUE); // Set big icon
  72. SetIcon(m_hIcon, FALSE); // Set small icon
  73. // TODO: Add extra initialization here
  74. m_ListCtrl.InsertColumn(0, TEXT("姓名"), LVCFMT_CENTER, 60);
  75. m_ListCtrl.InsertColumn(1, TEXT("年龄"), LVCFMT_CENTER, 60);
  76. m_ListCtrl.InsertColumn(2, TEXT("手机"), LVCFMT_CENTER, 60);
  77. m_ListCtrl.InsertColumn(4, TEXT("QQ"), LVCFMT_CENTER, 60);
  78. m_ListCtrl.InsertColumn(5, TEXT("地址"), LVCFMT_CENTER, 60);
  79. CString str = _T("");
  80. for( int i = 0; i < 50; i++ )
  81. {
  82. str.Format(_T("%02d"), i);
  83. int nItem = m_ListCtrl.InsertItem(0, str);
  84. m_ListCtrl.SetItemText(nItem, 1, TEXT("测试"));
  85. m_ListCtrl.SetItemText(nItem, 2, TEXT("测试"));
  86. m_ListCtrl.SetItemText(nItem, 3, TEXT("测试"));
  87. m_ListCtrl.SetItemText(nItem, 4, TEXT("测试"));
  88. }
  89. //设置控件皮肤
  90. SkinSB_Init(GetDlgItem(IDC_EDIT1)->GetSafeHwnd(), m_bmScroll);
  91. SkinSB_Init(m_ListCtrl, m_bmScroll);
  92. return TRUE; // return TRUE unless you set the focus to a control
  93. }
  94. void CSkinSBDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  95. {
  96. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  97. {
  98. CAboutDlg dlgAbout;
  99. dlgAbout.DoModal();
  100. }
  101. else
  102. {
  103. CDialog::OnSysCommand(nID, lParam);
  104. }
  105. }
  106. // If you add a minimize button to your dialog, you will need the code below
  107. // to draw the icon. For MFC applications using the document/view model,
  108. // this is automatically done for you by the framework.
  109. void CSkinSBDemoDlg::OnPaint()
  110. {
  111. if (IsIconic())
  112. {
  113. CPaintDC dc(this); // device context for painting
  114. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  115. // Center icon in client rectangle
  116. int cxIcon = GetSystemMetrics(SM_CXICON);
  117. int cyIcon = GetSystemMetrics(SM_CYICON);
  118. CRect rect;
  119. GetClientRect(&rect);
  120. int x = (rect.Width() - cxIcon + 1) / 2;
  121. int y = (rect.Height() - cyIcon + 1) / 2;
  122. // Draw the icon
  123. dc.DrawIcon(x, y, m_hIcon);
  124. }
  125. else
  126. {
  127. CDialog::OnPaint();
  128. }
  129. }
  130. // The system calls this function to obtain the cursor to display while the user drags
  131. // the minimized window.
  132. HCURSOR CSkinSBDemoDlg::OnQueryDragIcon()
  133. {
  134. return static_cast<HCURSOR>(m_hIcon);
  135. }