本文整理汇总了C++中CImageList::Attach方法的典型用法代码示例。如果您正苦于以下问题:C++ CImageList::Attach方法的具体用法?C++ CImageList::Attach怎么用?C++ CImageList::Attach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CImageList
的用法示例。
在下文中一共展示了CImageList::Attach方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnCreate
int CContentsView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
ReloadSettings();
// _virtualMode = false;
// _sortIndex = 0;
_sortID = kpidName;
_ascending = true;
ListView_SetUnicodeFormat(*this, TRUE);
HIMAGELIST hImg = GetSysImageList(true);
CImageList *pImgList = CImageList::FromHandlePermanent(hImg);
if (pImgList == NULL) {
CImageList img;
img.Attach(hImg);
this->SetImageList(&img, LVSIL_SMALL);
img.Detach();
}
else
this->SetImageList(pImgList, LVSIL_SMALL);
hImg = GetSysImageList(false);
pImgList = CImageList::FromHandlePermanent(hImg);
if (pImgList == NULL) {
CImageList img;
img.Attach(hImg);
this->SetImageList(&img, LVSIL_NORMAL);
img.Detach();
}
else
this->SetImageList(pImgList, LVSIL_NORMAL);
CWnd *pParent = GetTopLevelParent();
_dropTargetSpec = new CDropTarget(pParent);
_dropTarget = _dropTargetSpec;
// ::DragAcceptFiles(hWnd, TRUE);
RegisterDragDrop(*pParent, _dropTarget);
// _exStyle |= LVS_EX_HEADERDRAGDROP;
// DWORD extendedStyle = _listView.GetExtendedListViewStyle();
// extendedStyle |= _exStyle;
// _listView.SetExtendedListViewStyle(extendedStyle);
// this->SetExtendedStyle(_exStyle);
SetTimer(kTimerID, kTimerElapse, NULL);
return 0;
}
示例2: CDialog
CFileDlg::CFileDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileDlg::IDD, pParent)
{
HRESULT hresut=CoInitialize(NULL);
SHFILEINFO sfi;
SHGetFileInfo
(
L"\\\\", //随便传递两个字节
FILE_ATTRIBUTE_NORMAL,
&sfi,
sizeof(SHFILEINFO),
SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_PIDL
);
m_hIcon = sfi.hIcon;
WCHAR Temp[100] = {0};
HIMAGELIST hImageList;
// 加载系统图标列表
hImageList = (HIMAGELIST)SHGetFileInfoW
(
Temp,
FILE_ATTRIBUTE_NORMAL,
&sfi,
sizeof(SHFILEINFO),
SHGFI_LARGEICON | SHGFI_SYSICONINDEX | SHGFI_PIDL
);
m_pImageList_Large.Attach(hImageList);
// 加载系统图标列表
hImageList = (HIMAGELIST)SHGetFileInfoW
(
Temp,
FILE_ATTRIBUTE_NORMAL,
&sfi,
sizeof(SHFILEINFO),
SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_PIDL
);
m_pImageList_Small.Attach(hImageList);
m_wParent = pParent;
}
示例3: InitDirectoryImageList
BOOL CFileWindow::InitDirectoryImageList( CImageList & imglst )
{
SHFILEINFO shFinfo; HIMAGELIST hImageList = NULL;
hImageList = (HIMAGELIST)SHGetFileInfo( "C:\\", 0, &shFinfo, sizeof( shFinfo ), SHGFI_SYSICONINDEX | SHGFI_SMALLICON );
if ( ! hImageList ) return FALSE;
if( imglst.Detach() ) AfxMessageBox( "This should not occur!");
imglst.Attach( hImageList );
return TRUE;
}
示例4: AddQuestion
void AddQuestion(HIMAGELIST hmyImageList)
{
CImageList imgList;
// Attach the image list handle to the CImageList object.
imgList.Attach(hmyImageList);
// Add a new icon to the image list.
imgList.Add(AfxGetApp()->LoadStandardIcon(IDI_QUESTION));
// Detach the handle from the CImageList object.
imgList.Detach();
}
示例5:
//*****************************************************************************
//*
//* CreateDragImage
//*
//*****************************************************************************
CImageList *CTreeListCtrl::CreateDragImage(HTREEITEM hItem, int nCol) {
CImageList *pImageList;
HIMAGELIST hImageList;
ASSERT(::IsWindow(m_hWnd));
hImageList = TreeList_CreateDragImageEx(m_hWnd, hItem, nCol);
if(!hImageList) {
return NULL;
}
pImageList = new CImageList;
VERIFY(pImageList->Attach(hImageList));
return pImageList;
}
示例6: setTrueColor
// CToolBarEx
bool CToolBarEx::setTrueColor(UINT nIDResource)
{
BITMAP bm;
CBitmap bitmap;
CImageList ilist;
if (!bitmap.Attach(LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(nIDResource),
IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_CREATEDIBSECTION))) return 0;
if (!bitmap.GetBitmap(&bm)) return 0;
if (!ilist.Attach(ImageList_Create(24, ITEM_H, ILC_COLORDDB | ILC_MASK, bm.bmWidth / 24, 0))) return 0;
RGBTRIPLE* rgb = (RGBTRIPLE*)(bm.bmBits);
COLORREF rgbMask = RGB(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
if (ilist.Add(&bitmap, rgbMask) == -1) return 0;
SendMessage(TB_SETIMAGELIST, 0, (LPARAM)ilist.m_hImageList);
ilist.Detach();
bitmap.DeleteObject();
return 1;
}
示例7: AddFile
void CPackagePage::AddFile(LPCTSTR pszFile)
{
HANDLE hFile = CreateFile( CString( _T("\\\\?\\") ) + pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL );
if ( hFile == INVALID_HANDLE_VALUE )
{
CString strFormat, strMessage;
strFormat.LoadString( IDS_PACKAGE_CANT_OPEN );
strMessage.Format( strFormat, pszFile );
AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
return;
}
DWORD nLow, nHigh;
nLow = GetFileSize( hFile, &nHigh );
QWORD nSize = ( (QWORD)nHigh << 32 ) + (QWORD)nLow;
CloseHandle( hFile );
SHFILEINFO pInfo = {};
HIMAGELIST hIL = (HIMAGELIST)SHGetFileInfo( pszFile, 0, &pInfo, sizeof(pInfo),
SHGFI_SYSICONINDEX|SHGFI_SMALLICON );
if ( hIL != NULL && m_hImageList == NULL )
{
m_hImageList = hIL;
CImageList pTemp;
pTemp.Attach( hIL );
m_wndList.SetImageList( &pTemp, LVSIL_SMALL );
pTemp.Detach();
}
int nItem = m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE, m_wndList.GetItemCount(),
pszFile, 0, 0, pInfo.iIcon, NULL );
m_wndList.SetItemText( nItem, 1, SmartSize( nSize ) );
UpdateWindow();
}
示例8: Init
void CDirectoryTreeCtrl::Init(bool bAllowCDROM /*= true*/)
{
#ifdef _UNICODE
// Win9x: Explicitly set to Unicode to receive Unicode notifications.
SendMessage(CCM_SETUNICODEFORMAT, TRUE);
#endif
DeleteAllItems();
SHFILEINFO shFinfo;
HIMAGELIST hImgList;
CImageList imageList;
// Get the system image list using a "path" which is available on all systems. [patch by bluecow]
hImgList = (HIMAGELIST)SHGetFileInfo(_T("."), FILE_ATTRIBUTE_DIRECTORY, &shFinfo, sizeof(shFinfo), SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
imageList.Attach(hImgList);
SetImageList(&imageList, TVSIL_NORMAL);
// Don't destroy the system's image list
imageList.Detach();
TCHAR drivebuffer[128], cDrv, *pos = drivebuffer;
::GetLogicalDriveStrings(ARRSIZE(drivebuffer), drivebuffer); // e.g. "a:\ c:\ d:\"
while(*pos != _T('\0'))
{
UINT dwDrvType = ::GetDriveType(pos);
// Skip floppy drives (check letter as some USB drives can also be removable) and in some cases CD/DVD
if ( ((dwDrvType != DRIVE_REMOVABLE) || (((cDrv = CHR2UP(*pos)) != _T('A')) && (cDrv != _T('B')))) &&
(bAllowCDROM || (dwDrvType != DRIVE_CDROM)) )
{
pos[2] = _T('\0');
AddChildItem(NULL, pos); // e.g. ("c:")
}
// Point to the next drive (4 chars interval)
pos += 4;
}
}
示例9: GetSysImgList
BOOL CProcessView::GetSysImgList()
/////////////////////////////////////////////////
{
CImageList sysImgList;
SHFILEINFO shFinfo;
HIMAGELIST hImageList = 0;
CString errorMessage;
TCHAR filename[MAX_PATH + 10];
if (GetModuleFileName(0, filename, MAX_PATH + 10))
{
hImageList = (HIMAGELIST)SHGetFileInfo(filename,
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON );
if (!hImageList)
{
int errorCode = GetLastError();
TCHAR buffer[1000];
memset(buffer, 0, 1000);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, errorCode, 0, buffer, 999, 0);
CString str;
str.Format(_T("SHGetFileInfo failed with error %d: %s"), errorCode, buffer);
errorMessage += str;
}
}
else
{
int errorCode = GetLastError();
TCHAR buffer[1000];
memset(buffer, 0, 1000);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, errorCode, 0, buffer, 999, 0);
CString str;
str.Format(_T("GetModuleFileName failed with error %d: %s"), errorCode, buffer);
errorMessage += str;
}
if (!hImageList)
{
/*
* Fall back to C:\\
* Not bullerproof, but better than nothing
*/
hImageList = (HIMAGELIST)SHGetFileInfo(_T("C:\\"),
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON );
if (!hImageList)
{
int errorCode = GetLastError();
TCHAR buffer[1000];
memset(buffer, 0, 1000);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, errorCode, 0, buffer, 999, 0);
CString str;
str.Format(_T("SHGetFileInfo failed with error %d: %s"), errorCode, buffer);
if (errorMessage != _T(""))
errorMessage += _T("\n");
errorMessage += str;
}
}
if (!hImageList)
{
AfxMessageBox(errorMessage);
return FALSE;
}
sysImgList.Attach(hImageList);
CListCtrl& lc = GetListCtrl();
lc.SetImageList( &sysImgList, LVSIL_SMALL);
sysImgList.Detach();
return TRUE;
}
示例10:
//.........这里部分代码省略.........
if(nStyle&TBBS_SEPARATOR)
continue;
m_mapCommands.SetAt(nID,-1);
}
}
}
//
////////////////////////////////////////
// built image list with all images used in the toolbars
VERIFY(m_ilImages.Create(ID_OXCUSTOMIZE_TBIMAGE_WIDTH,
ID_OXCUSTOMIZE_TBIMAGE_HEIGHT,ILC_COLOR24|ILC_MASK,0,0));
// Iterate all the control bars and use only the toolbars
pos=pMainFrameWnd->m_listControlBars.GetHeadPosition();
while(pos!=NULL)
{
CToolBar* pToolbar=DYNAMIC_DOWNCAST(CToolBar,
(CControlBar*)pMainFrameWnd->m_listControlBars.GetNext(pos));
//If its a CToolBar
if(pToolbar!=NULL)
{
// Get the original imagelist of the toolbar
HIMAGELIST hOrigImageList=
(HIMAGELIST)pToolbar->SendMessage(TB_GETIMAGELIST);
int nFirstImageIndex=0;
if(hOrigImageList!=NULL)
{
CImageList origImageList;
CImageList* pOrigImageList=
CImageList::FromHandlePermanent(hOrigImageList);
if(pOrigImageList==NULL)
{
if(!origImageList.Attach(hOrigImageList))
{
TRACE(_T("COXCustomizeShortkeysPage::InitializeCommands: failed to retrieve image list from toolbars\n"));
return FALSE;
}
pOrigImageList=&origImageList;
}
int nOrigImageCount=pOrigImageList->GetImageCount();
ASSERT(0<nOrigImageCount);
nFirstImageIndex=m_ilImages.GetImageCount();
for(int nButtonIndex=0; nButtonIndex<nOrigImageCount; nButtonIndex++)
{
HICON hIcon=pOrigImageList->ExtractIcon(nButtonIndex);
ASSERT(hIcon!=NULL);
VERIFY(m_ilImages.Add(hIcon)!=-1);
VERIFY(::DestroyIcon(hIcon));
}
// Close everything
if((HIMAGELIST)origImageList!=NULL)
{
origImageList.Detach();
}
}
int nButtonCount=pToolbar->GetToolBarCtrl().GetButtonCount();
// Iterate all buttons on the toolbar
for(int nButtonIndex=0; nButtonIndex<nButtonCount; nButtonIndex++)
{
UINT nID=0;
示例11: OnBeginDrag
void SmartListCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
if ( !eventHandler_ )
return;
LPNMLISTVIEW info = (LPNMLISTVIEW)pNMHDR;
std::string text;
int image;
getData( info->iItem, text, image );
POINT pt;
GetCursorPos( &pt );
if ( dragImgList_ )
{
delete dragImgList_;
dragImgList_ = 0;
}
int pos = GetNextItem( -1, LVNI_SELECTED );
bool isFirst = true;
int xoff = 0;
int yoff = 0;
int xstep = 0;
int ystep = 0;
IMAGEINFO imf;
int maxDragWidth = 400;
int maxDragHeight = 350;
while ( pos != -1 ) {
if ( isFirst ) {
dragImgList_ = CreateDragImage( pos, &pt );
dragImgList_->GetImageInfo( 0, &imf );
xstep = imf.rcImage.right - imf.rcImage.left;
ystep = imf.rcImage.bottom - imf.rcImage.top;
yoff = imf.rcImage.bottom;
isFirst = false;
}
else
{
if ( yoff + ystep > maxDragHeight && xoff + xstep > maxDragWidth )
generateDragListEndItem_ = true; // reached the max, so generate a 'more...' item in GetData
CImageList* oneImgList = CreateDragImage( pos, &pt );
generateDragListEndItem_ = false;
CImageList* tempImgList = new CImageList();
tempImgList->Attach(
ImageList_Merge(
dragImgList_->GetSafeHandle(),
0, oneImgList->GetSafeHandle(), 0, xoff, yoff ) );
delete dragImgList_;
delete oneImgList;
dragImgList_ = tempImgList;
dragImgList_->GetImageInfo( 0, &imf );
yoff += ystep;
if ( yoff > maxDragHeight )
{
xoff += xstep;
if ( xoff > maxDragWidth )
break;
yoff = 0;
}
}
pos = GetNextItem( pos, LVNI_SELECTED );
}
if ( dragImgList_ )
{
CPoint offset( thumbWidthCur_ + 16 , max( 16, thumbHeightCur_ - 14 ) );
dragImgList_->SetBkColor( GetBkColor() );
dragImgList_->SetDragCursorImage( 0, offset );
dragImgList_->BeginDrag( 0, offset );
dragImgList_->DragEnter( 0, pt );
}
if ( delayedSelectionPending_ )
{
// if a selection timer is pending, force it
delayedSelectionNotify();
}
dragging_ = true;
eventHandler_->listStartDrag( info->iItem );
}