Пример #1
0
//
//  hwnd       - window to calc
//  szDlgUnits - (input)  size in dialog units
//  szClient   - (output) size of client area in pixels
//  szWindow   - (output) total size of based on current settings
//
void CalcDlgWindowSize(HWND hwnd, SIZE *szDlgUnits, SIZE *szClient, SIZE *szWindow)
{
	RECT rect;
	DWORD dwStyle;
	DWORD dwStyleEx;

	// work out the size in pixels of our main window, by converting
	// from dialog units
	SetRect(&rect, 0, 0, szDlgUnits->cx, szDlgUnits->cy);
	MapDialogRect(hwnd, &rect);

	if (szClient)
	{
		szClient->cx = GetRectWidth(&rect);
		szClient->cy = GetRectHeight(&rect);
	}

	dwStyle = GetWindowLong(hwnd, GWL_STYLE);
	dwStyleEx = GetWindowLong(hwnd, GWL_EXSTYLE);

	AdjustWindowRectEx(&rect, dwStyle, FALSE, dwStyleEx);

	if (szWindow)
	{
		szWindow->cx = GetRectWidth(&rect);
		szWindow->cy = GetRectHeight(&rect);
	}
}
Пример #2
0
/* Centers one window (hChild) with respect to
another (hParent), as per the Windows UX
Guidelines (2009).
This means placing the child window 45% of the
way from the top of the parent window (with 55%
of the space left between the bottom of the
child window and the bottom of the parent window).*/
BOOL CenterWindow(HWND hParent, HWND hChild)
{
	RECT rcParent;
	BOOL bRet = GetClientRect(hParent, &rcParent);

	if(!bRet)
	{
		return FALSE;
	}

	RECT rcChild;
	bRet = GetClientRect(hChild, &rcChild);

	if(!bRet)
	{
		return FALSE;
	}

	/* Take the offset between the two windows,
	and map it back to the desktop. */
	POINT ptOrigin;
	ptOrigin.x = (GetRectWidth(&rcParent) - GetRectWidth(&rcChild)) / 2;
	ptOrigin.y = static_cast<LONG>((GetRectHeight(&rcParent) - GetRectHeight(&rcChild)) * 0.45);

	SetLastError(0);
	int iRet = MapWindowPoints(hParent, HWND_DESKTOP, &ptOrigin, 1);

	if(iRet == 0 && GetLastError() != 0)
	{
		return FALSE;
	}

	return SetWindowPos(hChild, NULL, ptOrigin.x, ptOrigin.y,
		0, 0, SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOZORDER);
}
Пример #3
0
	void Window::HandleSizeMessage()
	{
		WINDOWINFO info;
		GetWindowInfo(m_handle, &info);

		bool resized = false;
		if (GetRectWidth(info.rcClient) != GetRectWidth(m_clientRect))
			resized = true;
		else if (GetRectHeight(info.rcClient) != GetRectHeight(m_clientRect))
			resized = true;

		m_clientRect = info.rcClient;
		m_windowRect = info.rcWindow;
				
		if (resized)
		{
			unsigned int clientWidth = GetClientWidth();
			unsigned int clientHeight = GetClientHeight();
			unsigned int windowWidth = GetWindowWidth();
			unsigned int windowHeight = GetWindowHeight();

			for (size_t i = 0; i < m_eventListeners.size(); ++i)
			{
				m_eventListeners[i]->WindowResized(clientWidth, clientHeight, windowWidth, windowHeight);
			}
		}
	}
Пример #4
0
BOOL PinStatusBar(HWND hStatusBar, int Width, int Height)
{
	RECT rc;
	BOOL bRet = GetWindowRect(hStatusBar, &rc);

	if(bRet)
	{
		/* Pin the status bar to the bottom of the window. */
		bRet = SetWindowPos(hStatusBar, NULL, 0, Height - GetRectHeight(&rc),
			Width, GetRectHeight(&rc), SWP_NOZORDER);
	}

	return bRet;
}
Пример #5
0
void CDisplayWindow::DrawThumbnail(HDC hdcMem)
{
	if(!m_bThumbnailExtracted)
	{
		ExtractThumbnailImage();
	}
	else
	{
		if(!m_bThumbnailExtractionFailed)
		{
			RECT rc;
			GetClientRect(m_hDisplayWindow,&rc);

			HDC hdcSrc = CreateCompatibleDC(hdcMem);
			HBITMAP hBitmapOld = (HBITMAP)SelectObject(hdcSrc,m_hbmThumbnail);

			BitBlt(hdcMem,m_xColumnFinal,THUMB_IMAGE_TOP,
				GetRectWidth(&rc) - m_xColumnFinal,GetRectHeight(&rc) - THUMB_HEIGHT_DELTA,
				hdcSrc,0,0,SRCCOPY);

			SelectObject(hdcSrc,hBitmapOld);
			DeleteDC(hdcSrc);
		}
	}
}
Пример #6
0
void CDialogSettings::SaveDialogPosition(HWND hDlg)
{
	RECT rc;
	GetWindowRect(hDlg,&rc);
	m_ptDialog.x = rc.left;
	m_ptDialog.y = rc.top;
	m_iWidth = GetRectWidth(&rc);
	m_iHeight = GetRectHeight(&rc);
}
Пример #7
0
UINT WinSpyDlg_Size(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
	int  cx, cy;
	HWND hwndCtrl;
	RECT rect;
	RECT rect2;

	if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)
	{
		cx = LOWORD(lParam);
		cy = HIWORD(lParam);

		// Resize the right-hand tab control so that
		// it fills the window
		hwndCtrl = GetDlgItem(hwnd, IDC_TAB2);
		GetWindowRect(hwndCtrl, &rect);
		ScreenToClient(hwnd, (POINT *)&rect.left);
		ScreenToClient(hwnd, (POINT *)&rect.right);

		MoveWindow(hwndCtrl, rect.left, rect.top, cx - rect.left - nLeftBorder, cy - rect.top - nBottomBorder, TRUE);

		GetWindowRect(hwndCtrl, &rect);
		ScreenToClient(hwnd, (POINT *)&rect.left);
		ScreenToClient(hwnd, (POINT *)&rect.right);
		rect.top++;

		// Work out the coords of the tab contents
		SendMessage(hwndCtrl, TCM_ADJUSTRECT, FALSE, (LPARAM)&rect);

		// Resize the tree control so that it fills the tab control.
		hwndCtrl = GetDlgItem(hwnd, IDC_TREE1);
		InflateRect(&rect, 1, 1);
		MoveWindow(hwndCtrl, rect.left, rect.top, GetRectWidth(&rect), GetRectHeight(&rect), TRUE);

		// Position the size-grip
		{
			int width = GetSystemMetrics(SM_CXVSCROLL);
			int height = GetSystemMetrics(SM_CYHSCROLL);

			GetClientRect(hwnd, &rect);

			MoveWindow(hwndSizer, rect.right - width, rect.bottom - height, width, height, TRUE);

		}

		GetWindowRect(hwndPin, &rect2);
		OffsetRect(&rect2, -rect2.left, -rect2.top);

		// Position the pin toolbar
		//SetWindowPos(hwndPin,
		//  HWND_TOP, rect.right-rect2.right, 1, rect2.right, rect2.bottom, 0);
		MoveWindow(hwndPin, rect.right - rect2.right, 1, rect2.right, rect2.bottom, TRUE);
	}

	return 0;
}
Пример #8
0
UINT WinSpyDlg_EnterSizeMove(HWND hwnd)
{
	RECT rect;
	GetWindowRect(hwnd, &rect);

	fyMaxed = (GetRectHeight(&rect) > szMinimized.cy);
	fxMaxed = (GetRectWidth(&rect) >= szExpanded.cx);

	return 0;
}
Пример #9
0
UINT WinSpyDlg_ExitSizeMove(HWND hwnd)
{
	RECT rect;
	UINT uLayout;
	HWND hwndTree;
	HTREEITEM hItem;

	static UINT uOldLayout = WINSPY_MINIMIZED;


	GetWindowRect(hwnd, &rect);

	szCurrent.cx = GetRectWidth(&rect);
	szCurrent.cy = GetRectHeight(&rect);

	fyMaxed = (szCurrent.cy > szMinimized.cy);
	fxMaxed = (szCurrent.cx >= szExpanded.cx);

	if (fyMaxed == FALSE)
	{
		uLayout = WINSPY_MINIMIZED;
	}
	else
	{
		if (fxMaxed)
			uLayout = WINSPY_EXPANDED;
		else
			uLayout = WINSPY_NORMAL;

		szLastMax = szCurrent;
	}

	SetSysMenuIconFromLayout(hwnd, uLayout);

	if (uLayout == WINSPY_EXPANDED && uOldLayout != WINSPY_EXPANDED)
	{
		hwndTree = GetDlgItem(hwnd, IDC_TREE1);

		RefreshTreeView(hwndTree);
		hItem = FindTreeItemByHwnd(hwndTree, spy_hCurWnd, NULL);
		if (hItem)
		{
			// Move it into view!
			SendMessage(hwndTree, TVM_ENSUREVISIBLE, 0, (LPARAM)hItem);
			SendMessage(hwndTree, TVM_SELECTITEM, TVGN_CARET, (LPARAM)hItem);
		}
	}

	GetPinnedPosition(hwnd, &ptPinPos);

	uOldLayout = uLayout;

	return 0;
}
Пример #10
0
VOID CZUIRender::DrawImage(HDC hDC, LPCTSTR lpszPath, RECT& rcSize, RECT& rcPaint)
{
	HBITMAP hBmp = NULL;
	HDC hMemDC = NULL;
	do 
	{
		if(NULL == lpszPath)
		{
			break;
		}

		hBmp = LoadImage(lpszPath);
		if(NULL == hBmp)
		{
			break;
		}

		hMemDC = ::CreateCompatibleDC(hDC);
		if(NULL == hMemDC)
		{
			break;
		}

		HBITMAP hOldBmp = (HBITMAP)::SelectObject(hMemDC, hBmp);

		// 
		RECT rc = {0};
		if((rcSize.left <= rcPaint.left) || (rcSize.top <= rcPaint.top))
		{
			rc.left = rcPaint.left;
			rc.top = rcPaint.top;
		}
		else
		{
			rc.left = rcSize.left;
			rc.top = rcSize.top;
		}
		rc.right = min(rcSize.right, rcPaint.right);
		rc.bottom = min(rcSize.bottom, rcPaint.bottom);

		::BitBlt(hDC, rc.left, rc.top, GetRectWidth(rc), GetRectHeight(rc), hMemDC, 0, 0, SRCCOPY);
		::SelectObject(hMemDC, hOldBmp);
	} while (0);
	if(hMemDC != NULL)
	{
		::DeleteDC(hMemDC);
	}
	if(hBmp != NULL)
	{
		FreeImage(hBmp);
	}
}
Пример #11
0
void CentreText(DC* pDC, Rect* pRect, char* pText, Colour eClr)
{
	int iX, iY;
	
	ASSERT(pDC);
    ASSERT(pText);
    ASSERT(((int)(GetRectWidth(pRect) - strlen(pText))) >= 0);
    
    /* Calculate left justified position. */
    iX = pRect->x1 + ((GetRectWidth(pRect) - strlen(pText)) / 2);
    iY = pRect->y1 + (GetRectHeight(pRect) / 2);
    
	LeftText(pDC, iX, iY, pText, eClr);
}
Пример #12
0
	bool Window::SetupWindow(const Description& description)
	{
		DWORD style = WS_OVERLAPPEDWINDOW;
		unsigned int windowX = (description.m_x < 0) ? CW_USEDEFAULT : description.m_x;
		unsigned int windowY = (description.m_y < 0) ? CW_USEDEFAULT : description.m_y;

		if (!description.m_resizable)
		{
			style &= ~WS_THICKFRAME;
			style &= ~WS_MAXIMIZEBOX;
		}

		if (!description.m_hasFrame)
		{
			style &= ~WS_SYSMENU;
			style &= ~WS_OVERLAPPED;
			style &= ~WS_CAPTION;
			style &= ~WS_THICKFRAME;
			style |= WS_POPUP;
		}
		
		m_clientRect.left = 0;
		m_clientRect.right = description.m_clientWidth;
		m_clientRect.top = 0;
		m_clientRect.bottom = description.m_clientHeight;

		m_windowRect = m_clientRect;
		AdjustWindowRect(&m_windowRect, style, FALSE);

		m_handle = CreateWindow("ApplicationWindow",
			description.m_caption.c_str(),
			style,
			windowX,
			windowY,
			GetRectWidth(m_windowRect),
			GetRectHeight(m_windowRect),
			NULL,
			NULL,
			m_instance,
			NULL);

		if (m_handle == NULL)
			return false;

		ShowWindow(m_handle, description.m_showState);
		UpdateWindow(m_handle);

		return true;
	}
