Hi!
Folgender Ablauf:
Ich hab 4 Bilder, die per SetPixel gezeichnet werden. Dise sollen aber in getrennte DCs gepackt werden, weil das Neuzeichnen zu lange dauert (-> flackern), und dann per BitBlt in eine Picturebox gebltet werden.
Mein bisheriger Code:
APIs, UDTs und Consts:
Programm:
BitBlt gibt 1 zurück -> scheinbar kein Fehler.
Wenn ich miteinen beliebigen Punkt vom "normal"-DC augebe, kommt immer 255, 255, 255.
Hab ich vllt. irgendwas vergessen? Muss man irgendeine Region o.Ä. bei nem eigenen DC setzen?
so long..
Andy
Folgender Ablauf:
Ich hab 4 Bilder, die per SetPixel gezeichnet werden. Dise sollen aber in getrennte DCs gepackt werden, weil das Neuzeichnen zu lange dauert (-> flackern), und dann per BitBlt in eine Picturebox gebltet werden.
Mein bisheriger Code:
APIs, UDTs und Consts:
Visual Basic-Quellcode
- Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
- Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
- Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDC As Long) As Long
- Private Declare Function DeleteDC Lib "gdi32" (ByVal hDC As Long) As Long
- Private Declare Function SetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
- Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
- Private Declare Function GetPixel Lib "gdi32" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
- Private Type COLORREF
- rgbRed As Byte
- rgbGreen As Byte
- rgbBlue As Byte
- rgbReserved As Byte
- End Type
- Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Visual Basic-Quellcode
- 'Bildauswahl
- Private cSel As Byte 'Farbe: cGn
- Private cSelOld As Byte 'zur Änderungsprüfung
- Private cmdDown As Boolean 'Farbe:cCn
- Private cmdDownOld As Boolean 'zur Änderungsprüfung
- 'Farbwerte (Anfang & Ende von Verlauf)
- Private cG1 As COLORREF
- Private cG2 As COLORREF
- Private cC1 As COLORREF
- Private cC2 As COLORREF
- 'DCs
- Private hDCn As Long 'normal
- Private hDCh As Long 'hover
- Private hDCnd As Long 'normal, down
- Private hDChd As Long 'hover, down
- Private Sub Form_Load()
- cG1 = NewColor(225, 222, 213)
- cG2 = NewColor(179, 176, 170)
- cC1 = NewColor(173, 201, 237)
- cC2 = NewColor(130, 151, 179)
- cSel = 0
- cSelOld = 1
- cmdDown = False
- cmdDownOld = True
- hDCn = CreateCompatibleDC(GetDC(0))
- hDCh = CreateCompatibleDC(GetDC(0))
- hDCnd = CreateCompatibleDC(GetDC(0))
- hDChd = CreateCompatibleDC(GetDC(0))
- picBG_Resize
- End Sub
- Private Sub picBG_Resize()
- DrawNiceButton hDCn, cG1, cG2, picBG.Width / 15, picBG.Height / 15, False
- DrawNiceButton hDCh, cC1, cC2, picBG.Width / 15, picBG.Height / 15, False
- DrawNiceButton hDCnd, cG1, cG2, picBG.Width / 15, picBG.Height / 15, True
- DrawNiceButton hDChd, cC1, cC2, picBG.Width / 15, picBG.Height / 15, True
- End Sub
- Private Sub DrawNiceButton(hDC As Long, cStart As COLORREF, cEnd As COLORREF, Width As Long, Height As Long, Pressed As Boolean)
- 'Debug-Output liefert gültige DCs und die richtigen Werte
- Debug.Print "DrawNiceButton: hDC=" & hDC & ", cStart=(" & cStart.rgbRed & ", " & cStart.rgbGreen & ", " & cStart.rgbBlue & "), cEnd=(" & cEnd.rgbRed & ", " & cEnd.rgbGreen & ", " & cEnd.rgbBlue & "), width=" & Width & ", height=" & Height & ", pressed=" & Pressed
- '...
- 'cThis hat den richtigen Wert, gleicher Code hat mit picBG.hDC funktioniert
- cThis = BalanceColor(cRowStart, cRowEnd, CSng(y) / ymax)
- CopyMemory lThis, cThis, 4
- SetPixel hDC, x, y, lThis
- '...
- End Sub
- Private Sub picBG_Paint()
- If cmdDown Then
- If cSel = 0 Then
- BitBlt picBG.hDC, 0, 0, picBG.Width / 15 - 1, picBG.Height / 15 - 1, hDCnd, 0, 0, SRCCOPY
- Else
- BitBlt picBG.hDC, 0, 0, picBG.Width / 15 - 1, picBG.Height / 15 - 1, hDChd, 0, 0, SRCCOPY
- End If
- Else
- If cSel = 0 Then
- Debug.Print BitBlt(picBG.hDC, 0, 0, picBG.Width / 15 - 1, picBG.Height / 15 - 1, hDCn, 0, 0, SRCCOPY)
- Else
- BitBlt picBG.hDC, 0, 0, picBG.Width / 15 - 1, picBG.Height / 15 - 1, hDCh, 0, 0, SRCCOPY
- End If
- End If
- End Sub
Wenn ich miteinen beliebigen Punkt vom "normal"-DC augebe, kommt immer 255, 255, 255.
Hab ich vllt. irgendwas vergessen? Muss man irgendeine Region o.Ä. bei nem eigenen DC setzen?
so long..
Andy
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von „Mad Andy“ ()