void CPictureListView::InitDialog(HWND hListView) { if (hListView) SubclassWindow(hListView); RECT rect; GetClientRect(&rect); m_nThumbnailSize = (rect.right - rect.left) - SCROLL_BAR_WIDTH; SetIconSpacing(m_nThumbnailSize, m_nThumbnailSize); m_ImageList.Create(m_nThumbnailSize, m_nThumbnailSize, ILC_COLOR24, 0, 1); SetImageList(m_ImageList, LVSIL_NORMAL); }
BOOL CFolderListCtrl::SetViewProp( const CFLCProperties& prop ) { if( prop == m_Properties ) return TRUE; CSCADString sPath = m_sFolderPath; m_Properties = prop; m_sFolderPath.Empty(); SetIconSpacing(m_Properties.m_nItemCX + 10, m_Properties.m_nItemCY+40); return SetCurFolder( sPath ); }
void CRasterResourceListCtrl::_OnInitListView(int cItems) { // Put an imagelist in the view, for our pic previews. // Destroy any old list if (_himlPics) { ImageList_Destroy(_himlPics); _himlPics = NULL; } CSize sizeImages(VIEW_IMAGE_SIZE, VIEW_IMAGE_SIZE); // Note: this color depth must match that which we get back from the ViewResource // Also: ILC_MASK must be specified, because of the overlay _himlPics = ImageList_Create(sizeImages.cx, sizeImages.cy, ILC_COLOR8 | ILC_MASK, cItems, 30); if (_himlPics) { CImageList *pTemp = CImageList::FromHandle(_himlPics); if (pTemp) { HIMAGELIST himlOld = (HIMAGELIST)SetImageList(pTemp, LVSIL_NORMAL); } // pTemp is a temporary object that we don't need to delete. // Load an overlay image to use for "unused" items HBITMAP hbmOverlay = LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_OVERLAYOLD40)); if (hbmOverlay) { int iOverlayImageIndex = ImageList_AddMasked(_himlPics, hbmOverlay, RGB(255, 0, 255)); ImageList_SetOverlayImage(_himlPics, iOverlayImageIndex, OVERLAYINDEX_UNUSED); DeleteObject(hbmOverlay); } HBITMAP hbmCorrupt = LoadBitmap(AfxGetResourceHandle(), MAKEINTRESOURCE(IDB_CORRUPTRESOURCE)); if (hbmCorrupt) { _iCorruptBitmapIndex = ImageList_Add(_himlPics, hbmCorrupt, NULL); DeleteObject(hbmCorrupt); } } // Adjust the icon spacing so things don't look too spread out. CSize sizeSpacing(sizeImages.cx + 20, sizeImages.cy + 30); SetIconSpacing(sizeSpacing); // LVS_EX_BORDERSELECT, supported on IE 4.0 or later. -> Removed, as it causes problems in details view // LVS_EX_DOUBLEBUFFER, supported on XP or later. SetExtendedStyle(GetExtendedStyle() | 0x00010000 | LVS_EX_INFOTIP); }
/* 仅图标模式有效。 初始化的时候,如果 SetFont(NULL); CY_LABEL_TEXT = 19。 如果 不写 SetFont(NULL); 这句话,CY_LABEL_TEXT = 16。 nSpaceY 小于 MIN_CY_IMAGESPACE 的话,会导致绘制后布局不正确。 另外,如果文字过长,覆盖到下一行图片的区域的话,也会导致刷新不正确。 */ BOOL CxResLibImgList::InitImageLayout( int nItemCx, int nItemCy , int nSpaceX, int nSpaceY, int nImgCx, int nImgCy, Color crImgBk ) { //if ( nItemCx < 1 || nItemCy < MIN_CY_SPACE_IMAGE || nSpaceX < 0 ) return FALSE; //if (MIN_CY_SPACE_IMAGE > nSpaceY) return FALSE; Clear(); DeleteAllItems(); m_nItemCx = nItemCx; m_nItemCy = nItemCy; m_nItemCxSpace = nSpaceX; m_nItemCySpace = nSpaceY; m_nImgCx = nImgCx; m_nImgCy = nImgCy; /* The cx and cy parameters are relative to the upper-left corner of an icon bitmap. Therefore, to set spacing between icons that do not overlap, the cx or cy values must include the size of the icon, plus the amount of empty space desired between icons. Values that do not include the width of the icon will result in overlaps. */ CSize szSpacing = SetIconSpacing(m_nItemCx + m_nItemCxSpace, m_nItemCy + m_nItemCySpace); if ( NULL != m_ImageList.GetSafeHandle() ) m_ImageList.DeleteImageList(); if (!m_ImageList.Create(m_nItemCx, m_nItemCy - MIN_CY_SPACE_ITEM, ILC_COLOR32, 1, 1)) { return FALSE; } // COLORREF clr = RGB(m_crImgBk.GetR(), m_crImgBk.GetG(), m_crImgBk.GetB()); m_ImageList.SetBkColor(clr); SetImageList( &m_ImageList, LVSIL_NORMAL ); return TRUE; }
void CFeedIcoItemListCtrl::Init() { //SetName(_T("RSSIcoListCtrl")); ModifyStyle(0, WS_CLIPCHILDREN); m_PosterImageList.Create(100,100,ILC_COLORDDB,1,1); m_imageRss_PosterBg = GetPng(_T("PNG_RSS_POSTER_BG")); m_imageRss_PosterDefault = GetPng(_T("PNG_RSS_POSTER_DEFAULT")); m_imageRss_PosterSelBg = GetPng(_T("PNG_RSS_POSTER_SELECTED_BG")); m_imageRss_GroupBg = GetPng(_T("PNG_RSS_GROUP_BG")); m_imageRss_Group_Drop_Up_Nor = GetPng(_T("RSS_GROUP_DROP_UP_NORMAL")); m_imageRss_Group_Drop_Up_Hov = GetPng(_T("RSS_GROUP_DROP_UP_HOVER")); m_imageRss_Group_Drop_Down_Nor = GetPng(_T("RSS_GROUP_DROP_DOWN_NORMAL")); m_imageRss_Group_Drop_Down_Hov = GetPng(_T("RSS_GROUP_DROP_DOWN_HOVER")); this->SetImageList(&m_PosterImageList,LVSIL_NORMAL); //AddImg2List(m_imageRss_PosterDefault); SetIconSpacing(150,150); m_FontBold.CreateFont(16,0,0,0,FW_BOLD,FALSE,FALSE,0,0,0,0,0,0,_TEXT("tahoma"));//标题 m_pMenuXP = NULL; EnableGroupView(TRUE); if ( thePrefs.GetWindowsVersion() >= _WINVER_VISTA_ ) { SetGroupHeight(38); } else { SetGroupHeight(28); } }
void TListViewCtrl::SetIconSpacing(const TPoint& pt) { PRECONDITION(GetHandle()); SetIconSpacing(pt.x, pt.y); }
void cMarketImage::LoadRemoteImages( int iGroup, bool bShowPurchased, LPCSTR szOrderBy, int page, int itemsperpage, bool bThumbnailsUpdate ) { if ( m_pParent ) { //m_pParent->m_textNoItems.ShowWindow( SW_HIDE ); m_pParent->CancelRefresh(); } for ( int i = 0; i <= MAX_ITEMS_PER_PAGE; i++ ) m_dwObjID [ i ] = 0; m_iItemClicked = -1; m_Images.DeleteImageList ( ); m_Images.Create ( 64, 64, ILC_COLOR32 | ILC_MASK, 1, 16 ); //m_Images.SetBkColor ( RGB ( 255, 255, 255 ) ); DeleteAllItems ( ); SetImageList ( &m_Images, LVSIL_NORMAL ); SetIconSpacing( 0, 130 ); SetRedraw( FALSE ); int iGroupID = 0; MarketGroup *pGroup = NULL; MarketObject *pObject = NULL; bool bIsSearch = false; bool bIsCart = false; bool bIsRoot = false; bool bIsItems = false; bool bNeedThumbnailUpdate = false; CString sThumbnailsNeeded = ""; if ( iGroup == 0 ) bIsRoot = true; else if ( iGroup == -1 ) bIsSearch = true; else if ( iGroup == -2 ) bIsCart = true; else if ( iGroup == -3 ) bIsItems = true; else if ( iGroup == -4 ) iGroupID = -4; else { pGroup = MarketObject::GetGroup( iGroup ); if ( pGroup ) iGroupID = pGroup->dwGroupID; } int imageCount = 0; int count = 0; if ( bIsRoot || bIsItems || (pGroup && pGroup->pChildGroup) ) { bool bIsArtistList = false; MarketGroup *pChild; if ( pGroup ) pChild = pGroup->pChildGroup; else if ( bIsItems ) { pChild = MarketObject::GetGroupList(); bIsArtistList = true; } else if ( bIsRoot ) { //main menu CBitmap bmpFolder; bmpFolder.LoadBitmap( IDB_FOLDER_ICON ); m_Images.Add( &bmpFolder, (CBitmap*)NULL ); imageCount++; CString sSearchResults = GetLanguageData( "TGC Store", "SearchResults" ); CString sShoppingCart = GetLanguageData( "TGC Store", "ShoppingCart" ); CString sFreeItems = GetLanguageData( "TGC Store", "FreeItems" ); CString sOnlineItems = GetLanguageData( "TGC Store", "OnlineItems" ); sSearchResults += "\\"; sShoppingCart += "\\"; sFreeItems += "\\"; sOnlineItems += "\\"; InsertItem ( 0, sSearchResults, 0 ); InsertItem ( 1, sShoppingCart, 0 ); InsertItem ( 2, sOnlineItems, 0 ); SetRedraw( TRUE ); Invalidate( ); return; } int iGroupCount = 0; while ( pChild ) { iGroupCount++; pChild = pChild->pNextGroup; } MarketGroup** pSortedGroupList = new MarketGroup* [ iGroupCount ]; if ( pGroup ) pChild = pGroup->pChildGroup; else pChild = MarketObject::GetGroupList(); iGroupCount = 0; while ( pChild ) { pSortedGroupList [ iGroupCount ] = pChild; iGroupCount++; pChild = pChild->pNextGroup; } ::sort( pSortedGroupList, pSortedGroupList + iGroupCount, cmpG ); CBitmap bmpFolder; bmpFolder.LoadBitmap( IDB_FOLDER_ICON ); m_Images.Add( &bmpFolder, (CBitmap*)NULL ); imageCount++; if ( bIsArtistList ) { bool bNeedImages = false; for( int i=0; i < iGroupCount; i++ ) { CString sName = pSortedGroupList [ i ]->szName; EnterCriticalSection( &theApp.m_csDirectoryChanges ); SetCurrentDirectory( theApp.m_szDirectory ); CString path = "Files\\TGCStore\\TEMP\\Artists\\"; path += sName; path += ".bmp"; CImage image; HRESULT hr = image.Load( path ); LeaveCriticalSection( &theApp.m_csDirectoryChanges ); sName += "\\"; if ( FAILED(hr) ) { InsertItem ( count++, sName, 0 ); bNeedImages = true; } else { CWindowDC wndDC( this ); CDC dc; dc.CreateCompatibleDC( &wndDC ); CBitmap bitmap; bitmap.CreateBitmap( 64,64, 1, 32, NULL ); CBitmap *oldBmp = dc.SelectObject( &bitmap ); image.StretchBlt( dc.GetSafeHdc( ), 0,0, 64,64 ); dc.SelectObject( oldBmp ); m_Images.Add( &bitmap, (CBitmap*)NULL ); InsertItem ( count++, sName, imageCount++ ); } } if ( bNeedImages && m_pParent && !m_pParent->AreArtistIconsLoaded() ) m_pParent->SetTimer( 5, 1000, NULL ); } else { for( int i=0; i < iGroupCount; i++ ) { CString sName = pSortedGroupList [ i ]->szName; sName += "\\"; InsertItem ( count++, sName, 0 ); } } delete [] pSortedGroupList; } CBitmap bmpNoThumbnail; bmpNoThumbnail.LoadBitmap( IDB_NO_THUMBNAIL ); m_Images.Add( &bmpNoThumbnail, (CBitmap*)NULL ); int iNoThumbnailIcon = imageCount; imageCount++; if ( bIsSearch ) pObject = MarketObject::GetSearchList( ); else if ( bIsCart ) pObject = MarketObject::GetCartList( ); else pObject = MarketObject::GetObjectList( ); int iObjCount = 0; while ( pObject ) { if ( ( bShowPurchased || !pObject->IsPurchased() ) && ( bIsSearch || bIsCart || iGroupID == -4 || pObject->GetGroupID( ) == iGroupID ) ) { iObjCount++; } pObject = pObject->pNextObject; } if ( iObjCount == 0 && count == 0 ) { //InsertItem ( 0, "<No Items>", -1 ); if ( m_pParent ) m_pParent->ShowNoItemsMsg(); if ( m_pParent ) m_pParent->SetPageNumbers( 1,1 ); SetRedraw( TRUE ); Invalidate(); m_pParent->m_textNoItems.Invalidate(); return; } if ( iObjCount == 0 ) { if ( m_pParent ) m_pParent->SetPageNumbers( 1,1 ); } else { if ( bIsSearch ) pObject = MarketObject::GetSearchList( ); else if ( bIsCart ) pObject = MarketObject::GetCartList( ); else pObject = MarketObject::GetObjectList( ); MarketObject **pSortedList = new MarketObject* [ iObjCount ]; iObjCount = 0; while ( pObject ) { if ( ( bShowPurchased || !pObject->IsPurchased() ) && ( bIsSearch || bIsCart || iGroupID == -4 || pObject->GetGroupID( ) == iGroupID ) ) { pSortedList [ iObjCount ] = pObject; iObjCount++; } pObject = pObject->pNextObject; } if ( szOrderBy && strlen( szOrderBy ) > 0 ) { MarketObject::SetSortIndex( szOrderBy ); ::sort( pSortedList, pSortedList + iObjCount, cmpO ); } //HZIP zpImages = OpenZip( "Files\\TGCStore\\TEMP\\Thumbnails.zip", NULL ); //if ( !zpImages ) MessageBox( "Failed to open image zip" ); //int count = 0; //int imageCount = 0; int start = 0; int end = iObjCount; if ( itemsperpage > 0 ) { int iMaxPage = (iObjCount-1) / itemsperpage + 1; if ( page > iMaxPage ) page = iMaxPage; if ( page < 1 ) page = 1; if ( m_pParent ) m_pParent->SetPageNumbers( page, iMaxPage ); if ( iObjCount > itemsperpage ) { start = (page-1) * itemsperpage; end = (page * itemsperpage); if ( end > iObjCount ) end = iObjCount; } } for ( int i = start; i < end; i++ ) { pObject = pSortedList [ i ]; try { if ( !pObject->GetThumbnail( ) ) throw 1; /* int iIndex = -1; ZRESULT result = FindZipItem( zpImages, pObject->GetThumbnail( ), true, &iIndex, NULL ); if ( result != ZR_OK ) { //char str [ 32 ]; //sprintf_s( str, 32, "Error: %d", result ); //MessageBox( str ); //MessageBox( pObject->GetThumbnail( ) ); } if ( iIndex < 0 ) throw 2; */ EnterCriticalSection( &theApp.m_csDirectoryChanges ); SetCurrentDirectory( theApp.m_szDirectory ); CString path = "Files\\TGCStore\\TEMP\\Thumbnails\\"; path += pObject->GetThumbnail( ); CImage image; HRESULT hr = image.Load( path ); LeaveCriticalSection( &theApp.m_csDirectoryChanges ); if ( FAILED(hr) ) { if ( bNeedThumbnailUpdate ) sThumbnailsNeeded += ";"; char szID [ 12 ]; sprintf_s( szID, 12, "%d", pObject->GetID() ); sThumbnailsNeeded += szID; bNeedThumbnailUpdate = true; throw 3; } CWindowDC wndDC( this ); CDC dc; dc.CreateCompatibleDC( &wndDC ); CBitmap bitmap; bitmap.CreateBitmap( 64,64, 1, 32, NULL ); CBitmap *oldBmp = dc.SelectObject( &bitmap ); image.StretchBlt( dc.GetSafeHdc( ), 0,0, 64,64 ); dc.SelectObject( oldBmp ); m_Images.Add( &bitmap, (CBitmap*)NULL ); //bitmap.DeleteObject( ); InsertItem ( count, pObject->GetName( ), imageCount ); if ( count <= MAX_ITEMS_PER_PAGE ) m_dwObjID [ count ] = pObject->GetID(); count++; imageCount++; } catch ( int ) { InsertItem ( count, pObject->GetName( ), iNoThumbnailIcon ); if ( count <= MAX_ITEMS_PER_PAGE ) m_dwObjID [ count ] = pObject->GetID(); count++; } } delete [] pSortedList; // CloseZip( zpImages ); //SetCurrentDirectory( szOldDir ); } if ( bNeedThumbnailUpdate && !bThumbnailsUpdate ) { if ( m_pParent ) m_pParent->UpdateThumbnails( sThumbnailsNeeded ); } SetRedraw( TRUE ); Invalidate( ); m_pParent->m_textNoItems.Invalidate(); }
void CPageNavigator::ActivateNewDoc(CAGDoc* pAGDoc, int nDefaultPage) { if (!m_hWnd) return; m_pAGDoc = pAGDoc; m_nPage = -1; // Stop all window updates to avoid flickering SetRedraw(false); // Remove any previously loaded items from the list control DeleteAllItems(); // Detach the image list from the list control RemoveImageList(LVSIL_NORMAL); // Destroy the image list m_ImageList.Destroy(); // Get out if no document to attach to if (!m_pAGDoc) return; ::SendMessage(m_hWnd, LVM_SETBKCOLOR, (WPARAM)0, (LPARAM)(COLORREF)RGB(241,243,245)); // Re-create the image list at the proper size bool bPortrait = m_pAGDoc->IsPortrait(); m_dxIcon = THUMBNAIL_WT; m_dyIcon = THUMBNAIL_HT; bool bOK = !!m_ImageList.Create(m_dxIcon, m_dyIcon, ILC_COLOR24, 1/*nInitial*/, 1/*nGrow*/); // Determine the document appropriate images to add to the image list AGDOCTYPE DocType = m_pAGDoc->GetDocType(); int nImages = 0; int* pidList1 = NULL; int* pidList2 = NULL; m_bIsCard = false; switch (DocType) { case DOC_BANNER: case DOC_BROCHURE: case DOC_BUSINESSCARD: case DOC_CDLABEL: case DOC_ENVELOPE: case DOC_FULLSHEET: case DOC_LABEL: case DOC_POSTCARD: case DOC_IRONON: case DOC_GIFTNAMECARD: case DOC_TRIFOLD: case DOC_HOLIDAYCARD: case DOC_PHOTOCARD: default: { nImages = (bPortrait ? sizeof(idList_PortraitPages1) : sizeof(idList_LandscapePages1)) / sizeof(int); pidList1 = (bPortrait ? idList_PortraitPages1 : idList_LandscapePages1); pidList2 = (bPortrait ? idList_PortraitPages2 : idList_LandscapePages2); m_bIsCard = false; break; } case DOC_HALFCARD: case DOC_QUARTERCARD: case DOC_NOTECARD: case DOC_CDBOOKLET: { nImages = (bPortrait ? sizeof(idList_PortraitCards1) : sizeof(idList_LandscapeCards1)) / sizeof(int); pidList1 = (bPortrait ? idList_PortraitCards1 : idList_LandscapeCards1); pidList2 = (bPortrait ? idList_PortraitCards2 : idList_LandscapeCards2); m_bIsCard = true; break; } } int nPages = m_pAGDoc->GetNumPages(); // Add the document appropriate images to the image list for (int nPass = 0; nPass < 2; nPass++) { for (int i = 0; i < nPages; i++) { int iIcon = (i < nImages ? i : nImages-1); int* pidList = (nPass == 0 ? pidList1 : pidList2); CImage Image(_AtlBaseModule.GetResourceInstance(), pidList[iIcon], "GIF"); HBITMAP hBitmap = Image.GetBitmapHandle(); //j HBITMAP hBitmap = ::LoadBitmap(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(pidList[iIcon])); if (!m_bIsCard) { CString strNumber; strNumber.Format("%d", i+1); DrawTextOnBitmap(hBitmap, strNumber, 16, RGB(0,0,0), 0, 2); } else if (i >= 4) { CString strNumber; strNumber.Format("+%d", i-3); DrawTextOnBitmap(hBitmap, strNumber, 16, RGB(0,0,0), 0, 2); } m_ImageList.Add(hBitmap); //j ::DeleteObject(hBitmap); } } // Attach the image list to the list control SetImageList(m_ImageList, LVSIL_NORMAL); // Set the icon spacing arbitrarily large to ensure that our icons are placed where we want them SetIconSpacing(1000, 1000); // Compute the spacing required on the top RECT ClientRect = {0,0,0,0}; GetClientRect(&ClientRect); m_yTop = (HEIGHT(ClientRect) - m_dyIcon) / 2; // Compute the spacing required on the left if (!m_bIsCard) m_xLeft = 2; else { int nIcons = 4; //(bPortrait ? 4 : 3); m_xLeft = (WIDTH(ClientRect) - (nIcons * m_dxIcon) - (2 * THUMBNAIL_GAP)) / 2; } // Insert the new list items int xLocation = m_xLeft; for (int i = 0; i < nPages; i++) { InsertItem(i/*nItem*/, "", i/*nImage*/); // shift the thumbnail to desired position int yCorrection = 0; POINT pt = {xLocation, m_yTop + yCorrection}; SetItemPosition(i, pt); xLocation += (m_dxIcon + THUMBNAIL_GAP); } SelectPage(nDefaultPage, true/*bSetState*/); SetRedraw(true); }
///////////////////////////////////////////////////////////////////////////// // handle custom drawing ///////////////////////////////////////////////////////////////////////////// void CCustomListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult) { int nItem; CSize sizeSpacing; CDC *pDC; CRect rect; CImageList *pImage; COLORREF color; NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR ); // Take the default processing unless we set this to something else below. *pResult = CDRF_DODEFAULT; // First thing - check the draw stage. If it's the control's prepaint // stage, then tell Windows we want messages for every item. if(CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage) { GetClientRect(&rect); //get device context pDC = CDC::FromHandle(pLVCD->nmcd.hdc); //clear background pDC->FillSolidRect(&rect, COLOR_BLACK); *pResult = CDRF_NOTIFYITEMDRAW; } else if(CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage) { //get the image list pImage = GetImageList(LVSIL_NORMAL); //get the item nItem = pLVCD->nmcd.dwItemSpec; //get the item spacing sizeSpacing = SetIconSpacing(0, 0); SetIconSpacing(sizeSpacing); //get device context pDC = CDC::FromHandle(pLVCD->nmcd.hdc); //get the item rect GetItemRect(nItem, &rect, LVIR_ICON); //set normal color color = TAB_COLOR_BACKGROUND; //offset the rect if needed if(LIST_CHIT_SPACING == m_nIconSize) { rect.OffsetRect(3, 0); } //fill selection background if(nItem == m_nSelection) { //get highlight color color = ::GetSysColor(COLOR_HIGHLIGHT); //fill it with the selected color pDC->FillSolidRect(&rect, color); } //offset the rect if needed if(LIST_CHIT_SPACING == m_nIconSize) { rect.OffsetRect(-3, 0); } //now draw the item if(NULL != pImage) { pImage->DrawIndirect(pDC, nItem, CPoint(rect.left + 4, rect.top + 2), CSize(32, 32), CPoint(0, 0)); } // Tell Windows to paint the control itself. *pResult = CDRF_SKIPDEFAULT; } }