Custom Dialog (Win)
BlitzMax Forums/MaxGUI Module/Custom Dialog (Win)
| ||
Hello all, I created a custom dialog type for my project, and thought I'd share if somebody finds this amusing. Keypoints: Dialog is true modal (could be also modeless) which means it halts program flow to get user information and continues when user closes the dialog. Useful when running eventhook-based system. Everything is created dynamically. If one looks Create() -method inside TDialog type, there is a example of methods used for setting style and controls in dialog. Everything is sized automatically depending on font specified in SetFont() -method. If font is not found then system default is used. I have tested this on Win7/8 EXAMPLE Strict Import maxgui.drivers Import maxgui.xpmanifest 'Not needed, but visually better Extern "win32" Function GetDlgItemTextW:Int(hwnd:Int, nIDDlgItem:Int, lpString:Short Ptr, nMaxCount:Int) Function DialogBoxIndirectParamW:Int(hinstance:Int,hDialogTemplate:Byte Ptr,hWndParent:Int,lpDialogFunc:Byte Ptr,dwInitParam:Int) Function EndDialog:Int(hDlg:Int,nResult:Int) EndExtern '------------------------------------- 'EXAMPLE (Eventhook-based application) '------------------------------------- Global app:TApp TApp.Create() Repeat WaitEvent() Forever Type TApp Field window2:tgadget = CreateWindow("Main",200,100,300,200,Null) Field button:tgadget = CreateButton("Dialog",100,50,80,36,window2) Function Create() app = New TApp AddHook(EmitEventHook,eventhook,app) EndFunction Function eventhook:Object(id:Int,data:Object,context:Object) If TApp(context) Then TApp(context).OnEvent(TEvent(data)) Return data End Function Method OnEvent(event:TEvent) Select event.id Case EVENT_WINDOWCLOSE End Case EVENT_GADGETACTION 'Show Dialog Local txt:String = CreateDialog("My very first dialog","Name:",10,10,160,75,window2) Print "Your name is "+txt EndSelect EndMethod EndType '--------------------------- 'END '--------------------------- Dialog type to be included: -Henri |