Author Topic: statusbar  (Read 1575 times)

0 Members and 1 Guest are viewing this topic.

Frankolinox

  • Guest
statusbar
« on: September 11, 2013, 08:10:32 AM »
here's a little statusbar example:

Code: [Select]
 'statusbar example for oxygenbasic by frankolinox, 11.sept.2013, bsa
  '
  $ filename "t.exe"
  include "statusbar.inc"
  includepath "$/inc/"
  '#include "RTL32.inc"
  '#include "RTL64.inc"
  include   "WinUtil.inc"
  
  MainWindow 320,200,WS_OVERLAPPEDWINDOW

  function GetNextWord(string*s,sys *i,*a,*nl) as string
  ======================================================
  sys b,j
  nl=0
  do
    select case asc s,i
    case 0         : a=0 : return ""
    case 33 to 255 : exit do
    end select
    i++
  end do
  b=i
  a=asc s,i
  do
    select case asc s,i
    case 0 to 32 : exit do
    end select
    i++    
  enddo
  j=i
  'check for end of line
  do
    select case asc s,i
    case 0         : nl=1 : exit do
    case 10        : nl=1 : exit do
    case 13        : nl=1 : exit do
    case 33 to 255 : exit do
    end select
    i++
  end do
  return mid s,b,j-b
  end function


  function CreateMenuFrom(string s) as sys
  ========================================
  sys    i=1,nl,a,id,co,hMenu
  string w,tx,mn
  hmenu=CreateMenu
  do
    w=GetNextWord(s,i,a,nl)
    select a
    case 0 : exit do
    case "0" to "9" : id=w
    case 34         : tx=mid w,2,len(w)-2
    case else       : co=w  
    end select
    if nl 'end of line
      select id 'interpret
      case 0    : 'no action
      case 1    : hMenuPopup = CreateMenu : mn=tx
      case 2    : AppendMenu hMenuPopup, MF_SEPARATOR, 0, null
      case 9    : AppendMenu hMenu, MF_POPUP, hMenuPopup, mn
      case else : AppendMenu hMenuPopup, MF_STRING, id, tx
      end select
      id=0 : nl=0
    end if
  end do
  return hMenu
  end function
  

  function WndProc ( hWnd, wMsg, wParam, lparam ) as sys callback
  '==============================================================

  static sys hdc,hMenu,hMenuPopup,myStatusbar
  static String txt
  dim zText as string
  static rect crect
  static PaintStruct Paintst
  sys id
  '
  select wMsg
  '==========
      
  case WM_CREATE

  'MENU ITEMS
  '
  %IDM_FILE_NEW     1001
  %IDM_FILE_OPEN    1002
  %IDM_FILE_SAVE    1003
  %IDM_FILE_SAVE_AS 1004
  %IDM_APP_EXIT     1005
  %IDM_EDIT_UNDO    1006
  %IDM_EDIT_CUT     1007
  %IDM_EDIT_COPY    1008
  %IDM_EDIT_PASTE   1009
  %IDM_EDIT_CLEAR   1010
  %IDM_APP_HELP     1011
  %IDM_APP_ABOUT    1012
  '
  string s=quote """
  1    menu "&File"
  1001 "&New"
  1002 "&Open..."
  1003 "&Save"
  1004 "Save&As..."
  2    separator
  1005 "E&xit"
  9    end

  1    menu "&Edit"
  1006 "&Undo"
  1007 "Cu&t"
  1008 "&Copy"
  1009 "&Paste"
  1010 "De&lete"
  9    end

  1    menu "&Help"
  1011 "&Help"
  1012 "&About&MenuDemo..."
  9    end
  """
  hMenu=CreateMenuFrom s
  SetMenu hWnd,hMenu
  '
  sys dis=MF_DISABLED or MF_GRAYED
  CheckMenuItem hMenu,IDM_FILE_NEW, MF_CHECKED
  EnableMenuItem hMenu,IDM_FILE_OPEN,dis
  '
  '------------------------ statusbar ----------------- //
      
      myStatusbar = CreateStatusWindowA (%WS_CHILD OR %WS_VISIBLE OR %SBS_SIZEGRIP, _
                                      "", hWnd, %ID_STATUSBAR)
      dim prts(1) as long
      prts(0) = 250 : prts(1) = -1
      zText = " statusbar oxygenbasic"
      Sendmessage myStatusbar, %SB_SETPARTS, 2, @prts(0)
      SendMessage myStatusbar, %SB_SETTEXTA, 0, zText 'ucase$(zText)
      
'-------------------------------- statusbar end -------------- //      
  '
  SetWindowText hwnd,"Menu Demo"
  '
  case WM_COMMAND

  hMenu = GetMenu(hwnd)
  if wparam = 1005 THEN
    'print "exit"
    SendMessage hwnd, WM_CLOSE, 0, 0
  end if
  
  case WM_SIZE  
  SendMessage myStatusbar, wMsg, wParam, lParam 'sizing statusbar
  
  case WM_DESTROY
  '
  PostQuitMessage 0

  case WM_KEYDOWN

    Select wParam
    Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE
    End Select
      
  case else
  '
  function=DefWindowProc hWnd,wMsg,wParam,lParam
  '
  end select
  end function

 '

"statusbar.inc":
Code: [Select]
 '
  %ID_STATUSBAR         = %WM_USER + 1025&  ' statusbar
  %SB_SETPARTS          = %WM_USER + 4
  %SB_SETTEXTA          = %WM_USER + 1
  %SBS_SIZEGRIP         = &H0010???

DECLARE FUNCTION CreateStatusWindowA LIB "COMCTL32.DLL" ALIAS "CreateStatusWindowA" ( _
   BYVAL style AS LONG _                                ' __in LONG style
 , BYREF lpszText AS STRING _ 'ASCIIZ _                           ' __in LPCSTR lpszText
 , BYVAL hwndParent AS DWORD _                          ' __in HWND hwndParent
 , BYVAL wID AS DWORD _                                 ' __in UINT wID
 ) AS DWORD                                             ' HWND

'$STATUSCLASSNAMEA      = "msctls_statusbar32"


place the example under "wingui" folder for running and testing.

btw: @charles: the strings for menu names are not entirely correct (from "menus3.o2bas").

regards, frank

X

Aurel

  • Guest
Re: statusbar
« Reply #1 on: September 11, 2013, 09:56:50 AM »
Good one Frank.. ;)
You again remind me that I still don't have menus in my include file ::)
I have playing with tooltips...but i hope i will add menu functions soon ;)

Aurel

  • Guest
Re: statusbar
« Reply #2 on: September 11, 2013, 10:09:18 AM »
By the way ,you can create status bar like this to:
Code: [Select]
Function SetStatusBar (byval shwnd as INT,byval stext as STRING,byval sflag as INT,byval ex as INT) as INT
  If sflag=0
    sflag= WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP | WS_CLIPSIBLINGS
  End If
  statHwnd =CreateWindowEx(ex,"msctls_statusbar32",stext,sflag,0,0,0,0,shwnd,0,0,0) 
  Return statHwnd
End Function

X
« Last Edit: September 11, 2013, 11:55:12 AM by Aurel »