vc dialog绘图

拖到对话框上一个静态文本框,id是IDC_STATIC1,在其上绘图
void CDilDlg::OnOK() 
{
	// TODO: Add extra validation here
	CWnd   *pWnd=GetDlgItem(IDC_STATIC1);
	CDC   *pControlDC=pWnd-> GetDC();
	pWnd-> Invalidate();
	pWnd-> UpdateWindow();
	pControlDC-> SelectStockObject(BLACK_BRUSH);
	pControlDC-> Rectangle(0,0,100,100);
	pWnd-> ReleaseDC(pControlDC);
}

对于有owner draw属性的控件比如按钮(把该属性勾选)可以用CxxDlg类的WM_DRAWITEM消息初始化时绘图 http://blog.csdn.net/luck_good/article/details/6961272
void CDilDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	// TODO: Add your message handler code here and/or call default
	   if (IDCANCEL==nIDCtl)//筛选出IDCANCEL
	   {  
		   CDC dc;  
		   dc.Attach(lpDrawItemStruct->hDC);  
		   
		   CWnd* pWnd=GetDlgItem(IDCANCEL);//取得IDCANCEL指针  
		   CRect r;  
		   CString strCaption;  
		   if (NULL!=pWnd) {  
			   pWnd->GetClientRect(&r);//使r代表按钮在父窗口中的位置和尺寸  
			   pWnd->GetWindowText(strCaption);//取得按钮上的文字  
		   }  
		   dc.SelectStockObject(BLACK_BRUSH);
		   dc.Rectangle(0,0,100,100);

		 //  dc.SetTextColor(RGB(255,0,0));//使按钮上文字的颜色为red  
		 //  dc.DrawText("dddd",&r,DT_CENTER|DT_VCENTER);//在按钮上重写文字  
		   
    }  

refer to http://topic.csdn.net/t/20050503/09/3981563.html

绘图类

CDC Class Members

Data Members
Construction/Destruction
Initialization
Device-Context Functions
Drawing-Tool Functions
Type-Safe Selection. Helpers
Color and Color Palette Functions
Drawing-Attribute Functions
Mapping Functions
Coordinate Functions
Region Functions
Clipping Functions
Line-Output Functions
Simple Drawing Functions
Ellipse and Polygon Functions
Bitmap Functions
Text Functions
Font Functions
Printer Escape Functions
Scrolling Functions
Metafile Functions
Path Functions

Data Members

m_hDCThe output-device context used by this CDC object.
m_hAttribDCThe attribute-device context used by this CDC object.

Construction

CDCConstructs a CDC object.

Initialization

CreateDCCreates a device context for a specific device.
CreateICCreates an information context for a specific device. This provides a fast way to get information about the device without creating a device context.
CreateCompatibleDCCreates a memory-device context that is compatible with another device context. You can use it to prepare images in memory.
DeleteDCDeletes the Windows device context associated with this CDC object.
FromHandleReturns a pointer to a CDC object when given a handle to a device context. If aCDC object is not attached to the handle, a temporary CDC object is created and attached.
DeleteTempMapCalled by the CWinApp idle-time handler to delete any temporaryCDC object created by FromHandle. Also detaches the device context.
AttachAttaches a Windows device context to this CDC object.
DetachDetaches the Windows device context from this CDC object.
SetAttribDCSets m_hAttribDC, the attribute device context.
SetOutputDCSets m_hDC, the output device context.
ReleaseAttribDCReleases m_hAttribDC, the attribute device context.
ReleaseOutputDCReleases m_hDC, the output device context.
GetCurrentBitmapReturns a pointer to the currently selected CBitmap object.
GetCurrentBrushReturns a pointer to the currently selected CBrush object.
GetCurrentFontReturns a pointer to the currently selected CFont object.
GetCurrentPaletteReturns a pointer to the currently selected CPalette object.
GetCurrentPenReturns a pointer to the currently selected CPen object.
GetWindowReturns the window associated with the display device context.

Device-Context Functions

