Exemple #1
0
// Windows-specific code to set the horizontal extent of the listbox, if
// necessary. If s is non-NULL, it's used to calculate the horizontal extent.
// Otherwise, all strings are used.
void wxListBox::SetHorizontalExtent(const wxString& s)
{
    // Only necessary if we want a horizontal scrollbar
    if (!(m_windowStyle & wxHSCROLL))
        return;
    TEXTMETRIC lpTextMetric;

    if ( !s.empty() )
    {
        int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L);
        HDC dc = GetWindowDC(GetHwnd());
        HFONT oldFont = 0;
        if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
            oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());

        GetTextMetrics(dc, &lpTextMetric);
        SIZE extentXY;
        ::GetTextExtentPoint32(dc, (LPTSTR) (const wxChar *)s, s.Length(), &extentXY);
        int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);

        if (oldFont)
            ::SelectObject(dc, oldFont);

        ReleaseDC(GetHwnd(), dc);
        if (extentX > existingExtent)
            SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L);
    }
    else
    {
        int largestExtent = 0;
        HDC dc = GetWindowDC(GetHwnd());
        HFONT oldFont = 0;
        if (GetFont().Ok() && GetFont().GetResourceHandle() != 0)
            oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle());

        GetTextMetrics(dc, &lpTextMetric);

        for (int i = 0; i < m_noItems; i++)
        {
            wxString str = GetString(i);
            SIZE extentXY;
            ::GetTextExtentPoint32(dc, str.c_str(), str.length(), &extentXY);
            int extentX = (int)(extentXY.cx + lpTextMetric.tmAveCharWidth);
            if (extentX > largestExtent)
                largestExtent = extentX;
        }
        if (oldFont)
            ::SelectObject(dc, oldFont);

        ReleaseDC(GetHwnd(), dc);
        SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L);
    }
}
Exemple #2
0
// Draws a recessed border around the gauge
static void
DrawGaugeBorder(HWND hWnd)
{
	HDC		hDC = GetWindowDC(hWnd);
	RECT	rect;
	int		cx, cy;
	HPEN	hShadowPen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
	HGDIOBJ	hOldPen;

	GetWindowRect(hWnd, &rect);
	cx = rect.right - rect.left;
	cy = rect.bottom - rect.top;

	// Draw a dark gray line segment
	hOldPen = SelectObject(hDC, (HGDIOBJ)hShadowPen);
	MoveToEx(hDC, 0, cy - 1, NULL);
	LineTo(hDC, 0, 0);
	LineTo(hDC, cx - 1, 0);

	// Draw a white line segment
	SelectObject(hDC, GetStockObject(WHITE_PEN));
	MoveToEx(hDC, 0, cy - 1, NULL);
	LineTo(hDC, cx - 1, cy - 1);
	LineTo(hDC, cx - 1, 0);

	SelectObject(hDC, hOldPen);
	DeleteObject(hShadowPen);
	ReleaseDC(hWnd, hDC);
}
Exemple #3
0
void DrawMap(HWND hWnd)
{
	HDC hDc = GetWindowDC(hWnd);

	HDC memDc = CreateCompatibleDC(NULL);  //缓存DC
	HBITMAP hBitMap = CreateCompatibleBitmap(hDc, 850, 650);
	SelectObject(memDc, hBitMap);
	//背景刷成绿色
	HBRUSH hBrushBack = CreateSolidBrush(RGB(0, 255, 0));
	RECT rectBack;
	rectBack.top = 0;
	rectBack.bottom = 650;
	rectBack.left = 0;
	rectBack.right = 850;
	FillRect(memDc, &rectBack, hBrushBack);

	DrawStoneAndBrike(memDc);
	
	DrawMan(memDc);

	BitBlt(hDc, 3, 25, 850, 650, memDc, 0, 0, SRCCOPY);//拷贝

	DeleteObject(memDc);
	DeleteObject(hBitMap);
	DeleteObject(hBrushBack);
	
	ReleaseDC(hWnd, hDc);
}
void CConfigMsgLogDlg::OnTimer(UINT nIDEvent)
{
    if (nIDEvent == m_unDispUpdateTimerId)
    {
        static bool bSwitchDisplay = true;
        CDC* pdc= GetWindowDC();
        pdc->SetTextColor(RGB(253,153,4));
        pdc->SetBkMode(TRANSPARENT);

        if(bSwitchDisplay)
        {
            SetWindowText("");
            pdc->DrawText(m_strCurrWndText,CRect(4,4,400,50),DT_END_ELLIPSIS);
            bSwitchDisplay = false;
        }
        else
        {
            pdc->DrawText(m_strCurrWndText,CRect(4,4,400,50),DT_END_ELLIPSIS);
            SetWindowText(m_strCurrWndText);
            bSwitchDisplay = true;
        }
        ReleaseDC(pdc);
    }
    CDialog::OnTimer(nIDEvent);
}
Exemple #5
0
HBITMAP CaptureWindow(HWND hWnd)
{
	RECT wnd;

	if ( ! GetWindowRect(hWnd, & wnd) )
		return NULL;

	HDC hDC = GetWindowDC(hWnd);

	HBITMAP hBmp = CreateCompatibleBitmap(hDC, wnd.right - wnd.left, wnd.bottom - wnd.top);

	if ( hBmp )
	{
		HDC hMemDC   = CreateCompatibleDC(hDC);
		HGDIOBJ hOld = SelectObject(hMemDC, hBmp);

		BitBlt(hMemDC, 0, 0, wnd.right - wnd.left, wnd.bottom - wnd.top, 
			hDC, 0, 0, SRCCOPY);

		SelectObject(hMemDC, hOld);
		DeleteObject(hMemDC);
	}
	
	ReleaseDC(hWnd, hDC);

	return hBmp;
}
Exemple #6
0
bool CFrame::findColor(CPnt5* pnt5)
{
	HWND hwnd = aigisHwnd();
	if (!hwnd)
	{
		return false;
	}
	HDC hdc = GetWindowDC(hwnd);
	if (!hdc)
	{
		return false;
	}

	bool bSame = true;
	for (size_t i = 0; i < EPD_MAX; i++)
	{
		POINT pntTmp = pnt5->getPoint((E_POINT_DIRECTION)i);
		COLORREF colorDefi = pnt5->getColor((E_POINT_DIRECTION)i);
		COLORREF colorFind = GetPixel(hdc, pntTmp.x, pntTmp.y);
		if (!CPnt5::isSameColor(colorDefi, colorFind ))
		{
			bSame = false;
			break;
		}
	}

	ReleaseDC(hwnd, hdc);
	return bSame;
}
Exemple #7
0
void IWindow::selectWindow()
{
    hWndDC = GetWindowDC(hWnd);
	hBufferDC = CreateCompatibleDC(hWndDC);
	hWndBitmap = CreateCompatibleBitmap(hWndDC, wndWidth, wndHeight);
	hWndBitmap = (HBITMAP)SelectObject(hBufferDC, hWndBitmap);

	if(!BitBlt(hBufferDC, 0, 0, wndWidth, wndHeight, hWndDC, 0, 0, SRCCOPY)){
		DWORD dwError = GetLastError();
		_tprintf(_T("BitBlt: dwError = %i \n"), dwError);
	}

	if(hWndDC != NULL)
	{
		HPEN hPen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
		hPen = (HPEN)SelectObject(hWndDC, hPen);

		MoveToEx(hWndDC, 1, 1, NULL);
		LineTo(hWndDC, wndWidth - 1, 1);
		LineTo(hWndDC, wndWidth - 1, wndHeight - 1);
		LineTo(hWndDC, 1, wndHeight - 1);
		LineTo(hWndDC, 1, 1);

		DeleteObject(SelectObject(hWndDC, hPen));
	}
}
LRESULT CALLBACK ToolbarWndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  switch (Msg)
  {
    case WM_NOTIFY:
    {
      switch (((LPNMHDR) lParam)->code)
      {
        case TTN_GETDISPINFOA:
        case TTN_GETDISPINFOW:
        {
          LPNMTTDISPINFO Info = (LPNMTTDISPINFO) lParam;
          Info->hinst = GetModuleHandle(NULL);
          Info->lpszText = MAKEINTRESOURCE(Info->hdr.idFrom);
          break;
        }
      }
      return 0;
    }
    case WM_NCPAINT:
    {
      RECT R;
      GetWindowRect(hWnd, &R);
      R.right -= R.left;
      R.bottom -= R.top;
      R.left = 0;
      R.top = 0;
      HDC DC = GetWindowDC(hWnd);
      DrawEdge(DC, &R, EDGE_ETCHED, BF_RECT);
      ReleaseDC(hWnd, DC);
      return 0;
    }
  }
  return CallWindowProc((WNDPROC)DefaultToolbarWndProc, hWnd, Msg, wParam, lParam);
}
Exemple #9
0
void CttView::BsmLine(CPoint st, CPoint ed)
{
	CDC* pDC = GetWindowDC();
	COLORREF color = RGB(0,0,0);
	int x,y;
	int dx=(((ed.x-st.x)>0)<<1)-1;
	int dy=(((ed.y-st.y)>0)<<1)-1;	//算y的增量是1还是-1
	//x若相等,则为横着的直线
	if(ed.x==st.x){
		int x=st.x, y=st.y;
		while(y!=ed.y){
			pDC->SetPixel(x,y,color);
			y+=dy;
		}
		pDC->SetPixel(x,y,color);
		return;
	}

	//斜率小于等于1 / 大于1
	if(fabs((1.0*ed.y-st.y)/(1.0*ed.x-st.x)) <= 1.0){
		if(st.x > ed.x)swap(st,ed);		//将小的x放st、大的放ed
		dy=(((ed.y-st.y)>0)<<1)-1;
		x=st.x;
		y=st.y;
		int dtx=ed.x-st.x;
		int dty=(ed.y-st.y)*dy;
		int e=2*dty-dtx;
		while(x!=ed.x || y!=ed.y){
			pDC->SetPixel(x,y,color);
			if(e>=0){
				x++;
				y+=dy;
				e+=dty+dty-dtx-dtx;
			}else{
				x++;
				e+=dty+dty;
			}
		}
	}else{	//斜率大于1,则xy交换
		if(st.y > ed.y)swap(st,ed);		//将小的y放st、大的放ed
		dx=(((ed.x-st.x)>0)<<1)-1;
		x=st.x;
		y=st.y;
		int dtx=(ed.x-st.x)*dx;
		int dty=ed.y-st.y;
		int e=2*dtx-dty;
		while(x!=ed.x || y!=ed.y){
			pDC->SetPixel(x,y,color);
			if(e>=0){
				y++;
				x+=dx;
				e+=dtx+dtx-dty-dty;
			}else{
				y++;
				e+=dtx+dtx;
			}
		}
	}
	pDC->SetPixel(x,y,color);
}
Exemple #10
0
//-----------------------------------------------------------------------------
// Name: HighlightWindow (from MSDN Spy Sample)
// Object: highlight or unhightlight a window
// Parameters : 
//     in : HWND hwnd : target window handle
//          BOOL fDraw : TRUE to draw, FALSE to clear
// Return : TRUE on success
//-----------------------------------------------------------------------------
void CSelectWindow::HighlightWindow( HWND hwnd, BOOL fDraw )
{
    #define DINV                3
    HDC hdc;
    RECT rc;
    BOOL bBorderOn;
    bBorderOn = fDraw;

    if (hwnd == NULL || !IsWindow(hwnd))
        return;

    hdc = GetWindowDC(hwnd);
    GetWindowRect(hwnd, &rc);
    OffsetRect(&rc, -rc.left, -rc.top);

    if (!IsRectEmpty(&rc))
    {
        PatBlt(hdc, rc.left, rc.top, rc.right - rc.left, DINV,  DSTINVERT);
        PatBlt(hdc, rc.left, rc.bottom - DINV, DINV,
            -(rc.bottom - rc.top - 2 * DINV), DSTINVERT);
        PatBlt(hdc, rc.right - DINV, rc.top + DINV, DINV,
            rc.bottom - rc.top - 2 * DINV, DSTINVERT);
        PatBlt(hdc, rc.right, rc.bottom - DINV, -(rc.right - rc.left),
            DINV, DSTINVERT);
    }

    ReleaseDC(hwnd, hdc);
}
Exemple #11
0
void CAboutDlg::OnNcPaint() 
{
	CDC*	pDC = GetWindowDC();
	CRect	rc, rcCut,rcDraw;
	GetWindowRect(&rc);
	rcDraw.top		=  0;
	rcDraw.left		=  0;
	rcDraw.right	= rc.Width() ;
	rcDraw.bottom	= rc.Height();

	CRect rcClient;
	GetClientRect(&rcClient);
	ClientToScreen(&rcClient);
	rcCut.left = rcClient.left - rc.left;
	rcCut.right = rcClient.right - rc.left;
	rcCut.top = rcClient.top - rc.top;
	rcCut.bottom = rcClient.bottom - rc.top;

	CRgn rgnCut,rgnResult;	  
	rgnCut.CreateRectRgnIndirect(&rcCut);
	rgnResult.CreateRectRgnIndirect(&rcDraw);
	rgnResult.CombineRgn(&rgnResult,&rgnCut, RGN_XOR);	
	pDC->SelectClipRgn(&rgnResult);

	pDC->FillSolidRect(rcDraw, RGB(0, 119, 158));
	ReleaseDC(pDC);
}
Exemple #12
0
/*
 * frame_draw_end - フレームの描画終了、フレームの最終位置を返す
 */
