How to draw transparent IMAGE to Window?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Justin.

Here is a way to draw a bitmap of any size with a transparent color, it should work drawing over bitmaps or patterns.

Code: Select all

;Draw bitmap setting a transparent color
;Ref : [url]http://msdn.microsoft.com/library/en-us/shellcc/platform/commctls/imagelist/reflist.asp[/url]

;this example draws a 200x200 256 colors bitmap at 0,0 coord in the window
;black (0,0,0) is set as the transparent color
;change the includebinary with your own bitmap (200x200 256 color)

;Justin 02/03

;structure
ptst.PAINTSTRUCT

global ptst,himglist

;CREATE IMAGE LIST 
;200x200 imglist 256 colors, 1 img
;transparent=black 
hbimglist=CatchImage(0,?limglist)
himglist=ImageList_Create_(200,200,#ILC_COLOR8|#ILC_MASK,1,0)
ImageList_AddMasked_(himglist,hbimglist,rgb(0,0,0)) ;set transparent color

;window procedure
procedure windowproc(hwnd,msg,wparam,lparam)
  retval=#PB_ProcessPureBasicEvents 
  select msg
    case #WM_PAINT ;DRAW IMAGE
      hdc=beginpaint_(hwnd,@ptst)
      ImageList_Draw_(himglist,0,hdc,0,0,#ILD_TRANSPARENT) 
      endpaint_(hwnd,@ptst)
      retval=0
  
  endselect
  procedurereturn retval
endprocedure

;WINDOW
OpenWindow(0,150,70,552,352,#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar,"Window1")

SetWindowCallback(@windowproc()) 

;EVENT LOOP
Repeat
until WaitWindowEvent()=#PB_EventCloseWindow

;free imglist
ImageList_Destroy_(himglist)
end
limglist : includebinary "yourimage.bmp"

BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Oh... nice to hear.. still looking forward for a more stable (fixed) version of PB.

greetz
MrVainSCL! aka Thorsten

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

?

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

Maybe he mean the Debugger. On my System is the problem, that when the debugger found a error the debugger nearly 100% crash.

After some of this crashes, my system will run out of memory and a shutdown is impossible.

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tranquil.

You are on the right way @GPI.

I never use the debugger couse it does not make sense! it crashes anyway without warning.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound
System 2: Mobile Pentium 4 2.4GHz 512 MB DDR GeForce4 420-32, Windows XP Home
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

@Fred:
GPI and tranquil exactly said what i mean! But just take a look to the closed topic and you will know something more about what i mean.

greetz
MrVainSCL! aka Thorsten

PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX9.0, SB AWE64, Win2000 + all Updates...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by searhin.

I never got any of these debugger crashes and i use the debugger quite often (but, admittedly, primarily not for debugging but for an easy way to quit my programs while testing). On my system PB is absolutely stable
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by GPI.

@tranquil
When the debugger crash: Show in the Statusbar of the debugger: there stands on which line the debugger crashed and why.

PII 333, 256MB, Asus TNT2Ultra 32MB, AWE Gold 64 4MB
Post Reply