Purebasic : Frameless Borderless Window with drop shadow

Help other Members. Share your Source Codes
Forum rules
If you share codes or scripts that you haven't developed by yourself,
then you have to mention and give some credits in your post to the original author of the code or script.
inc
Site Admin
Posts: 92
Joined: 18 Apr 2016 19:38
Has thanked: 49 times
Been thanked: 52 times
Status: Offline

Purebasic : Frameless Borderless Window with drop shadow

Postby inc » 21 Sep 2016 16:56

Another fine plain sourcecode for a borderless or call it frameless Window with a typically Drop Shadow.
I've seen that many people ask for code, so here it comes...
I have also added a simple progressbar that count to 0 and close automatically if you don't hit ESC.

To style the progressbar you need the PureColor Lib. Attached to this post.

Image

Code: Select all

;======================================================================================
;
; create a borderless or frameless window with drop shadow
;
; needed for this code to customize the progressbar: PureColor
; inc. 19.19.2016 // small fix on 29.10.2016
;
; PureBasic 5.30 x86
;
;======================================================================================
Enumeration
  #Wnd
  #LineTop
  #Gadget_LineTop
  #LineLeft
  #Gadget_LineLeft
  #LineRight
  #Gadget_LineRight
  #LineBottom
  #Gadget_LineBottom
  #Header
  #INFOTEXT
  #Frame
  #Progressbar
  #TextFooter
  #Escape
  #ESCExit
EndEnumeration
;Define startup effect
#AW_BLEND = $80000

