

includepath "$/inc/"
include "minwin.inc"

'% HWND_TOP       0
'% HWND_BOTTOM    1
'% SWP_NOSIZE     1
'% SWP_NOMOVE     2
'% SWP_SHOWWINDOW 0x40

% TCIF_TEXT       1
% TCN_SELCHANGE   -551
% TCN_SELCHANGING -552
% TCM_INSERTITEM  0x1307
% TCM_GETCURSEL   0x130B
% TCM_SETCURSEL   0x130C

% COLOR_WINDOW    5

type NMHDR
  sys hwndFrom,idFrom
  int code
end type

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

sys hWndMain,hWndTab,hwnd0,hwnd01,hwnd1,hwnd2,hwnd3,hinst

Declare Sub InitCommonControls lib "comctl32.dll" ()

 
function MakeWindow(sys num)
============================
hwnd0=CreateWindowEx(0,"edit", "text "+num+1, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 
                     0,28,300, 300, 
                     hwndTab, NULL, hinst, NULL)
end function

 
function WndProc(sys hwnd, int ms, sys wParam, lParam) as sys callback
======================================================================
static int iPage=-1
select ms
case WM_CLOSE   : DestroyWindow(hwnd)
case WM_DESTROY : PostQuitMessage(0)
case WM_NOTIFY  :
  NMHDR hdr at lparam
  select hdr.code
  case TCN_SELCHANGING
    'leaving tab
  case -2
    'selected tab
    int i = SendMessage(hwndtab,TCM_GETCURSEL,0,0)
    if i<>iPage
      iPage=i
      DestroyWindow hwnd0
      MakeWindow(iPage)
    end if
  end select
case else : return DefWindowProc(hwnd, ms, wParam, lParam)
end select
end function
 

function WinMain(sys hInstance, hPrevInstance, char*lpCmdLine, int nCmdShow) as sys
===================================================================================
WNDCLASSEX wc
sys        hwnd
MSG        ms

hinst=hInstance
 
wc.cbSize        = sizeof(WNDCLASSEX)
wc.style         = 0
wc.lpfnWndProc   = @WndProc
wc.cbClsExtra    = 0
wc.cbWndExtra    = 0
wc.hInstance     = hInstance
wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION)
wc.hCursor       = LoadCursor(NULL, IDC_ARROW)
wc.hbrBackground = COLOR_WINDOW+1
wc.lpszMenuName  = NULL
wc.lpszClassName = strptr "myWindowClass"
wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION)
 
int rg=RegisterClassEx(&wc)

 
hwndMain = CreateWindowEx(WS_EX_CLIENTEDGE,"myWindowClass","The title of my window",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, CW_USEDEFAULT, 350, 300,
                          NULL, NULL, hInstance, NULL)
ShowWindow(hwndMain, nCmdShow)
UpdateWindow(hwndMain)
InitCommonControls()
hwndTab=CreateWindowEx(0,"SysTabControl32", "",
                       WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE,
                       0, 0, 300, 250, 
                       hwndMain, NULL, hInstance, NULL)
TCITEM tie
tie.mask = TCIF_TEXT
tie.pszText = "Hi1"
SendMessage hwndTab,TCM_INSERTITEM,0,@tie
tie.mask = TCIF_TEXT
tie.pszText = "Hi2"
SendMessage hwndTab,TCM_INSERTITEM,1,@tie
tie.mask = TCIF_TEXT 
tie.pszText = "Hi3"
SendMessage hwndTab,TCM_INSERTITEM,2,@tie
tie.mask = TCIF_TEXT
tie.pszText = "Hi4"
SendMessage hwndTab,TCM_INSERTITEM,3,@tie
 
SendMessage hwndTab,TCM_SETCURSEL,3,0
'print SendMessage hwndTab,TCM_GETCURSEL,0,0

ShowWindow(hwndTab, SW_SHOW)
UpdateWindow(hwndTab)
 
while(GetMessage(&ms, NULL, 0, 0) > 0)
  TranslateMessage(&ms)
  DispatchMessage(&ms)
wend
return ms.wParam
end function


char*cmdline 
sys inst
&cmdline=GetCommandLine
inst=GetModuleHandle 0
WinMain inst,0,cmdline,SW_NORMAL
end

