标签:
LRESULT QMainFrame::onPaint(WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; HDC hDC = ::BeginPaint(m_hWnd, &ps); RECT rcClient; GetClientRect(&rcClient); assert(hDC); { /**画字体 DrawText(hDC,_T("test"), _tcslen(_T("test")),&rcClient,DT_CENTER | DT_VCENTER | DT_WORD_ELLIPSIS | DT_SINGLELINE ); COLORREF clroldTextColor = SetTextColor(hDC,RGB(255,0,0));//设置字段的颜色 COLORREF clrBackColor = SetBkColor(hDC,RGB(0,255,0));//设置字段的背景 HFONT hFont = CreateFont( 15, 0, 0, 0, 500, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_SWISS, _T("arial") );//创建一个字体 HFONT hOldFont =(HFONT) ::SelectObject(hDC, (HGDIOBJ)hFont);//创建字体 TextOut(hDC, 0, 0, _T("test"), _tcslen(_T("test"))); ::SelectObject(hDC, (HGDIOBJ)hOldFont);//还原字体 DeleteObject((HGDIOBJ)hFont);//删除创建字体 SetTextColor(hDC, clroldTextColor);//还原字段颜色 设置 SetBkColor(hDC, clrBackColor);//还原字段背景色 设置 */ /**输出点 for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { SetPixel(hDC, i, j, RGB(0, 0, 255));//画一个像素点 } } */ /** 画线 HPEN hPen= CreatePen(PS_SOLID, 3, RGB(255, 0, 0));//产生一个画笔 HPEN hOldPen = (HPEN)::SelectObject(hDC, (HGDIOBJ)hPen);//设置画笔 { MoveToEx(hDC, 0, 0, NULL);//设置画线的开始点 LineTo(hDC, rcClient.right, rcClient.bottom);//设置画线的结束点 } ::SelectObject(hDC, (HGDIOBJ)hOldPen);//还原画笔 DeleteObject((HGDIOBJ)hPen); //记得删除 使得GDI对象不被增加 */ /**画面 RECT rc2; rc2.left = 0; rc2.right = 100; rc2.top = 0; rc2.bottom = 50; HPEN hPen = (HPEN)::GetStockObject(NULL_PEN);//调用系统中的画笔 画无边框画面 //HPEN hPen = CreatePen(PS_SOLID, 3, RGB(255, 0, 0));//产生一个画笔 来修改边框 HPEN hOldPen = (HPEN)::SelectObject(hDC, (HGDIOBJ)hPen);//设置画笔 { HBRUSH hBrush = ::CreateSolidBrush(RGB(0, 0, 255));//创建一个画刷 HBRUSH hOldBrush = (HBRUSH)::SelectObject(hDC, (HGDIOBJ)hBrush); { ::Rectangle(hDC, rc2.left, rc2.top, rc2.right, rc2.bottom); } ::SelectObject(hDC, (HGDIOBJ)hOldBrush);//还原画刷 DeleteObject((HGDIOBJ)hBrush); //记得删除 使得GDI对象不被增加 } ::SelectObject(hDC, (HGDIOBJ)hOldPen);//还原画笔 DeleteObject((HGDIOBJ)hPen); //记得删除 使得GDI对象不被增加 */ } ::EndPaint(m_hWnd, &ps); return TRUE; }win32学习之 --------GDI使用 代码记录
,