Date: 02-16-2022
Return to Index
created by gbSnippets
'text
SetTextColor(hDC, %Red)
TextOut(hDC, 50, 75, "Johnny Carson", 13) 'x,y,temp$,Len(temp$)
SetBkColor(hDC, %Yellow)
TextOut(hDC, 50, 125, "Red Dog", 7) 'x,y,temp$,Len(temp$)
'BITMAP
hDeskTopDC = GetDC(%Null)
hMemDC = CreateCompatibleDC(hDeskTopDC) 'memory DC
hBMP = CreateCompatibleBitmap(hDeskTopDC, w,h) 'memory bitmap
hMemOld = SelectObject(hMemDC, hBMP) 'select bitmap into memory DC
BitBlt hDC_Graphic, 0,0,w,h, hMemDC, 0,0, %SRCCopy 'copy memory DC to Grpahic Control DC
hBMP = SelectObject(hMemDC, hMemOld) 'unselect bitmap out of memory dc
hBMPDC = GetDC(hBMP)
ReleaseDC(%Null, hDeskTopDC)
GetStockObject
SetDCBrushColor SetDCPenColor
GetDeBrushcOlor GetDCPenColor
- need not use Delete Object on stock objects
'Stock Logical Objects
%Black_Brush
%DkGray_Brush
%DC_Brush - solid color brush. default white. change with SetDCBrushColor
%Gray_Brush
%Null_Brush (%Hollow_Brush)
%LTGray_Brush
%White_Brush
%Black_Pen
%DC_Pen - solid pen color. default white. change with SetDCPenColor
%Null_Pen
%White_Pen
%ANSI_FIXED_FONT - fixed pitch
%ANSI_VAR_FONT - variable pitch
%DEVICE_DEFAULT_FONT - device-dependent font.
%DEFAULT_GUI_FONT - default font for user interface objects such as menus and dialog boxes
%OEM_FIXED_FONT - OEM fixed pitch
%SYSTEM_FONT - Tahoma
%SYSTEM_FIXED_FONT -
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg, hCtl, hDc as DWord, PS as PaintStruct
%ID_Control = 104
Function PBMain() As Long
Dialog New Pixels, 0, "GDI Examples",300,300,200,200, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Paint
hDC = BeginPaint(hDlg, PS) 'get a handle to the dialog DC
'save original pen/brush
Local origPen, origBrush As Dword
origPen = SelectObject(hdc,GetStockObject(%DC_Pen))
origBrush = SelectObject(hdc,GetStockObject(%DC_Brush))
'Brush - default is %White_Brush
SelectObject(hdc, GetStockObject(%Black_Brush))
SelectObject(hdc, GetStockObject(%Black_Pen)) 'pen
Rectangle(hdc,10,10,60,60) 'left/top/right/bottom
'Pen - default is %Black_Brush
SelectObject(hdc, GetStockObject(%White_Pen)) 'pen
SelectObject(hdc, GetStockObject(%White_Brush))
Rectangle(hdc,10,80,60,140) 'left/top/right/bottom
'DC_Pen / DC_Brush allows changing the color
SelectObject(hdc, GetStockObject(%DC_Brush))
SelectObject(hdc, GetStockObject(%DC_Pen))
SetDCPenColor(hdc, %Red)
SetDCBrushColor(hdc, %Blue)
Rectangle(hdc,130,10,180,60) 'left/top/right/bottom
SetDCPenColor(hdc, %Yellow)
SetDCBrushColor(hdc, %Red)
Rectangle(hdc,130,80,180,130) 'left/top/right/bottom
SelectObject(hDC,origPen)
SelectObject(hDC,origBrush)
EndPaint hDlg, PS 'releases the handle to the dialog DC
End Select
End Function
'gbs_01007
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm