Win32 - How to add controls to TabControl?

Windows specific forum
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Win32 - How to add controls to TabControl?

Post 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
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Re: Win32 - How to add controls to TabControl?

Post 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.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Re: Win32 - How to add controls to TabControl?

Post 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!
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Post Reply