
'====================================================================
'' Nested modeless dialog demo, modeless dialog as main.
'====================================================================

#include "dialogs.bas"

'====================================================================

Dim Shared As HWND g_hNestedDlg

'====================================================================

Function NestedDialogProc( Byval hDlg As  HWND, _
                           Byval uMsg As UINT, _
                           Byval wParam As WPARAM, _
                           Byval lParam As LPARAM ) As Integer
  Select Case uMsg

    Case WM_COMMAND

      If loword(wParam) = IDCANCEL Then
        DestroyWindow( hDlg )
      End If

    Case WM_CLOSE

      DestroyWindow( hDlg )

      '' Reset so main can determine if nested dialog is open.
      ''
      g_hNestedDlg = 0


  End Select

  Return 0

End Function

'====================================================================

Function MainDialogProc( Byval hDlg As  HWND, _
                         Byval uMsg As UINT, _
                         Byval wParam As WPARAM, _
                         Byval lParam As LPARAM ) As Integer

  Select Case uMsg

    Case WM_COMMAND

      Select Case loword(wParam)

        Case 100

          '' Open nested dialog only if not already open.
          ''
          If IsWindow( g_hNestedDlg ) = 0 Then
            Dim As LPDLGTEMPLATE lpdt
            Dialog( 1, 0, 0, 120, 90, "Nested Dialog", lpdt, _
                    WS_OVERLAPPED Or WS_SYSMENU Or DS_CENTER _
                    Or WS_VISIBLE )
            DefPushButton( IDCANCEL, -1, 60, 40, 12, "Close" )
            g_hNestedDlg = CreateModelessDialog( hDlg, _
                                                 @NestedDialogProc,_
                                                 0, lpdt )
          End If

        Case IDCANCEL

          DestroyWindow( hDlg )

      End Select

    Case WM_CLOSE

      DestroyWindow( hDlg )

    Case WM_DESTROY

      PostQuitMessage( null )

  End Select

  Return 0

End Function

'====================================================================

Dim As LPDLGTEMPLATE lpdt

Dim As HWND hDlg
Dim As MSG wMsg

Dialog( 2, 0, 0, 150, 100, "Main Dialog", lpdt, _
        WS_OVERLAPPED Or WS_SYSMENU Or DS_CENTER Or WS_VISIBLE )

DefPushButton( 100, 30, 70, 40, 12, "Go" )
PushButton( IDCANCEL, 80, 70, 40, 12, "Close" )

hDlg = CreateModelessDialog( 0, @MainDialogProc, 0, lpdt )

Do While GetMessage( @wMsg, null, 0, 0 ) <> 0
  If IsDialogMessage( hDlg,  @wMsg ) = 0 Then
    If IsDialogMessage( g_hNestedDlg,  @wMsg ) = 0 Then
      TranslateMessage( @wMsg )
      DispatchMessage( @wMsg )
    End If
  End If
Loop

'====================================================================
 