It is currently Tue Jan 26, 2021 10:37 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Enable \ Disable Gadgets in a Fancy way [Windows]
PostPosted: Mon Oct 05, 2009 5:34 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3843
x86 ; x64
PB x86 ;x 64 v4.31

Code:
Global desktop.RECT,wr.RECT,W,H,FrT,hWnd_1,hWnd_2,GiD,Op,FiC,NMsg$,T2S,Quit,Thread

Procedure RoundedBox(X, Y, W, H, R,FrT,FrC,FiC)
  ;X = Starting x position - Y = Starting y pos. - W = Button Width - H = Button Height - FrT = Frame Thickness - FrC = Frame Color - FiC = Fill Color 
  Box(X,Y,W,H,GetWindowColor(0))              ;Windows background color in case of Image output
  Circle(X+R,Y+R, R,FrC)
  Circle(X+R,Y+R, R-FrT,FiC) 
  Circle(X+W-R,Y+R,R,FrC)
  Circle(X+W-R,Y+R,R-FrT,FiC)
  Circle(X+R,Y+H-R,R,FrC)
  Circle(X+R,Y+H-R,R-FrT,FiC)
  Circle(X+W-R,Y+H-R,R,FrC)
  Circle(X+W-R,Y+H-R,R-FrT,FiC)
  Box(X+R,Y,W-2*R,H,FrC)
  Box(X+R,Y+FrT,W-2*R,H-2*FrT,FiC)
  Box(X,Y+R,W,H-2*R,FrC)
  Box(X+FrT,Y+R,W-2*FrT,H-2*R,FiC) 
EndProcedure

Procedure DisGadget(GiD,Op,FiC)
    ;GiD = GadgetID -  Op = Opacity Degree - FiC = Filter Color
    GetWindowRect_(GadgetID(GiD), wr.RECT)
    hWnd_2 = OpenWindow(5,wr\left ,wr\top, W+2*FrT,H+2*FrT,"test",#WS_POPUP,hWnd_1)
    SetWindowColor(5,FiC)
    SetWindowLongPtr_(hWnd_2,#GWL_EXSTYLE,#WS_EX_LAYERED)
    SetLayeredWindowAttributes_(hWnd_2,0,Op,#LWA_ALPHA)   
EndProcedure

Procedure NotifyMsg(*Parameter)
  desktop.RECT
  OpenWindow(1,(desktop\right-120),(desktop\bottom-20),100,20,"",#PB_Window_BorderLess)
  TextGadget(10,0,0,100,20,NMsg$,#SS_CENTERIMAGE | #SS_CENTER| #WS_BORDER)
  SetGadgetColor(10,#PB_Gadget_BackColor,$BCFFFF)
  SetGadgetColor(10,#PB_Gadget_FrontColor,$0102FE)
  SetGadgetFont(10, #PB_Default) 
  Repeat
    Delay(T2S)
    CloseWindow(1)   
    KillThread(Thread)
    quit = 1
 Until quit = 1
EndProcedure

X = 50
Y = 45
W = 100
H = 40
If H > W
  Swap H,W
EndIf
R = 12             ; radius
a$ = "Hello !!!"
FiC=$01FFFE        ;Fill Color
FrC=$FD0202        ;Frame Color
FrT=4              ;Frame Thickness
If H < 3*R
  R = H/3
EndIf

NMsg$="Test To Go"                         ;Message
T2S=8000                                   ;Time for message to stay
quit=0

SystemParametersInfo_(#SPI_GETWORKAREA, 0, @desktop.RECT, 0)

hWnd_1 = OpenWindow(0,0,0,640,480,"Enable \ Disable Gadgets",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

    SetWindowColor(0,$B5D4E6)   
      CreateImage(0,W,H)
    StartDrawing(ImageOutput(0))
      RoundedBox(0,0,W,H,R,FrT,FrC,FiC)
      DrawingMode(#PB_2DDrawing_Transparent)
      ;Draw Text need more care (Get text length in pixels and calculate the position exact)
      DrawText((W-TextWidth(a$))/2,(H-TextHeight(a$))/2,a$,$FD0202)
    StopDrawing()   
    ButtonImageGadget(0, 20, 20, W+2*FrT,H+2*FrT, ImageID(0))
    ButtonGadget(1,20,440,80,25,"Dis\En",#PB_Button_Toggle)

Repeat
SetActiveWindow(0)
Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Thread = CreateThread(@NotifyMsg(),23)
           
          Case 1
            Flag = Flag!1
            If Flag = 1
            DisGadget(0,150,$FFFFFF)
            Else
            CloseWindow(5)
            EndIf
           
        EndSelect
      Case #PB_Event_CloseWindow
        Quit = 2
    EndSelect
  Until Quit = 2
End


Have fun

_________________
Egypt my love


Top
 Profile  
Reply with quote  
 Post subject: Re: Enable \ Disable Gadgets in a Fancy way [Windows]
PostPosted: Mon Oct 05, 2009 11:36 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 1032
Location: Canada
Disable the button and then move the window, you will leave behind the grayed out area and be able to press the button again.
Eventually the code crashes on line 38 with "the specified #Window is not initialized"

_________________
Image Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Enable \ Disable Gadgets in a Fancy way [Windows]
PostPosted: Tue Oct 06, 2009 1:03 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3843
@Paul Hi
Yes I know that and I left it to the fellow programmer to handle using windows callback() or any other way he like
For resizing and moving if he liked the idea
I remember Fluid Byte talking @ you that you are expert in DirectX and Media staff
I am glad you are back

usually I do not post a final solution I want the others to have full choice

_________________
Egypt my love


Last edited by RASHAD on Tue Oct 06, 2009 1:45 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Enable \ Disable Gadgets in a Fancy way [Windows]
PostPosted: Tue Oct 06, 2009 1:27 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3843
Updated as fast as I can

Code:
Global desktop.RECT,wr.RECT,W,H,FrT,hWnd_1,hWnd_2,GiD,Op,FiC,NMsg$,T2S,Quit,Thread

Procedure RoundedBox(X, Y, W, H, R,FrT,FrC,FiC)
  ;X = Starting x position - Y = Starting y pos. - W = Button Width - H = Button Height - FrT = Frame Thickness - FrC = Frame Color - FiC = Fill Color 
  Box(X,Y,W,H,GetWindowColor(0))              ;Windows background color in case of Image output
  Circle(X+R,Y+R, R,FrC)
  Circle(X+R,Y+R, R-FrT,FiC) 
  Circle(X+W-R,Y+R,R,FrC)
  Circle(X+W-R,Y+R,R-FrT,FiC)
  Circle(X+R,Y+H-R,R,FrC)
  Circle(X+R,Y+H-R,R-FrT,FiC)
  Circle(X+W-R,Y+H-R,R,FrC)
  Circle(X+W-R,Y+H-R,R-FrT,FiC)
  Box(X+R,Y,W-2*R,H,FrC)
  Box(X+R,Y+FrT,W-2*R,H-2*FrT,FiC)
  Box(X,Y+R,W,H-2*R,FrC)
  Box(X+FrT,Y+R,W-2*FrT,H-2*R,FiC) 
EndProcedure

Procedure DisGadget(GiD,Op,FiC)
    ;GiD = GadgetID -  Op = Opacity Degree - FiC = Filter Color
    GetWindowRect_(GadgetID(GiD), wr.RECT)
    hWnd_2 = OpenWindow(5,wr\left ,wr\top, W+2*FrT,H+2*FrT,"test",#WS_POPUP,hWnd_1)
    SetWindowColor(5,FiC)
    SetWindowLongPtr_(hWnd_2,#GWL_EXSTYLE,#WS_EX_LAYERED)
    SetLayeredWindowAttributes_(hWnd_2,0,Op,#LWA_ALPHA)   
EndProcedure

Procedure NotifyMsg(*Parameter)
  desktop.RECT
  OpenWindow(1,(desktop\right-120),(desktop\bottom-20),100,20,"",#PB_Window_BorderLess)
  TextGadget(10,0,0,100,20,NMsg$,#SS_CENTERIMAGE | #SS_CENTER| #WS_BORDER)
  SetGadgetColor(10,#PB_Gadget_BackColor,$BCFFFF)
  SetGadgetColor(10,#PB_Gadget_FrontColor,$0102FE)
  SetGadgetFont(10, #PB_Default) 
  Repeat
    Delay(T2S)
    CloseWindow(1)   
    KillThread(Thread)
    quit = 1
 Until quit = 1
EndProcedure

Procedure WndProc(hwnd, uMsg, wParam, lParam)
        If IsGadget(0)
        GetWindowRect_(GadgetID(0), wr.RECT)
        EndIf
        result = #PB_ProcessPureBasicEvents
       
        Select uMsg
               
        Case #WM_SIZE,#WM_MOVE,#WM_PAINT
             If IsWindow(5)
             MoveWindow_(WindowID(5),wr\left ,wr\top, W+2*FrT,H+2*FrT,1)
             EndIf         
   EndSelect
   
  ProcedureReturn result
EndProcedure

X = 50
Y = 45
W = 100
H = 40
If H > W
  Swap H,W
EndIf
R = 12             ; radius
a$ = "Hello !!!"
FiC=$01FFFE        ;Fill Color
FrC=$FD0202        ;Frame Color
FrT=4              ;Frame Thickness
If H < 3*R
  R = H/3
EndIf

NMsg$="Test To Go"                         ;Message
T2S=8000                                   ;Time for message to stay
quit=0

SystemParametersInfo_(#SPI_GETWORKAREA, 0, @desktop.RECT, 0)

hWnd_1 = OpenWindow(0,0,0,640,480,"Enable \ Disable Gadgets",#PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)

    SetWindowColor(0,$B5D4E6)   
      CreateImage(0,W,H)
    StartDrawing(ImageOutput(0))
      RoundedBox(0,0,W,H,R,FrT,FrC,FiC)
      DrawingMode(#PB_2DDrawing_Transparent)
      ;Draw Text need more care (Get text length in pixels and calculate the position exact)
      DrawText((W-TextWidth(a$))/2,(H-TextHeight(a$))/2,a$,$FD0202)
    StopDrawing()   
    ButtonImageGadget(0, 20, 20, W+2*FrT,H+2*FrT, ImageID(0))
    ButtonGadget(1,20,440,80,25,"Dis\En",#PB_Button_Toggle)
    SetWindowCallback(@WndProc())   

Repeat
SetActiveWindow(0)
Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 0
            Thread = CreateThread(@NotifyMsg(),23)
           
          Case 1
            Flag = Flag!1
            If Flag = 1
            DisGadget(0,150,$FFFFFF)
            Else
            CloseWindow(5)
            EndIf
           
        EndSelect
      Case #PB_Event_CloseWindow
        Quit = 2
    EndSelect
  Until Quit = 2
End


have fun

_________________
Egypt my love


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 22 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye