May 04, 2024, 02:41:26 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Status Bar panes styles

Started by fasecero, February 17, 2009, 02:31:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

Hi, this small example shows how you can adjust the style of each pane of the status bar, as well to assign icons to them . You can also specify a background color.

To show an icon in the third pane copy an icon to the directory where the program is located and adjusts the name of the file in:

hicon=LoadIconFromFile(GETSTARTPATH+"YourIcon.ico")      (line 37)

To change the color of the background uncomment:

'StatusBarSetBkColor(win, STATUSBAR, RGB(89,198,133))      (line 65)


'demo of a status window control with styles and icons
'Requires EBASIC 1.0 or greater
'Compile as a WINDOWS target

' INCLUDES
$INCLUDE "windows.inc"

' status bar flags
CONST SBT_NOBORDERS = 0x100
CONST SBT_POPOUT = 512

' status bar messages
CONST WM_USER = 0x400
CONST SB_SETTEXTA = (WM_USER+1)
CONST SB_SETICON = (WM_USER+15)
CONST CCM_FIRST = 0x2000
CONST SB_SETBKCOLOR = (CCM_FIRST + 1)

' load image constants
CONST IMAGE_ICON = 1
CONST LR_LOADFROMFILE = 0x10

' CONSTANTS
CONST STATUSBAR = 1

' VARIABLES
DEF win:window
DEF quit:INT
DEF hicon: uint
def panes[4]:INT 'the array describing the widths of the panes in the status window

' CONTROLS
OPENWINDOW win,0,0,640,400,@SIZE|@MINBOX|@MAXBOX,0,"Status Styles",&mainwindow
CONTROL win,@STATUS,"Status",0,0,0,0,0,STATUSBAR

' MAIN LOOP
hicon=LoadIconFromFile(GETSTARTPATH+"YourIcon.ico")
StatusBarInit()
quit = 0
WAITUNTIL quit=1
CLOSEWINDOW win
DeleteIcon(hicon)
END

' WINDOW PROCEDURE
sub mainwindow
select @MESSAGE
case @IDCLOSEWINDOW
quit = 1
case @IDSIZE
StatusBarResize()
endselect
return
ENDSUB

' FUNCTION TO INIT THE STATUS BAR
SUB StatusBarInit()
def left, top, width, height : INT
' get the windows client size and set up 4 panes for the status window
GETCLIENTSIZE win,left,top,width,height
panes = width - 400, width - 250, width - 100, -1
CONTROLCMD win,STATUSBAR,@SWSETPANES,4,panes

' set the background color
'StatusBarSetBkColor(win, STATUSBAR, RGB(89,198,133))

' set the panes styles
CONTROLCMD win, STATUSBAR, @SWSETPANETEXT, 0, "  (default)"
StatusBarPaneSetStyle(win, STATUSBAR, 1, 0, "lower pane with icon")
StatusBarPaneSetStyle(win, STATUSBAR, 2, SBT_NOBORDERS, "No borders pane")
StatusBarPaneSetStyle(win, STATUSBAR, 3, SBT_POPOUT, "Popout pane")

' set an icon to a pane
StatusBarPaneSetIcon(win, STATUSBAR, 1, hicon)

' update the styles, it must be a better way ...
GETSIZE win,left,top,width,height
SETSIZE win,left,top,width+1,height+1
ENDSUB

' FUNCTION TO RESIZE THE STATUS BAR
SUB StatusBarResize()
def left, top, width, height : INT
'resize the status window and update the panes
'check to make sure the status window exists
'it may not have been added to the window yet.
IF CONTROLEXISTS(win, STATUSBAR) THEN
'Tell the status window we are sizing
CONTROLCMD win, STATUSBAR, @SWRESIZE
'get the client size of the window and
'display it in the status bar
'calculate the right edges of the other panes.
GETCLIENTSIZE win, left, top, width, height
panes = width - 400, width - 250, width - 100, -1
CONTROLCMD win, STATUSBAR, @SWSETPANES, 4, panes
ENDIF
ENDSUB

' SET THE STYLE OF A PANE
' styles: 0, SBT_NOBORDERS, SBT_POPOUT
SUB StatusBarPaneSetStyle(w as window, statusid as uint, panenumber as INT, style AS INT, OPT initialtext="" as STRING), INT
RETURN SENDMESSAGE(w, SB_SETTEXTA, panenumber | style, initialtext, statusid)
ENDSUB

' SET THE BACKGROUND COLOR OF THE STATUS BAR
SUB StatusBarSetBkColor(w as window, statusid as uint, color_rgb as INT), INT
RETURN SENDMESSAGE(w, SB_SETBKCOLOR, 0, color_rgb, statusid)
ENDSUB

' SET AN ICON TO A PANE
SUB StatusBarPaneSetIcon(w as window, statusid as uint, panenumber as INT, hicon AS uint), INT
RETURN SENDMESSAGE(w, SB_SETICON, panenumber, hicon, statusid)
ENDSUB

' LOAD AN ICON FROM A FILE
SUB LoadIconFromFile(string path), uint
return _LoadImage(_GetModuleHandle(0), path, IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
ENDSUB

' DELETE AN ICON
SUB DeleteIcon(uint iconid)
_DeleteObject(iconid)
ENDSUB