Tamplan
Messages postés26Date d'inscriptionjeudi 2 janvier 2003StatutMembreDernière intervention31 mars 2009
-
15 janv. 2006 à 11:53
PCPT
Messages postés13272Date d'inscriptionlundi 13 décembre 2004StatutMembreDernière intervention 3 février 2018
-
16 janv. 2006 à 20:57
Bonjour à tous,
Voici mon problème :
Je voudrais faire une bitmap d'une fenêtre dont je connais le hwnd
pour rendre cette fenêtre transparente selon la couleur des points
contenus dans cette bitmap.
Donc si j'ai bien compris, je dois faire une bitmap
de cette fenêtre puis créer une région dépendante de la couleur des
points de cette bitmap pour ensuite appliquer cette région à la fenêtre.
Je n'y arrive pas ... Pourriez-vous me donner un petit coup de main je vous prie ?
D'avance merci pour votre aide
PS : Analysée avec Winspector Spy, la fenêtre n'a pas de contrôles (bouton ou autre), c'est bien une "image"
A voir également:
Transparence création de bitmap sur une fenêtre dont je connais le hwnd
dans la 2e, tu poses une shape par défaut, et un bouton par défaut.
puis ce code :
Option Explicit
Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Const RC_PALETTE As Long = &H100
Const SIZEPALETTE As Long = 104
Const RASTERCAPS As Long = 38
Private Type PALETTEENTRY
peRed As Byte
peGreen As Byte
peBlue As Byte
peFlags As Byte
End Type
Private Type LOGPALETTE
palVersion As Integer
palNumEntries As Integer
palPalEntry(255) As PALETTEENTRY ' Enough for 256 colors
End Type
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type PicBmp
Size As Long
Type As Long
hBmp As Long
hPal As Long
Reserved As Long
End Type
Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal iCapabilitiy As Long) As Long
Private Declare Function GetSystemPaletteEntries Lib "gdi32" (ByVal hdc As Long, ByVal wStartIndex As Long, ByVal wNumEntries As Long, lpPaletteEntries As PALETTEENTRY) As Long
Private Declare Function CreatePalette Lib "gdi32" (lpLogPalette As LOGPALETTE) As Long
Private Declare Function SelectPalette Lib "gdi32" (ByVal hdc As Long, ByVal hPalette As Long, ByVal bForceBackground As Long) As Long
Private Declare Function RealizePalette Lib "gdi32" (ByVal hdc 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 DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
'
'
'
Private Sub Form_Load()
Shape1.Shape = 2
Shape1.FillStyle = 0
Shape1.FillColor = 255
Me.BackColor = 65280
Me.Show
End Sub
'
'
'
Private Sub Command1_Click()
Dim lDC As Long
lDC = GetDC(Me.hWnd) 'ici bien sur le handle désiré
Tamplan
Messages postés26Date d'inscriptionjeudi 2 janvier 2003StatutMembreDernière intervention31 mars 2009 15 janv. 2006 à 23:03
Ok merci de t'occuper de mon problème.
Voici le code que j'utilise :
Option Explicit
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long,
ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As
Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal
nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Boolean) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Global RegionDébut As Long
Private Const RGN_XOR = 3
Public Function ScreenRegion(ByRef Screen As IMeedioScreen) As Long
Dim x As Long
Dim y As Long
Dim RectScreen As RECT
Dim RetRgn As Long
Dim TmpRgn As Long
Dim TempObject As Object
Dim Rgn_Start As Long
Dim Rgn_End As Long
Dim hdc As Long
Dim mWidth As Long
Dim mHeight As Long
Set TempObject = Screen
hdc = GetWindowDC(Screen.WindowHandle)
SelectObject hdc, TempObject.Handle
GetWindowRect Screen.WindowHandle, RectScreen
mWidth = RectScreen.Right - RectScreen.Left
mHeight = RectScreen.Bottom - RectScreen.Top
RetRgn = CreateRectRgn(0, 0, mWidth, mHeight)
If mWidth > 0 Then
For y = 0 To mHeight - 1
Rgn_Start = -1
For x = 0 To mWidth - 1
If GetPixel(hdc, x, y) = 0 Then
If Rgn_Start -1 Then Rgn_Start x
Rgn_End = x + 1
If x = (mWidth - 1) Then
TmpRgn = CreateRectRgn(Rgn_Start, y, Rgn_End, y + 1)
Call CombineRgn(RetRgn, TmpRgn, RetRgn, RGN_XOR)
Call DeleteObject(TmpRgn)
End If
Else
If Rgn_Start > -1 Then
TmpRgn = CreateRectRgn(Rgn_Start, y, Rgn_End, y + 1)
Call CombineRgn(RetRgn, TmpRgn, RetRgn, RGN_XOR)
Call DeleteObject(TmpRgn)
End If
Rgn_Start = -1
End If
Next x
Next y
End If
DoEvents
SetWindowRgn Screen.WindowHandle, RetRgn, True
ReleaseDC Screen.WindowHandle, hdc
Set TempObject = Nothing
End Function
Screen est un objet du SDK de Meedio, il possédé un hwnd et un handle (comme une picturebox je présume)
Je suis obligé de passé par un objet temporaire pour récupérer le
handle et bidouillé pour avoir les dimensions de la région de départ.
Ca semble fonctionner mais cette fenêtre est en fait un menu composé
d'images (1 image par "bouton" en surbrillance), je n'arrive pas à
redonner la région d'origine entre changement de "bouton".