GetSafeHdcReturns m_hDC, the output device context.
SaveDCSaves the current state of the device context.
RestoreDCRestores the device context to a previous state saved with SaveDC.
ResetDCUpdates the m_hAttribDC device context.
GetDeviceCapsRetrieves a specified kind of device-specific information about a given display device’s capabilities.
IsPrintingDetermines whether the device context is being used for printing.

Drawing-Tool Functions

GetBrushOrgRetrieves the origin of the current brush.
SetBrushOrgSpecifies the origin for the next brush selected into a device context.
EnumObjectsEnumerates the pens and brushes available in a device context.

Type-Safe Selection Helpers

SelectObjectSelects a GDI drawing object such as a pen.
SelectStockObjectSelects one of the predefined stock pens, brushes, or fonts provided by Windows.

Color and Color Palette Functions

GetNearestColorRetrieves the closest logical color to a specified logical color that the given device can represent.
SelectPaletteSelects the logical palette.
RealizePaletteMaps palette entries in the current logical palette to the system palette.
UpdateColorsUpdates the client area of the device context by matching the current colors in the client area to the system palette on a pixel-by-pixel basis.
GetHalftoneBrushRetrieves a halftone brush.

Drawing-Attribute Functions

GetBkColorRetrieves the current background color.
SetBkColorSets the current background color.
GetBkModeRetrieves the background mode.
SetBkModeSets the background mode.
GetPolyFillModeRetrieves the current polygon-filling mode.
SetPolyFillModeSets the polygon-filling mode.
GetROP2Retrieves the current drawing mode.
SetROP2Sets the current drawing mode.
GetStretchBltModeRetrieves the current bitmap-stretching mode.
SetStretchBltModeSets the bitmap-stretching mode.
GetTextColorRetrieves the current text color.
SetTextColorSets the text color.
GetColorAdjustmentRetrieves the color adjustment values for the device context.
SetColorAdjustmentSets the color adjustment values for the device context using the specified values.

Mapping Functions

GetMapModeRetrieves the current mapping mode.
SetMapModeSets the current mapping mode.
GetViewportOrgRetrieves the x- and y-coordinates of the viewport origin.
SetViewportOrgSets the viewport origin.
OffsetViewportOrgModifies the viewport origin relative to the coordinates of the current viewport origin.
GetViewportExtRetrieves the x- and y-extents of the viewport.
SetViewportExtSets the x- and y-extents of the viewport.
ScaleViewportExtModifies the viewport extent relative to the current values.
GetWindowOrgRetrieves the x- and y-coordinates of the origin of the associated window.
SetWindowOrgSets the window origin of the device context.
OffsetWindowOrgModifies the window origin relative to the coordinates of the current window origin.
GetWindowExtRetrieves the x- and y-extents of the associated window.
SetWindowExtSets the x- and y-extents of the associated window.
ScaleWindowExtModifies the window extents relative to the current values.

Coordinate Functions

DPtoHIMETRICConverts device units into HIMETRIC units.
DPtoLPConverts device units into logical units.
HIMETRICtoDPConverts HIMETRIC units into device units.
HIMETRICtoLPConverts HIMETRIC units into logical units.
LPtoDPConverts logical units into device units.
LPtoHIMETRICConverts logical units into HIMETRIC units.

Region Functions

FillRgnFills a specific region with the specified brush.
FrameRgnDraws a border around a specific region using a brush.
InvertRgnInverts the colors in a region.
PaintRgnFills a region with the selected brush.

Clipping Functions

SetBoundsRectControls the accumulation of bounding-rectangle information for the specified device context.
GetBoundsRectReturns the current accumulated bounding rectangle for the specified device context.
GetClipBoxRetrieves the dimensions of the tightest bounding rectangle around the current clipping boundary.
SelectClipRgnCombines the given region with the current clipping region by using the specified mode.
ExcludeClipRectCreates a new clipping region that consists of the existing clipping region minus the specified rectangle.
ExcludeUpdateRgnPrevents drawing within invalid areas of a window by excluding an updated region in the window from a clipping region.
IntersectClipRectCreates a new clipping region by forming the intersection of the current region and a rectangle.
OffsetClipRgnMoves the clipping region of the given device.
PtVisibleSpecifies whether the given point is within the clipping region.
RectVisibleDetermines whether any part of the given rectangle lies within the clipping region.

