通常HSPでメニューバーを表示するにはHSPのサンプルにあるようにWindowsAPIを使い作成しますが、一から作るのは面倒くさいので簡単に作ってしまおう っというのが下のモジュールです。
//////////メニューバー簡易作成モジュール//////////
#module
#uselib "user32.dll"
#cfunc CreateMenu "CreateMenu"
#cfunc CreatePopupMenu "CreatePopupMenu"
#func AppendMenu "AppendMenuA" int, int, int, str
#func SetMenu "SetMenu" int, int
#func GetMenuItemRect "GetMenuItemRect" int, int,
int, sptr
#func DrawMenuBar "DrawMenuBar" int
#func DestroyMenu "DestroyMenu" int
#deffunc menubar str menu1,var hm
menu=menu1:b="":tag_(0)="":i=0:l=0:sindo=1
sdim tag,64,2:dim ct,3:dim rect,4
notesel menu
id=CreateMenu()
hm=id:hmenupar=id:hmenu_(sindo)=id
repeat -1
noteget
b,i:kk=instr(b,0,":")
if
kk!-1|i=notemax+1{ct(2)=ct(1):ct(1)=ct(0):tag(1)=tag(0):h=0:k=strmid(b,kk+1,1)
if ":"=k:tag(0)=strmid(b,kk+2,strlen(b)-kk-2):ct(0)=1:h=1
if "{"=k:ct(0)=2:h=1
if "}"=k:ct(0)=3:h=1
if "-"=k:ct(0)=4:h=1
if h=0&&i!notemax+1:i+:continue
if ct(1)=0:i+:continue
if ct(1)=1&&ct(0)=2:tag_(sindo)=tag(1)
if ct(1)=1&&ct(0)!2:l+:AppendMenu
Hmenu_(sindo),0,l,tag(1)
if ct(1)=4&&ct(0)!2:AppendMenu Hmenu_(sindo),$800,$0,""
if
ct(1)=2&&ct(2)=1:sindo+:hmenu_(sindo)=CreatePopupMenu()
if ct(1)=3:sindo-:if sindo<1:sindo=1:else{
AppendMenu Hmenu_(sindo),$10,hmenu_(sindo+1),tag_(sindo)}
}
i+:if i=notemax+2:break
loop
SetMenu hwnd,hmenupar
DrawMenuBar hwnd
GetMenuItemRect hwnd,hm,0,varptr(rect)
return rect(3)-rect(1)
#deffunc delmenu int hm_
SetMenu hwnd,0
DestroyMenu hm_
DrawMenuBar hwnd
mes hm_
return
#global
//////////////////////////////////////////////////
menu={"
::ファイル
:{
::新規(&N)\t
::開く(&O)...\tCtrl+O
::上書き保存(&S)\tCtrl+S
::名前を付けて保存(&A)...
:-
::印刷(P)...\tCtrl+P
:-
::終了(&X)\tCtrl+Q
:}
::編集
"}
menubar menu,hm
ご覧の通り、文字列で階層付けをしてこれを命令に渡すだけで後は勝手に処理するようになっています。
Copyright(C)Begriff
2007-2009.