int frame_draw_end(const HWND hWnd)
{
	HDC hdc;
	int draw_cnt;
	int ret;

	if (frame_rect[0].left == 0 && frame_rect[0].right == 0 &&
		frame_rect[0].top == 0 && frame_rect[0].bottom == 0) {
		frame_free();
		return -1;
	}

	// 前回描画分を消去
	hdc = GetWindowDC(hWnd);
	for (draw_cnt = 0;draw_cnt < FRAME_CNT;draw_cnt++) {
		DrawFocusRect(hdc, (LPRECT)&frame_rect[draw_cnt]);
	}
	ReleaseDC(hWnd, hdc);

	// 境界位置の取得
	ret = frame_rect[0].left - GetSystemMetrics(SM_CXFRAME);

	frame_free();
	return ret;
}
FilteredListBox::FilteredListBox( DWORD dwStyle,int x,int y,int nWidth,int nHeigth,HWND hWndParent,HMENU hMenu,HINSTANCE hInstance )
	:ListBox(dwStyle | LBS_OWNERDRAWVARIABLE | LBS_HASSTRINGS,WS_EX_CLIENTEDGE,x,y,nWidth,nHeigth,hWndParent,hMenu,hInstance)
{
	HDC dc = GetWindowDC();
	GetTextMetrics(dc,&m_TextMetrics);
	ReleaseDC(dc);
}
// WM_MEASUREITEM handler
// Since we have owner drawn menus, we need to provide information about 
//  the menus back to Windows so it can layout the menubar appropriately.
BOOL cef_dark_window::HandleMeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
    static wchar_t szMenuString[256] = L"";

    if (lpMIS->CtlType == ODT_MENU) {
        HDC dc      = GetWindowDC();
        HMENU menu  = GetMenu();
        int items   = ::GetMenuItemCount(menu);
        
        InitMenuFont();
        
        HGDIOBJ fontOld = ::SelectObject(dc, mMenuFont);            

        ::GetMenuString(menu, lpMIS->itemID, szMenuString, _countof(szMenuString), MF_BYCOMMAND);

        RECT rectTemp;
        SetRectEmpty(&rectTemp);

        // Calc the size of this menu item 
        ::DrawText(dc, szMenuString, ::wcslen(szMenuString), &rectTemp, DT_SINGLELINE|DT_CALCRECT);

        lpMIS->itemHeight = ::RectHeight(rectTemp);
        lpMIS->itemWidth = ::RectWidth(rectTemp);
 
        ::SelectObject(dc, fontOld);            
        ReleaseDC(dc);
        return TRUE;
    }

    return FALSE;
}
// Like UpdateNonClientArea, but sets up a clipping region to just update the system buttons
void cef_dark_window::UpdateNonClientButtons () 
{
    // create a simple clipping region
    //  that only includes the system buttons (min/max/restore/close)
    HDC hdc = GetWindowDC();

    RECT rectCloseButton ;
    ComputeCloseButtonRect (rectCloseButton) ;
 
    RECT rectMaximizeButton ;
    ComputeMaximizeButtonRect (rectMaximizeButton) ;
 
    RECT rectMinimizeButton ;
    ComputeMinimizeButtonRect (rectMinimizeButton) ;

    RECT rectWindow ;
    ComputeLogicalWindowRect (rectWindow) ;
    ::ExcludeClipRect (hdc, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom);

    RECT rectButtons;
    rectButtons.top = rectCloseButton.top;
    rectButtons.right = rectCloseButton.right;
    rectButtons.bottom = rectCloseButton.bottom;
    rectButtons.left = rectMinimizeButton.left;

    HRGN hrgnUpdate = ::CreateRectRgnIndirect(&rectButtons);

    if (::SelectClipRgn(hdc, hrgnUpdate) != NULLREGION) {
        DoPaintNonClientArea(hdc);
    }

    ::DeleteObject(hrgnUpdate);
    ReleaseDC(hdc);
}
Exemple #16
0
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                    PSTR szCmdLine, int nCmdShow)			
{									
    MSG       msg;	
	HDC	hdcWindow;

	RegisterMyWindow(hInstance);

   	if (!InitialiseMyWindow(hInstance, nCmdShow))
		return FALSE;

	hdcWindow = GetWindowDC (Application.ghwnd);
	Application.setBuffers();

	while (Application.Running())					
    {							
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
		    if (msg.message==WM_QUIT)
				break;
			TranslateMessage (&msg);							
			DispatchMessage (&msg);
		}

		else
		{	
			Application.MainLoop();
		}
    }

    Application.releaseResources();
	return msg.wParam ;										
}
Exemple #17
0
void CttView::ADTFill(const COLORREF color){
	if (m_point.size() <= 2)return;
	CDC* pDC = GetWindowDC();
	CPen pen1(0, 0, color);
	pDC->SelectObject(&pen1);
	int start, end, msz=m_point.size();
	start = 10000;
	end = 0;
	for (int i = 0; i < msz; i++){
		start = min(start, m_point[i].y);
		end = max(end, m_point[i].y);
	}
	vector<EdgeTable> net(end+1);
	net.assign(end + 1, EdgeTable());
	Edge te;
	int miny;
	for (int i = 0; i < msz-1; i++){
		te = Edge(m_point[i], m_point[i + 1], miny);
		net[miny].Add(te);
	}
	te = Edge(m_point[msz-1], m_point[0], miny);
	net[miny].Add(te);
	
	EdgeTable adt = EdgeTable(start);
	for (int i = start; i <= end; i++){
		for (int j = 0; j < net[i].e.size(); j++)
			adt.Add(net[i].e[j]);
		for (int j = 1; j < adt.e.size(); j += 2){
			pDC->MoveTo((int)adt.e[j-1].x0, i);
			pDC->LineTo((int)adt.e[j].x0, i);
		}
		adt.Update();
	}
}
Exemple #18
0
void clearScreen(){
	HDC hdc = GetWindowDC(hwnd);
	RECT rect = {155, 65, 300, 92};
	HBRUSH brush = CreateSolidBrush(RGB(255, 255, 255));
	FillRect(hdc, &rect, brush);				
	DeleteObject(brush);
}
Exemple #19
0
void CColorSlide::DynamicStat(ENUM_SLIDERSTATE aState)
{
	if (m_nWidth <= 0)
	{
		return;
	}
	CDC* pDC =GetWindowDC();	
	if (pDC == NULL)
	{
		return;
	}
	pDC->SetBkColor(TRANSPARENT);
	CRect lrcClientRect;
	GetClientRect(lrcClientRect);
	m_nWidth = lrcClientRect.Width();
	lrcClientRect.bottom;
	m_nHeight = lrcClientRect.Height();

	CMemDC TempDC(pDC, CRect(lrcClientRect.left, lrcClientRect.top,lrcClientRect.right, lrcClientRect.bottom));
	PaintBK(lrcClientRect,TempDC.GetSafeHdc());
	if( m_SlideType != PERCENT_SLIDE ) 
	DrawSlider(aState,lrcClientRect,TempDC.GetSafeHdc());
	BitBlt(pDC->GetSafeHdc(),0,0,m_nWidth,m_nHeight,TempDC.GetSafeHdc(),0,0,SRCCOPY);
	ReleaseDC(pDC);
}
Exemple #20
0
void App::render()
{
    ProcessRunnable::Vec2 res;
    ProcessRunnable* runnable = (ProcessRunnable*)mProcessRunnable;
    if (runnable->isResumed())
        res = runnable->get();
    else
    {
        return;
    }

    const int bottomBoundary = m_height - 80;
    RECT rect = getRect(0, 0, m_width, bottomBoundary);

    int cx = (int)(res.x / 2);
    int cy = (int)(res.y / 2);

    int middleH = m_height / 2;
    RECT rectPos = getRect(0 + cx, middleH - cy, 10 + cx, middleH + 10 - cy);
    if (middleH - cy > (bottomBoundary - (rectPos.bottom - rectPos.top)))
    {
        runnable->stop();
        return;
    }

    HDC hDC = GetWindowDC(mHwnd);

    FillRect(hDC, &rect, (HBRUSH)(COLOR_WINDOW + 2));
    Rectangle(hDC, rectPos.left, rectPos.top, rectPos.right, rectPos.bottom);
    DeleteDC(hDC);
}
Exemple #21
0
VOID FASTCALL
DefWndScreenshot(HWND hWnd)
{
    RECT rect;
    HDC hdc;
    INT w;
    INT h;
    HBITMAP hbitmap;
    HDC hdc2;

    OpenClipboard(hWnd);
    EmptyClipboard();

    hdc = GetWindowDC(hWnd);
    GetWindowRect(hWnd, &rect);
    w = rect.right - rect.left;
    h = rect.bottom - rect.top;

    hbitmap = CreateCompatibleBitmap(hdc, w, h);
    hdc2 = CreateCompatibleDC(hdc);
    SelectObject(hdc2, hbitmap);

    BitBlt(hdc2, 0, 0, w, h,
           hdc, 0, 0,
           SRCCOPY);

    SetClipboardData(CF_BITMAP, hbitmap);

    ReleaseDC(hWnd, hdc);
    ReleaseDC(hWnd, hdc2);

    CloseClipboard();
}
Exemple #22
0
void CFrame::logColor(CPnt5* pnt5)
{
	HWND hwnd = aigisHwnd();
	if (!hwnd)
	{
		return ;
	}
	HDC hdc = GetWindowDC(hwnd);
	if (!hdc)
	{
		return ;
	}

	cout << dec << pnt5->getPoint(EPD_MID).x << ", " << pnt5->getPoint(EPD_MID).y;
	for (size_t i = 0; i < EPD_MAX; i++)
	{
		POINT pntTmp = pnt5->getPoint((E_POINT_DIRECTION)i);
		COLORREF colorFind = GetPixel(hdc, pntTmp.x, pntTmp.y);
		cout << ", 0x" << hex << colorFind;
		CStcVal::s_arrColor[i] = colorFind;
	}
	cout << endl;
	
	ReleaseDC(hwnd, hdc);
}
Exemple #23
0
//////////////////
// Create window DC, including non-client area.
// 
WPNCWinDC::WPNCWinDC(WPWin *w)
{
	assert(w);
	win = w;
	hdc = GetWindowDC((*win)());
	assert(hdc);
}
Exemple #24
0
LRESULT CMainWindow::Splitter_OnMouseMove(HWND hwnd, UINT /*iMsg*/, WPARAM wParam, LPARAM lParam)
{
    RECT rect;
    RECT clientrect;

    POINT pt;

    if (bDragMode == FALSE)
        return 0;

    pt.x = (short)LOWORD(lParam);  // horizontal position of cursor
    pt.y = (short)HIWORD(lParam);

    GetClientRect(hwnd, &clientrect);
    GetWindowRect(hwnd, &rect);
    POINT zero = {0,0};
    ClientToScreen(hwnd, &zero);
    OffsetRect(&clientrect, zero.x-rect.left, zero.y-rect.top);

    //convert the mouse coordinates relative to the top-left of
    //the window
    ClientToScreen(hwnd, &pt);
    pt.x -= rect.left;
    pt.y -= rect.top;

    //same for the window coordinates - make them relative to 0,0
    OffsetRect(&rect, -rect.left, -rect.top);

    if (pt.x < 0)
        pt.x = 0;
    if (pt.x > rect.right-4)
        pt.x = rect.right-4;
    if (pt.y < 0)
        pt.y = 0;
    if (pt.y > rect.bottom-4)
        pt.y = rect.bottom-4;

    if ((wParam & MK_LBUTTON) && ((bVertical && (pt.y != oldy)) || (!bVertical && (pt.x != oldx))))
    {
        HDC hdc = GetWindowDC(hwnd);

        if (bVertical)
        {
            DrawXorBar(hdc, clientrect.left, oldy+2, clientrect.right-clientrect.left-2, 4);
            DrawXorBar(hdc, clientrect.left, pt.y+2, clientrect.right-clientrect.left-2, 4);
        }
        else
        {
            DrawXorBar(hdc, oldx+2, clientrect.top, 4, clientrect.bottom-clientrect.top-2);
            DrawXorBar(hdc, pt.x+2, clientrect.top, 4, clientrect.bottom-clientrect.top-2);
        }

        ReleaseDC(hwnd, hdc);

        oldx = pt.x;
        oldy = pt.y;
    }

    return 0;
}
void OnScreenDisplayWnd::Display(char * str, int timeout)
{
   SIZE size;
   HFONT defFont;
   HDC hdc;

   if (str != m_text)
      strncpy(m_text, str, sizeof(m_text));

   hdc = GetWindowDC(m_hWnd);
   defFont = (HFONT)SelectObject(hdc, m_font);
   SetTextColor(hdc, m_fgColor);
   GetTextExtentPoint32(hdc, m_text, strlen(m_text), &size);
   SelectObject(hdc, defFont);
   ReleaseDC(m_hWnd, hdc);

   //HACK: to erase the background, hide the window...
   if (!m_hasBackground && IsWindowVisible(m_hWnd))
      ShowWindowAsync(m_hWnd, SW_HIDE);

   SetWindowPos(m_hWnd, NULL, 0, 0, size.cx+10, size.cy+10, 
                SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS|SWP_NOREPOSITION);
   InvalidateRect(m_hWnd, NULL, TRUE);

   ShowWindowAsync(m_hWnd, SW_SHOW);
   m_lastTimeout = timeout;
   if (timeout)
      SetTimer(m_hWnd, 1, timeout, NULL);
}
Exemple #26
0
/*
 * highlightWindowFrame
 *
 * Highlight (or unhighlight) the specified
 * window handle's frame.
 */