Пример #13
0
void UpdatePanelTrans(HWND hwndPanel, RECT *rect)
{
	POINT ptZero = { 0, 0 };
	COLORREF crKey = RGB(0, 0, 0);

	const BYTE SourceConstantAlpha = 220;//255;
	BLENDFUNCTION blendPixelFunction = { AC_SRC_OVER, 0, 0, AC_SRC_ALPHA };
	blendPixelFunction.SourceConstantAlpha = SourceConstantAlpha;
	RECT rect2;
	//rect->right = rect->left + 316;
	//rect->bottom = rect->top + 382;

	POINT pt;
	pt.x = rect->left;
	pt.y = rect->top;
	SIZE sz;
	sz.cx = GetRectWidth(rect);
	sz.cy = GetRectHeight(rect);

	HDC hdcSrc = GetDC(0);
	HDC hdcMem = CreateCompatibleDC(hdcSrc);
	HBITMAP hbm;
	HANDLE hold;

	GetClientRect(hwndPanel, &rect2);
	hbm = MakeDockPanelBitmap(rect);
	hold = SelectObject(hdcMem, hbm);

	//FillRect(hdcMem, &rect, GetSysColorBrush(COLOR_HIGHLIGHT));
	//SetWindowLongPtr(hwndPanel, GWL_EXSTYLE, GetWindowLongPtr(hwndPanel, GWL_EXSTYLE) | WS_EX_LAYERED);

	UpdateLayeredWindow(hwndPanel,
		hdcSrc,
		&pt, //pos
		&sz, //size
		hdcMem,
		&ptZero,
		crKey,
		&blendPixelFunction,
		ULW_ALPHA);

	SelectObject(hdcMem, hold);
	DeleteDC(hdcMem);
	ReleaseDC(0, hdcSrc);
}
Пример #14
0
//
//  Retrieve current layout for main window
//
UINT GetWindowLayout(HWND hwnd)
{
	RECT rect;
	BOOL xMaxed, yMaxed;

	GetWindowRect(hwnd, &rect);

	yMaxed = GetRectHeight(&rect) > szMinimized.cy;
	xMaxed = GetRectWidth(&rect) >= szExpanded.cx;

	if (yMaxed == FALSE)
	{
		return WINSPY_MINIMIZED;
	}
	else
	{
		if (xMaxed)
			return WINSPY_EXPANDED;
		else
			return WINSPY_NORMAL;
	}
}
Пример #15
0
HBITMAP MakeDockPanelBitmap(RECT *rect)
{
	int width  = GetRectWidth(rect);
	int height = GetRectHeight(rect);
	
	DWORD *pdwBox;

	static HBITMAP hbmBox, hbm;
	HDC		hdcBox, hdcDIB, hdcSrc;
	HANDLE	hOldBox, hOldDIB;

	RECT *sprite = 0;
	POINT pos = { 0 };

	// 32bpp bitmap
	BITMAPINFOHEADER bih = { sizeof(bih) };
	
	bih.biWidth			= width;
	bih.biHeight		= height;
	bih.biPlanes		= 1;
	bih.biBitCount		= 32;
	bih.biCompression	= BI_RGB;
	bih.biSizeImage		= 0;

    hdcSrc = GetDC(0);

	if(hbmBox == 0)
	{
		hbmBox	= LoadPNGImage(IDB_SELBOX, (void **)&pdwBox);
	}

	hdcBox	= CreateCompatibleDC(hdcSrc);
	hOldBox	= SelectObject(hdcBox, hbmBox);

	hbm		= CreateDIBSection(hdcSrc, (BITMAPINFO *)&bih, DIB_RGB_COLORS, (void**)&pdwBox, 0, 0);
	hdcDIB	= CreateCompatibleDC(hdcSrc);
	hOldDIB	= SelectObject(hdcDIB, hbm);

    if(1)//type & DOCKRECT_TYPE_THICK)
    {
	    // corners
	    BitBlt(hdcDIB, 0, 0, 32, 32, hdcBox, 0, 0, SRCCOPY);
	    BitBlt(hdcDIB, width - 32, 0, 32, 32, hdcBox, 32, 0, SRCCOPY);
	    BitBlt(hdcDIB, 0, height-32, 32, 32, hdcBox, 0, 32, SRCCOPY);
	    BitBlt(hdcDIB, width-32, height-32, 32, 32, hdcBox, 32, 32, SRCCOPY);

	    // sides
	    StretchBlt(hdcDIB, 0, 32, 32, height-64, hdcBox, 0,32,32,1,SRCCOPY);
	    StretchBlt(hdcDIB, width-32, 32, 32, height-64, hdcBox, 32,32,32,1,SRCCOPY);
	    StretchBlt(hdcDIB, 32, 0, width-64, 32, hdcBox, 32,0,1,32,SRCCOPY);
	    StretchBlt(hdcDIB, 32, height-32, width-64, 32, hdcBox, 32,32,1,32,SRCCOPY);

        //if(type & DOCKRECT_TYPE_SHADED)
        {
        	// middle
	        StretchBlt(hdcDIB, 32, 32, width-64, height-64, hdcBox, 32,32,1,1,SRCCOPY);
        }
    }
    /*else if(type & DOCKRECT_TYPE_SHADED)
    {
        StretchBlt(hdcDIB, 0, 0, width, height, hdcBox, 32,32,1,1,SRCCOPY);
    }*/


	SelectObject(hdcDIB,	hOldDIB);
	SelectObject(hdcBox,	hOldBox);

	DeleteDC(hdcBox);
	DeleteDC(hdcDIB);

	ReleaseDC(0, hdcSrc);
	return hbm;
}
Пример #16
0
void CDisplayWindow::ExtractThumbnailImageInternal(ThumbnailEntry_t *pte)
{
	IExtractImage *pExtractImage = NULL;
	IShellFolder *pShellFolder = NULL;
	LPITEMIDLIST pidlParent = NULL;
	LPITEMIDLIST pidlFull = NULL;
	LPITEMIDLIST pridl = NULL;
	HBITMAP hBitmap;
	BITMAP bm;
	RECT rc;
	SIZE size;
	TCHAR szImage[MAX_PATH];
	DWORD dwPriority;
	DWORD dwFlags;
	HRESULT hr;

	m_bThumbnailExtracted = TRUE;
	m_bThumbnailExtractionFailed = TRUE;

	hr = GetIdlFromParsingName(m_ImageFile,&pidlFull);

	if(SUCCEEDED(hr))
	{
		pidlParent = ILClone(pidlFull);
		ILRemoveLastID(pidlParent);

		pridl = ILClone(ILFindLastID(pidlFull));

		hr = BindToIdl(pidlParent, IID_PPV_ARGS(&pShellFolder));

		if(SUCCEEDED(hr))
		{
			hr = GetUIObjectOf(pShellFolder, NULL, 1, (LPCITEMIDLIST *) &pridl,
				IID_PPV_ARGS(&pExtractImage));

			if(SUCCEEDED(hr))
			{
				GetClientRect(m_hDisplayWindow,&rc);

				/* First, query the thumbnail so that its actual aspect
				ratio can be calculated. */
				dwFlags = IEIFLAG_OFFLINE|IEIFLAG_QUALITY|IEIFLAG_ORIGSIZE;
				size.cx = GetRectHeight(&rc) - THUMB_HEIGHT_DELTA;
				size.cy = GetRectHeight(&rc) - THUMB_HEIGHT_DELTA;

				hr = pExtractImage->GetLocation(szImage,SIZEOF_ARRAY(szImage),
					&dwPriority,&size,32,&dwFlags);

				if(SUCCEEDED(hr))
				{
					hr = pExtractImage->Extract(&hBitmap);

					if(SUCCEEDED(hr))
					{
						/* Get bitmap information (including height and width). */
						GetObject(hBitmap,sizeof(BITMAP),&bm);

						/* Delete the original bitmap. */
						DeleteObject(hBitmap);

						/* ...now query the thumbnail again, this time adjusting
						the width of the suggested area based on the actual aspect
						ratio. */
						dwFlags = IEIFLAG_OFFLINE|IEIFLAG_QUALITY|IEIFLAG_ASPECT|IEIFLAG_ORIGSIZE;
						size.cy = GetRectHeight(&rc) - THUMB_HEIGHT_DELTA;
						size.cx = (LONG)((double)size.cy * ((double)bm.bmWidth / (double)bm.bmHeight));
						m_iImageWidth = size.cx;
						m_iImageHeight = size.cy;
						pExtractImage->GetLocation(szImage,SIZEOF_ARRAY(szImage),
							&dwPriority,&size,32,&dwFlags);
						hr = pExtractImage->Extract(&m_hbmThumbnail);

						if(SUCCEEDED(hr))
						{
							/* Check first if we've been cancelled. This might happen,
							for example, if another file is selected while the current
							thumbnail is been found. */
							EnterCriticalSection(&m_csDWThumbnails);

							if(!pte->bCancelled)
							{
								m_bThumbnailExtractionFailed = FALSE;
								InvalidateRect(m_hDisplayWindow,NULL,FALSE);
							}

							LeaveCriticalSection(&m_csDWThumbnails);
						}
						else
						{
							m_bThumbnailExtractionFailed = TRUE;
							m_hbmThumbnail = NULL;
						}
					}
				}

				pExtractImage->Release();
			}

			pShellFolder->Release();
		}

		CoTaskMemFree(pidlFull);
		CoTaskMemFree(pidlParent);
		CoTaskMemFree(pridl);
	}
}
Пример #17
0
	unsigned int Window::GetWindowHeight() const
	{
		return GetRectHeight(m_windowRect);
	}
