'modified from a fsw example in the FBEdit samples

$ filename "TabControl.exe"
'uses rtl32
'uses rtl64

'% review

uses dialogs


% TCIF_PARAM=8
% TCIF_TEXT=1
% TCM_GETITEM=0x1305
% TCM_INSERTITEM=0x1307
% TCM_GETCURSEL=0x130B
dword TCN_SELCHANGE=   -551    '64-bit
dword TCN_SELCHANGING= -552    '64-bit

type TCITEM
  int   mask,dwState,dwStateMask
  char* pszText
  int   cchTextMax,iImage
  sys   lParam
end type
typedef TCITEM TC_ITEM

! GetDlgItem lib "user32.dll" (sys hDlg, int nIDDlgItem) as sys
'=================================================

% IDD_DLG0 1000
% IDC_BTN1 1002
% IDC_TAB1 1001
% IDD_TAB1 1100
% CHK_1 1101
% EDT_1 1102
% IDD_TAB2 1200
% CHK_2 1201
% CHK_3 1202
% EDT_2 1001
% EDT_3 1002
% EDT_4 1003

sys hInstance


function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam) as sys callback
    return FALSE
end function

function Tab1Proc( sys hDlg, uint uMsg, sys wParam, lParam) as bool callback
    return FALSE
end function

function Tab2Proc( sys hDlg, uint uMsg, sys wParam, lParam) as bool callback
    return FALSE
end function


function DlgProc( sys hDlg, uint uMsg, sys wParam, lParam) as bool callback
    sys id, event
        TCITEM ts
    NMHDR lpNMHDR
    sys hTab

    select case uMsg
       case WM_INITDIALOG

          'Get handle of tabstrip
          hTab=GetDlgItem(hDlg,IDC_TAB1)
          ts.mask=TCIF_TEXT Or TCIF_PARAM

          'Create Tab1 child dialog
          ts.pszText="Tab1"
          Dialog ( 6,25,200,103, "Tab1", WS_CHILD or WS_VISIBLE)
          Autocheckbox ("Checkbox", CHK_1, 14,38,172,9, &h50010003)
          Edittext     ("Edit", EDT_1, 14,49,172,13, &h50010000, WS_EX_CLIENTEDGE)
          ts.lparam = Createmodelessdialog(hdlg,@Tab1Proc,0)

          SendMessage(hTab,TCM_INSERTITEM,0, @ts)

          ' Create Tab2 child dialog
          ts.pszText="Tab2"
          Dialog ( 6,25,200,103, "Tab2",WS_CHILD)
          Edittext ("edit1", EDT_2, 8,55,174,13, &h50010000, WS_EX_CLIENTEDGE)
          Edittext ("edit2", EDT_3, 8,73,174,13, &h50010000)
          Edittext ("edit3", EDT_4, 8,92,174,13, &h50010000, WS_EX_CLIENTEDGE)
          ts.lParam= Createmodelessdialog(hdlg,@Tab2Proc,0)
          SendMessage(htab,TCM_INSERTITEM,1, @ts)

       case WM_NOTIFY
          NMHDR lpNMHDR at lParam
             if lpNMHDR.code=TCN_SELCHANGING Then
               ' Hide the currently selected dialog
               id=SendMessage(lpNMHDR.hwndFrom,TCM_GETCURSEL,0,0)
               ts.mask=TCIF_PARAM
               SendMessage(lpNMHDR.hwndFrom,TCM_GETITEM,id, @ts)
               ShowWindow(ts.lParam,SW_HIDE)
             elseif lpNMHDR.code=TCN_SELCHANGE Then
               ' Show the currently selected dialog
               id=SendMessage(lpNMHDR.hwndFrom,TCM_GETCURSEL,0,0)
               ts.mask=TCIF_PARAM
               SendMessage(lpNMHDR.hwndFrom,TCM_GETITEM,id, @ts)
               ShowWindow(ts.lParam,SW_SHOW)
             endif
     '
       case WM_CLOSE
          EndDialog(hDlg, 0)
     '
       case WM_COMMAND
          id=loword(wParam)
          event=hiword(wParam)
          select case id
             case IDC_BTN1
                EndDialog(hDlg, 0)

             case IDCANCEL
                ' This allows user to close dialog
                ' with Escape key;
                EndDialog(hDlg, 0)
          end select
     '
       case else
          return FALSE

    end select

    return TRUE
end function

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

init_common_controls()

'WS_CLIPSIBLINGS required for parent window and tab control.
Dialog(6,6,248,188, "Tab Demo",
       WS_OVERLAPPED Or WS_SYSMENU Or DS_CENTER or WS_CLIPSIBLINGS or DS_SETFONT, 10, "MS Sans Serif" )

' Base style defined in Control procedure is WS_CHILD or WS_VISIBLE.
Control( "", IDC_TAB1,  WC_TABCONTROL, WS_CLIPSIBLINGS, 2, 3, 244, 157 )

PushButton( "Cancel", IDC_BTN1, 176,160,64,15, WS_TABSTOP )

CreateModalDialog( null, @DlgProc, 0 )

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