Purebasic : Frameless Borderless Window with normal 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: 91
Joined: 18 Apr 2016 19:38
Has thanked: 44 times
Been thanked: 51 times
Status: Offline

Purebasic : Frameless Borderless Window with normal shadow

Postby inc » 29 Oct 2016 16:24

Another fine plain sourcecode for a borderless or call it frameless Window with a typically windows 7 style 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 normal windows 7 styled shadow
;
; needed for this code to customize the progressbar: PureColor
; inc. 29.19.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

Import ""
   GetProcAddress(hMod, Name.p-ascii)
EndImport

#DWMWA_NCRENDERING_POLICY = 2
#DWMNCRP_ENABLED = 2

Structure Margin
   cxLeftWidth.l
   cxRightWidth.l
   cyTopHeight.l
   cyBottomHeight.l
EndStructure

Procedure DwmSetWindowAttribute(hWnd, attr, attrValue)
   Static hMod
   Static Func
     
   Protected Value.integer\i = attrValue
   
   If Not hMod And Not Func
      hMod = GetModuleHandle_("dwmapi")
      Func = GetProcAddress(hMod, "DwmSetWindowAttribute")
   EndIf
   
   If Func
      ProcedureReturn CallFunctionFast(Func, hWnd, attr, Value, SizeOf(Value))
   EndIf
   
   ProcedureReturn -1
EndProcedure


Procedure DwmExtendFrameIntoClientArea(hWnd, Top, Left, Right, Bottom)
   Static hMod
   Static Func
   
   Protected Margin.Margin   

   Margin\cxLeftWidth = Left   
   Margin\cxRightWidth = Right
   Margin\cyTopHeight = Top
   Margin\cyBottomHeight = Bottom
   
   If Not hMod And Not Func
      hMod = GetModuleHandle_("dwmapi")
      Func = GetProcAddress(hMod, "DwmExtendFrameIntoClientArea")
   EndIf
   
   If Func
      ProcedureReturn CallFunctionFast(Func, hWnd, Margin)
   EndIf   
   
   ProcedureReturn -1
EndProcedure

;{ 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()
  Protected Window.i
 
  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)
 
  Window =  OpenWindow(#Wnd, 510, 311, 510, 240, " ", #PB_Window_BorderLess|#PB_Window_ScreenCentered|#WS_VISIBLE|#PB_Window_Invisible)
     SetWindowColor(#Wnd,RGBA(128, 128, 128, 122))
     ;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 NORMAL win7 style 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))
       
        ;GIVE OUR BORDERLESS WINDOW A NORMAL WINDOWS 7 STYLE SHADOW
        If Window
          DwmSetWindowAttribute(WindowID(#Wnd), #DWMWA_NCRENDERING_POLICY, #DWMNCRP_ENABLED)
          DwmExtendFrameIntoClientArea(WindowID(#Wnd), 1, 1, 1, 1)
        EndIf
       
       
    ;Use Tool start up effect
    AnimateWindow_(WindowID(#Wnd),250,#AW_BLEND)
    HideWindow(#Wnd,#False)
 
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


319,537 Page visits

Powered by phpBB® Forum Software © phpBB Limited