home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / TabControl2066305182007.psc / TabControl32 / frmTabControl.frm next >
Text File  |  2007-05-15  |  15KB  |  510 lines

  1. VERSION 5.00
  2. Begin VB.Form frmTabControl 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   8445
  5.    ClientLeft      =   60
  6.    ClientTop       =   450
  7.    ClientWidth     =   10395
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   8445
  10.    ScaleWidth      =   10395
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command21 
  13.       Caption         =   "set Item Size"
  14.       Height          =   450
  15.       Left            =   8535
  16.       TabIndex        =   25
  17.       Top             =   2040
  18.       Width           =   1680
  19.    End
  20.    Begin VB.CommandButton Command20 
  21.       Caption         =   "single line scroll"
  22.       Height          =   315
  23.       Left            =   7455
  24.       TabIndex        =   24
  25.       Top             =   6735
  26.       Width           =   2595
  27.    End
  28.    Begin VB.CommandButton Command19 
  29.       Caption         =   "multiline mode"
  30.       Height          =   330
  31.       Left            =   7440
  32.       TabIndex        =   23
  33.       Top             =   6270
  34.       Width           =   2625
  35.    End
  36.    Begin VB.CommandButton Command18 
  37.       Caption         =   "set tabs to top"
  38.       Height          =   300
  39.       Left            =   7500
  40.       TabIndex        =   22
  41.       Top             =   5100
  42.       Width           =   2550
  43.    End
  44.    Begin VB.CommandButton Command17 
  45.       Caption         =   "set tabs to horizontal"
  46.       Height          =   315
  47.       Left            =   7425
  48.       TabIndex        =   21
  49.       Top             =   5880
  50.       Width           =   2625
  51.    End
  52.    Begin VB.CommandButton Command16 
  53.       Caption         =   "set tabs to vertical"
  54.       Height          =   300
  55.       Left            =   7455
  56.       TabIndex        =   20
  57.       Top             =   5460
  58.       Width           =   2625
  59.    End
  60.    Begin VB.CommandButton Command15 
  61.       Caption         =   "set tabs to bottom"
  62.       Height          =   390
  63.       Left            =   7440
  64.       TabIndex        =   19
  65.       Top             =   4620
  66.       Width           =   2550
  67.    End
  68.    Begin VB.CommandButton Command14 
  69.       Caption         =   "set style tabs"
  70.       Height          =   285
  71.       Left            =   7335
  72.       TabIndex        =   18
  73.       Top             =   4275
  74.       Width           =   2760
  75.    End
  76.    Begin VB.CommandButton Command13 
  77.       Caption         =   "set Style flat buttons"
  78.       Height          =   375
  79.       Left            =   7290
  80.       TabIndex        =   17
  81.       Top             =   3810
  82.       Width           =   2820
  83.    End
  84.    Begin VB.CommandButton Command9 
  85.       Caption         =   "set style buttons"
  86.       Height          =   390
  87.       Left            =   7215
  88.       TabIndex        =   16
  89.       Top             =   3345
  90.       Width           =   2910
  91.    End
  92.    Begin VB.CommandButton Command12 
  93.       Caption         =   "del last tab"
  94.       Height          =   405
  95.       Left            =   9345
  96.       TabIndex        =   15
  97.       Top             =   795
  98.       Width           =   915
  99.    End
  100.    Begin VB.CommandButton Command11 
  101.       Caption         =   "get bottom tab"
  102.       Height          =   390
  103.       Left            =   7245
  104.       TabIndex        =   14
  105.       Top             =   2940
  106.       Width           =   1470
  107.    End
  108.    Begin VB.CommandButton Command10 
  109.       Caption         =   "getRowCount"
  110.       Height          =   420
  111.       Left            =   7245
  112.       TabIndex        =   13
  113.       Top             =   2475
  114.       Width           =   1155
  115.    End
  116.    Begin VB.Timer Timer1 
  117.       Interval        =   10
  118.       Left            =   9690
  119.       Top             =   1455
  120.    End
  121.    Begin VB.PictureBox Picture1 
  122.       BeginProperty Font 
  123.          Name            =   "MS Sans Serif"
  124.          Size            =   13.5
  125.          Charset         =   0
  126.          Weight          =   700
  127.          Underline       =   0   'False
  128.          Italic          =   0   'False
  129.          Strikethrough   =   0   'False
  130.       EndProperty
  131.       Height          =   1620
  132.       Left            =   3150
  133.       ScaleHeight     =   1560
  134.       ScaleWidth      =   1860
  135.       TabIndex        =   12
  136.       Top             =   4515
  137.       Width           =   1920
  138.    End
  139.    Begin VB.CommandButton Command7 
  140.       Caption         =   "Set Padding"
  141.       Height          =   330
  142.       Left            =   8475
  143.       TabIndex        =   11
  144.       Top             =   2520
  145.       Width           =   1845
  146.    End
  147.    Begin VB.TextBox txtCY 
  148.       Height          =   285
  149.       Left            =   8940
  150.       TabIndex        =   10
  151.       Text            =   "16"
  152.       Top             =   1725
  153.       Width           =   645
  154.    End
  155.    Begin VB.TextBox txtCX 
  156.       Height          =   345
  157.       Left            =   8940
  158.       TabIndex        =   8
  159.       Text            =   "64"
  160.       Top             =   1275
  161.       Width           =   690
  162.    End
  163.    Begin VB.CommandButton Command8 
  164.       Caption         =   "deselect all"
  165.       Height          =   435
  166.       Left            =   7080
  167.       TabIndex        =   6
  168.       Top             =   1890
  169.       Width           =   1125
  170.    End
  171.    Begin VB.CommandButton Command6 
  172.       Caption         =   "select tab 2"
  173.       Height          =   510
  174.       Left            =   6945
  175.       TabIndex        =   5
  176.       Top             =   1305
  177.       Width           =   1380
  178.    End
  179.    Begin VB.CommandButton Command5 
  180.       Caption         =   "del selected tab"
  181.       Height          =   465
  182.       Left            =   7905
  183.       TabIndex        =   4
  184.       Top             =   765
  185.       Width           =   1350
  186.    End
  187.    Begin VB.CommandButton Command4 
  188.       Caption         =   "clear"
  189.       Height          =   540
  190.       Left            =   7065
  191.       TabIndex        =   3
  192.       Top             =   750
  193.       Width           =   780
  194.    End
  195.    Begin VB.CommandButton Command3 
  196.       Caption         =   "Selected tab"
  197.       Height          =   450
  198.       Left            =   8820
  199.       TabIndex        =   2
  200.       Top             =   225
  201.       Width           =   1260
  202.    End
  203.    Begin VB.CommandButton Command2 
  204.       Caption         =   "add tab"
  205.       Height          =   510
  206.       Left            =   7860
  207.       TabIndex        =   1
  208.       Top             =   150
  209.       Width           =   795
  210.    End
  211.    Begin VB.CommandButton Command1 
  212.       Caption         =   "tab count"
  213.       Height          =   510
  214.       Left            =   6975
  215.       TabIndex        =   0
  216.       Top             =   150
  217.       Width           =   810
  218.    End
  219.    Begin VB.Label Label2 
  220.       Caption         =   "cy"
  221.       Height          =   210
  222.       Left            =   8460
  223.       TabIndex        =   9
  224.       Top             =   1635
  225.       Width           =   360
  226.    End
  227.    Begin VB.Label Label1 
  228.       Caption         =   "cx"
  229.       Height          =   300
  230.       Left            =   8445
  231.       TabIndex        =   7
  232.       Top             =   1320
  233.       Width           =   420
  234.    End
  235. End
  236. Attribute VB_Name = "frmTabControl"
  237. Attribute VB_GlobalNameSpace = False
  238. Attribute VB_Creatable = False
  239. Attribute VB_PredeclaredId = True
  240. Attribute VB_Exposed = False
  241. ' ======================================================================================
  242. ' Name:     frmTabControl.frm
  243. ' Author:   Joshy Francis (joshylogicss@yahoo.co.in)
  244. ' Date:     14 May 2007
  245. '
  246. ' Requires: None
  247. '
  248. ' Copyright ⌐ 2000-2007 Joshy Francis
  249. ' --------------------------------------------------------------------------------------
  250. 'The implementation of TabControl in VB.All by API.
  251. 'you can freely use this code anywhere.But I wants you must include the copyright info
  252. 'All functions in this module written by me.
  253. ' --------------------------------------------------------------------------------------
  254. 'No updates.This is the first version.
  255. 'I Just included comments on every important lines.Sorry for my bad english.
  256. 'I developed this program by converting the C Documentation to VB and experiments with VB.
  257. 'You can improve this program by your experiments.I didn't done all parts of the
  258. 'TabControl.
  259.  
  260. Option Explicit
  261. Dim PrevClickedItem As Long
  262.  
  263. Private Sub Command1_Click()
  264. MsgBox GetCount
  265. End Sub
  266.  
  267. Private Sub Command10_Click()
  268. MsgBox GetRowCount
  269. End Sub
  270.  
  271. Private Sub Command11_Click()
  272. Dim bt As Long
  273. bt = GetBottomTab
  274. MsgBox GetText(bt), , bt
  275. End Sub
  276.  
  277. Private Sub Command12_Click()
  278. DelTab GetCount - 1
  279. SelTab GetCount - 1
  280. End Sub
  281.  
  282. Private Sub Command13_Click()
  283. 'Changes the Style of Tabcontrol
  284. Dim stl As Long
  285.     stl = GetWindowLong(Wnd, GWL_STYLE)
  286. If (stl And TCS_BUTTONS) = TCS_BUTTONS Then
  287. Else
  288.     stl = stl Or TCS_BUTTONS
  289. End If
  290. If (stl And TCS_FLATBUTTONS) = TCS_FLATBUTTONS Then
  291. Else
  292.     stl = stl Or TCS_FLATBUTTONS
  293. End If
  294.     SetWindowLong Wnd, GWL_STYLE, stl
  295.  
  296. End Sub
  297.  
  298. Private Sub Command14_Click()
  299. 'Changes the Style of Tabcontrol
  300. Dim stl As Long
  301.     stl = GetWindowLong(Wnd, GWL_STYLE)
  302. If (stl And TCS_BUTTONS) = TCS_BUTTONS Then
  303.     stl = stl And Not TCS_BUTTONS
  304. End If
  305. If (stl And TCS_FLATBUTTONS) = TCS_FLATBUTTONS Then
  306.     stl = stl And Not TCS_FLATBUTTONS
  307. End If
  308.     SetWindowLong Wnd, GWL_STYLE, stl
  309. End Sub
  310.  
  311. Private Sub Command15_Click()
  312. 'Changes the Style of Tabcontrol
  313. Dim stl As Long
  314.     stl = GetWindowLong(Wnd, GWL_STYLE)
  315. If (stl And TCS_BOTTOM) = TCS_BOTTOM Then
  316. Else
  317.     stl = stl Or TCS_BOTTOM
  318. End If
  319.     SetWindowLong Wnd, GWL_STYLE, stl
  320. End Sub
  321.  
  322. Private Sub Command16_Click()
  323. 'Changes the Style of Tabcontrol
  324. Dim stl As Long
  325.     stl = GetWindowLong(Wnd, GWL_STYLE)
  326. If (stl And TCS_VERTICAL) = TCS_VERTICAL Then
  327. Else
  328.     stl = stl Or TCS_VERTICAL
  329. End If
  330.     SetWindowLong Wnd, GWL_STYLE, stl
  331. End Sub
  332.  
  333. Private Sub Command17_Click()
  334. 'Changes the Style of Tabcontrol
  335. Dim stl As Long
  336.     stl = GetWindowLong(Wnd, GWL_STYLE)
  337. If (stl And TCS_VERTICAL) = TCS_VERTICAL Then
  338.     stl = stl And Not TCS_VERTICAL
  339. End If
  340.     SetWindowLong Wnd, GWL_STYLE, stl
  341. End Sub
  342.  
  343. Private Sub Command18_Click()
  344. 'Changes the Style of Tabcontrol
  345. Dim stl As Long
  346.     stl = GetWindowLong(Wnd, GWL_STYLE)
  347. If (stl And TCS_BOTTOM) = TCS_BOTTOM Then
  348.     stl = stl And Not TCS_BOTTOM
  349. End If
  350.     SetWindowLong Wnd, GWL_STYLE, stl
  351. End Sub
  352.  
  353. Private Sub Command19_Click()
  354. 'Changes the Style of Tabcontrol
  355. Dim stl As Long
  356.     stl = GetWindowLong(Wnd, GWL_STYLE)
  357. If (stl And TCS_MULTILINE) = TCS_MULTILINE Then
  358. Else
  359.     stl = stl Or TCS_MULTILINE
  360. End If
  361.     SetWindowLong Wnd, GWL_STYLE, stl
  362.  
  363. End Sub
  364.  
  365. Private Sub Command2_Click()
  366. 'Add new tab
  367. Dim c As Long
  368.     c = GetCount
  369. Dim str As String
  370.     str = "Tab " & c
  371. AddTab c, str
  372.     SelTab c
  373. End Sub
  374.  
  375.  
  376. Private Sub Command20_Click()
  377. 'Changes the Style of Tabcontrol
  378. Dim stl As Long
  379.     stl = GetWindowLong(Wnd, GWL_STYLE)
  380. If (stl And TCS_MULTILINE) = TCS_MULTILINE Then
  381.     stl = stl And Not TCS_MULTILINE
  382. End If
  383.     SetWindowLong Wnd, GWL_STYLE, stl
  384. End Sub
  385.  
  386. Private Sub Command21_Click()
  387. 'Sets the ItemSize
  388. Dim cx As Integer, cy As Integer
  389.     cx = Val(txtCX)
  390.     cy = Val(txtCY)
  391. SetItemSIze cx, cy
  392.     txtCX = cx
  393.     txtCY = cy
  394. End Sub
  395.  
  396. Private Sub Command3_Click()
  397. Dim c As Long
  398.     c = GetSelected
  399. MsgBox GetText(c), , c
  400. End Sub
  401.  
  402. Private Sub Command4_Click()
  403. ClearTabs
  404. End Sub
  405.  
  406. Private Sub Command5_Click()
  407. DelTab GetSelected
  408. End Sub
  409.  
  410. Private Sub Command6_Click()
  411. SelTab 1
  412. End Sub
  413.  
  414. Private Sub Command7_Click()
  415. SetPadding Val(txtCX), Val(txtCY)
  416. End Sub
  417.  
  418. Private Sub Command8_Click()
  419. DeselectAll
  420. End Sub
  421.  
  422. Private Sub Command9_Click()
  423. Dim stl As Long
  424.     stl = GetWindowLong(Wnd, GWL_STYLE)
  425. If (stl And TCS_BUTTONS) = TCS_BUTTONS Then
  426. Else
  427.     stl = stl Or TCS_BUTTONS
  428. End If
  429. If (stl And TCS_FLATBUTTONS) = TCS_FLATBUTTONS Then
  430.     stl = stl And Not TCS_FLATBUTTONS
  431. End If
  432.     SetWindowLong Wnd, GWL_STYLE, stl
  433. End Sub
  434.  
  435. Private Sub Form_Load()
  436. 'Very simple way to create the Tabcontrol
  437. CreateTabControl hwnd
  438. End Sub
  439.  
  440. Private Sub Form_Unload(Cancel As Integer)
  441. 'Unload the tabcontrol
  442. DestroyTabControl
  443. End Sub
  444. Sub TabClicked(ByVal PrevTab As Long)
  445. 'The Main Event
  446. 'I did not included the subclassing.Because I found this way is very safe and useful.
  447.  
  448.     Dim tr As RECT, cR As RECT, stl As Long, RC As Long, i As Long, c As RECT, bt As Long
  449. On Error Resume Next
  450.     Picture1.BorderStyle = 1
  451.         GetClientRect Wnd, cR
  452.             i = GetSelected
  453.     tr = GetTabRect(i)
  454. '        cR.Top = cR.Top + tR.Bottom
  455.         cR.Top = tr.Bottom
  456.     stl = GetWindowLong(Wnd, GWL_STYLE)
  457.     RC = GetRowCount
  458.         If (stl And TCS_SCROLLOPPOSITE) = TCS_SCROLLOPPOSITE And RC > 1 Then
  459.             cR.Bottom = cR.Bottom - tr.Bottom
  460. '            If (tR.Top - tR.Bottom <= 0) Then 'And ((tR.Bottom / tR.Top) > 2) Then
  461. '                    If tR.Top < tR.Bottom Then RC = 2
  462. '''                    If tR.Top < tR.Bottom Then RC = 1
  463. '''                For stl = 1 To RC
  464. '''                    cR.Bottom = cR.Bottom - tR.Bottom
  465. '''                Next
  466. '                    cR.Bottom = cR.Bottom - (tR.Bottom * (RC - 1))
  467. '            End If
  468.                 bt = GetBottomTab
  469.             c = GetTabRect(bt)
  470.                 If bt = 0 Then
  471.                     cR.Bottom = cR.Bottom - tr.Bottom
  472.                 Else
  473.                    cR.Bottom = tr.Bottom - c.Bottom
  474.                 End If
  475.         ElseIf (stl And TCS_BUTTONS) = TCS_BUTTONS Then
  476.             cR.Bottom = cR.Bottom - tr.Bottom
  477.                 If RC > 1 Then
  478.                     c = GetTabRect(GetCount - 1)
  479.                     cR.Top = c.Bottom
  480.                     cR.Bottom = cR.Bottom + tr.Bottom
  481.                     cR.Bottom = cR.Bottom - c.Bottom
  482.                 End If
  483.         ElseIf (stl And TCS_BOTTOM) = TCS_BOTTOM Then
  484.             MoveWindow Picture1.hwnd, 0, 0, 0, 0, 1
  485.             Exit Sub
  486.         ElseIf (stl And TCS_VERTICAL) = TCS_VERTICAL Then
  487.             MoveWindow Picture1.hwnd, 0, 0, 0, 0, 1
  488.             Exit Sub
  489.         Else
  490.             cR.Bottom = cR.Bottom - tr.Bottom
  491.                 If RC > 1 Then
  492.                     c = GetTabRect(GetCount - 1)
  493.                     cR.Top = tr.Bottom
  494.                 End If
  495.         End If
  496. MoveWindow Picture1.hwnd, cR.Left + 5, cR.Top + 5, cR.Right - 5, cR.Bottom - 5, 1
  497.     Picture1.Cls
  498.         Picture1.Print GetText(i)
  499.  
  500. End Sub
  501. Private Sub Timer1_Timer()
  502. 'Timer Used to TabEvent
  503. Dim i As Long
  504.     i = GetSelected
  505. If PrevClickedItem <> i Then
  506.     TabClicked PrevClickedItem
  507.         PrevClickedItem = i
  508. End If
  509. End Sub
  510.