How to Window and Gadget BackColor & FrontColor use RGBA()

Just starting out? Need help? Post your questions and find answers here.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

How to Window and Gadget BackColor & FrontColor use RGBA()

Post by gurj »

How to Window and Gadget BackColor & FrontColor use RGBA()
for through Window and suspend Gadget
that will is nice ! thanks.
my pb for chinese:
http://ataorj.ys168.com
User avatar
TI-994A
Addict
Addict
Posts: 2704
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by TI-994A »

gurj wrote:...Window and Gadget BackColor & FrontColor use RGBA() ... through Window and suspend Gadget
Something like this (Windows only):

Code: Select all

;*****************************************************************
; this portion of the code downloads a PNG image from 
; DropBox and requires PureBasic v.5.4 minimum in order 
; for the ReceiveHTTPFile() function to work properly.

InitNetwork()
UsePNGImageDecoder()
bgFile.s = GetTemporaryDirectory() + "donald.png"
If FileSize(bgFile) < 1
  ReceiveHTTPFile("https://www.dropbox.com/s/" + 
                  "yt0gc8de39hmupo/donaldMove.png?dl=1", bgFile)
EndIf
donald = LoadImage(#PB_Any, bgFile)

;*****************************************************************

Procedure WndProc(win, msg, wParam, lParam)
  Shared mainWindow
  Protected result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_LBUTTONDOWN 
      SendMessage_(WindowID(mainWindow), #WM_NCLBUTTONDOWN, #HTCAPTION, 0) 
  EndSelect 
  ProcedureReturn result
EndProcedure

Procedure makeInvisible(win)
  SetWindowLongPtr_(WindowID(win), #GWL_EXSTYLE, 
                    GetWindowLongPtr_(WindowID(win), #GWL_EXSTYLE) | #WS_EX_LAYERED) 
  SetLayeredWindowAttributes_(WindowID(win), $6f6f6f, 0, #LWA_COLORKEY) 
  SetWindowColor(win, $6f6f6f) 
EndProcedure

If donald
  wFlags = #PB_Window_ScreenCentered | #PB_Window_BorderLess
  mainWindow = OpenWindow(#PB_Any, 0, 0, 550, 550, "", wFlags)
  bgImage = ImageGadget(#PB_Any, 0, 0, 0, 0, ImageID(donald)) 
  closeBtn = ButtonGadget(#PB_Any, 520, 0, 30, 30, "X") 
  txtInput = StringGadget(#PB_Any, 350, 300, 200, 30, "")
  submitBtn = ButtonGadget(#PB_Any, 350, 350, 200, 30, "SUBMIT") 
  DisableGadget(bgImage, #True)
  SetWindowCallback(@WndProc())
  makeInvisible(mainWindow)
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case closeBtn
            appQuit = 1
          Case submitBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(txtInput) + #DQUOTE$)
        EndSelect
    EndSelect
  Until appQuit = 1 
Else
  MessageRequester("Invisible Window", "Background image not found.")
EndIf
Hope it helps. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

Thanks TI-994A very much!
This code is nice in pb5.43,bad in pb5.51,code:

Code: Select all

; Thanks TI-994A very much!
; This code is nice in pb5.43,bad in pb5.51,code:
Procedure makeInvisible(win)
 SetWindowColor(win, $6f6f6f) 
 win=WindowID(win)
 SetWindowLongPtr_(win, #GWL_EXSTYLE,GetWindowLongPtr_(win, #GWL_EXSTYLE) | #WS_EX_LAYERED) 
 SetLayeredWindowAttributes_(win, $6f6f6f, 0, #LWA_COLORKEY) 
EndProcedure
Procedure lineG(Image,Gadget,x1,y1,x2,y2,lineWidth)
 xx=Abs(x1-x2):yy=Abs(y1-y2):zz.f=Sqr(xx*xx+yy*yy)
 z_.f=lineWidth/zz:zy.f=z_*yy:zx.f=z_*xx:zy2.f=zy/2:zx2.f=zx/2
 Width=xx+zy:Height=yy+zx
 If CreateImage(Image,Width,Height,32,$ffffffff) And
    StartVectorDrawing(ImageVectorOutput(Image))
  x_=zy2:x1_=Width-zy2:If (x1-x2)*(y1-y2)>-1
   ;[(x1-x2)*(y1-y2)>-1] == [(x1<x2 And y1<y2) Or (x1>=x2 And y1>=y2)]
   y_=zx2:y1_=Height-zx2:Else:y_=Height-zx2:y1_=zx2:EndIf
  MovePathCursor(x_,y_):AddPathLine(x1_,y1_,#PB_Path_Default)
  VectorSourceColor($ff0000ff):StrokePath(lineWidth)
 StopVectorDrawing():EndIf
 If x1>x2:a=x2:Else:a=x1:EndIf:If y1>y2:b=y2:Else:b=y1:EndIf
 ImageGadget(Gadget,a-zy2,b-zx2,Width,Height,ImageID(Image))
EndProcedure
win0=OpenWindow(0, 0, 0, 550, 550, "Move/drag Image", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
TextGadget(99,20,50,400,25,"DragDrop Gadget 1(line) or 2(Point) or 3(Point)")
TitleBarHeight=GetSystemMetrics_(#SM_CYCAPTION)
rex=WindowX(0):rey=WindowY(0)+TitleBarHeight
wFlags = #PB_Window_BorderLess

win1=OpenWindow(1, rex, rey, 550, 550, "", wFlags,WindowID(0))
gx0=128:gy0=28:gx_=28:gy_=28:lineWidth=10
lineG(0,1,gx0,gy0,gx_,gy_,lineWidth)

win2=OpenWindow(2, rex, rey, 550, 550, "", wFlags,WindowID(0))
If  CreateImage(1,16,16,32,$ffffffff)
 If StartVectorDrawing(ImageVectorOutput(1))
  AddPathCircle(8, 8,8)
  VectorSourceColor(RGBA(0, 0, 0, 255))
  FillPath()
  StopVectorDrawing()
 EndIf
 ImageGadget(2,  20, 20,16,16,ImageID(1))
 ImageGadget(3,120,20,16,16,ImageID(1))
ImageGadget(4,80,20,16,16,ImageID(1)):EndIf
DisableGadget(4,1)

makeInvisible(1)
makeInvisible(2)
;SetWindowPos_(WindowID(1),#HWND_BOTTOM,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
;SetWindowPos_(WindowID(2),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
StickyWindow(2,1)
;*****************************
;DragDrop Gadget 1(line) or 2(Point) or 3(Point)
;*****************************
Repeat:fw=GetForegroundWindow_():If fw=win0 Or fw=win1 Or fw=win2
  SetWindowState(2,#PB_Window_Normal)
  Else:SetWindowState(0,#PB_Window_Minimize):EndIf;for hide WindowID(2),#HWND_TOPMOST
 Select WaitWindowEvent()
  Case #PB_Event_Gadget
   If GetAsyncKeyState_(#VK_LBUTTON):eg=EventGadget():EndIf
  Case #WM_LBUTTONUP:jx=0:eg=-1
  Case #WM_MOUSEMOVE
   If eg>0:If jx=1
     x01=WindowMouseX(1):y01=WindowMouseY(1)
     If x00<>x01 Or y00<>y01
      x00=x01:y00=y01:x=x01-x0:y=y01-y0
      gx_=gx+x:gy_=gy+y:If eg>1:UseGadgetList( WindowID(1));SetActiveWindow(1)
       lineG(0,1,gx0+8,gy0+8,gx_+8,gy_+8,lineWidth)        ;Gosub lin
      Else:ResizeGadget(1,gx1+x,gy1+y,#PB_Ignore,#PB_Ignore)
      ResizeGadget(3,gx0+x,gy0+y,#PB_Ignore,#PB_Ignore):EndIf
      If eg=1:ResizeGadget(2,gx+x,gy+y,#PB_Ignore,#PB_Ignore)
       Else:ResizeGadget(eg,gx_,gy_,#PB_Ignore,#PB_Ignore):EndIf:EndIf
     Else:jx=1:Gosub cs:EndIf:EndIf
   Case #PB_Event_MoveWindow:If EventWindow()=0
    rex=WindowX(0):rey=WindowY(0)+TitleBarHeight
    ResizeWindow(1, rex, rey,#PB_Ignore,#PB_Ignore)
   ResizeWindow(2, rex, rey,#PB_Ignore,#PB_Ignore):EndIf
  Case #PB_Event_CloseWindow:appQuit = 1
 EndSelect
Until appQuit = 1 

End
cs: :x0=WindowMouseX(1):y0=WindowMouseY(1)
If eg=1:gx1=GadgetX(1):gy1=GadgetY(1)
 gx=GadgetX(2):gy=GadgetY(2)
 gx0=GadgetX(3):gy0=GadgetY(3)
Else:gx=GadgetX(eg):gy=GadgetY(eg)
gx0=GadgetX(5-eg):gy0=GadgetY(5-eg):EndIf
Return
Last edited by gurj on Thu Jan 12, 2017 10:00 am, edited 1 time in total.
my pb for chinese:
http://ataorj.ys168.com
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by netmaestro »

@TI-994A: I was skimming this and almost moved on until this caught my eye:
bgFile.s = GetTemporaryDirectory() + "donald.png"
And I guess I'm on the bandwagon with the crazed millions and so I couldn't resist it.

Then you deflated me with a duck. Ack. :evil:
BERESHEIT
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

How to use makeInvisible(win) to makeInvisible(Gadget) for
ScrollAreaGadget() and ContainerGadget() ?
Thanks TI-994A again !
Last edited by gurj on Thu Jan 12, 2017 9:54 am, edited 1 time in total.
my pb for chinese:
http://ataorj.ys168.com
User avatar
TI-994A
Addict
Addict
Posts: 2704
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by TI-994A »

gurj wrote:How to use makeInvisible(win) to makeInvisible(Gadget) for ScrollAreaGadget() and ContainerGadget() ?
A modified version to handle container-type gadgets as well:

Code: Select all

;*****************************************************************
; this portion of the code downloads a PNG image from 
; DropBox and requires PureBasic v.5.4 minimum in order 
; for the ReceiveHTTPFile() function to work properly.

InitNetwork()
UsePNGImageDecoder()
bgFile.s = GetTemporaryDirectory() + "donald.png"
If FileSize(bgFile) < 1
  ReceiveHTTPFile("https://www.dropbox.com/s/" + 
                  "yt0gc8de39hmupo/donaldMove.png?dl=1", bgFile)
EndIf
donald = LoadImage(#PB_Any, bgFile)

;*****************************************************************

Procedure WndProc(win, msg, wParam, lParam)
  Shared mainWindow
  Protected result = #PB_ProcessPureBasicEvents
  Select msg
    Case #WM_LBUTTONDOWN 
      SendMessage_(WindowID(mainWindow),#WM_NCLBUTTONDOWN,#HTCAPTION,0) 
  EndSelect 
  ProcedureReturn result
EndProcedure

Procedure makeInvisible(id, gadget = 0)
  If gadget
    SetGadgetColor(id, #PB_Gadget_BackColor, $6f6f6f) 
    id = GadgetID(id)
  Else
    SetWindowColor(id, $6f6f6f) 
    id = WindowID(id)
  EndIf
  SetWindowLongPtr_(id, #GWL_EXSTYLE, 
                    GetWindowLongPtr_(id, #GWL_EXSTYLE) | #WS_EX_LAYERED) 
  SetLayeredWindowAttributes_(id, $6f6f6f, 0, #LWA_COLORKEY) 
EndProcedure

If donald
  wFlags = #PB_Window_ScreenCentered | #PB_Window_BorderLess
  mainWindow = OpenWindow(#PB_Any, 0, 0, 550, 550, "", wFlags)
  makeInvisible(mainWindow)
  
  bgImage = ImageGadget(#PB_Any, 0, 0, 0, 0, ImageID(donald)) 
  closeBtn = ButtonGadget(#PB_Any, 520, 0, 30, 30, "X") 
  txtInput = StringGadget(#PB_Any, 350, 480, 200, 30, "")
  submitBtn = ButtonGadget(#PB_Any, 350, 520, 200, 30, "SUBMIT") 
  DisableGadget(bgImage, #True)
  SetWindowCallback(@WndProc())
  
  container = ContainerGadget(#PB_Any, 30, 30, 200, 100)
  containerTxt = StringGadget(#PB_Any, 0, 0, 200, 30, "")
  containerBtn = ButtonGadget(#PB_Any, 0, 40, 200, 30, 
                              "I'm in the container!")
  makeInvisible(container, 1)
  CloseGadgetList()
  
  scrollGadget = ScrollAreaGadget(#PB_Any, 350, 180, 200, 280, 400, 600)
  scrollTxt = StringGadget(#PB_Any, 10, 20, 160, 30, "")
  scrollBtn = ButtonGadget(#PB_Any, 10, 60, 160, 30, 
                              "I'm in the scroll area!")  
  makeInvisible(scrollGadget, 1)
  CloseGadgetList()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case closeBtn
            appQuit = 1
          Case submitBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(txtInput) + #DQUOTE$)            
          Case containerBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(containerTxt) + #DQUOTE$)
          Case scrollBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(scrollTxt) + #DQUOTE$)            
        EndSelect
    EndSelect
  Until appQuit = 1 
Else
  MessageRequester("Invisible Window", "Background image not found.")
EndIf
And, it's not Addict... it's TI-994A. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
TI-994A
Addict
Addict
Posts: 2704
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by TI-994A »

netmaestro wrote:Then you deflated me with a duck. Ack. :evil:
He'll always be The Real Donald! :lol:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

Thanks TI-994A again ! You are great !
i use :

Code: Select all

;InitNetwork()
UsePNGImageDecoder()
; bgFile.s = GetTemporaryDirectory() + "donald.png"
; If FileSize(bgFile) < 1
;   ReceiveHTTPFile("https://www.dropbox.com/s/" + 
;                   "yt0gc8de39hmupo/donaldMove.png?dl=1", bgFile)
;  EndIf
bgFile.s = "D:\exe1\PureB\PureBasic\Examples\Sources\Data\CdPlayer.png"
;i make CdPlayer.png is transparent
donald = LoadImage(#PB_Any, bgFile)
my pb for chinese:
http://ataorj.ys168.com
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by netmaestro »

He'll always be The Real Donald!
Fair enough. Probably more qualified too. Let's try to run him in four years!
BERESHEIT
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

Thanks TI-994A again !

makeInvisible(Gadget) for ScrollAreaGadget() and ContainerGadget()
must first their parent window makeInvisible(win)

makeInvisible(mainWindow),then:
makeInvisible(container, 1)
makeInvisible(scrollGadget, 1)
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

so makeInvisible(Gadget) isn't true work.
not must makeInvisible(Gadget), must makeInvisible(win)
and must use appoint transparentColor
and must SetGadgetColor(Gadget, #PB_Gadget_BackColor, color)
ok:

Code: Select all

;from TI-994A

transparentColor=#Green;for Gadget
Procedure makeInvisible(win,transparentColor__=#Green);user may change Default Color
 SetWindowColor(win,transparentColor__) 
 win=WindowID(win)
 SetWindowLongPtr_(win, #GWL_EXSTYLE,GetWindowLongPtr_(win, #GWL_EXSTYLE) | #WS_EX_LAYERED) 
 SetLayeredWindowAttributes_(win, transparentColor__, 0, #LWA_COLORKEY) 
EndProcedure

wFlags = #PB_Window_ScreenCentered | #PB_Window_BorderLess
mainWindow = OpenWindow(#PB_Any, 0, 0, 560, 550, "", wFlags)
;******************
;try:
  makeInvisible(mainWindow)
  SetWindowColor(mainWindow, #Red);try delete the line
;******************
  ;bgImage = ImageGadget(#PB_Any, 0, 0, 0, 0, ImageID(donald)) 
  ;DisableGadget(bgImage, #True)
  closeBtn = ButtonGadget(#PB_Any, 520, 0, 30, 30, "X") 
  StringG = StringGadget(#PB_Any, 200, 200, 140, 30, "String in the ...")
  txtInput = StringGadget(#PB_Any, 250, 250, 200, 30, "String in the ...")
  SetGadgetColor(txtInput, #PB_Gadget_FrontColor, $000099)
  SetGadgetColor(txtInput, #PB_Gadget_BackColor, transparentColor)
  submitBtn = ButtonGadget(#PB_Any, 250, 300, 200, 30, "SUBMIT") 
  
; Procedure WndProc(win, msg, wParam, lParam);Move/drag Window
;   Shared mainWindow
;   Protected result = #PB_ProcessPureBasicEvents
;   Select msg
;     Case #WM_LBUTTONDOWN 
;       SendMessage_(WindowID(mainWindow),#WM_NCLBUTTONDOWN,#HTCAPTION,0) 
;   EndSelect 
;   ProcedureReturn result
; EndProcedure
;   SetWindowCallback(@WndProc())
  
  container = ContainerGadget(#PB_Any, 30, 30, 200, 100)
  containerTxt = StringGadget(#PB_Any, 20, 20, 140, 30, "String in the ...")
  containerBtn = ButtonGadget(#PB_Any, 20, 60, 140, 30, "I'm in the container!")
  SetGadgetColor(container, #PB_Gadget_BackColor, transparentColor)
  CloseGadgetList()
  
  scrollGadget = ScrollAreaGadget(#PB_Any, 350, 180, 200, 280, 400, 600)
  scrollTxt = StringGadget(#PB_Any, 10, 20, 160, 30, "String in the ...")
  scrollBtn = ButtonGadget(#PB_Any, 10, 60, 160, 30,"I'm in the scroll area!") 
  SetGadgetColor(scrollGadget, #PB_Gadget_BackColor, transparentColor)
  CloseGadgetList()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case closeBtn
            appQuit = 1
          Case submitBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(txtInput) + #DQUOTE$)            
          Case containerBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(containerTxt) + #DQUOTE$)
          Case scrollBtn
            MessageRequester("Invisible Window", 
                             "You entered, " + #DQUOTE$ + 
                             GetGadgetText(scrollTxt) + #DQUOTE$)            
        EndSelect
    EndSelect
  Until appQuit = 1 
my pb for chinese:
http://ataorj.ys168.com
User avatar
TI-994A
Addict
Addict
Posts: 2704
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by TI-994A »

gurj wrote:so makeInvisible(Gadget) isn't true work.
not must makeInvisible(Gadget), must makeInvisible(win)
and must use appoint transparentColor
and must SetGadgetColor(Gadget, #PB_Gadget_BackColor, color)

There is no true way of making a window transparent. The only available method is to make the window background colour transparent (LWA_COLORKEY). The level of transparency could also be controlled by using the LWA_ALPHA directive.

Code: Select all

;transparencyLevel from 0 (fully transparent) to 255 (fully opaque)
SetLayeredWindowAttributes_(WindowID(win), color, transparencyLevel, #LWA_ALPHA)
So, if the background is reset to another colour, that colour would be visible.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

Thanks TI-994A again !
I always study your codes,have:
SetLayeredWindowAttributes_(WindowID(win), color, transparencyLevel, #LWA_ALPHA)
this transparent Back_ and Front_ concurrent.
I more love your that makeInvisible(win) !
Thanks TI-994A again ! New year happy !
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

Code: Select all

Procedure WinTransparentColor(Win,TransparentColor=#Green);user may change Default Color
 SetWindowColor(Win,TransparentColor) 
  Win=WindowID(Win)
 SetWindowLongPtr_(Win, #GWL_EXSTYLE,$00080000)
 SetLayeredWindowAttributes_(Win,TransparentColor, 0, #LWA_COLORKEY);#LWA_COLORKEY=1
EndProcedure;if (BackColor of Gadget of Win) is also TransparentColor,then Gadget Transparent
Procedure WinTransparentLevel(Win,TransparentLevel=127)
;user may change Default Level 0 (fully transparent) To 255 (fully opaque)
  Win=WindowID(Win)
 SetWindowLongPtr_(Win, #GWL_EXSTYLE,$00080000)
 SetLayeredWindowAttributes_(Win, 0,TransparentLevel, #LWA_ALPHA);#LWA_ALPHA=2
EndProcedure

;**************
;not recommend:
Procedure WinTransparent(Win,TransparentColor=#Green,TransparentLevel=127)
 ;if TransparentLevel=255,=WinTransparentColor()
 SetWindowColor(Win,TransparentColor)
  Win=WindowID(Win)
 SetWindowLongPtr_(Win, #GWL_EXSTYLE,$00080000)
 SetLayeredWindowAttributes_(Win, TransparentColor,TransparentLevel, 3);3=#LWA_COLORKEY|#LWA_ALPHA
EndProcedure
Last edited by gurj on Sat Jan 14, 2017 12:15 am, edited 1 time in total.
my pb for chinese:
http://ataorj.ys168.com
User avatar
gurj
Enthusiast
Enthusiast
Posts: 693
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

Re: How to Window and Gadget BackColor & FrontColor use RGBA

Post by gurj »

WinBackColorRGBA():

Code: Select all

Procedure WinTransparentColor(Win,TransparentColor=#Green)
 SetWindowColor(Win,TransparentColor) 
 Win=WindowID(Win)
 SetWindowLongPtr_(Win, #GWL_EXSTYLE,$00080000)
 SetLayeredWindowAttributes_(Win,TransparentColor, 0, #LWA_COLORKEY);#LWA_COLORKEY=1
EndProcedure
Procedure WinTransparent(Win,TransparentColor=#Green,TransparentLevel=127)
 ;if TransparentLevel=255,=WinTransparentColor()
 SetWindowColor(Win,TransparentColor)
 Win=WindowID(Win)
 SetWindowLongPtr_(Win, #GWL_EXSTYLE,$00080000)
 SetLayeredWindowAttributes_(Win, TransparentColor,TransparentLevel, 3);3=#LWA_COLORKEY|#LWA_ALPHA
EndProcedure
Procedure WinBackColorRGBA(RGBA,Win,TransparentColor=#Green,TransparentLevel=127)
 If CreateImage(0,500, 400, 32,$ffffffff) And
    StartVectorDrawing(ImageVectorOutput(0))
  AddPathBox(0, 0,500, 400)
  VectorSourceColor(RGBA)
  FillPath()
  StopVectorDrawing()
  UseGadgetList(WindowID(Win))
  ImageGadget(0, 0, 0, 0, 0, ImageID(0))
  DisableGadget(0,1)
 WinTransparent(Win,TransparentColor,TransparentLevel):EndIf
EndProcedure
If OpenWindow(0,0,0,500,400,"",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
 WinBackColorRGBA(RGBA(0,0,0,140),0,RGB(0,0,0),100);try change RGBA RGB
 ; SetWindowColor(0,#Red)
 ButtonGadget(1, 10, 10,200, 20, "Button 0")
 Repeat:Select WaitWindowEvent()
   Case #PB_Event_CloseWindow:Quit = 1
 EndSelect:Until Quit = 1
EndIf:End
my pb for chinese:
http://ataorj.ys168.com
Post Reply