StatusBar the easy way [Windows]

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4664
Joined: Sun Apr 12, 2009 6:27 am

StatusBar the easy way [Windows]

Post by RASHAD »

Hi
- StatusBar height
- Colored text - Font - Background
- Control text position
- Icons
- Field tips

Edit :
For 2nd. snippet you can use
#DT_BOTTOM ,#DT_TOP ,#DT_LEFT ,#DT_CENTER ,#DT_RIGHT And #DT_VCENTER with #DT_SINGLELINE
as flags to control the position of the text

Code: Select all

Global hSB,iinf.ICONINFO ,icoHnd
Global Dim Fields(2)
Fields(0) = 150
Fields(1) = 190
Fields(2) = 390

iinf\fIcon = 1

#SBT_TOOLTIPS = $800
#SB_SETICON = #WM_USER + 15
 
Procedure dtext(img,font,text$,x,y,w,h,fcolor,bcolor)
  CreateImage(img,w,h,24,bcolor)
  StartDrawing(ImageOutput(img))
    DrawingFont(FontID(font))
    DrawingMode(#PB_2DDrawing_Transparent )
    DrawText(x,y,text$,fcolor)
  StopDrawing()
  iinf\hbmMask = ImageID(img)
  iinf\hbmColor = ImageID(img)
  icoHnd = CreateIconIndirect_(iinf)
  FreeImage(img)
  ProcedureReturn icoHnd
EndProcedure
 
Procedure sizeCB()
  MoveWindow_(hSB ,0,WindowY(0,#PB_Window_FrameCoordinate)+WindowHeight(0)-40,WindowWidth(0),40,1)
EndProcedure

LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\CdPlayer.ico")
LoadFont(0,"Tahoma",16)
LoadFont(1,"Georgia",16)

OpenWindow(0, 0, 0, 500, 200, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget| #PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
  
hSB = CreateWindowEx_(0,"msctls_statusbar32","",#SBARS_SIZEGRIP| #WS_CHILD|#WS_VISIBLE|#SBT_TOOLTIPS , 0, 0, 0, 0, WindowID(0),0,0,0)
SendMessage_(hSB, #SB_SETMINHEIGHT, 40, 0)
SendMessage_(hSB, #WM_SIZE, 0,0)
SendMessage_(hSB, #SB_SETPARTS, 3, @Fields())

dtext(10,0,"RASHAD",40,8,150,40,$0000FF,$FFFFFE)
SendMessage_(hSB, #SB_SETICON, 0, icoHnd)

SendMessage_(hSB, #SB_SETICON, 1, ImageID(0))
SendMessage_(hSB, #SB_SETTIPTEXT, 1, "ToolTip")

dtext(10,1,"RASHAD",50,8,200,40,$00F3F5,$F43401)
SendMessage_(hSB, #SB_SETICON, 2, icoHnd)

InvalidateRect_(WindowID(0),0,1)
BindEvent(#PB_Event_SizeWindow,@sizeCB())
 
Repeat
  Select WaitWindowEvent(10)
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1
Little bit advanced :

Code: Select all

Global hSB,iinf.ICONINFO ,icoHnd,r.RECT
Global Dim Fields(2)
Fields(0) = 150
Fields(1) = 190
Fields(2) = 390

iinf\fIcon = 1

#SBT_TOOLTIPS = $800
#SB_SETICON = #WM_USER + 15
 
Procedure dtext(img,font,text$,x,y,w,h,fcolor,bcolor,flags)
  CreateImage(img,w,h,24,bcolor)
  hdc = StartDrawing(ImageOutput(img))
    SelectObject_(hdc,FontID(font))
    SetTextColor_(hdc,fcolor)
    SetBkColor_(hdc,bcolor)
    SetBkMode_(hdc,#TRANSPARENT	)
    r\left = x :r\top = y : r\right = w : r\bottom = h
    DrawText_(hDC,@text$,Len(Text$),r , flags) 
  StopDrawing()
  iinf\hbmMask = ImageID(img)
  iinf\hbmColor = ImageID(img)
  icoHnd = CreateIconIndirect_(iinf)
  FreeImage(img)
  ProcedureReturn icoHnd
EndProcedure
 
Procedure sizeCB()
  MoveWindow_(hSB ,0,WindowY(0,#PB_Window_FrameCoordinate)+WindowHeight(0)-40,WindowWidth(0),40,1)
EndProcedure

LoadImage(0,#PB_Compiler_Home+"Examples\Sources\Data\CdPlayer.ico")
LoadFont(0,"Tahoma",16)
LoadFont(1,"Georgia",18)

OpenWindow(0, 0, 0, 500, 200, "", #PB_Window_SystemMenu|#PB_Window_SizeGadget| #PB_Window_MaximizeGadget|#PB_Window_ScreenCentered)
  
hSB = CreateWindowEx_(0,"msctls_statusbar32","",#SBARS_SIZEGRIP| #WS_CHILD|#WS_VISIBLE|#SBT_TOOLTIPS , 0, 0, 0, 0, WindowID(0),0,0,0)
SendMessage_(hSB, #SB_SETMINHEIGHT, 40, 0)
SendMessage_(hSB, #WM_SIZE, 0,0)
SendMessage_(hSB, #SB_SETPARTS, 3, @Fields())

dtext(10,0," RASHAD",0,0,150,40,$0000FF,$FFFFFE, #DT_LEFT |#DT_VCENTER | #DT_SINGLELINE	)
SendMessage_(hSB, #SB_SETICON, 0, icoHnd)

SendMessage_(hSB, #SB_SETICON, 1, ImageID(0))
SendMessage_(hSB, #SB_SETTIPTEXT, 1, "ToolTip")

dtext(10,1,"RASHAD ",0,0,200,40,$00F3F5,$F43401,#DT_VCENTER |#DT_CENTER| #DT_SINGLELINE	)
SendMessage_(hSB, #SB_SETICON, 2, icoHnd)

InvalidateRect_(WindowID(0),0,1)
BindEvent(#PB_Event_SizeWindow,@sizeCB())
 
Repeat
  Select WaitWindowEvent(10)
    Case #PB_Event_CloseWindow
      Quit = 1
  EndSelect
Until Quit = 1
Egypt my love
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: StatusBar the easy way [Windows]

Post by RSBasic »

Image
Image
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: StatusBar the easy way [Windows]

Post by Kwai chang caine »

Works great on my W10 x64 / v5.61 x86
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply