本文整理汇总了C++中GetWindowDC函数的典型用法代码示例。如果您正苦于以下问题:C++ GetWindowDC函数的具体用法?C++ GetWindowDC怎么用?C++ GetWindowDC使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetWindowDC函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetWindowDC
// 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);
}
}
示例2: DrawGaugeBorder
// 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);
}
示例3: DrawMap
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);
}
示例4: GetWindowDC
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);
}
示例5: CaptureWindow
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;
}
示例6: aigisHwnd
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;
}
示例7: GetWindowDC
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));
}
}
示例8: ToolbarWndProc
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);
}
示例9: GetWindowDC
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);
}
示例10: GetWindowDC
//-----------------------------------------------------------------------------
// 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);
}
示例11: GetWindowDC
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);
}
示例12: frame_draw_end
/*
* 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;
}
示例13: GetWindowDC
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);
}
示例14: GetWindowDC
// 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;
}
示例15: WinMain
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 ;
}