Line-Output Functions

GetCurrentPositionRetrieves the current position of the pen (in logical coordinates).
MoveToMoves the current position.
LineToDraws a line from the current position up to, but not including, a point.
ArcDraws an elliptical arc.
ArcToDraws an elliptical arc. This function is similar to Arc, except that the current position is updated.
AngleArcDraws a line segment and an arc, and moves the current position to the ending point of the arc.
GetArcDirectionReturns the current arc direction for the device context.
SetArcDirectionSets the drawing direction to be used for arc and rectangle functions.
PolyDrawDraws a set of line segments and Bézier splines. This function updates the current position.
PolylineDraws a set of line segments connecting the specified points.
PolyPolylineDraws multiple series of connected line segments. The current position is neither used nor updated by this function.
PolylineToDraws one or more straight lines and moves the current position to the ending point of the last line.
PolyBezierDraws one or more Bézier splines. The current position is neither used nor updated.
PolyBezierToDraws one or more Bézier splines, and moves the current position to the ending point of the last Bézier spline.

Simple Drawing Functions

FillRectFills a given rectangle by using a specific brush.
FrameRectDraws a border around a rectangle.
InvertRectInverts the contents of a rectangle.
DrawIconDraws an icon.
DrawDragRectErases and redraws a rectangle as it is dragged.
FillSolidRectFills a rectangle with a solid color.
Draw3dRectDraws a three-dimensional rectangle.
DrawEdgeDraws the edges of a rectangle.
DrawFrameControlDraw a frame control.
DrawStateDisplays an image and applies a visual effect to indicate a state.

Ellipse and Polygon Functions

ChordDraws a chord (a closed figure bounded by the intersection of an ellipse and a line segment).
DrawFocusRectDraws a rectangle in the style used to indicate focus.
EllipseDraws an ellipse.
PieDraws a pie-shaped wedge.
PolygonDraws a polygon consisting of two or more points (vertices) connected by lines.
PolyPolygonCreates two or more polygons that are filled using the current polygon-filling mode. The polygons may be disjoint or they may overlap.
PolylineDraws a polygon consisting of a set of line segments connecting specified points.
RectangleDraws a rectangle using the current pen and fills it using the current brush.
RoundRectDraws a rectangle with rounded corners using the current pen and filled using the current brush.

Bitmap Functions

PatBltCreates a bit pattern.
BitBltCopies a bitmap from a specified device context.
StretchBltMoves a bitmap from a source rectangle and device into a destination rectangle, stretching or compressing the bitmap if necessary to fit the dimensions of the destination rectangle.
GetPixelRetrieves the RGB color value of the pixel at the specified point.
SetPixelSets the pixel at the specified point to the closest approximation of the specified color.
SetPixelVSets the pixel at the specified coordinates to the closest approximation of the specified color.SetPixelV is faster than SetPixel because it does not need to return the color value of the point actually painted.
FloodFillFills an area with the current brush.
ExtFloodFillFills an area with the current brush. Provides more flexibility than theFloodFill member function.
MaskBltCombines the color data for the source and destination bitmaps using the given mask and raster operation.
PlgBltPerforms a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the given device context.

Text Functions

