WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Menu Buttons in Dialog


;Menu buttons
;Guido 10/03
;Note: The menu button is a checkbox in the dialog editor, you later change
;      the style to pushlike.

;Creates a popup menu
;items   : '|' delimited list of menu item names
;Returns : menu handle
#definefunction MNCreate(items)
	user32=strcat(dirwindows(1),"user32.dll")
	MF_STRING=0
	
	hmenu=dllcall(user32,long:"CreatePopupMenu")
	
	for id=1 to itemcount(items,"|")
		dllcall(user32,long:"AppendMenuA",long:hmenu,long:MF_STRING,long:id,lpstr:itemextract(id,items,"|"))
	next
	
	return hmenu
#endfunction

;Shows a popup menu and waits for selection
;hdlg    : dialog handle
;hmenu   : menu handle
;hbut    : button handle
;Returns : position in list of selected menu item
#definefunction MNTrackMenu(hdlg,hmenu,hbut)
	user32=strcat(dirwindows(1),"user32.dll")
	RECT=binaryalloc(16)
	
	HWND_DESKTOP=0
	TPM_LEFTALIGN=0
  TPM_LEFTBUTTON=0
  TPM_VERTICAL=64
  TPM_RETURNCMD=256
	
	dllcall(user32,long:"GetClientRect",long:hbut,lpbinary:RECT)                       
  dllcall(user32,long:"MapWindowPoints",long:hbut,long:HWND_DESKTOP,lpbinary:RECT,long:2)
        
	r=dllcall(user32,long:"TrackPopupMenuEx",long:hmenu,long:TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL|TPM_RETURNCMD,long:binarypeek4(RECT,0),long:binarypeek4(RECT,12),long:hdlg,lpnull)
	binaryfree(RECT)
	return r
#endfunction

;Destroys a menu
;hmenu : menu handle
#definefunction MNDestroy(hmenu)
  user32=strcat(dirwindows(1),"user32.dll")
  return dllcall(user32,long:"DestroyMenu",long:hmenu)
#endfunction


;+------------------------------------------------------
;TEST
#definesubroutine dlgproc(hdlg,msg,id,p4,p5)
	select msg	
		case 0
			user32=strcat(dirwindows(1),"user32.dll")
			GWL_STYLE=-16
			BS_PUSHLIKE=4096
			
			;give checkbox pushlike style
			hbut1=dllcall(user32,long:"GetDlgItem",long:hdlg,long:100) ;100=button id, got with roboscripter
			os=dllcall(user32,long:"GetWindowLongA",long:hbut1,long:GWL_STYLE)
			dllcall(user32,long:"SetWindowLongA",long:hbut1,long:GWL_STYLE,long:os|BS_PUSHLIKE)

			;give checkbox pushlike style
			hbut2=dllcall(user32,long:"GetDlgItem",long:hdlg,long:101) ;101=button id, got with roboscripter
			os=dllcall(user32,long:"GetWindowLongA",long:hbut2,long:GWL_STYLE)
			dllcall(user32,long:"SetWindowLongA",long:hbut2,long:GWL_STYLE,long:os|BS_PUSHLIKE)
			
			;create menu 
			hmenu1=MNCreate("Open|Close")
			hmenu2=MNCreate("Option1|Option2")
			
			DialogProcOptions(hdlg,2,1) ;buttons	
			DialogProcOptions(hdlg,4,1) ;checkbox		
			break
			
		case 4 ;checkbutton
			select id			
				case 2
					dialogcontrolset(hdlg,2,1,1) ;check button
					select MNTrackMenu(hdlg,hmenu1,hbut1)
						case 1
							message("","Open")
							break
						case 2
							message("","Close")
							break
					endselect
					dialogcontrolset(hdlg,2,1,0) ;uncheck button
					return -2
				case 3
					dialogcontrolset(hdlg,3,1,1) ;check button
					select MNTrackMenu(hdlg,hmenu2,hbut2)
						case 1
							message("","Option1")
							break
						case 2
							message("","Option2")
							break
					endselect 
					dialogcontrolset(hdlg,3,1,0) ;uncheck button
					return -2
			endselect
			
		case 2 ;button
			select id
				case 1 ;cancel, destroy menu
					MNDestroy(hmenu1)
					MNDestroy(hmenu2)
					return -1
			endselect
		
	endselect
	return -1
#endsubroutine

MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`Menu Button`
MyDialogX=029
MyDialogY=046
MyDialogWidth=246
MyDialogHeight=130
MyDialogNumControls=003
MyDialogProcedure=`dlgproc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`091,063,036,012,PUSHBUTTON,DEFAULT,"Cancel",2,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`000,000,044,012,CHECKBOX,MyVariable1,"File",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`045,000,044,012,CHECKBOX,MyVariable2,"Option",1,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`


ButtonPushed=Dialog("MyDialog")

Article ID:   W15920
File Created: 2004:03:30:15:41:42
Last Updated: 2004:03:30:15:41:42