What's changed in this code between 4.20 & 4.30 [Resolved]
Posted: Tue Nov 24, 2009 5:37 pm
Post removed because the real problem is in the code above 
http://www.purebasic.com
https://www.purebasic.fr/english/

Code: Select all
; Author: Mischa (updated for PB3.93 by Donald)
; Date: 04. January 2004
; OS: Windows
; Demo: No
; Creates a .pbi file in the directory of a bitmap, which should
; be used as skin/background for a window...
; The created .pbi file will contain the calculated window mask data
; as well include the converted bitmap (into .png format).
; Note: an example for using the created .pbi file can be found at
; "WindowSkin_Example.pb" !
; Modifié par KCC (Adaptation en 4.10 + Indentation de ce code et du code masque généré + Rajout des surlignages de label
; + Modification chemin du fichier dans le chemin de l'image) + Rajout du module de selection couleur de GILLOU
Procedure WindowCallBack(WindowId, Message, lParam, wParam)
If Message = #WM_PAINT
StartDrawing(WindowOutput(0))
DrawImage(ImageID(1), 0, 0)
StopDrawing()
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
UsePNGImageEncoder()
UsePNGImageDecoder()
Structure myBITMAPINFO
bmiHeader.BITMAPINFOHEADER
bmiColors.RGBQUAD[1]
EndStructure
Structure RGB
v.l
EndStructure
Procedure CreateMask()
hDC = StartDrawing(ImageOutput(1))
main = CreateRectRgn_(0,0,0,0)
picl_X = ImageWidth(1)
picl_Y = ImageHeight(1)
mem = AllocateMemory(picl_X*picl_Y*4)
bmi.myBITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = picl_X
bmi\bmiHeader\biHeight = picl_Y
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
GetDIBits_(hDC,ImageID(1),1,picl_Y-1,mem,bmi,#DIB_RGB_COLORS)
*pixel.RGB = mem
trans.RGB
trans\v = *pixel\v
If Blue (trans\v)=255 And Green (trans\v)=0 And Red (trans\v)=0 : messag$= " -> Rouge"
ElseIf Blue (trans\v)=0 And Green (trans\v)=255 And Red (trans\v)=0 : messag$= " -> Vert"
ElseIf Blue (trans\v)=0 And Green (trans\v)=0 And Red (trans\v)=255 : messag$= " -> Bleu"
ElseIf Blue (trans\v)=255 And Green (trans\v)=255 And Red (trans\v)=255 : messag$= " -> Blanc"
ElseIf Blue (trans\v)=0 And Green (trans\v)=0 And Red (trans\v)=0 : messag$= " -> Noir"
EndIf
coulon = MessageRequester ( "Sélection de la couleur du masque" , "Couleur détectée : " + "Rouge : " + Str ( Blue (trans\v))+ " ; Vert : " + Str ( Green (trans\v))+ " ; Bleu : " + Str ( Red (trans\v))+messag$+ Chr (13)+ Chr (13)+ "Acceptez-vous cette couleur? (Oui : Utiliser la couleur ; Non : Ouvrir la palette de couleur)" , #PB_MessageRequester_YesNo )
If coulon<>6
trans\v = ColorRequester ()
trans\v = RGB ( Blue (trans\v), Green (trans\v), Red (trans\v))
EndIf
For ay=0 To picl_Y-2
For ax=0 To picl_X-1
If *pixel\v <> trans\v
sub = CreateRectRgn_(ax,picl_Y-ay-1,ax+1,picl_Y-ay-2)
CombineRgn_(main,main,sub,#RGN_OR)
DeleteObject_(sub)
EndIf
*pixel + 4
Next ax
Next ay
StopDrawing()
ProcedureReturn main
EndProcedure
File.s = OpenFileRequester("Open Bitmap","","Bitmap|*.bmp;*.png",0)
If File
Image = LoadImage(1, File)
w = ImageWidth(1)
h = ImageHeight(1)
ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)
HWnd = OpenWindow(0, screenx, screeny, w, h, "Mask-Image", #WS_POPUP)
Mask = CreateMask()
Oldsize = GetRegionData_(Mask, 0, 0)
*Source = AllocateMemory(Oldsize)
GetRegionData_(mask,oldsize,*Source)
*Target = AllocateMemory(Oldsize + 8)
Newsize = PackMemory(*Source,*Target,Oldsize,9)
Newfile.s = ReplaceString(File, GetExtensionPart(File),"png")
SaveImage(1, Newfile, #PB_ImagePlugin_PNG)
Rest = Newsize % 4
NomFenetre.s = Left(GetFilePart(File),Len(GetFilePart(File)) - 4)
File = ReplaceString(ReplaceString(File, GetFilePart(File), GetFilePart(File)),GetExtensionPart(File),"pbi")
If CreateFile(0, File)
WriteStringN(0,"UsePNGImageDecoder()")
WriteStringN(0,"")
WriteStringN(0,"Procedure OpenMaskedWindow_" + NomFenetre + "(WinID, x, y, Title.s, imID)")
WriteStringN(0,"")
WriteStringN(0," Hwnd" + NomFenetre + " = OpenWindow(winID, GetSystemMetrics_(#SM_CXSCREEN), y, " + Str(w) + ", " + Str(h) + ", Title, #WS_POPUP)")
WriteStringN(0," Memhandle = GlobalAlloc_(#GMEM_MOVEABLE," + Str(Oldsize + 8) + ")")
WriteStringN(0," *Mem = GlobalLock_(Memhandle)")
WriteStringN(0," UnpackMemory(?" + NomFenetre + "_Mask, *Mem)")
WriteStringN(0," Region = ExtCreateRegion_(0," + Str(Oldsize) + ", *Mem)")
WriteStringN(0," SetWindowRgn_(Hwnd" + NomFenetre + ", Region, #True)")
WriteStringN(0," Pic = CatchImage(imID,?" + NomFenetre +")")
WriteStringN(0," Brush = CreatePatternBrush_(Pic)")
WriteStringN(0," SetClassLong_(Hwnd" + NomFenetre + ", #GCL_HBRBACKGROUND, Brush)")
WriteStringN(0," ResizeWindow(WinID, x, y, #PB_Ignore, #PB_Ignore)")
WriteStringN(0," GlobalUnlock_(Memhandle)")
WriteStringN(0," GlobalFree_(Memhandle)")
WriteStringN(0," DeleteObject_(Region)")
WriteStringN(0," ProcedureReturn Hwnd" + NomFenetre)
WriteStringN(0,"")
WriteStringN(0," DataSection")
WriteStringN(0,"")
WriteStringN(0," " + Left(GetFilePart(File),Len(GetFilePart(File)) - 4)+":")
WriteStringN(0," ;***********")
WriteStringN(0,"")
WriteStringN(0," IncludeBinary " + Chr(34) + GetFilePart(Newfile) + Chr(34))
WriteStringN(0,"")
WriteStringN(0," " + Left(GetFilePart(File),Len(GetFilePart(File)) - 4) + "_Mask:")
WriteStringN(0," ;***********")
WriteStringN(0,"")
String.s = " Data.l "
For i = 0 To Newsize - 4 - Rest Step 4
String + "$" + LSet(Hex(PeekL(*Target + i)),8," ")
Count + 1
If Count = 10
Count = 0
WriteStringN(0, String)
String = " Data.l "
Else
String + ","
EndIf
Next i
If Count
String = Left(String, Len(String) - 1)
WriteStringN(0, String)
EndIf
WriteStringN(0,"")
WriteStringN(0," EndDataSection")
WriteStringN(0,"")
WriteStringN(0,"EndProcedure")
CloseFile(0)
MessageRequester("Fichier .pbi créé!","Cliquez droit pour sortir.",0)
Else
MessageRequester("Error!", "Can't create '"+ ReplaceString(ReplaceString(file, GetFilePart(file),"MaskWindow_" + GetFilePart(file)),GetExtensionPart(file),"pbi'"),0)
EndIf
SetWindowRgn_(hwnd, mask, #True)
ResizeWindow(0,(screenx - w) / 2,(screeny - h) / 2, #PB_Ignore, #PB_Ignore)
SetWindowCallback(@WindowCallback())
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONDOWN
SendMessage_(hwnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
Case #WM_RBUTTONDOWN
Quit=1
EndSelect
Until Quit=1
DeleteObject_(mask)
EndIf
EndI know that FRED is more on the french forum that before.Denis wrote:Ask to Fred on french forum
So i not always all understand in the release notersts wrote:Did you read the release notes?
Code: Select all
; Creates a .pbi file in the directory of a bitmap, which should
; be used as skin/background for a window...
; The created .pbi file will contain the calculated window mask data
; as well include the converted bitmap (into .png format).
; Note: an example for using the created .pbi file can be found at
; "WindowSkin_Example.pb" !
; Modifié par KCC (Adaptation en 4.10 + Indentation de ce code et du code masque généré + Rajout des surlignages de label
; + Modification chemin du fichier dans le chemin de l'image) + Rajout du module de selection couleur de GILLOU
Procedure WindowCallBack(WindowId, Message, lParam, wParam)
If Message = #WM_PAINT
StartDrawing(WindowOutput(0))
DrawImage(ImageID(1), 0, 0)
StopDrawing()
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
UsePNGImageEncoder()
UsePNGImageDecoder()
Structure myBITMAPINFO
bmiHeader.BITMAPINFOHEADER
bmiColors.RGBQUAD[1]
EndStructure
Structure RGB
v.l
EndStructure
Procedure CreateMask()
hDC = StartDrawing(ImageOutput(1))
main = CreateRectRgn_(0,0,0,0)
picl_X = ImageWidth(1)
picl_Y = ImageHeight(1)
mem = AllocateMemory(picl_X*picl_Y*4)
bmi.myBITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = picl_X
bmi\bmiHeader\biHeight = picl_Y
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
GetDIBits_(hDC,ImageID(1),1,picl_Y-1,mem,bmi,#DIB_RGB_COLORS)
*pixel.RGB = mem
trans.RGB
trans\v = *pixel\v
If Blue (trans\v)=255 And Green (trans\v)=0 And Red (trans\v)=0 : messag$= " -> Red"
ElseIf Blue (trans\v)=0 And Green (trans\v)=255 And Red (trans\v)=0 : messag$= " -> Green"
ElseIf Blue (trans\v)=0 And Green (trans\v)=0 And Red (trans\v)=255 : messag$= " -> Blue"
ElseIf Blue (trans\v)=255 And Green (trans\v)=255 And Red (trans\v)=255 : messag$= " -> White"
ElseIf Blue (trans\v)=0 And Green (trans\v)=0 And Red (trans\v)=0 : messag$= " -> Black"
EndIf
coulon = MessageRequester ( "Selection of the color of the mask" , "Detected color : " + "Red : " + Str ( Blue (trans\v))+ " ; Green : " + Str ( Green (trans\v))+ " ; Blue : " + Str ( Red (trans\v))+messag$+ Chr (13)+ Chr (13)+ "You accept this color? (Yes : To use the color ; No : To open the pallet of color)" , #PB_MessageRequester_YesNo )
If coulon<>6
trans\v = ColorRequester ()
trans\v = RGB ( Blue (trans\v), Green (trans\v), Red (trans\v))
EndIf
For ay=0 To picl_Y-2
For ax=0 To picl_X-1
If *pixel\v <> trans\v
sub = CreateRectRgn_(ax,picl_Y-ay-1,ax+1,picl_Y-ay-2)
CombineRgn_(main,main,sub,#RGN_OR)
DeleteObject_(sub)
EndIf
*pixel + 4
Next ax
Next ay
StopDrawing()
ProcedureReturn main
EndProcedure
File.s = OpenFileRequester("Open Bitmap","","Bitmap|*.bmp;*.png",0)
If File
Image = LoadImage(1, File)
w = ImageWidth(1)
h = ImageHeight(1)
ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)
HWnd = OpenWindow(0, screenx, screeny, w, h, "Mask-Image", #WS_POPUP)
Mask = CreateMask()
Oldsize = GetRegionData_(Mask, 0, 0)
*Source = AllocateMemory(Oldsize)
GetRegionData_(mask,oldsize,*Source)
*Target = AllocateMemory(Oldsize + 8)
Newsize = PackMemory(*Source,*Target,Oldsize,9)
Newfile.s = ReplaceString(File, GetExtensionPart(File),"png")
SaveImage(1, Newfile, #PB_ImagePlugin_PNG)
Rest = Newsize % 4
NomFenetre.s = Left(GetFilePart(File),Len(GetFilePart(File)) - 4)
File = ReplaceString(ReplaceString(File, GetFilePart(File), GetFilePart(File)),GetExtensionPart(File),"pbi")
If CreateFile(0, File)
WriteStringN(0,"UsePNGImageDecoder()")
WriteStringN(0,"")
WriteStringN(0,"Procedure OpenMaskedWindow_" + NomFenetre + "(WinID, x, y, Title.s, imID)")
WriteStringN(0,"")
WriteStringN(0," Hwnd" + NomFenetre + " = OpenWindow(winID, GetSystemMetrics_(#SM_CXSCREEN), y, " + Str(w) + ", " + Str(h) + ", Title, #WS_POPUP)")
WriteStringN(0," Memhandle = GlobalAlloc_(#GMEM_MOVEABLE," + Str(Oldsize + 8) + ")")
WriteStringN(0," *Mem = GlobalLock_(Memhandle)")
WriteStringN(0," UnpackMemory(?" + NomFenetre + "_Mask, *Mem)")
WriteStringN(0," Region = ExtCreateRegion_(0," + Str(Oldsize) + ", *Mem)")
WriteStringN(0," SetWindowRgn_(Hwnd" + NomFenetre + ", Region, #True)")
WriteStringN(0," Pic = CatchImage(imID,?" + NomFenetre +")")
WriteStringN(0," Brush = CreatePatternBrush_(Pic)")
WriteStringN(0," SetClassLong_(Hwnd" + NomFenetre + ", #GCL_HBRBACKGROUND, Brush)")
WriteStringN(0," ResizeWindow(WinID, x, y, #PB_Ignore, #PB_Ignore)")
WriteStringN(0," GlobalUnlock_(Memhandle)")
WriteStringN(0," GlobalFree_(Memhandle)")
WriteStringN(0," DeleteObject_(Region)")
WriteStringN(0," ProcedureReturn Hwnd" + NomFenetre)
WriteStringN(0,"")
WriteStringN(0," DataSection")
WriteStringN(0,"")
WriteStringN(0," " + Left(GetFilePart(File),Len(GetFilePart(File)) - 4)+":")
WriteStringN(0," ;***********")
WriteStringN(0,"")
WriteStringN(0," IncludeBinary " + Chr(34) + GetFilePart(Newfile) + Chr(34))
WriteStringN(0,"")
WriteStringN(0," " + Left(GetFilePart(File),Len(GetFilePart(File)) - 4) + "_Mask:")
WriteStringN(0," ;***********")
WriteStringN(0,"")
String.s = " Data.l "
For i = 0 To Newsize - 4 - Rest Step 4
String + "$" + LSet(Hex(PeekL(*Target + i)),8," ")
Count + 1
If Count = 10
Count = 0
WriteStringN(0, String)
String = " Data.l "
Else
String + ","
EndIf
Next i
If Count
String = Left(String, Len(String) - 1)
WriteStringN(0, String)
EndIf
WriteStringN(0,"")
WriteStringN(0," EndDataSection")
WriteStringN(0,"")
WriteStringN(0,"EndProcedure")
CloseFile(0)
MessageRequester("File .pbi created!","Click right to leave.",0)
Else
MessageRequester("Error!", "Can't create '"+ ReplaceString(ReplaceString(file, GetFilePart(file),"MaskWindow_" + GetFilePart(file)),GetExtensionPart(file),"pbi'"),0)
EndIf
SetWindowRgn_(hwnd, mask, #True)
;ResizeWindow(0,#PB_Ignore,#PB_Ignore,0,(screenx - w) / 2,(screeny - h) / 2, #PB_Ignore, #PB_Ignore)
;ResizeWindow(0,#PB_Ignore,#PB_Ignore,(screenx - w) / 2,(screeny - h) / 2, #PB_Ignore, #PB_Ignore)
ResizeWindow(0,#PB_Ignore,#PB_Ignore,(screenx - w) / 2,(screeny - h) / 2)
SetWindowCallback(@WindowCallback())
Repeat
Select WaitWindowEvent()
Case #WM_LBUTTONDOWN
SendMessage_(hwnd,#WM_NCLBUTTONDOWN, #HTCAPTION,0)
Case #WM_RBUTTONDOWN
Quit=1
EndSelect
Until Quit=1
DeleteObject_(mask)
EndIf
End
Code: Select all
ProcedureDLL GrabRegion(ImageID, transcolor) ; HBITMAP ImageID, COLORREF transcolor
;===============================================
; =
; Very fast bitmap -> region creator =
; By netmaestro =
; Contributors: eesau, nico, flype =
; June 26, 2007 =
; =
; *** IMPORTANT *** =
; =
; transcolor must be in BGR format =
; =
;===============================================
Structure RECTARRAY
rect.RECT[0]
EndStructure
GetObject_(ImageID, SizeOf(BITMAP), @bmp.BITMAP)
Protected width = bmp\bmWidth
Protected height = bmp\bmHeight
Protected hVisibleRgn = CreateRectRgn_(0, 0, width, height)
BmiInfo.BITMAPINFOHEADER
With BmiInfo
\biSize = SizeOf(BITMAPINFOHEADER)
\biWidth = width
\biHeight = -height
\biPlanes = 1
\biBitCount = 32
\biCompression = #BI_RGB
EndWith
rowbytes = SizeOf(LONG)*width
*ColorBits = AllocateMemory(rowbytes*height)
hDC = GetWindowDC_(#Null)
iRes = GetDIBits_(hDC, ImageID, 0, height, *ColorBits, @bmiInfo, #DIB_RGB_COLORS)
ReleaseDC_(#Null, hDC)
Structure_Max=(width*height*16)+SizeOf(RGNDATAHEADER)
*Buffer.RGNDATAHEADER=AllocateMemory(Structure_Max)
*rd.RECTARRAY=*Buffer+SizeOf(RGNDATAHEADER)
rectcount = 0
For y=0 To height-1
pxcount=0
For x=0 To rowbytes-1 Step 4
*px.LONG = *ColorBits + rowbytes * y + x
If *px\l = transcolor
transcount = 1 : firsttrans = pxcount
x+SizeOf(LONG) : *px.LONG = *ColorBits + rowbytes * y + x
While *px\l = transcolor And x <= rowbytes-1
transcount+1 : pxcount+1 : x+SizeOf(LONG)
*px = *ColorBits + rowbytes * y + x
Wend
x-SizeOf(LONG) : *px.LONG = *ColorBits + rowbytes * y + x
*rd\rect[rectcount]\left = firsttrans
*rd\rect[rectcount]\top = y
*rd\rect[rectcount]\right = firsttrans+transcount
*rd\rect[rectcount]\bottom = y+1
rectcount+1
EndIf
pxcount+1
Next
Next
With *Buffer
\dwSize = SizeOf(RGNDATAHEADER)
\iType = #RDH_RECTANGLES
\nCount = rectcount
\nRgnSize = rectcount * SizeOf(RECT)
\rcBound\left = 0
\rcBound\top = 0
\rcBound\right = width
\rcBound\bottom = height
EndWith
RegionSize=SizeOf(RGNDATAHEADER)+(rectcount * SizeOf(RECT))
hTransparentRgn = ExtCreateRegion_(0, RegionSize, *Buffer)
CombineRgn_(hVisibleRgn, hVisibleRgn, hTransparentRgn, #RGN_XOR)
FreeMemory(*Buffer)
FreeMemory(*ColorBits)
DeleteObject_(hTransparentRgn)
ProcedureReturn hVisibleRgn
EndProcedure
; Use your own image here, this is just for demo
CreateImage(0, 520,270)
StartDrawing(ImageOutput(0))
Box(0,0,520,270,RGB(255,0,255))
Ellipse(258,130,254,126,#Black)
Ellipse(255,127,254,126,RGB(255,255,223))
DrawingMode(#PB_2DDrawing_Outlined)
Ellipse(255,127,254,126,#Black)
StopDrawing()
; Simple code to use bitmap & region for skinned window
hBrush = CreatePatternBrush_(ImageID(0))
OpenWindow(0,0,0,ImageWidth(0),ImageHeight(0),"",#PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetClassLongPtr_(WindowID(0),#GCL_HBRBACKGROUND, hBrush)
SetWindowRgn_(WindowID(0), GrabRegion(ImageID(0),RGB(255,0,255)),#True)
CreatePopupMenu(0)
MenuItem(9, "Exit")
HideWindow(0,0)
quit=0
Repeat:
EventID = WaitWindowEvent()
Select EventID
Case #WM_LBUTTONDOWN
SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case #WM_RBUTTONUP
DisplayPopupMenu(0,WindowID(0))
Case #PB_Event_CloseWindow
quit=1
Case #PB_Event_Menu
If EventMenu()=9 : quit=1 : EndIf
EndSelect
Until quit
DeleteObject_(hBrush)


Code: Select all
HideWindow(0, #False)