LRESULT CALLBACK Explorerplusplus::TabProxyWndProc(HWND hwnd,UINT Msg,WPARAM wParam,LPARAM lParam,int iTabId)
{
	switch(Msg)
	{
	case WM_ACTIVATE:
		/* Restore the main window if necessary, and switch
		to the actual tab. */
		if(IsIconic(m_hContainer))
		{
			ShowWindow(m_hContainer,SW_RESTORE);
		}

		OnSelectTab(iTabId,FALSE);
		return 0;
		break;

	case WM_SETFOCUS:
		SetFocus(m_hListView[iTabId]);
		break;

	case WM_SYSCOMMAND:
		switch(wParam)
		{
		case SC_CLOSE:
			break;

		default:
			SendMessage(m_hListView[iTabId],WM_SYSCOMMAND,wParam,lParam);
			break;
		}
		break;

	/* Generate a thumbnail of the current tab. Basic procedure:
	1. Generate a full-scale bitmap of the main window.
	2. Overlay a bitmap of the specified tab onto the main
	window bitmap.
	3. Shrink the resulting bitmap down to the correct thumbnail size.
	
	A thumbnail will be dynamically generated, provided the main window
	is not currently minimized (as we won't be able to grap a screenshot
	of it). If the main window is minimized, we'll use a cached screenshot
	of the tab (taken before the main window was minimized). */
	case WM_DWMSENDICONICTHUMBNAIL:
		{
			HDC hdc;
			HDC hdcSrc;
			HBITMAP hbmTab = NULL;
			HBITMAP hPrevBitmap;
			Gdiplus::Color color(0,0,0);
			HRESULT hr;
			int iBitmapWidth;
			int iBitmapHeight;
			int iWidth;
			int iHeight;
			int iMaxWidth;
			int iMaxHeight;

			iMaxWidth = HIWORD(lParam);
			iMaxHeight = LOWORD(lParam);

			/* If the main window is minimized, it won't be possible
			to generate a thumbnail for any of the tabs. In that
			case, use a static 'No Preview Available' bitmap. */
			if(IsIconic(m_hContainer))
			{
				hbmTab = (HBITMAP)LoadImage(GetModuleHandle(0),MAKEINTRESOURCE(IDB_NOPREVIEWAVAILABLE),IMAGE_BITMAP,0,0,0);

				SetBitmapDimensionEx(hbmTab,223,130,NULL);
			}
			else
			{
				hbmTab = CaptureTabScreenshot(iTabId);
			}

			SIZE sz;

			GetBitmapDimensionEx(hbmTab,&sz);

			iBitmapWidth = sz.cx;
			iBitmapHeight = sz.cy;


			/* Shrink the bitmap. */
			HDC hdcThumbnailSrc;
			HBITMAP hbmThumbnail;
			POINT pt;

			hdc = GetDC(m_hContainer);
			hdcSrc = CreateCompatibleDC(hdc);

			SelectObject(hdcSrc,hbmTab);

			hdcThumbnailSrc = CreateCompatibleDC(hdc);

			/* If the current height of the main window
			is less than the width, we'll create a thumbnail
			of maximum width; else maximum height. */
			if((iBitmapWidth / iMaxWidth) > (iBitmapHeight / iMaxHeight))
			{
				iWidth = iMaxWidth;
				iHeight = iMaxWidth * iBitmapHeight / iBitmapWidth;
			}
			else
			{
				iHeight = iMaxHeight;
				iWidth = iMaxHeight * iBitmapWidth / iBitmapHeight;
			}

			/* Thumbnail bitmap. */
			Gdiplus::Bitmap bmpThumbnail(iWidth,iHeight,PixelFormat32bppARGB);

			bmpThumbnail.GetHBITMAP(color,&hbmThumbnail);

			hPrevBitmap = (HBITMAP)SelectObject(hdcThumbnailSrc,hbmThumbnail);

			/* Finally, shrink the full-scale bitmap down into a thumbnail. */
			SetStretchBltMode(hdcThumbnailSrc,HALFTONE);
			SetBrushOrgEx(hdcThumbnailSrc,0,0,&pt);
			StretchBlt(hdcThumbnailSrc,0,0,iWidth,iHeight,hdcSrc,0,0,iBitmapWidth,iBitmapHeight,SRCCOPY);

			SelectObject(hdcThumbnailSrc,hPrevBitmap);
			DeleteDC(hdcThumbnailSrc);

			HMODULE hDwmapi;
			DwmSetIconicThumbnailProc DwmSetIconicThumbnail;

			hDwmapi = LoadLibrary(_T("dwmapi.dll"));

			if(hDwmapi != NULL)
			{
				DwmSetIconicThumbnail = (DwmSetIconicThumbnailProc)GetProcAddress(hDwmapi,"DwmSetIconicThumbnail");

				if(DwmSetIconicThumbnail != NULL)
				{
					hr = DwmSetIconicThumbnail(hwnd,hbmThumbnail,0);
				}
			}

			FreeLibrary(hDwmapi);

			/* Delete the thumbnail bitmap. */
			DeleteObject(hbmTab);
			SelectObject(hdcSrc,hPrevBitmap);
			DeleteObject(hbmThumbnail);
			DeleteDC(hdcSrc);
			ReleaseDC(m_hContainer,hdc);

			return 0;
		}
		break;

	case WM_DWMSENDICONICLIVEPREVIEWBITMAP:
		{
			HMODULE hDwmapi;
			TabPreviewInfo_t tpi;

			DwmSetIconicLivePreviewBitmapProc DwmSetIconicLivePreviewBitmap;

			tpi.hbm = NULL;

			if(IsIconic(m_hContainer))
			{
				/* TODO: Show an image here... */
			}
			else
			{
				GetTabLivePreviewBitmap(iTabId,&tpi);
			}

			hDwmapi = LoadLibrary(_T("dwmapi.dll"));

			if(hDwmapi != NULL)
			{
				DwmSetIconicLivePreviewBitmap = (DwmSetIconicLivePreviewBitmapProc)GetProcAddress(hDwmapi,"DwmSetIconicLivePreviewBitmap");

				if(DwmSetIconicLivePreviewBitmap != NULL)
				{
					DwmSetIconicLivePreviewBitmap(hwnd,tpi.hbm,&tpi.ptOrigin,0);
				}
			}

			FreeLibrary(hDwmapi);

			if(tpi.hbm != NULL)
			{
				DeleteObject(tpi.hbm);
			}

			return 0;
		}
		break;

	case WM_CLOSE:
		{
			TCITEM tcItem;
			int nTabs;
			int i = 0;

			nTabs = TabCtrl_GetItemCount(m_hTabCtrl);

			if(nTabs == 1)
			{
				/* If this is the last tab, we'll close
				the whole application. */
				SendMessage(m_hContainer,WM_CLOSE,0,0);
			}
			else
			{
				for(i = 0;i < nTabs;i++)
				{
					tcItem.mask = TCIF_PARAM;
					TabCtrl_GetItem(m_hTabCtrl,i,&tcItem);

					if((int)tcItem.lParam == iTabId)
					{
						/* Close the tab... */
						CloseTab(i);
						break;
					}
				}
			}
		}
		break;
	}

	return DefWindowProc(hwnd,Msg,wParam,lParam);
}
Example #2
0
void    CZiMainFrame::Notify(TNotifyUI & msg)
{
	if(msg.sType == _T("windowinit"))
	{
		OnPrepare(msg);
	}
	else if(msg.sType == _T("killfocus"))
	{
		OnKillFocus(msg);
	}
	else if (msg.sType == _T("setfocus")) {
		/*
		int a= 1;
		if (msg.pSender->GetName() == _T("SearchCombo")) {
			CComboUI * pSearchCombo = DuiControl(CComboUI, _T("SearchCombo"));
			pSearchCombo->Activate();
		}
		*/
	}
	else if(msg.sType == _T("return"))
	{
		DuiClickButtonMap(_T("SearchEdit"),    OnReturnSearch);
	}
	else if(msg.sType == _T("click"))
	{
		DuiClickButtonMap(_T("MinBtn"),        OnClickMin);
		DuiClickButtonMap(_T("CloseBtn"),      OnClickClose);
		DuiClickButtonMap(_T("SearchTip"),     OnClickMatchButton);
		DuiClickButtonMap(_T("SettingBtn"),    OnClickSettingButton);
		DuiClickButtonMap(_T("SearchBtn"),     OnClickSearchButton);
	}
	else if(msg.sType == _T("selectchanged"))
	{
		// tab 切换. ( friends 和 group )
		OnSelectTab(msg);
	}
	else if(msg.sType == _T("itemselect"))
	{
		// search item click. 
		OnSelectSearch(msg);
	}
	else if(msg.sType == _T("itemclick"))
	{
		// List . 
		OnSelectItemList(msg);
	}
	else if(msg.sType == _T("itemactivate"))
	{
		// 增加 select 响应双击操作. 
		OnItemChat(msg);
		OnSelectItemList(msg);
	}
	else if(msg.sType == _T("menu"))
	{
		// 右键支持
		//char szLog[256] = {0};
		//sprintf(szLog, "Class: %ws, Name = %ws\n", 
		//	msg.pSender->GetClass(), msg.pSender->GetName());
		//::OutputDebugStringA(szLog);
		DuiClickButtonMap(_T("FriendsList"),    OnClickRightButton);
		DuiClickButtonMap(_T("GroupsList"),     OnClickRightButton);
	}
	else if(msg.sType == _T("menuclick"))
	{
		// 右键点击
		//char szLog[256] = {0};
		//sprintf(szLog, "Class: %ws, Name = %ws\n", 
		//	msg.pSender->GetClass(), msg.pSender->GetName()
		//	);
		//::OutputDebugStringA(szLog);

		DuiClickMenuMap(Event_OpenItem,         OnClickRightMenu);
		DuiClickMenuMap(Event_ModifyItem,       OnClickRightMenu);
		DuiClickMenuMap(Event_DeleteItem,       OnClickRightMenu);
		DuiClickMenuMap(Event_CreateGroup,      OnCreateGroup);
	}
}