#include #include #include #include #include #include #include #include "resource.h" #include "dbgcdraw.h" #include "chklistv.h" #include "lvprops.h" static HINSTANCE g_hInstance; static const int c_nMaxImages = 20; static const int c_nAdditionalMarginX = 10; static const int c_nAdditionalMarginY = 10; class CListviewTestDialog { private: HWND m_hWnd; CCheckedListviewHandler m_CheckedListviewHandler; SIZE m_sizeImage; SIZE m_sizeMargin; private: CListviewTestDialog(void); CListviewTestDialog( const CListviewTestDialog & ); CListviewTestDialog &operator=( const CListviewTestDialog & ); private: explicit CListviewTestDialog( HWND hWnd ) : m_hWnd(hWnd) { ZeroMemory(&m_sizeImage,sizeof(SIZE)); m_sizeMargin.cx = c_nAdditionalMarginX; m_sizeMargin.cy = c_nAdditionalMarginY; } ~CListviewTestDialog(void) { } LRESULT OnListClick( WPARAM wParam, LPARAM lParam ) { m_CheckedListviewHandler.HandleListClick( wParam, lParam ); return 0; } LRESULT OnListDblClk( WPARAM wParam, LPARAM lParam ) { m_CheckedListviewHandler.HandleListDblClk( wParam, lParam ); return 0; } LRESULT OnGetCheckState( WPARAM wParam, LPARAM lParam ) { LRESULT lResult = 0; NMGETCHECKSTATE *pNmGetCheckState = reinterpret_cast(lParam); if (pNmGetCheckState) { LVITEM LvItem = {0}; LvItem.iItem = pNmGetCheckState->nItem; LvItem.mask = LVIF_PARAM; if (ListView_GetItem( pNmGetCheckState->hdr.hwndFrom, &LvItem )) { if (LvItem.lParam) { lResult = LVCHECKSTATE_CHECKED; } else { lResult = LVCHECKSTATE_UNCHECKED; } } } return lResult; } LRESULT OnSetCheckState( WPARAM wParam, LPARAM lParam ) { LRESULT lResult = 0; NMSETCHECKSTATE *pNmSetCheckState = reinterpret_cast(lParam); if (pNmSetCheckState) { LVITEM LvItem = {0}; LvItem.mask = LVIF_PARAM; LvItem.iItem = pNmSetCheckState->nItem; LvItem.lParam = (pNmSetCheckState->nCheck == LVCHECKSTATE_CHECKED) ? 1 : 0; ListView_SetItem( pNmSetCheckState->hdr.hwndFrom, &LvItem ); } return 0; } LRESULT OnListCustomDraw( WPARAM wParam, LPARAM lParam ) { LRESULT lResult = CDRF_DODEFAULT; m_CheckedListviewHandler.HandleListCustomDraw( wParam, lParam, lResult ); return lResult; } LRESULT OnListKeyDown( WPARAM wParam, LPARAM lParam ) { LRESULT lResult = FALSE; m_CheckedListviewHandler.HandleListKeyDown( wParam, lParam, lResult ); return lResult; } LRESULT OnInitDialog( WPARAM, LPARAM ) { HWND hwndList = GetDlgItem( m_hWnd, IDC_LIST ); if (hwndList) { // // Attach this control to the checkbox handler // m_CheckedListviewHandler.Attach(hwndList); // // Load an image for the image list // struct { UINT nResId; HBITMAP hBitmap; int nImageIndex; } Images[] = { { IDB_IMAGE1, NULL, 0 }, { IDB_IMAGE2, NULL, 0 }, { IDB_IMAGE3, NULL, 0 }, { IDB_IMAGE4, NULL, 0 }, { IDB_IMAGE5, NULL, 0 } }; WIA_TRACE((TEXT("line: %d"), __LINE__ )); bool bSuccess = true; for (int i=0;i(LoadImage(g_hInstance,MAKEINTRESOURCE(Images[i].nResId), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION )); if (!Images[i].hBitmap) { bSuccess = false; } } if (bSuccess) { // // Get the image's dimensions // BITMAP bm = {0}; if (GetObject( Images[0].hBitmap, sizeof(BITMAP), &bm )) { m_sizeImage.cx = bm.bmWidth; m_sizeImage.cy = bm.bmHeight; // // Create the image list // HIMAGELIST hImageList = ImageList_Create( m_sizeImage.cx, m_sizeImage.cy, ILC_COLOR24, 1, 1 ); if (hImageList) { // // Set the image list // ListView_SetImageList( hwndList, hImageList, LVSIL_NORMAL ); // // Add the image to the image list // bSuccess = true; for (int i=0;i(&Data) ); if (IDOK == nRes) { m_CheckedListviewHandler.FullImageHit(Data.bFullItemSelect); m_sizeMargin.cx = Data.sizeItemSpacing.cx; m_sizeMargin.cy = Data.sizeItemSpacing.cy; if (Data.bCustomIcon) { m_CheckedListviewHandler.SetCheckboxImages( (HICON)LoadImage( g_hInstance, MAKEINTRESOURCE(IDI_CHECKED), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR ), (HICON)LoadImage( g_hInstance, MAKEINTRESOURCE(IDI_UNCHECKED), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR ) ); } else { m_CheckedListviewHandler.CreateDefaultCheckBitmaps(); } ListView_SetIconSpacing( GetDlgItem(m_hWnd,IDC_LIST), m_sizeImage.cx + m_sizeMargin.cx, m_sizeImage.cy + m_sizeMargin.cy ); InvalidateRect( GetDlgItem(m_hWnd,IDC_LIST), NULL, TRUE ); UpdateWindow( GetDlgItem(m_hWnd,IDC_LIST) ); } } LRESULT OnNotify( WPARAM wParam, LPARAM lParam ) { SC_BEGIN_NOTIFY_MESSAGE_HANDLERS() { } SC_END_NOTIFY_MESSAGE_HANDLERS(); } LRESULT OnCommand( WPARAM wParam, LPARAM lParam ) { SC_BEGIN_COMMAND_HANDLERS() { SC_HANDLE_COMMAND(IDOK,OnOK); SC_HANDLE_COMMAND(IDCANCEL,OnCancel); SC_HANDLE_COMMAND(IDC_SELECTCURR,OnSelectCurr); SC_HANDLE_COMMAND(IDC_SELECTALL,OnSelectAll); SC_HANDLE_COMMAND(IDC_SELECTNONE,OnSelectNone); SC_HANDLE_COMMAND(IDC_PROPERTIES,OnProperties); } SC_END_COMMAND_HANDLERS(); } public: static INT_PTR CALLBACK DialogProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { SC_BEGIN_DIALOG_MESSAGE_HANDLERS(CListviewTestDialog) { SC_HANDLE_DIALOG_MESSAGE( WM_INITDIALOG, OnInitDialog ); SC_HANDLE_DIALOG_MESSAGE( WM_COMMAND, OnCommand ); SC_HANDLE_DIALOG_MESSAGE( WM_NOTIFY, OnNotify ); } SC_END_DIALOG_MESSAGE_HANDLERS(); } }; int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR, int ) { WIA_DEBUG_CREATE( hInstance ); g_hInstance = hInstance; InitCommonControls(); DialogBox(hInstance,MAKEINTRESOURCE(IDD_LISTVIEW_TEST_DIALOG), NULL, CListviewTestDialog::DialogProc ); WIA_DEBUG_DESTROY(); return 0; }