Page 1 of 1

Win32 - How to add controls to TabControl?

Posted: Fri Feb 14, 2014 2:14 pm
by va!n
Can someone explain me, how to add controls to TabControls / panels and whats wrong with my code?
Btw, which coding style is correct -> creating controls / gui directly after the mainwindow has been created; or creating all controls / gui inside #WM_CREATE ?
Thanks!

Code: Select all

Procedure WindowCallback(Window, Message, wParam, lParam) 
  Select Message 
    Case #WM_CLOSE 
      If MessageBox_(Window, "Exit program?", "EXIT", #MB_YESNO) = #IDYES 
        DestroyWindow_(Window) 
      Else 
        Result  = 0 
      EndIf 
    Case #WM_DESTROY 
      PostQuitMessage_(0) 
      Result  = 0 
    Default 
      Result  = DefWindowProc_(Window, Message, wParam, lParam) 
  EndSelect 
  ProcedureReturn Result 
EndProcedure 

#Style  = #WS_VISIBLE | #WS_BORDER | #WS_SYSMENU 
#StyleEx  = 0 ;| #WS_EX_OVERLAPPEDWINDOW 

WindowClass.s  = "TestClass" 
wc.WNDCLASSEX 
wc\cbsize  = SizeOf(WNDCLASSEX) 
wc\lpfnWndProc  = @WindowCallback() 
wc\hCursor  = LoadCursor_(0, #IDC_CROSS)
; #IDC_SIZEALL = Size Arrow 
; #IDC_CROSS   = Cross 
wc\hbrBackground  = #COLOR_WINDOW + 1 
wc\lpszClassName  = @WindowClass 
RegisterClassEx_(@wc) 

hWndMain  = CreateWindowEx_(#StyleEx, WindowClass, "Test-Window", #Style, 10, 10, 800, 600, 0, 0, 0, 0) 


       ; // Create TabControl
        
        hTabCntrl =  CreateWindowEx_(0, "systabcontrol32", "", #WS_VISIBLE|#WS_CHILD , 10, 10, 780, 550, hWndMain, #NUL, tab_hinst, #Null)
        
        TC_ITEM.TC_ITEM
        TC_ITEM\Mask=#TCIF_TEXT
        TC_ITEM\pszText=@"Tab 0"
        SendMessage_(hTabCntrl,#TCM_INSERTITEM,0,@TC_ITEM)
                
        TC_ITEM.TC_ITEM
        TC_ITEM\Mask=#TCIF_TEXT
        TC_ITEM\pszText=@"Tab 1"
        SendMessage_(hTabCntrl,#TCM_INSERTITEM,1,@TC_ITEM)
        
        TC_ITEM.TC_ITEM
        TC_ITEM\Mask=#TCIF_TEXT
        TC_ITEM\pszText=@"Tab 2"
        SendMessage_(hTabCntrl,#TCM_INSERTITEM,2,@TC_ITEM)
  
        CreateWindowEx_(0, "Button", "Button on Tab X", #WS_CHILD | #WS_VISIBLE, 50, 50, 200, 24, hTabCntrl, 0, 0, 0) 


ShowWindow_(hWndMain,  #SW_SHOWDEFAULT) 
UpdateWindow_(hWndMain); 

While GetMessage_(msg.MSG, #Null, 0, 0 ) 
  TranslateMessage_(msg) 
  DispatchMessage_(msg) 
Wend

Re: Win32 - How to add controls to TabControl?

Posted: Fri Feb 14, 2014 4:52 pm
by Sparkie
Add a child static control for each tab item. Add individual controls the child static control of the tab you want the control to appear on. Hide/show the static control as the tab selection changes.

Re: Win32 - How to add controls to TabControl?

Posted: Sat Feb 15, 2014 11:55 am
by va!n
Thanks for your fast reply! I have tried this last neight but it seems i am doing something wrong until now.
Today i will try it again, to get it work :P Anyway many thanks for the hint!