TextOutWrites a character string at a specified location using the currently selected font.
ExtTextOutWrites a character string within a rectangular region using the currently selected font.
TabbedTextOutWrites a character string at a specified location, expanding tabs to the values specified in an array of tab-stop positions.
DrawTextDraws formatted text in the specified rectangle.
GetTextExtentComputes the width and height of a line of text on the attribute device context using the current font to determine the dimensions.
GetOutputTextExtentComputes the width and height of a line of text on the output device context using the current font to determine the dimensions.
GetTabbedTextExtentComputes the width and height of a character string on the attribute device context.
GetOutputTabbedTextExtentComputes the width and height of a character string on the output device context.
GrayStringDraws dimmed (grayed) text at the given location.
GetTextAlignRetrieves the text-alignment flags.
SetTextAlignSets the text-alignment flags.
GetTextFaceCopies the typeface name of the current font into a buffer as a null-terminated string.
GetTextMetricsRetrieves the metrics for the current font from the attribute device context.
GetOutputTextMetricsRetrieves the metrics for the current font from the output device context.
SetTextJustificationAdds space to the break characters in a string.
GetTextCharacterExtraRetrieves the current setting for the amount of intercharacter spacing.
SetTextCharacterExtraSets the amount of intercharacter spacing.

Font Functions

GetFontDataRetrieves font metric information from a scalable font file. The information to retrieve is identified by specifying an offset into the font file and the length of the information to return.
GetKerningPairsRetrieves the character kerning pairs for the font that is currently selected in the specified device context.
GetOutlineTextMetricsRetrieves font metric information for TrueType fonts.
GetGlyphOutlineRetrieves the outline curve or bitmap for an outline character in the current font.
GetCharABCWidthsRetrieves the widths, in logical units, of consecutive characters in a given range from the current font.
GetCharWidthRetrieves the fractional widths of consecutive characters in a given range from the current font.
GetOutputCharWidthRetrieves the widths of individual characters in a consecutive group of characters from the current font using the output device context.
SetMapperFlagsAlters the algorithm that the font mapper uses when it maps logical fonts to physical fonts.
GetAspectRatioFilterRetrieves the setting for the current aspect-ratio filter.

Printer Escape Functions

QueryAbortCalls theAbortProc callback function for a printing application and queries whether the printing should be terminated.
EscapeAllows applications to access facilities that are not directly available from a particular device through GDI. Also allows access to Windows escape functions. Escape calls made by an application are translated and sent to the device driver.
DrawEscapeAccesses drawing capabilities of a video display that are not directly available through the graphics device interface (GDI).
StartDocInforms the device driver that a new print job is starting.
StartPageInforms the device driver that a new page is starting.
EndPageInforms the device driver that a page is ending.
SetAbortProcSets a programmer-supplied callback function that Windows calls if a print job must be aborted.
AbortDocTerminates the current print job, erasing everything the application has written to the device since the last call of theStartDoc member function.
EndDocEnds a print job started by the StartDoc member function.

Scrolling Functions

ScrollDCScrolls a rectangle of bits horizontally and vertically.

Metafile Functions

PlayMetaFilePlays the contents of the specified metafile on the given device. The enhanced version ofPlayMetaFile displays the picture stored in the given enhanced-format metafile. The metafile can be played any number of times.
AddMetaFileCommentCopies the comment from a buffer into a specified enhanced-format metafile.

Path Functions

AbortPathCloses and discards any paths in the device context.
BeginPathOpens a path bracket in the device context.
CloseFigureCloses an open figure in a path.
EndPathCloses a path bracket and selects the path defined by the bracket into the device context.
FillPathCloses any open figures in the current path and fills the path’s interior by using the current brush and polygon-filling mode.
FlattenPathTransforms any curves in the path selected into the current device context, and turns each curve into a sequence of lines.
GetMiterLimitReturns the miter limit for the device context.
GetPathRetrieves the coordinates defining the endpoints of lines and the control points of curves found in the path that is selected into the device context.
SelectClipPathSelects the current path as a clipping region for the device context, combining the new region with any existing clipping region by using the specified mode.
SetMiterLimitSets the limit for the length of miter joins for the device context.
StrokeAndFillPathCloses any open figures in a path, strikes the outline of the path by using the current pen, and fills its interior by using the current brush.
StrokePathRenders the specified path by using the current pen.
WidenPathRedefines the current path as the area that would be painted if the path were stroked using the pen currently selected into the device context.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值