PDA

Click to See Complete Forum and Search --> : Drawing on offscreen dc's


YoungBuck
Jun 16th, 2000, 12:30 PM
this is what I have so far:

MODULE1

Dim dcMain As Long
Dim bmpMain As Long

Dim dcPic As Long

Public Sub Init(hdc As Integer, h As Integer, w As Integer)
Dim ret As Long
dcMain = CreateCompatibleDC(hdc)
bmpMain = CreateCompatibleBitmap(dcMain, w, h)
ret = SelectObject(dcMain, bmpMain)
dcPic = CreateCompatibleDC(dcMain)
Dim pic1 As IPictureDisp
Set pic1 = LoadPicture("c:\windows\circles.bmp")
ret = SelectObject(dcPic, pic1)
Set pic1 = Nothing
End Sub

Public Sub Destroy()
Dim ret As Long
ret = DeleteDC(dcMain)
ret = DeleteObject(bmpMain)
ret = DeleteDC(dcPic)
End Sub

Public Sub showdc(hdc As Long, h As Integer, w As Integer)
Dim ret As Integer
ret = BitBlt(hdc, 0, 0, w, h, dcMain, 0, 0, SRCCOPY)
End Sub

Public Sub drawdcmain()
Dim ret As Long, ctr As Integer
Dim pen As Long
pen = CreatePen(PS_SOLID, 2, RGB(0, 255, 0))
ret = SelectObject(dcMain, pen)
For ctr = 1 To 95
ret = TextOut(dcMain, Rnd * 100, Rnd * 100, "JON", 3)
Next ctr
ret = DeleteObject(pen)
End Sub



FORM1



Private Sub Form_Load()
Call Init(Me.hdc, Me.Height / Screen.TwipsPerPixelY, Me.Width / Screen.TwipsPerPixelX)
drawdcmain
End Sub

Private Sub Form_Unload(Cancel As Integer)
Destroy
End Sub

Private Sub Timer1_Timer()
Call showdc(Me.hdc, Me.Height / 15, Me.Width / 15)
End Sub



what i want to know is how come everytime that the offscreen dc (dcMain) is drawn on with the TextOut function that it always appears black when blt'd to the screen, no matter what the pen is changed too, do I have to add a pallete? Also how come a bunch or garble is printed to the screen as well and is there anything you can do to clear it before blting it to the screen?