;{ Declare 1px FRAME AROUND OUR WINDOW
;LineTop
CreateImage(#LineTop,508,1,32,RGB(0, 0, 0))
  StartDrawing(ImageOutput(#LineTop))
  StopDrawing()
;LineLeft
CreateImage(#LineLeft,1,240,32,RGB(0, 0, 0))
  StartDrawing(ImageOutput(#LineLeft))
  StopDrawing()
;LineRight
CreateImage(#LineRight,1,240,32,RGB(0, 0, 0))
  StartDrawing(ImageOutput(#LineRight))
  StopDrawing()
;LineBottom
CreateImage(#LineBottom,508,1,32,RGB(0, 0, 0))
  StartDrawing(ImageOutput(#LineBottom))
  StopDrawing()
;}


; MAIN WINDOW
Procedure OpenWnd()
  Font1 = LoadFont(#PB_Any, "Segoe UI", 11, #PB_Font_HighQuality)
  Font2 = LoadFont(#PB_Any, "Segoe UI", 10, #PB_Font_HighQuality)
  Font3 = LoadFont(#PB_Any, "Segoe UI", 9, #PB_Font_HighQuality)
 
  If OpenWindow(#Wnd, 510, 311, 510, 240, " ", #PB_Window_BorderLess|#PB_Window_ScreenCentered|#WS_VISIBLE|#PB_Window_Invisible)
     SetWindowColor(#Wnd,RGBA(128, 128, 128, 122))
     ;GIVE OUR BORDERLESS WINDOW A DROP SHADOW
      SetClassLongPtr_(WindowID(#Wnd), #GCL_STYLE, #CS_DROPSHADOW)
     ;SET OUR TOOL ALWAYS ON TOP (TOPMOST)
      SetWindowPos_(WindowID(#Wnd),#HWND_TOPMOST,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE)
   
    ;HEADER
    TextGadget(#Header, 0, 0, 510, 30, "Frameless Window with DROP SHADOW", #SS_CENTERIMAGE|#SS_CENTER)
     SetGadgetColor(#Header, #PB_Gadget_FrontColor, RGB(255, 255, 255))
     SetGadgetColor(#Header, #PB_Gadget_BackColor, RGB(40, 40, 40))
     SetGadgetFont(#Header, FontID(Font1))
     
    ;INFO TEXT
    TextGadget(#INFOTEXT, 10, 70, 490, 20, "Some text here.", #SS_CENTERIMAGE|#SS_CENTER)
     SetGadgetColor(#INFOTEXT, #PB_Gadget_FrontColor, RGB(40, 40, 40))
     SetGadgetColor(#INFOTEXT, #PB_Gadget_BackColor, RGBA(128, 128, 128, 122))
     SetGadgetFont(#INFOTEXT, FontID(Font2))
     
    ;FRAME PROGRESSBAR
    CreateImage(#Frame, 408, 17,32, RGB(24, 24, 24))
     StartDrawing(ImageOutput(#Frame))
        DrawingMode(#PB_2DDrawing_Outlined)
        Box(0, 0, 408, 17, RGB(92,146,191))
     StopDrawing()
     ImageGadget(#Frame, 49, 120, 408, 17, ImageID(#Frame))
     
     ;PROGRESSBAR
      ProgressBarGadget(#Progressbar,  50, 121, 406,  15, 0, 100)
      PureCOLOR_SetGadgetColor(#ProgressBar, RGB(24, 24, 24), #PureCOLOR_DontSetBackColor)
      PureCOLOR_SetGadgetColor(#ProgressBar, RGB(92,146,191),RGB(24, 24, 24))
      ;DEFINE PROGRESSBAR SPEED
      AddWindowTimer(0,123,500)
     
    ;ESC INFOTEXT
    TextGadget(#ESCExit, 163, 90, 180, 18, " ", #SS_CENTERIMAGE|#SS_CENTER)
     SetGadgetColor(#ESCExit, #PB_Gadget_FrontColor, RGB(40,40,40))
     SetGadgetColor(#ESCExit, #PB_Gadget_BackColor, RGBA(128, 128, 128, 122))
     SetGadgetFont(#ESCExit, FontID(Font3))
     
    ;TEXT FOOTER
    TextGadget(#TextFooter, 345, 215, 180, 25, "simple example by inc in 2016")
     SetGadgetColor(#TextFooter, #PB_Gadget_FrontColor, RGB(40,40,40))
     SetGadgetColor(#TextFooter, #PB_Gadget_BackColor, RGBA(128, 128, 128, 122))
     SetGadgetFont(#TextFooter, FontID(Font3))     
     
     ;BLACK FRAME AROUND THE TOOL
        ;LineTop
        ImageGadget(#Gadget_LineTop,1,0,508,1,ImageID(#LineTop))
        ;LineLeft
        ImageGadget(#Gadget_LineLeft,0,0,1,240,ImageID(#LineLeft))
        ;LineRight
        ImageGadget(#Gadget_LineRight,509,0,1,240,ImageID(#LineRight))
        ;LineBottom
        ImageGadget(#Gadget_LineBottom,1,239,508,1,ImageID(#LineBottom))
       
    ;Use Tool start up effect
    AnimateWindow_(WindowID(#Wnd),250,#AW_BLEND)
    HideWindow(#Wnd,#False)
  EndIf
EndProcedure

OpenWnd()

Repeat
  Event = WaitWindowEvent()
  EventGadget = EventGadget()
  EventType = EventType()
 
  Select Event
    Case #PB_Event_Gadget
     
  EndSelect
 
  ;DRAG WITH MOUSE
  Select Event
    Case #WM_LBUTTONDOWN
         If WindowMouseX(#Wnd) >= 0 And WindowMouseX(#Wnd) <= 510 And WindowMouseY(#Wnd) >= 0 And WindowMouseY(#Wnd) <= 30
            SendMessage_(WindowID(#Wnd), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
          EndIf
         
    Case #PB_Event_Timer
         Closing + 1
         SetGadgetState(#Progressbar,Closing)
         SetGadgetText(#ESCExit,"Closing in " + StrF(100-(Closing/1),1) + " Seconds or hit ESC") ; update text display
         If Closing = 100
           RemoveWindowTimer(0,123)
           End
         EndIf
  EndSelect

  ;ESC END PROGRAM
  If GetAsyncKeyState_(#VK_ESCAPE)
     End
  EndIf
ForEver
Only registered members are able to see and download attachments from Aftermath. You must LOGIN or REGISTER to view these files.

alveo

Return to “Purebasic”

Who is online

Users browsing this forum: No registered users and 1 guest

Created by Matti from StylesFactory.pl and Warlords of Draenor


443,918 Page visits

Powered by phpBB® Forum Software © phpBB Limited