////////////////////////////////////////////////////////////////
//
// CPixelsManager::SetVolumePixels
//
// Here we have a surface which:
//          1 - is D3DFMT_R5G6B5 or D3DFMT_X8R8G8B8/D3DFMT_A8R8G8B8
//          2 - can be locked
//
// Requires PLAIN pixels
//
////////////////////////////////////////////////////////////////
bool CPixelsManager::SetVolumePixels ( IDirect3DVolume9* pD3DSurface, const CPixels& pixels, const RECT* pRect, uint uiSlice )
{
    if ( !pD3DSurface )
        return false;

    // Calc surface rect
    D3DVOLUME_DESC SurfDesc;
    pD3DSurface->GetDesc ( &SurfDesc );

    POINT SurfSize = { SurfDesc.Width, SurfDesc.Height };
    RECT SurfRect = { 0, 0, SurfDesc.Width, SurfDesc.Height };
    if ( pRect )
        SurfRect = *pRect;

    // Calc pixels rect
    uint uiPixelsWidth, uiPixelsHeight;
    if ( !GetPlainDimensions ( pixels, uiPixelsWidth, uiPixelsHeight ) )
        return false;

    POINT PixelsSize = { uiPixelsWidth, uiPixelsHeight };
    RECT PixelsRect = { 0, 0, uiPixelsWidth, uiPixelsHeight };

    // Validate rects
    if ( !ClipRects ( PixelsSize, PixelsRect, SurfSize, SurfRect ) )
        return false;

    // Check if pRect can be NULL
    pRect = &SurfRect;
    if ( SurfRect.left == 0 && SurfRect.top == 0 && SurfRect.right == SurfDesc.Width && SurfRect.bottom == SurfDesc.Height )
        pRect = NULL;        

    // Get pixels from pD3DSurface
    D3DLOCKED_RECT LockedRect;
    if ( FAILED ( LockVolumeRect ( pD3DSurface, &LockedRect, pRect, D3DLOCK_NOSYSLOCK, uiSlice ) ) )
        return false;

    // Get sizes
    uint SurfRectWidth = GetRectWidth ( SurfRect );
    uint SurfRectHeight = GetRectHeight ( SurfRect );

    uint PixelsRectWidth = GetRectWidth ( PixelsRect );
    uint PixelsRectHeight = GetRectHeight ( PixelsRect );

    uint CopyWidth = Min ( SurfRectWidth, PixelsRectWidth );
    uint CopyHeight = Min ( SurfRectHeight, PixelsRectHeight );

    // Prepare pixels
    uint ulPixelsPitch = uiPixelsWidth * XRGB_BYTES_PER_PIXEL;
    const char* pPixelsData = pixels.GetData ();
    pPixelsData += PixelsRect.left * XRGB_BYTES_PER_PIXEL;
    pPixelsData += PixelsRect.top * ulPixelsPitch;

    uint ulSurfPitch = LockedRect.Pitch;
    BYTE* pSurfBits = (BYTE*)LockedRect.pBits;

    if ( CRenderItemManager::GetBitsPerPixel ( SurfDesc.Format ) == 32 )
    {
        if (  SurfDesc.Format == D3DFMT_A8R8G8B8 )
        {
            uint uiCopyWidthBytes = CopyWidth * XRGB_BYTES_PER_PIXEL;
            // Copy lines into surface
            for ( uint i = 0; i < CopyHeight; i++ )
            {
                memcpy ( pSurfBits + ulSurfPitch * i, pPixelsData + ulPixelsPitch * i, uiCopyWidthBytes );
            }
        }
        else
        {
            // Copy lines into surface
            for ( uint i = 0; i < CopyHeight; i++ )
            {
                const DWORD* pLinePixelsStart = (DWORD*)( pPixelsData + ulPixelsPitch * i );
                DWORD* pLineSurfStart = (DWORD*)( pSurfBits + ulSurfPitch * i );
                for ( uint x = 0; x < CopyWidth; x++ )
                {
                    DWORD x8r8g8b8 = pLinePixelsStart[x];
                    x8r8g8b8 |= 0xff000000;
                    pLineSurfStart[x] = x8r8g8b8;
                }
            }
        }
    }
    else
    if ( CRenderItemManager::GetBitsPerPixel ( SurfDesc.Format ) == 16 )
    {
        // Copy lines into surface
        for ( uint i = 0; i < CopyHeight; i++ )
        {
            const DWORD* pLinePixelsStart = (DWORD*)( pPixelsData + ulPixelsPitch * i );
            WORD* pLineSurfStart = (WORD*)( pSurfBits + ulSurfPitch * i );
            for ( uint x = 0; x < CopyWidth; x++ )
            {
                DWORD x8r8g8b8 = pLinePixelsStart[x];
                WORD r = ( x8r8g8b8 & 0xF80000 ) >> 8;
                WORD g = ( x8r8g8b8 & 0xFC00 ) >> 5;
                WORD b = ( x8r8g8b8 & 0xF8 ) >> 3;
                WORD r5g6b5 = r | g | b;
                pLineSurfStart[x] = r5g6b5;
            }
        }
    }

    pD3DSurface->UnlockBox ();
    return true;
}
////////////////////////////////////////////////////////////////
//
// CPixelsManager::GetVolumePixels
//
// Here we have a surface which:
//          1 - is D3DFMT_R5G6B5 or D3DFMT_X8R8G8B8/D3DFMT_A8R8G8B8
//          2 - can be locked
//
// Returns PLAIN pixels
//
////////////////////////////////////////////////////////////////
bool CPixelsManager::GetVolumePixels ( IDirect3DVolume9* pD3DSurface, CPixels& outPixels, const RECT* pRect, uint uiSlice )
{
    if ( !pD3DSurface )
        return false;

    // Calc surface rect
    D3DVOLUME_DESC SurfDesc;
    pD3DSurface->GetDesc ( &SurfDesc );

    POINT SurfSize = { SurfDesc.Width, SurfDesc.Height };
    RECT SurfRect = { 0, 0, SurfDesc.Width, SurfDesc.Height };
    if ( pRect )
        SurfRect = *pRect;

    // Calc pixels rect
    uint uiPixelsWidth = GetRectWidth ( SurfRect );
    uint uiPixelsHeight = GetRectHeight ( SurfRect );

    POINT PixelsSize = { uiPixelsWidth, uiPixelsHeight };
    RECT PixelsRect = { 0, 0, uiPixelsWidth, uiPixelsHeight };

    // Validate rects
    if ( !ClipRects ( PixelsSize, PixelsRect, SurfSize, SurfRect ) )
        return false;

    // Check if pRect can be NULL
    pRect = &SurfRect;
    if ( SurfRect.left == 0 && SurfRect.top == 0 && SurfRect.right == SurfDesc.Width && SurfRect.bottom == SurfDesc.Height )
        pRect = NULL;        

    // Get pixels from pD3DSurface
    D3DLOCKED_RECT LockedRect;
    if ( FAILED ( LockVolumeRect ( pD3DSurface, &LockedRect, pRect, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK, uiSlice ) ) )
        return false;

    // Get sizes
    uint SurfRectWidth = GetRectWidth ( SurfRect );
    uint SurfRectHeight = GetRectHeight ( SurfRect );

    uint PixelsRectWidth = GetRectWidth ( PixelsRect );
    uint PixelsRectHeight = GetRectHeight ( PixelsRect );

    uint CopyWidth = Min ( SurfRectWidth, PixelsRectWidth );
    uint CopyHeight = Min ( SurfRectHeight, PixelsRectHeight );

    // Prepare pixels
    uint ulPixelsPitch = uiPixelsWidth * XRGB_BYTES_PER_PIXEL;
    outPixels.SetSize ( ulPixelsPitch * uiPixelsHeight + SIZEOF_PLAIN_TAIL );
    memset ( outPixels.GetData (), 0x81,  outPixels.GetSize () );
    char* pPixelsData = outPixels.GetData ();
    pPixelsData += PixelsRect.left * XRGB_BYTES_PER_PIXEL;
    pPixelsData += PixelsRect.top * ulPixelsPitch;

    uint ulSurfPitch = LockedRect.Pitch;
    BYTE* pSurfBits = (BYTE*)LockedRect.pBits;

    if ( CRenderItemManager::GetBitsPerPixel ( SurfDesc.Format ) == 32 )
    {
        if (  SurfDesc.Format == D3DFMT_A8R8G8B8 )
        {
            uint uiCopyWidthBytes = CopyWidth * XRGB_BYTES_PER_PIXEL;
            // Copy lines into buffer
            for ( uint i = 0; i < CopyHeight; i++ )
            {
                memcpy ( pPixelsData + ulPixelsPitch * i, pSurfBits + i * ulSurfPitch, uiCopyWidthBytes );
            }
        }
        else
        {
            // Copy lines into buffer
            for ( uint i = 0; i < CopyHeight; i++ )
            {
                DWORD* pLinePixelsStart = (DWORD*)( pPixelsData + ulPixelsPitch * i );
                const DWORD* pLineSurfStart = (DWORD*)( pSurfBits + ulSurfPitch * i );
                for ( uint x = 0; x < CopyWidth; x++ )
                {
                    DWORD x8r8g8b8 = pLineSurfStart[x];
                    x8r8g8b8 |= 0xff000000;
                    pLinePixelsStart[x] = x8r8g8b8;
                }
            }
        }
    }
    else
    if ( CRenderItemManager::GetBitsPerPixel ( SurfDesc.Format ) == 16 )
    {
        // Copy lines into buffer
        for ( uint i = 0; i < CopyHeight; i++ )
        {
            DWORD* pLinePixelsStart = (DWORD*)( pPixelsData + ulPixelsPitch * i );
            const WORD* pLineSurfStart = (WORD*)( pSurfBits + ulSurfPitch * i );
            for ( uint x = 0; x < CopyWidth; x++ )
            {
                WORD r5g6b5 = pLineSurfStart[x];
                BYTE r = ( r5g6b5 & 0xF800 ) >> 11 << 3;
                BYTE g = ( r5g6b5 & 0x7E0 ) >> 5 << 2;
                BYTE b = ( r5g6b5 & 0x1F ) << 3;

                DWORD x8r8g8b8 = (r << 16) | (g << 8) | b;
                x8r8g8b8 |= 0xFF070307;
                pLinePixelsStart[x] = x8r8g8b8;
            }
        }
    }

    pD3DSurface->UnlockBox ();

    // Fixup plain format attributes
    return SetPlainDimensions ( outPixels, uiPixelsWidth, uiPixelsHeight );
}
/* It is up to the caller to delete the bitmap returned by this method. */
void Explorerplusplus::GetTabLivePreviewBitmap(int iTabId,TabPreviewInfo_t *ptpi)
{
	HDC hdcTab;
	HDC hdcTabSrc;
	HBITMAP hbmTab;
	HBITMAP hbmTabPrev;
	Gdiplus::Color color(0,0,0);
	MENUBARINFO mbi;
	POINT pt;
	BOOL bVisible;
	RECT rcTab;

	HWND hTab = m_hListView[iTabId];

	hdcTab = GetDC(hTab);
	hdcTabSrc = CreateCompatibleDC(hdcTab);

	GetClientRect(hTab,&rcTab);

	Gdiplus::Bitmap bi(GetRectWidth(&rcTab),GetRectHeight(&rcTab),PixelFormat32bppARGB);
	bi.GetHBITMAP(color,&hbmTab);

	hbmTabPrev = (HBITMAP)SelectObject(hdcTabSrc,hbmTab);

	bVisible = IsWindowVisible(hTab);

	if(!bVisible)
	{
		ShowWindow(hTab,SW_SHOW);
	}

	PrintWindow(hTab,hdcTabSrc,PW_CLIENTONLY);

	if(!bVisible)
	{
		ShowWindow(hTab,SW_HIDE);
	}

	SetStretchBltMode(hdcTabSrc,HALFTONE);
	SetBrushOrgEx(hdcTabSrc,0,0,&pt);
	StretchBlt(hdcTabSrc,0,0,GetRectWidth(&rcTab),GetRectHeight(&rcTab),hdcTabSrc,
		0,0,GetRectWidth(&rcTab),GetRectHeight(&rcTab),SRCCOPY);

	MapWindowPoints(hTab,m_hContainer,(LPPOINT)&rcTab,2);

	mbi.cbSize	 = sizeof(mbi);
	GetMenuBarInfo(m_hContainer,OBJID_MENU,0,&mbi);

	/* The operating system will automatically
	draw the main window. Therefore, we'll just shift
	the tab into it's proper position. */
	ptpi->ptOrigin.x = rcTab.left;

	/* Need to include the menu bar in the offset. */
	ptpi->ptOrigin.y = rcTab.top + mbi.rcBar.bottom - mbi.rcBar.top;

	ptpi->hbm = hbmTab;
	ptpi->iTabId = iTabId;

	SelectObject(hdcTabSrc,hbmTabPrev);
	DeleteDC(hdcTabSrc);
	ReleaseDC(hTab,hdcTab);
}
HBITMAP Explorerplusplus::CaptureTabScreenshot(int iTabId)
{
	HDC hdc;
	HDC hdcSrc;
	HBITMAP hBitmap;
	HBITMAP hPrevBitmap;
	Gdiplus::Color color(0,0,0);
	RECT rcMain;
	RECT rcTab;

	HWND hTab = m_hListView[iTabId];

	GetClientRect(m_hContainer,&rcMain);
	GetClientRect(hTab,&rcTab);

	/* Main window BitBlt. */
	hdc = GetDC(m_hContainer);
	hdcSrc = CreateCompatibleDC(hdc);

	/* Any bitmap sent back to the operating system will need to be in 32-bit
	ARGB format. */
	Gdiplus::Bitmap bi(GetRectWidth(&rcMain),GetRectHeight(&rcMain),PixelFormat32bppARGB);
	bi.GetHBITMAP(color,&hBitmap);

	/* BitBlt the main window into the bitmap. */
	hPrevBitmap = (HBITMAP)SelectObject(hdcSrc,hBitmap);
	BitBlt(hdcSrc,0,0,GetRectWidth(&rcMain),GetRectHeight(&rcMain),hdc,0,0,SRCCOPY);


	/* Now BitBlt the tab onto the main window. */
	HDC hdcTab;
	HDC hdcTabSrc;
	HBITMAP hbmTab;
	HBITMAP hbmTabPrev;
	BOOL bVisible;

	hdcTab = GetDC(hTab);
	hdcTabSrc = CreateCompatibleDC(hdcTab);
	hbmTab = CreateCompatibleBitmap(hdcTab,GetRectWidth(&rcTab),GetRectHeight(&rcTab));

	hbmTabPrev = (HBITMAP)SelectObject(hdcTabSrc,hbmTab);

	bVisible = IsWindowVisible(hTab);

	if(!bVisible)
	{
		ShowWindow(hTab,SW_SHOW);
	}

	PrintWindow(hTab,hdcTabSrc,PW_CLIENTONLY);

	if(!bVisible)
	{
		ShowWindow(hTab,SW_HIDE);
	}

	MapWindowPoints(hTab,m_hContainer,(LPPOINT)&rcTab,2);
	BitBlt(hdcSrc,rcTab.left,rcTab.top,GetRectWidth(&rcTab),GetRectHeight(&rcTab),hdcTabSrc,0,0,SRCCOPY);

	SelectObject(hdcTabSrc,hbmTabPrev);
	DeleteObject(hbmTab);
	DeleteDC(hdcTabSrc);
	ReleaseDC(hTab,hdcTab);


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

	hdcThumbnailSrc = CreateCompatibleDC(hdc);

	/* Thumbnail bitmap. */
	Gdiplus::Bitmap bmpThumbnail(GetRectWidth(&rcMain),GetRectHeight(&rcMain),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);
	BitBlt(hdcThumbnailSrc,0,0,GetRectWidth(&rcMain),GetRectHeight(&rcMain),hdcSrc,0,0,SRCCOPY);

	SetBitmapDimensionEx(hbmThumbnail,GetRectWidth(&rcMain),GetRectHeight(&rcMain),NULL);

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

	DeleteObject(hBitmap);

	SelectObject(hdcSrc,hPrevBitmap);

	DeleteDC(hdcSrc);
	ReleaseDC(m_hContainer,hdc);

	return hbmThumbnail;
}
void CManageBookmarksDialog::SetupToolbar()
{
	m_hToolbar = CreateToolbar(m_hDlg,
		WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN|
		TBSTYLE_TOOLTIPS|TBSTYLE_LIST|TBSTYLE_TRANSPARENT|
		TBSTYLE_FLAT|CCS_NODIVIDER|CCS_NORESIZE,
		TBSTYLE_EX_MIXEDBUTTONS|TBSTYLE_EX_DRAWDDARROWS|
		TBSTYLE_EX_DOUBLEBUFFER|TBSTYLE_EX_HIDECLIPPEDBUTTONS);

	SendMessage(m_hToolbar,TB_SETBITMAPSIZE,0,MAKELONG(16,16));
	SendMessage(m_hToolbar,TB_BUTTONSTRUCTSIZE,static_cast<WPARAM>(sizeof(TBBUTTON)),0);

	m_himlToolbar = ImageList_Create(16,16,ILC_COLOR32|ILC_MASK,0,48);
	HBITMAP hBitmap = LoadBitmap(GetInstance(),MAKEINTRESOURCE(IDB_SHELLIMAGES));
	ImageList_Add(m_himlToolbar,hBitmap,NULL);
	DeleteObject(hBitmap);
	SendMessage(m_hToolbar,TB_SETIMAGELIST,0,reinterpret_cast<LPARAM>(m_himlToolbar));

	TBBUTTON tbb;
	TCHAR szTemp[64];

	tbb.iBitmap		= SHELLIMAGES_BACK;
	tbb.idCommand	= TOOLBAR_ID_BACK;
	tbb.fsState		= TBSTATE_ENABLED;
	tbb.fsStyle		= BTNS_BUTTON|BTNS_AUTOSIZE;
	tbb.dwData		= 0;
	SendMessage(m_hToolbar,TB_INSERTBUTTON,0,reinterpret_cast<LPARAM>(&tbb));

	tbb.iBitmap		= SHELLIMAGES_FORWARD;
	tbb.idCommand	= TOOLBAR_ID_FORWARD;
	tbb.fsState		= TBSTATE_ENABLED;
	tbb.fsStyle		= BTNS_BUTTON|BTNS_AUTOSIZE;
	tbb.dwData		= 0;
	SendMessage(m_hToolbar,TB_INSERTBUTTON,1,reinterpret_cast<LPARAM>(&tbb));

	LoadString(GetInstance(),IDS_MANAGE_BOOKMARKS_TOOLBAR_ORGANIZE,szTemp,SIZEOF_ARRAY(szTemp));

	tbb.iBitmap		= SHELLIMAGES_COPY;
	tbb.idCommand	= TOOLBAR_ID_ORGANIZE;
	tbb.fsState		= TBSTATE_ENABLED;
	tbb.fsStyle		= BTNS_BUTTON|BTNS_AUTOSIZE|BTNS_SHOWTEXT|BTNS_DROPDOWN;
	tbb.dwData		= 0;
	tbb.iString		= reinterpret_cast<INT_PTR>(szTemp);
	SendMessage(m_hToolbar,TB_INSERTBUTTON,2,reinterpret_cast<LPARAM>(&tbb));

	LoadString(GetInstance(),IDS_MANAGE_BOOKMARKS_TOOLBAR_VIEWS,szTemp,SIZEOF_ARRAY(szTemp));

	tbb.iBitmap		= SHELLIMAGES_VIEWS;
	tbb.idCommand	= TOOLBAR_ID_VIEWS;
	tbb.fsState		= TBSTATE_ENABLED;
	tbb.fsStyle		= BTNS_BUTTON|BTNS_AUTOSIZE|BTNS_SHOWTEXT|BTNS_DROPDOWN;
	tbb.dwData		= 0;
	tbb.iString		= reinterpret_cast<INT_PTR>(szTemp);
	SendMessage(m_hToolbar,TB_INSERTBUTTON,3,reinterpret_cast<LPARAM>(&tbb));

	LoadString(GetInstance(),IDS_MANAGE_BOOKMARKS_TOOLBAR_IMPORTEXPORT,szTemp,SIZEOF_ARRAY(szTemp));

	tbb.iBitmap		= SHELLIMAGES_PROPERTIES;
	tbb.idCommand	= TOOLBAR_ID_IMPORTEXPORT;
	tbb.fsState		= TBSTATE_ENABLED;
	tbb.fsStyle		= BTNS_BUTTON|BTNS_AUTOSIZE|BTNS_SHOWTEXT|BTNS_DROPDOWN;
	tbb.dwData		= 0;
	tbb.iString		= reinterpret_cast<INT_PTR>(szTemp);
	SendMessage(m_hToolbar,TB_INSERTBUTTON,4,reinterpret_cast<LPARAM>(&tbb));

	RECT rcTreeView;
	GetWindowRect(GetDlgItem(m_hDlg,IDC_MANAGEBOOKMARKS_TREEVIEW),&rcTreeView);
	MapWindowPoints(HWND_DESKTOP,m_hDlg,reinterpret_cast<LPPOINT>(&rcTreeView),2);

	RECT rcSearch;
	GetWindowRect(GetDlgItem(m_hDlg,IDC_MANAGEBOOKMARKS_EDITSEARCH),&rcSearch);
	MapWindowPoints(HWND_DESKTOP,m_hDlg,reinterpret_cast<LPPOINT>(&rcSearch),2);

	DWORD dwButtonSize = static_cast<DWORD>(SendMessage(m_hToolbar,TB_GETBUTTONSIZE,0,0));
	SetWindowPos(m_hToolbar,NULL,rcTreeView.left,rcSearch.top - (HIWORD(dwButtonSize) - GetRectHeight(&rcSearch)) / 2,
		rcSearch.left - rcTreeView.left - 10,HIWORD(dwButtonSize),0);
}
Пример #23
0
INT_PTR CALLBACK CBaseDialog::BaseDialogProc(HWND hDlg,UINT uMsg,
	WPARAM wParam,LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_INITDIALOG:
		m_hDlg = hDlg;

		if(m_bResizable)
		{
			RECT rcMain;
			GetWindowRect(m_hDlg,&rcMain);

			/* Assume that the current width and height of
			the dialog are the minimum width and height.
			Note that at this point, the dialog has NOT
			been initialized in any way, so it will not
			have had a chance to be resized yet. */
			m_iMinWidth = GetRectWidth(&rcMain);
			m_iMinHeight = GetRectHeight(&rcMain);

			std::list<CResizableDialog::Control_t> ControlList;
			m_dsc = DIALOG_SIZE_CONSTRAINT_NONE;
			GetResizableControlInformation(m_dsc,ControlList);

			m_prd = new CResizableDialog(m_hDlg,ControlList);
		}
		break;

	case WM_GETMINMAXINFO:
		if(m_bResizable)
		{
			LPMINMAXINFO pmmi = reinterpret_cast<LPMINMAXINFO>(lParam);

			pmmi->ptMinTrackSize.x = m_iMinWidth;
			pmmi->ptMinTrackSize.y = m_iMinHeight;

			if(m_dsc == DIALOG_SIZE_CONSTRAINT_X)
			{
				pmmi->ptMaxTrackSize.y = m_iMinHeight;
			}

			if(m_dsc == DIALOG_SIZE_CONSTRAINT_Y)
			{
				pmmi->ptMaxTrackSize.x = m_iMinWidth;
			}

			return 0;
		}
		break;

	case WM_NOTIFY:
		switch(reinterpret_cast<NMHDR *>(lParam)->code)
		{
		case LVN_ENDSCROLL:
			{
				OSVERSIONINFO VersionInfo;
				VersionInfo.dwOSVersionInfoSize	= sizeof(VersionInfo);
				GetVersionEx(&VersionInfo);

				/* Automatic fix for KB813791 (gridlines draw incorrectly on Windows XP). */
				if(VersionInfo.dwMajorVersion == WINDOWS_XP_MAJORVERSION)
				{
					InvalidateRect(reinterpret_cast<NMHDR *>(lParam)->hwndFrom,NULL,TRUE);
					UpdateWindow(reinterpret_cast<NMHDR *>(lParam)->hwndFrom);
				}
			}
			break;
		}
		break;

	case WM_SIZE:
		if(m_bResizable)
		{
			m_prd->UpdateControls(LOWORD(lParam),HIWORD(lParam));
			return 0;
		}
		break;

	case WM_DESTROY:
		{
			/* If this is a modeless dialog, notify the
			caller that the dialog is been destroyed. */
			if(m_bShowingModelessDialog)
			{
				if(m_pmdn != NULL)
				{
					m_pmdn->OnModelessDialogDestroy(m_iResource);
					m_pmdn->Release();
				}
			}

			INT_PTR Res = OnDestroy();

			/* Within WM_DESTROY, all child windows
			still exist. */
			SaveState();

			return Res;
		}
		break;

	case WM_NCDESTROY:
		g_WindowMap.erase(g_WindowMap.find(hDlg));
		break;
	}

	return ForwardMessage(hDlg,uMsg,wParam,lParam);
}
Пример #24
0
void Explorerplusplus::CreateMainControls(void)
{
	SIZE	sz;
	RECT	rc;
	DWORD	ToolbarSize;
	TCHAR	szBandText[32];
	int		i = 0;

	/* If the rebar is locked, prevent bands from
	been rearranged. */
	if(m_bLockToolbars)
		RebarStyles |= RBS_FIXEDORDER;

	/* Create and subclass the main rebar control. */
	m_hMainRebar = CreateWindowEx(0,REBARCLASSNAME,EMPTY_STRING,RebarStyles,
		0,0,0,0,m_hContainer,NULL,GetModuleHandle(0),NULL);
	SetWindowSubclass(m_hMainRebar,RebarSubclassStub,0,(DWORD_PTR)this);

	for(i = 0;i < NUM_MAIN_TOOLBARS;i++)
	{
		switch(m_ToolbarInformation[i].wID)
		{
		case ID_MAINTOOLBAR:
			CreateMainToolbar();
			ToolbarSize = (DWORD)SendMessage(m_hMainToolbar,TB_GETBUTTONSIZE,0,0);
			m_ToolbarInformation[i].cyMinChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyMaxChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyChild = HIWORD(ToolbarSize);
			SendMessage(m_hMainToolbar,TB_GETMAXSIZE,0,(LPARAM)&sz);

			if(m_ToolbarInformation[i].cx == 0)
				m_ToolbarInformation[i].cx = sz.cx;

			m_ToolbarInformation[i].cxIdeal = sz.cx;
			m_ToolbarInformation[i].hwndChild = m_hMainToolbar;
			break;

		case ID_ADDRESSTOOLBAR:
			CreateAddressBar();
			LoadString(m_hLanguageModule,IDS_ADDRESSBAR,szBandText,SIZEOF_ARRAY(szBandText));
			GetWindowRect(m_hAddressBar,&rc);
			m_ToolbarInformation[i].cyMinChild = GetRectHeight(&rc);
			m_ToolbarInformation[i].lpText = szBandText;
			m_ToolbarInformation[i].hwndChild = m_hAddressBar;
			break;

		case ID_BOOKMARKSTOOLBAR:
			CreateBookmarksToolbar();
			ToolbarSize = (DWORD)SendMessage(m_hBookmarksToolbar,TB_GETBUTTONSIZE,0,0);
			m_ToolbarInformation[i].cyMinChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyMaxChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyChild = HIWORD(ToolbarSize);
			SendMessage(m_hBookmarksToolbar,TB_GETMAXSIZE,0,(LPARAM)&sz);

			if(m_ToolbarInformation[i].cx == 0)
				m_ToolbarInformation[i].cx = sz.cx;

			m_ToolbarInformation[i].cxIdeal = sz.cx;
			m_ToolbarInformation[i].hwndChild = m_hBookmarksToolbar;
			break;

		case ID_DRIVESTOOLBAR:
			CreateDrivesToolbar();
			ToolbarSize = (DWORD)SendMessage(m_pDrivesToolbar->GetHWND(),TB_GETBUTTONSIZE,0,0);
			m_ToolbarInformation[i].cyMinChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyMaxChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyChild = HIWORD(ToolbarSize);
			SendMessage(m_pDrivesToolbar->GetHWND(),TB_GETMAXSIZE,0,(LPARAM)&sz);

			if(m_ToolbarInformation[i].cx == 0)
				m_ToolbarInformation[i].cx = sz.cx;

			m_ToolbarInformation[i].cxIdeal = sz.cx;
			m_ToolbarInformation[i].hwndChild = m_pDrivesToolbar->GetHWND();
			break;

		case ID_APPLICATIONSTOOLBAR:
			CreateApplicationToolbar();
			ToolbarSize = (DWORD)SendMessage(m_pApplicationToolbar->GetHWND(),TB_GETBUTTONSIZE,0,0);
			m_ToolbarInformation[i].cyMinChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyMaxChild = HIWORD(ToolbarSize);
			m_ToolbarInformation[i].cyChild = HIWORD(ToolbarSize);
			SendMessage(m_pApplicationToolbar->GetHWND(),TB_GETMAXSIZE,0,(LPARAM)&sz);

			if(m_ToolbarInformation[i].cx == 0)
				m_ToolbarInformation[i].cx = sz.cx;

			m_ToolbarInformation[i].cxIdeal = sz.cx;
			m_ToolbarInformation[i].hwndChild = m_pApplicationToolbar->GetHWND();
			break;
		}

		m_ToolbarInformation[i].cbSize = sizeof(REBARBANDINFO);
		SendMessage(m_hMainRebar,RB_INSERTBAND,(WPARAM)-1,(LPARAM)&m_ToolbarInformation[i]);
	}
}
Пример #25
0
/* TODO: This should be linked to OnSize(). */
void Explorerplusplus::SetListViewInitialPosition(HWND hListView)
{
	RECT			rc;
	int				MainWindowWidth;
	int				MainWindowHeight;
	int				IndentBottom = 0;
	int				IndentTop = 0;
	int				IndentLeft = 0;
	int				iIndentRebar = 0;

	GetClientRect(m_hContainer,&rc);

	MainWindowWidth = GetRectWidth(&rc);
	MainWindowHeight = GetRectHeight(&rc);

	if(m_hMainRebar)
	{
		GetWindowRect(m_hMainRebar,&rc);
		iIndentRebar += GetRectHeight(&rc);
	}

	if(m_bShowStatusBar)
	{
		GetWindowRect(m_hStatusBar,&rc);
		IndentBottom += GetRectHeight(&rc);
	}

	if(m_bShowDisplayWindow)
	{
		IndentBottom += m_DisplayWindowHeight;
	}

	if(m_bShowFolders)
	{
		GetClientRect(m_hHolder,&rc);
		IndentLeft = GetRectWidth(&rc);
	}

	IndentTop = iIndentRebar;

	if(m_bShowTabBar)
	{
		if(!m_bShowTabBarAtBottom)
		{
			IndentTop += TAB_WINDOW_HEIGHT;
		}
	}

	if(!m_bShowTabBarAtBottom)
	{
		SetWindowPos(hListView,NULL,IndentLeft,IndentTop,
			MainWindowWidth - IndentLeft,MainWindowHeight -
			IndentBottom - IndentTop,
			SWP_HIDEWINDOW|SWP_NOZORDER);
	}
	else
	{
		SetWindowPos(hListView,NULL,IndentLeft,IndentTop,
			MainWindowWidth - IndentLeft,MainWindowHeight -
			IndentBottom - IndentTop - TAB_WINDOW_HEIGHT,
			SWP_HIDEWINDOW|SWP_NOZORDER);
	}
}
Пример #26
0
	unsigned int Window::GetClientHeight() const
	{
		return GetRectHeight(m_clientRect);
	}
Пример #27
0
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
	DWORD tick = GetTickCount();
	(void)tick;

	unsigned cmd_line_flags = 0;
	int argc;
	LPWSTR *argv = CommandLineToArgvW(GetCommandLineW(), &argc);
	for (int i = 1; i < argc; ++i)
	{
		const FlagsName *f;
		for (f = g_flags_names; f->name; ++f)
		{
			if (_wcsicmp(argv[i], f->wname) == 0)
			{
				cmd_line_flags |= f->flags;
				break;
			}
		}

		if (!f->name)
		{
			Help(argv[i]);
			return 1;
		}
	}

	GTC;

	char exe[MAX_PATH];
	GetModuleFileName(GetModuleHandle(0), exe, sizeof exe);
	PathRemoveFileSpec(exe);
	PathCombine(g_ini_path, exe, g_ini_file_name);
	ODS(strprintf("dispswitch: %s: INI path is \"%s\".\n", __FUNCTION__, g_ini_path));

	// 	STARTUPINFO si;
	// 	GetStartupInfo(&si);

	GTC;

	std::vector<MonitorInfo> monitors;
	EnumDisplayMonitors(0, 0, &GetAllMonitorsMonitorEnumProc, LPARAM(&monitors));
	if (monitors.size() <= 1)
		return 0;

	std::sort(monitors.begin(), monitors.end(), [](const MonitorInfo &a, const MonitorInfo &b) { return a.info.rcWork.left < b.info.rcWork.left; });

	for (unsigned i = 0; i < monitors.size(); ++i)
	{
		const MonitorInfo *mi = &monitors[i];
		(void)mi;

		ODS(strprintf("dispswitch: monitor %u/%u:\n", 1 + i, monitors.size()));
		ODS(strprintf("    Original index: %u\n", (unsigned)mi->original_index));
		ODS(strprintf("    Device=\"%s\"\n", mi->info.szDevice));
		ODS(strprintf("    MonitorRect=(%ld,%ld)-(%ld,%ld)\n",
			mi->info.rcMonitor.left, mi->info.rcMonitor.top, mi->info.rcMonitor.right, mi->info.rcMonitor.bottom));
		ODS(strprintf("    WorkRect=(%ld,%ld)-(%ld,%ld)\n",
			mi->info.rcWork.left, mi->info.rcWork.top, mi->info.rcWork.right, mi->info.rcWork.bottom));
	}

	//
	std::vector<PROCESSENTRY32> processes;
	EnumProcesses(&processes);

	GTC;

	// 
	HWND fg = GetForegroundWindow();
	WindowDetails fg_details;
	GetWindowDetails(processes, fg, &fg_details);

	ODS(strprintf("exe=%s\n", fg_details.exe_file));

	std::vector<HWND> hwnds;
	if (fg_details.flags&F_TAKE_EXE)
	{
		EnumWindows(&GetAllVisibleWindowsWindowEnumProc, LPARAM(&hwnds));
		ODS(strprintf("%u hwnds.\n", hwnds.size()));
		std::vector<HWND>::iterator hwnd = hwnds.begin();
		while (hwnd != hwnds.end())
		{
			char exe_file[MAX_PATH];
			GetExeFileForWindow(processes, *hwnd, exe_file);
			if (strcmp(exe_file, fg_details.exe_file) == 0)
				++hwnd;
			else
				hwnd = hwnds.erase(hwnd);
		}
	}
	else
	{
		HWND h = fg;
		do
		{
			hwnds.push_back(h);
			h = GetParent(h);
		} while (h && (fg_details.flags&F_TAKE_PARENT));
	}

	GTC;

	ODS(strprintf("%u hwnds.\n", hwnds.size()));

	for (unsigned i = 0; i < hwnds.size(); ++i)
	{
		HWND fg_wnd = hwnds[i];

		bool was_zoomed = false;
		if (IsZoomed(fg_wnd))
		{
			was_zoomed = true;
			ShowWindow(fg_wnd, SW_RESTORE);
		}

		RECT fg_rect;
		GetWindowRect(fg_wnd, &fg_rect);

		ODS(strprintf("dispswitch: old rect=(%ld,%ld)->(%ld,%ld).\n", fg_rect.left, fg_rect.top, fg_rect.right,
			fg_rect.bottom));

		HMONITOR fg_monitor = MonitorFromRect(&fg_rect, MONITOR_DEFAULTTOPRIMARY);

		size_t monitor_idx;
		for (monitor_idx = 0; monitor_idx < monitors.size(); ++monitor_idx)
		{
			if (monitors[monitor_idx].hmonitor == fg_monitor)
				break;
		}

		if (monitor_idx >= monitors.size())
		{
			// Oh dear.
			continue;
		}

		const MONITORINFOEX *old_info = &monitors[monitor_idx].info;

		++monitor_idx;
		monitor_idx %= monitors.size();

		const MONITORINFOEX *new_info = &monitors[monitor_idx].info;

		//
		RECT dr;
		dr.left = fg_rect.left - old_info->rcWork.left;
		dr.top = fg_rect.top - old_info->rcWork.top;
		dr.right = fg_rect.right - old_info->rcWork.right;
		dr.bottom = fg_rect.bottom - old_info->rcWork.bottom;

		if (fg_details.flags&F_DONT_RESIZE)
		{
			LONG cx = (fg_rect.left + fg_rect.right) / 2 - old_info->rcWork.left;
			LONG cy = (fg_rect.top + fg_rect.bottom) / 2 - old_info->rcWork.top;

			float tcx = cx / (float)GetRectWidth(old_info->rcWork);
			float tcy = cy / (float)GetRectHeight(old_info->rcWork);

			LONG fg_w = GetRectWidth(fg_rect);
			LONG fg_h = GetRectHeight(fg_rect);

			fg_rect.left = new_info->rcWork.left + LONG(tcx*GetRectWidth(new_info->rcWork) + .5f) - fg_w / 2;
			fg_rect.top = new_info->rcWork.top + LONG(tcy*GetRectHeight(new_info->rcWork) + .5f) - fg_h / 2;

			fg_rect.right = fg_rect.left + fg_w;
			fg_rect.bottom = fg_rect.top + fg_h;

			// don't let it go outside the work rect.
			LONG dx = new_info->rcWork.left - fg_rect.left;
			if (dx < 0)
				dx = 0;

			LONG dy = new_info->rcWork.top - fg_rect.top;
			if (dy < 0)
				dy = 0;

			OffsetRect(&fg_rect, dx, dy);
		}
		else
		{
			float left_frac, top_frac, right_frac, bottom_frac;
			{
				RECT local_rect = fg_rect;
				OffsetRect(&local_rect, -old_info->rcWork.left, -old_info->rcWork.top);

				left_frac = local_rect.left / float(GetRectWidth(old_info->rcWork));
				top_frac = local_rect.top / float(GetRectHeight(old_info->rcWork));
				right_frac = local_rect.right / float(GetRectWidth(old_info->rcWork));
				bottom_frac = local_rect.bottom / float(GetRectHeight(old_info->rcWork));
			}

			if (fg_details.flags&F_SIDE_RELATIVE)
			{
				fg_rect.left = new_info->rcWork.left + dr.left;
				fg_rect.top = new_info->rcWork.top + dr.top;
				fg_rect.right = new_info->rcWork.right + dr.right;
				fg_rect.bottom = new_info->rcWork.bottom + dr.bottom;
			}
			else
			{
				// round to nearest instead of round to zero, prevents window
				// floating towards the origin with repeated invocations (or at
				// least it did with the test window).
				fg_rect.left = new_info->rcWork.left + LONG(left_frac*GetRectWidth(new_info->rcWork) + .5f);
				fg_rect.top = new_info->rcWork.top + LONG(top_frac*GetRectHeight(new_info->rcWork) + .5f);
				fg_rect.right = new_info->rcWork.left + LONG(right_frac*GetRectWidth(new_info->rcWork) + .5f);
				fg_rect.bottom = new_info->rcWork.top + LONG(bottom_frac*GetRectHeight(new_info->rcWork) + .5f);
			}

			// Work out a minimum size for this window.
			LONG min_width, min_height;
			{
				// Include a small client area
				RECT rect = { 0, 0, 100, 100 };
				DWORD style = GetWindowLong(fg_wnd, GWL_STYLE);
				DWORD ex_style = GetWindowLong(fg_wnd, GWL_EXSTYLE);
				BOOL menu = !!GetMenu(fg_wnd);
				AdjustWindowRectEx(&rect, style, menu, ex_style);

				min_width = GetRectWidth(rect);
				min_height = GetRectHeight(rect);

				ODS(strprintf("dispswitch: min size=%ldx%ld\n", min_width, min_height));
			}

			// Clamp size, rather crudely.
			if (GetRectWidth(fg_rect) < min_width)
				fg_rect.right = fg_rect.left + min_width;

			if (GetRectHeight(fg_rect) < min_height)
				fg_rect.bottom = fg_rect.top + min_height;
		}

		ODS(strprintf("dispswitch: new rect=(%ld,%ld)->(%ld,%ld).\n", fg_rect.left, fg_rect.top, fg_rect.right,
			fg_rect.bottom));

		// 		BOOL ok=MoveWindow(fg_wnd,fg_rect.left,fg_rect.top,fg_rect.right-fg_rect.left,
		// 			fg_rect.bottom-fg_rect.top,TRUE);
		BOOL ok = SetWindowPos(fg_wnd, 0, fg_rect.left, fg_rect.top, fg_rect.right - fg_rect.left,
			fg_rect.bottom - fg_rect.top, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOCOPYBITS);
		if (!ok)
		{
			DWORD err = GetLastError();
			(void)err;
			ODS(strprintf("dispswitch:     move failed. Error: 0x%08lX\n", err));
		}

		if (was_zoomed)
			ShowWindow(fg_wnd, SW_MAXIMIZE);
	}

	return 0;
}
Пример #28
0
//
// Position / size controls and main window based
// on current system metrics
//
void WinSpyDlg_SizeContents(HWND hwnd)
{
	int x, y, cx, cy;
	int i;
	RECT rect, rect1;
	HWND hwndTab;
	HWND hwndCtrl;

	int nPaneWidth;     // width of each dialog-pane
	int nPaneHeight;    // height of each dialog-pane
	int nActualPaneWidth; // what the tab-control is set to.

	int nTabWidth;
	int nTabHeight;

	int nDesiredTabWidth;

	// HARD-CODED sizes for each window layout.
	// These are DIALOG UNITS, so it's not too bad.
	duMinimized.cx = 254;
	duMinimized.cy = 25;//6;

	duNormal.cx = duMinimized.cx;
	duNormal.cy = 251;

	duExpanded.cx = 432;//390;
	duExpanded.cy = duNormal.cy;

	// work out the size (in pixels) of each window layout
	CalcDlgWindowSize(hwnd, &duMinimized, 0, &szMinimized);
	CalcDlgWindowSize(hwnd, &duNormal, 0, &szNormal);
	CalcDlgWindowSize(hwnd, &duExpanded, 0, &szExpanded);

	// resize to NORMAL layout (temporarily)
	SetWindowPos(hwnd, 0, 0, 0, szNormal.cx, szNormal.cy, SWP_SIZEONLY | SWP_NOREDRAW);

	// Locate main Property sheet control
	hwndTab = GetDlgItem(hwnd, IDC_TAB1);

	// Get SCREEN coords of tab control
	GetWindowRect(hwndTab, &rect);

	// Get SCREEN coords of dialog's CLIENT area
	if (IsIconic(hwnd))
	{
		// If the window is minimized, calc the client rect manually

		rect1.left = 0;
		rect1.top = 0;
		rect1.right = szNormal.cx - 2 * GetSystemMetrics(SM_CXFRAME);
		rect1.bottom = szNormal.cy - 2 * GetSystemMetrics(SM_CYFRAME) - GetSystemMetrics(SM_CYCAPTION);
	}
	else
		GetClientRect(hwnd, &rect1);

	MapWindowPoints(hwnd, 0, (POINT *)&rect1, 2);

	// Now we know what the border is between TAB and left-side
	nLeftBorder = rect.left - rect1.left;
	nBottomBorder = rect1.bottom - rect.bottom;

	nDesiredTabWidth = (rect1.right - rect1.left) - nLeftBorder * 2;

	//
	// Find out the size of the biggest dialog-tab-pane
	//
	SetRect(&rect, 0, 0, 0, 0);

	for (i = 0; i < NUMTABCONTROLITEMS; i++)
	{
		// Get tab-pane relative to parent (main) window
		GetClientRect(WinSpyTab[i].hwnd, &rect1);
		MapWindowPoints(WinSpyTab[i].hwnd, hwnd, (POINT *)&rect1, 2);

		// find biggest
		UnionRect(&rect, &rect, &rect1);
	}

	nPaneWidth = GetRectWidth(&rect);
	nPaneHeight = GetRectHeight(&rect);

	// Resize the tab control based on this biggest rect
	SendMessage(hwndTab, TCM_ADJUSTRECT, TRUE, (LPARAM)&rect);

	nTabWidth = GetRectWidth(&rect);
	nTabHeight = GetRectHeight(&rect);

	// Resize the tab control now we know how big it needs to be
	SetWindowPos(hwndTab, hwnd, 0, 0, nDesiredTabWidth, nTabHeight, SWP_SIZEONLY);

	//
	// Tab control is now in place.
	// Now find out exactly where to position every
	// tab-pane. (We know how big they are, but we need
	// to find where to move them to).
	//
	GetWindowRect(hwndTab, &rect);
	ScreenToClient(hwnd, (POINT *)&rect.left);
	ScreenToClient(hwnd, (POINT *)&rect.right);

	SendMessage(hwndTab, TCM_ADJUSTRECT, FALSE, (LPARAM)&rect);

	x = rect.left;
	y = rect.top;
	cx = nPaneWidth;
	cy = nPaneHeight;

	nActualPaneWidth = GetRectWidth(&rect);

	// Center each dialog-tab in the tab control
	x += (nActualPaneWidth - nPaneWidth) / 2;

	// position each dialog in the right place
	for (i = 0; i < NUMTABCONTROLITEMS; i++)
	{
		SetWindowPos(WinSpyTab[i].hwnd, hwndTab, x, y, cx, cy, SWP_NOACTIVATE);
	}


	SetWindowPos(hwnd, 0, 0, 0, szMinimized.cx, szMinimized.cy, SWP_NOMOVE | SWP_NOZORDER);

	// Even though we are initially minimized, we want to
	// automatically expand to normal view the first time a
	// window is selected.
	szCurrent = szMinimized;
	szLastMax = szNormal;
	szLastExp = szExpanded;

	SetWindowPos(hwndTab, //GetDlgItem(hwnd, IDC_MINIMIZE)
		HWND_BOTTOM, 0, 0, 0, 0, SWP_ZONLY);

	// Finally, move the little expand / shrink button
	// so it is right-aligned with the edge of the tab.
	hwndCtrl = GetDlgItem(hwnd, IDC_EXPAND);
	GetWindowRect(hwndCtrl, &rect);
	MapWindowPoints(0, hwnd, (POINT *)&rect, 2);

	x = nDesiredTabWidth + nLeftBorder - GetRectWidth(&rect);
	y = rect.top;

	SetWindowPos(hwndCtrl, 0, x, y, 0, 0, SWP_MOVEONLY);
}