static void
highlightWindowFrame(HWND hWnd)
{
  HDC     hdc;
  RECT    rc;

  if (!IsWindow(hWnd))
    return;

  hdc = GetWindowDC(hWnd);
  GetWindowRect(hWnd, &rc);
  OffsetRect(&rc, -rc.left, -rc.top);

  if (!IsRectEmpty(&rc)) {
    PatBlt(hdc, rc.left, rc.top, rc.right-rc.left, DINV, DSTINVERT);
    PatBlt(hdc, rc.left, rc.bottom-DINV, DINV, -(rc.bottom-rc.top-2*DINV),
	   DSTINVERT);
    PatBlt(hdc, rc.right-DINV, rc.top+DINV, DINV, rc.bottom-rc.top-2*DINV,
	   DSTINVERT);
    PatBlt(hdc, rc.right, rc.bottom-DINV, -(rc.right-rc.left), DINV,
	   DSTINVERT);
  }

  ReleaseDC(hWnd, hdc);
  UpdateWindow(hWnd);
}
void CSkinListBox::OnNcPaint()
{
	//如果资源没有就是不想绘制边框了
	if ( m_pBackImgN == NULL ) 
	{
		__super::OnNcPaint();
		return;
	}

	CRect rcWindow;
	GetWindowRect(&rcWindow);

	CRect rcClient;
	GetClientRect(&rcClient);

	ClientToScreen(&rcClient);
	rcClient.OffsetRect(-rcWindow.left, -rcWindow.top);

	rcWindow.OffsetRect(-rcWindow.left, -rcWindow.top);

	CDC *pWindowDC = GetWindowDC();
	CMemoryDC MemDC(pWindowDC,rcWindow);

	DrawParentWndBg(GetSafeHwnd(),MemDC.GetSafeHdc());

	if (m_pBackImgN != NULL && !m_pBackImgN->IsNull())
		m_pBackImgN->Draw(&MemDC, rcWindow);
	
	pWindowDC->BitBlt(rcWindow.left,rcWindow.top,rcWindow.Width(),rcWindow.Height(),&MemDC,0,0,SRCCOPY);

	ReleaseDC(pWindowDC);
}
Exemple #28
0
static
QPixmap grabWindow( HWND hWnd, QString *title=0, QString *windowClass=0 )
{
    RECT windowRect;
    GetWindowRect(hWnd, &windowRect);
    int w = windowRect.right - windowRect.left;
    int h = windowRect.bottom - windowRect.top;
    HDC targetDC = GetWindowDC(hWnd);
    HDC hDC = CreateCompatibleDC(targetDC);
    HBITMAP tempPict = CreateCompatibleBitmap(targetDC, w, h);
    HGDIOBJ oldPict = SelectObject(hDC, tempPict);
    BitBlt(hDC, 0, 0, w, h, targetDC, 0, 0, SRCCOPY);
    tempPict = (HBITMAP) SelectObject(hDC, oldPict);
    QPixmap pm = QPixmap::fromWinHBITMAP(tempPict);

    DeleteDC(hDC);
    ReleaseDC(hWnd, targetDC);

    KWindowInfo winInfo( findRealWindow(hWnd), NET::WMVisibleName, NET::WM2WindowClass );
    if ( title ) {
        (*title) = winInfo.visibleName();
    }

    if ( windowClass ) {
        (*windowClass) = winInfo.windowClassName();
    }
    return pm;
}
Exemple #29
0
DWORD WINAPI overlayWindowThread(LPVOID parameter) {
	ShowWindow(overlayWindow, SW_SHOW);
	HDC windowDC = GetDC(overlayWindow);

	HDC screenDC = GetWindowDC(GetDesktopWindow());

	overlayDC = CreateCompatibleDC(screenDC);
	HBITMAP overlayBitmap = CreateCompatibleBitmap(screenDC, w, h);
	SelectObject(overlayDC, overlayBitmap);

	POINT zero = { 0, 0 };
	SIZE size = { w, h };

	BLENDFUNCTION bf;
	bf.AlphaFormat = AC_SRC_OVER;
	bf.BlendFlags = 0;
	bf.SourceConstantAlpha = 255;
	bf.AlphaFormat = AC_SRC_ALPHA;

	for (;;) {
		if (update) {
			UpdateLayeredWindow(overlayWindow, screenDC, &zero, &size, overlayDC, &zero, NULL, &bf, ULW_ALPHA);
			update = FALSE;
		}

		Sleep(1);
	}
}
Exemple #30
0
LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_TEST :
                        {
                           HDC   hDC;
                           RECT  rect;
                           int   i;

                           // Figure out the position and size of the first
                           // block in the pattern.
                           //..............................................
                           rect.top     = GetSystemMetrics( SM_CYSIZEFRAME );
                           rect.left    = GetSystemMetrics( SM_CXSIZEFRAME );
                           rect.left   += GetSystemMetrics( SM_CXSMICON )+100;
                           rect.bottom  = rect.top + 
                                          GetSystemMetrics( SM_CYCAPTION )-1;
                           rect.right   = rect.left+5;

                           hDC = GetWindowDC( hWnd );

                           // Paint 10 blocks in the caption of the window.
                           //..............................................
                           for ( i = 0; i < 10; i++ )
                           {
                              FillRect( hDC, &rect, 
                                        GetStockObject( WHITE_BRUSH ) );
                              rect.left  += 10;
                              rect.right += 10;
                           }
                           
                           ReleaseDC( hWnd, hDC ); 
                        }
                        break;

                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
      
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
}