Esempio n. 1
0
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;
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
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;
}
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();
}
Esempio n. 5
0
//*****************************************************************************
//*
//*		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;
}
Esempio n. 6
0
// 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;
}
Esempio n. 7
0
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();
}
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;
	}
}
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;
}
Esempio n. 10
0
BOOL COXCustomizeShortkeysPage::
InitializeShortkeys(CFrameWnd* pFrameWnd, 
					LPCTSTR lpszProfileName/*=_T("CustomizeShortkeys")*/)
{
	ASSERT(pFrameWnd!=NULL);

	CWinApp* pApp=AfxGetApp();
	ASSERT(pApp!=NULL);

	CWnd* pWnd=AfxGetMainWnd();
	ASSERT(pWnd!=NULL);
	CFrameWnd* pMainFrameWnd=DYNAMIC_DOWNCAST(CFrameWnd,pWnd);
	ASSERT(pMainFrameWnd!=NULL);

	// build array of all commands available in the system
	//
	// document menus
	if(m_pCustomizeManager->IsMDIFramework())
	{
		POSITION pos=pApp->GetFirstDocTemplatePosition();
		while(pos!=NULL)
		{
			CDocTemplate* pDocTemplate=pApp->GetNextDocTemplate(pos);
			ASSERT(pDocTemplate!=NULL);
			CMultiDocTemplate* pMultiDocTemplate=
				DYNAMIC_DOWNCAST(CMultiDocTemplate,pDocTemplate);
			if(pMultiDocTemplate!=NULL)
			{
				if(pMultiDocTemplate->m_hMenuShared!=NULL)
					RetrieveCommandsFromMenu(pMultiDocTemplate->m_hMenuShared);
			}
		}
	}

	// default menu
	HINSTANCE hInstance=AfxFindResourceHandle(MAKEINTRESOURCE(IDR_MAINFRAME),RT_MENU);
	if(hInstance!=NULL)
	{
		HMENU hMenu=::LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MAINFRAME));
		if(hMenu!=NULL)
		{
			RetrieveCommandsFromMenu(hMenu);
			::DestroyMenu(hMenu);
		}
	}

	// toolbars
	//
	// Iterate all the control bars and use only the toolbars
	POSITION pos=pFrameWnd->m_listControlBars.GetHeadPosition();
	while(pos!=NULL)
	{
		CToolBar* pToolbar=DYNAMIC_DOWNCAST(CToolBar, 
			(CControlBar*)pFrameWnd->m_listControlBars.GetNext(pos));
		//If it is a CToolBar
		if(pToolbar!=NULL)
		{
			// Get the original imagelist of the toolbar
			int nButtonCount=pToolbar->GetToolBarCtrl().GetButtonCount();
			// Iterate all buttons on the toolbar
			for(int nButtonIndex=0; nButtonIndex<nButtonCount; nButtonIndex++)
			{
				UINT nID=0;
				UINT nStyle=0;
				int nImageIndex=0;
				pToolbar->GetButtonInfo(nButtonIndex,nID,nStyle,nImageIndex);
				//If the Item is not a button
				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;
				UINT nStyle=0;
				int nImageIndex=0;
				pToolbar->GetButtonInfo(nButtonIndex,nID,nStyle,nImageIndex);
				//If the Item is not a button
				if(nStyle&TBBS_SEPARATOR || nImageIndex==-1)
					continue;

				int nImageIndexTest=-1;
				// check if this button is in the commands map
				VERIFY(m_mapCommands.Lookup(nID,nImageIndexTest));
				if(nImageIndexTest==-1)
				{
					nImageIndexTest=nImageIndex+nFirstImageIndex;
					m_mapCommands.SetAt(nID,nImageIndexTest);
				}
			}
		}
	}

	// add to the image list images that would be used in tree of all available 
	// commands in order to represent: command groups, command without image,
	// new menu ite and separator item
	//
	int nFirstImageIndex=m_ilImages.GetImageCount();
	HICON hIcon=pApp->LoadIcon(IDI_OX_CUSTOMIZE_COMMANDGROUP);
	ASSERT(hIcon!=NULL);
	VERIFY(m_ilImages.Add(hIcon)==nFirstImageIndex+ID_OX_IMAGEOFFSET_MENUGROUP);

	hIcon=pApp->LoadIcon(IDI_OX_CUSTOMIZE_NOIMAGE);
	ASSERT(hIcon!=NULL);
	VERIFY(m_ilImages.Add(hIcon)==nFirstImageIndex+ID_OX_IMAGEOFFSET_NOIMAGE);

	//
	/////////////////////////

	m_shortkeysOrganizer.Attach(pFrameWnd,TRUE);
	
	if(lpszProfileName!=NULL)
	{
		m_sProfileName=lpszProfileName;
		VERIFY(m_shortkeysOrganizer.LoadState(m_sProfileName));
	}

	return TRUE;
}
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 );

}