based on spangly's code I made a requester style 3 button modal dialog.
The procedure takes the button text as argument. You can also specify which button is to be the default button.
Code: Select all
;
; 3-Button Requester-Style Modal Dialog with arbitrary Button-Text and Default-Button
; by Sputnik
; based on code by spangly
;
Declare Requester_3Btn(hWndParent.l,title$,msgtxt$,btn1$,btn2$,btn3$,btn_default.l)
Declare Requester_3Btn_Callback(hWnd, uMsg, wParam, lParam)
style.l = #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget
style = style | #PB_Window_MaximizeGadget|#PB_Window_SizeGadget | #PB_Window_TitleBar
If OpenWindow(0, 0, 0, 660,450, style,"Modal Test") = 0 :End : EndIf
result = Requester_3Btn(WindowID(),"Window Title","Message Text","Button 1","Button 2","Button 3",2)
MessageRequester("Information","You have chosen button "+Str(result),#PB_MessageRequester_Ok)
result = Requester_3Btn(WindowID(),"File already exists","How do you want to proceed ?","Replace","Append","Cancel",3)
MessageRequester("Information","You have chosen button "+Str(result),#PB_MessageRequester_Ok)
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_Event_CloseWindow
End
;-
Procedure.l Requester_3Btn(hWndParent.l,title$,msgtxt$,btn1$,btn2$,btn3$,btn_default.l)
; Parameters : hWndParent.l Handle of parent window
; title$,msgtxt$ Titlebar Text, Message Text
; btn1$,btn2$,btn3$ Text for Buttons
; btn_default.l Default Button 1,2, or 3
; returns : 1,2 or 3 for selected Button
; 0 for cancel
Structure DLG_INFO
titletxt.s
msgtxt.s
btn1txt.s
btn2txt.s
btn3txt.s
hnd_btn1.l
hnd_btn2.l
hnd_btn3.l
dflt_btn.l
EndStructure
di.DLG_INFO
di\titletxt = title$
di\msgtxt = msgtxt$
di\btn1txt = btn1$
di\btn2txt = btn2$
di\btn3txt = btn3$
di\dflt_btn = btn_default
Structure DLG_TEMPLATE
style.l
dwExtendedStyle.l
cdit.w
x.w
y.w
cx.w ; size of client-area in DialogUnits
cy.w ;
menu.w
class.w
title.l
EndStructure
dt.DLG_TEMPLATE
dt\style = #WS_POPUP | #WS_BORDER | #WS_SYSMENU | #DS_MODALFRAME | #WS_CAPTION | #DS_CENTER
; desired dialog-box size is 323 x 100 pixel (will produce 322 x 99)
dlgX = 323
dlgY = 100
; converting pixels to dialogunits
; dialogunitX = (pixelX * 4) / baseunitX
; dialogunitY = (pixelY * 8) / baseunitY
baseunit = GetDialogBaseUnits_()
baseunitX = PeekW(@baseunit)
baseunitY = PeekW(@baseunit+2)
titleheight = GetSystemMetrics_(#SM_CYCAPTION)
frameX = GetSystemMetrics_(#SM_CXFIXEDFRAME)
frameY = GetSystemMetrics_(#SM_CYFIXEDFRAME)
dt\cx = ((dlgX - (2 * frameX)) * 4) / baseunitX
dt\cy = ((dlgY - titleheight - (2 * frameY)) * 8) / baseunitY
; calling the dialog-box
Hnd_selected_btn = DialogBoxIndirectParam_(0,@dt,hWndParent,@Requester_3Btn_Callback(),@di)
; translating button-handle to a number
selected = 0
Select Hnd_selected_btn
Case di\hnd_btn1
selected = 1
Case di\hnd_btn2
selected = 2
Case di\hnd_btn3
selected = 3
EndSelect
ProcedureReturn selected
EndProcedure
;-
Procedure Requester_3Btn_Callback(hWnd, uMsg, wParam, lParam) ;DlgProc
Select uMsg
Case #WM_INITDIALOG
; is sent when the dialog box is created but before it is displayed
; wParam : handle of dialog box
; lParam : address of additional initialization information
; (=pointer To my DLG_INFO Struct)
*p.DLG_INFO = lParam
CreateGadgetList(hWnd)
TextGadget(#PB_Any, 11, 11, 296, 15,*p\msgtxt)
; uses handles to identify buttons
*p\hnd_btn1 = GadgetID(ButtonGadget(#PB_Any, 11, 41, 95, 23,*p\btn1txt))
*p\hnd_btn2 = GadgetID(ButtonGadget(#PB_Any, 111, 41, 95, 23,*p\btn2txt))
*p\hnd_btn3 = GadgetID(ButtonGadget(#PB_Any, 212, 41, 95, 23,*p\btn3txt))
SetWindowText_(hWnd,*p\titletxt)
; setting default button and keyboard-focus
rc = 0
Select *p\dflt_btn
Case 2
SendMessage_(*p\hnd_btn2,#BM_SETSTYLE,#BS_DEFPUSHBUTTON,#True)
SetFocus_(*p\hnd_btn2)
Case 3
SendMessage_(*p\hnd_btn3,#BM_SETSTYLE,#BS_DEFPUSHBUTTON,#True)
SetFocus_(*p\hnd_btn3)
Default
rc = 1
EndSelect
ProcedureReturn rc ; rc = 1 : default; keyboard-focus on first button
; rc = 0 : you have set keyboard-focus and default-button yourself
Case #WM_COMMAND
; is sent when a button is selected
; lParam : handle of control
EndDialog_(hWnd,lParam) ; returns handle of selected button and ends dialog
; this is the returned value of the DialogBoxIndirectParam call
Case #WM_SYSCOMMAND
; is sent when a window-control or menu item is selected
; wParam : type of system command requested
; : the four low-order bits are used internally by Windows
; : they have to be masked with $FFF0
If wParam&$FFF0 = #SC_CLOSE ; returns zero if close-button or ESC was pressed
EndDialog_(hWnd,0)
EndIf
EndSelect
ProcedureReturn 0 ; returns zero for messages that are not handled here
; WM_COMMAND,WM_SYSCOMMAND should also return zero
EndProcedure