Modal Window: A solution with Windows API

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by teachco.

1. Save the WindowID of the main window in a variable, for example MainWinID.
I inserted MainWinID = WindowID() directly after the openWindow-statement.

2. After the openWindow-statement of the modal dialog window I inserted
EnableWindow_(WindowID(),#FALSE)

3. Attention! Don't forget to enable the calling window again, if you close the dialog window. In the event-loop you have to insert
EnableWindow_(WindowID),#TRUE) at every button(-event), which close the dialog window. That's it.


Edited by - teachco on 17 June 2002 11:26:16
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

I LOVE YOU!!! :oops:

Even tho' this is an ancient post... It's exactly what I needed :)
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

Another old example:

Code: Select all

Enumeration
    #WINDOW_0
    #WINDOW_1
    #STRING_0
    #BUTTON_0
    #BUTTON_1
EndEnumeration

Procedure OpenModalWindow()
    CallerID = WindowID(#WINDOW_0)
    CallerNumber = EventWindowID()
    If OpenWindow(#WINDOW_1, 300, 300, 200, 200,  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar, "Modal Window")
        EnableWindow_(CallerID, #FALSE)
        SetWindowPos_(WindowID(#WINDOW_1), #HWND_TOPMOST, 0, 0, 0, 0, #SWP_NOMOVE | #SWP_NOSIZE)
        SetForegroundWindow_(WindowID(#WINDOW_1))
        If CreateGadgetList(WindowID(#WINDOW_1))
               ButtonGadget(#BUTTON_1, 40, 65, 110, 35, "Close")
        EndIf
        Repeat
            EventID.l = WaitWindowEvent()
            Select EventID
                Case #PB_EventGadget
                    Select EventGadgetID()
                        Case #BUTTON_1
                            Quit = 1
                    EndSelect
                Case #PB_EventCloseWindow
                    Quit = 1
            EndSelect
        Until Quit = 1
        CloseWindow(#WINDOW_1)
    EndIf
    EnableWindow_(CallerID, #TRUE)
    SetForegroundWindow_(CallerID)
    UseWindow(CallerNumber)
EndProcedure

;Open main window
If OpenWindow(#WINDOW_0, 200, 200, 200, 200,  #PB_Window_SystemMenu | #PB_Window_TitleBar , "Parent Window")
    If CreateGadgetList(WindowID())
        ButtonGadget(#BUTTON_0, 40, 65, 110, 35, "open new window")
    EndIf
EndIf
Repeat
    EventID.l = WaitWindowEvent()
    If EventID = #PB_EventGadget
        GadgetID = EventGadgetID()
        If GadgetID = #BUTTON_0
            OpenModalWindow()
        EndIf
    EndIf
Until EventID = #PB_EventCloseWindow
End
:D
--Kale

Image
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

That one's neeto burito too :)
It could be adapted to create clone-ish windows :)
DARKGuy
User
User
Posts: 40
Joined: Thu Mar 11, 2004 10:08 pm
Contact:

Post by DARKGuy »

The code seems very useful but, forgive my ignorance...what's a modal window? XD
IT"S NOT WISE TO START CODING SOMETHING WITHOUT KNOWING THE LANGUAGE....WE DON'T GET PAID TO WRITE SOURCE FOR YOU YA KNOW....
In honor to darklordz...
PolyVector
Enthusiast
Enthusiast
Posts: 499
Joined: Wed Sep 17, 2003 9:17 pm
Location: Southern California
Contact:

Post by PolyVector »

It's a window that takes all user input so that no other window recieves input (until the modal window closes)... Like an error dialog
DARKGuy
User
User
Posts: 40
Joined: Thu Mar 11, 2004 10:08 pm
Contact:

Post by DARKGuy »

ohhh ok, now I understand, thanks PolyVector :)
IT"S NOT WISE TO START CODING SOMETHING WITHOUT KNOWING THE LANGUAGE....WE DON'T GET PAID TO WRITE SOURCE FOR YOU YA KNOW....
In honor to darklordz...
Post Reply