home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / 3dtabs / win.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-08  |  20.0 KB  |  499 lines

  1. VERSION 2.00
  2. Begin Form win 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Resizable Window"
  5.    ClientHeight    =   5010
  6.    ClientLeft      =   1395
  7.    ClientTop       =   1740
  8.    ClientWidth     =   7215
  9.    Height          =   5700
  10.    Icon            =   WIN.FRX:0000
  11.    KeyPreview      =   -1  'True
  12.    Left            =   1335
  13.    LinkTopic       =   "Form2"
  14.    ScaleHeight     =   5010
  15.    ScaleWidth      =   7215
  16.    Top             =   1110
  17.    Width           =   7335
  18.    Begin PictureBox tabbox 
  19.       BackColor       =   &H00C0C0C0&
  20.       BorderStyle     =   0  'None
  21.       Height          =   495
  22.       Left            =   120
  23.       ScaleHeight     =   33
  24.       ScaleMode       =   3  'Pixel
  25.       ScaleWidth      =   417
  26.       TabIndex        =   0
  27.       Top             =   0
  28.       Width           =   6255
  29.       Begin PictureBox invbox 
  30.          AutoRedraw      =   -1  'True
  31.          BackColor       =   &H00C0C0C0&
  32.          BorderStyle     =   0  'None
  33.          Height          =   255
  34.          Left            =   240
  35.          ScaleHeight     =   17
  36.          ScaleMode       =   3  'Pixel
  37.          ScaleWidth      =   81
  38.          TabIndex        =   1
  39.          Top             =   120
  40.          Visible         =   0   'False
  41.          Width           =   1215
  42.       End
  43.    End
  44.    Begin SSFrame f3d 
  45.       Font3D          =   3  'Inset w/light shading
  46.       ForeColor       =   &H00000000&
  47.       Height          =   3615
  48.       Index           =   5
  49.       Left            =   360
  50.       TabIndex        =   7
  51.       Tag             =   "3d Containers"
  52.       Top             =   960
  53.       Width           =   6015
  54.       Begin TextBox t 
  55.          BackColor       =   &H00C0C0C0&
  56.          BorderStyle     =   0  'None
  57.          FontBold        =   0   'False
  58.          FontItalic      =   0   'False
  59.          FontName        =   "MS Sans Serif"
  60.          FontSize        =   8.25
  61.          FontStrikethru  =   0   'False
  62.          FontUnderline   =   0   'False
  63.          Height          =   2655
  64.          Index           =   5
  65.          Left            =   360
  66.          MultiLine       =   -1  'True
  67.          ScrollBars      =   2  'Vertical
  68.          TabIndex        =   14
  69.          Top             =   720
  70.          Width           =   5415
  71.       End
  72.       Begin Label l 
  73.          BackStyle       =   0  'Transparent
  74.          Caption         =   "V. A note on 3d effects."
  75.          FontBold        =   -1  'True
  76.          FontItalic      =   0   'False
  77.          FontName        =   "MS Sans Serif"
  78.          FontSize        =   12
  79.          FontStrikethru  =   0   'False
  80.          FontUnderline   =   0   'False
  81.          Height          =   375
  82.          Index           =   3
  83.          Left            =   240
  84.          TabIndex        =   20
  85.          Top             =   240
  86.          Width           =   3855
  87.       End
  88.    End
  89.    Begin SSFrame f3d 
  90.       Font3D          =   3  'Inset w/light shading
  91.       ForeColor       =   &H00000000&
  92.       Height          =   3615
  93.       Index           =   6
  94.       Left            =   720
  95.       TabIndex        =   8
  96.       Tag             =   "Dummy"
  97.       Top             =   840
  98.       Width           =   6015
  99.       Begin TextBox t 
  100.          BackColor       =   &H00C0C0C0&
  101.          BorderStyle     =   0  'None
  102.          FontBold        =   0   'False
  103.          FontItalic      =   0   'False
  104.          FontName        =   "MS Sans Serif"
  105.          FontSize        =   8.25
  106.          FontStrikethru  =   0   'False
  107.          FontUnderline   =   0   'False
  108.          Height          =   2655
  109.          Index           =   6
  110.          Left            =   480
  111.          MultiLine       =   -1  'True
  112.          ScrollBars      =   2  'Vertical
  113.          TabIndex        =   15
  114.          Top             =   840
  115.          Width           =   5415
  116.       End
  117.       Begin Label l 
  118.          BackStyle       =   0  'Transparent
  119.          Caption         =   "VI."
  120.          FontBold        =   -1  'True
  121.          FontItalic      =   0   'False
  122.          FontName        =   "MS Sans Serif"
  123.          FontSize        =   12
  124.          FontStrikethru  =   0   'False
  125.          FontUnderline   =   0   'False
  126.          Height          =   375
  127.          Index           =   4
  128.          Left            =   240
  129.          TabIndex        =   21
  130.          Top             =   240
  131.          Width           =   3855
  132.       End
  133.    End
  134.    Begin SSFrame f3d 
  135.       Font3D          =   3  'Inset w/light shading
  136.       ForeColor       =   &H00000000&
  137.       Height          =   3615
  138.       Index           =   0
  139.       Left            =   1080
  140.       TabIndex        =   2
  141.       Tag             =   "Intro"
  142.       Top             =   1800
  143.       Width           =   6015
  144.       Begin TextBox t 
  145.          BackColor       =   &H00C0C0C0&
  146.          BorderStyle     =   0  'None
  147.          FontBold        =   0   'False
  148.          FontItalic      =   0   'False
  149.          FontName        =   "MS Sans Serif"
  150.          FontSize        =   8.25
  151.          FontStrikethru  =   0   'False
  152.          FontUnderline   =   0   'False
  153.          Height          =   3255
  154.          Index           =   0
  155.          Left            =   120
  156.          MultiLine       =   -1  'True
  157.          ScrollBars      =   2  'Vertical
  158.          TabIndex        =   9
  159.          Top             =   240
  160.          Width           =   5655
  161.       End
  162.    End
  163.    Begin SSFrame f3d 
  164.       Font3D          =   3  'Inset w/light shading
  165.       ForeColor       =   &H00000000&
  166.       Height          =   3615
  167.       Index           =   1
  168.       Left            =   120
  169.       TabIndex        =   3
  170.       Tag             =   "Step 1"
  171.       Top             =   480
  172.       Width           =   6015
  173.       Begin TextBox t 
  174.          BackColor       =   &H00C0C0C0&
  175.          BorderStyle     =   0  'None
  176.          FontBold        =   0   'False
  177.          FontItalic      =   0   'False
  178.          FontName        =   "MS Sans Serif"
  179.          FontSize        =   8.25
  180.          FontStrikethru  =   0   'False
  181.          FontUnderline   =   0   'False
  182.          Height          =   2655
  183.          Index           =   1
  184.          Left            =   480
  185.          MultiLine       =   -1  'True
  186.          ScrollBars      =   2  'Vertical
  187.          TabIndex        =   17
  188.          Top             =   720
  189.          Width           =   5415
  190.       End
  191.       Begin Label l 
  192.          BackStyle       =   0  'Transparent
  193.          Caption         =   "I. Creating the controls."
  194.          FontBold        =   -1  'True
  195.          FontItalic      =   0   'False
  196.          FontName        =   "MS Sans Serif"
  197.          FontSize        =   12
  198.          FontStrikethru  =   0   'False
  199.          FontUnderline   =   0   'False
  200.          Height          =   375
  201.          Index           =   2
  202.          Left            =   240
  203.          TabIndex        =   11
  204.          Top             =   240
  205.          Width           =   3855
  206.       End
  207.    End
  208.    Begin SSFrame f3d 
  209.       Font3D          =   3  'Inset w/light shading
  210.       ForeColor       =   &H00000000&
  211.       Height          =   3615
  212.       Index           =   2
  213.       Left            =   480
  214.       TabIndex        =   4
  215.       Tag             =   "Step 2"
  216.       Top             =   960
  217.       Width           =   6015
  218.       Begin TextBox t 
  219.          BackColor       =   &H00C0C0C0&
  220.          BorderStyle     =   0  'None
  221.          FontBold        =   0   'False
  222.          FontItalic      =   0   'False
  223.          FontName        =   "MS Sans Serif"
  224.          FontSize        =   8.25
  225.          FontStrikethru  =   0   'False
  226.          FontUnderline   =   0   'False
  227.          Height          =   2655
  228.          Index           =   2
  229.          Left            =   480
  230.          MultiLine       =   -1  'True
  231.          ScrollBars      =   2  'Vertical
  232.          TabIndex        =   10
  233.          Top             =   720
  234.          Width           =   5415
  235.       End
  236.       Begin Label l 
  237.          BackStyle       =   0  'Transparent
  238.          Caption         =   "II. Adding the code."
  239.          FontBold        =   -1  'True
  240.          FontItalic      =   0   'False
  241.          FontName        =   "MS Sans Serif"
  242.          FontSize        =   12
  243.          FontStrikethru  =   0   'False
  244.          FontUnderline   =   0   'False
  245.          Height          =   375
  246.          Index           =   6
  247.          Left            =   240
  248.          TabIndex        =   16
  249.          Top             =   240
  250.          Width           =   3855
  251.       End
  252.    End
  253.    Begin SSFrame f3d 
  254.       Font3D          =   3  'Inset w/light shading
  255.       ForeColor       =   &H00000000&
  256.       Height          =   3615
  257.       Index           =   3
  258.       Left            =   600
  259.       TabIndex        =   5
  260.       Tag             =   "Step 3"
  261.       Top             =   960
  262.       Width           =   6015
  263.       Begin TextBox t 
  264.          BackColor       =   &H00C0C0C0&
  265.          BorderStyle     =   0  'None
  266.          FontBold        =   0   'False
  267.          FontItalic      =   0   'False
  268.          FontName        =   "MS Sans Serif"
  269.          FontSize        =   8.25
  270.          FontStrikethru  =   0   'False
  271.          FontUnderline   =   0   'False
  272.          Height          =   2655
  273.          Index           =   3
  274.          Left            =   480
  275.          MultiLine       =   -1  'True
  276.          ScrollBars      =   2  'Vertical
  277.          TabIndex        =   12
  278.          Top             =   720
  279.          Width           =   5415
  280.       End
  281.       Begin Label l 
  282.          BackStyle       =   0  'Transparent
  283.          Caption         =   "III. Set additional properties."
  284.          FontBold        =   -1  'True
  285.          FontItalic      =   0   'False
  286.          FontName        =   "MS Sans Serif"
  287.          FontSize        =   12
  288.          FontStrikethru  =   0   'False
  289.          FontUnderline   =   0   'False
  290.          Height          =   375
  291.          Index           =   0
  292.          Left            =   240
  293.          TabIndex        =   18
  294.          Top             =   240
  295.          Width           =   3855
  296.       End
  297.    End
  298.    Begin SSFrame f3d 
  299.       Font3D          =   3  'Inset w/light shading
  300.       ForeColor       =   &H00000000&
  301.       Height          =   3615
  302.       Index           =   4
  303.       Left            =   360
  304.       TabIndex        =   6
  305.       Tag             =   "Step 4"
  306.       Top             =   720
  307.       Width           =   6015
  308.       Begin TextBox t 
  309.          BackColor       =   &H00C0C0C0&
  310.          BorderStyle     =   0  'None
  311.          FontBold        =   0   'False
  312.          FontItalic      =   0   'False
  313.          FontName        =   "MS Sans Serif"
  314.          FontSize        =   8.25
  315.          FontStrikethru  =   0   'False
  316.          FontUnderline   =   0   'False
  317.          Height          =   2655
  318.          Index           =   4
  319.          Left            =   360
  320.          MultiLine       =   -1  'True
  321.          ScrollBars      =   2  'Vertical
  322.          TabIndex        =   13
  323.          Top             =   720
  324.          Width           =   5415
  325.       End
  326.       Begin Label l 
  327.          BackStyle       =   0  'Transparent
  328.          Caption         =   "IV. That's it!"
  329.          FontBold        =   -1  'True
  330.          FontItalic      =   0   'False
  331.          FontName        =   "MS Sans Serif"
  332.          FontSize        =   12
  333.          FontStrikethru  =   0   'False
  334.          FontUnderline   =   0   'False
  335.          Height          =   375
  336.          Index           =   1
  337.          Left            =   240
  338.          TabIndex        =   19
  339.          Top             =   240
  340.          Width           =   3855
  341.       End
  342.    End
  343.    Begin Menu zfile 
  344.       Caption         =   "&File"
  345.    End
  346.    Begin Menu zedit 
  347.       Caption         =   "&Edit"
  348.    End
  349.    Begin Menu zopt 
  350.       Caption         =   "&Options"
  351.    End
  352.    Begin Menu z1 
  353.       Caption         =   "Dummy"
  354.    End
  355.    Begin Menu z2 
  356.       Caption         =   "Dummy"
  357.    End
  358.    Begin Menu z3 
  359.       Caption         =   "Dummy"
  360.    End
  361. Option Explicit
  362. Const WM_USER = &H400
  363. Const EM_GETRECT = WM_USER + 2
  364. Const EM_SETRECT = WM_USER + 3
  365. Dim i%, numpages%, r%
  366. Dim page() As control
  367. Dim tb As TabData
  368. Dim nl$
  369. Declare Function SendMessage& Lib "User" (ByVal hWnd%, ByVal wMsg%, ByVal wParam%, lParam As Any)
  370. Sub Form_Load ()
  371. nl = Chr$(13) & Chr$(10)
  372. Initialize
  373. LoadText
  374. End Sub
  375. Sub Form_Resize ()
  376. Dim i%
  377. If windowstate <> 1 Then
  378.     TabResize Me, -1, -1, tabbox, invbox, page(), tb
  379.     ResizeTextboxes
  380. End If
  381. End Sub
  382. Sub Initialize ()
  383. numpages = 6            'set to highest index (total-1)
  384. '===create an array of controls =========================
  385. ReDim page(0 To numpages)
  386. For i = 0 To numpages: Set page(i) = f3d(i): Next
  387. '===fill in the fields of the struct=====================
  388. tb.num = numpages       'number of tabs
  389. tb.active = 0           'initial focus
  390. tb.cols = 4             'number of tabs in each row
  391. tb.orient = tabsup      '0 = up, 1 = down
  392. tb.left = 0
  393. tb.top = 0
  394. tb.Width = 0
  395. tb.Height = 0
  396. 'for resizable forms, set a minimum for a page h,w
  397. tb.minwidth = 4095
  398. tb.minheight = 2535
  399. DefineControl Me, tabbox, invbox, page(), tb
  400. End Sub
  401. Sub LoadText ()
  402. Dim s$
  403. s$ = "   This sample shows how to create a tab control on a sizable Form."
  404. s = s & " The initial width of the window and the tab control is still determined by the design-time size of Page(0), but if the window is resized, the tab control and each of the pages will be resized to fit the window."
  405. s = s & nl & nl
  406. s = s & "   The window can be maximized and minimized."
  407. s = s & " If the window is resized too small to allow display of the tab captions, the window size is reset to a minimum size."
  408. s = s & " The default minimum width is the width needed for the display of the captions; the default minimum height is set (in TabResize()) to tab control height + 20 pixels."
  409. s = s & " You may specify larger sizes by setting tb.minwidth and tb.minheight before calling DefineControl()."
  410. s = s & nl & nl
  411. s = s & "   The tab control will resize the tabs and pages(), but it does not resize the controls on each page()."
  412. s = s & " You must do this in response to one of the resize events."
  413. s = s & " This sample uses textboxes for the display of text so that a scrolling functionality can be enabled as needed, and it resizes them in response to form_resize."
  414. t(0) = s
  415. s = "   The tabbox and invbox are exactly the same as in the first sample."
  416. s = s & " This sample uses 3D frames instead of pictureboxes for the pages, and a single textbox in place of multiple labels on each page(). The 3d frames are named f3d(0) - f3d(6)."
  417. s = s & " The textboxes are named t(0) - t(6)."
  418. s = s & " Some of the pages still contain some labels."
  419. s = s & " There are 7 pages on this sample, which produces one blank (unused) tab."
  420. s = s & nl & nl & "   To create a sizable window, set the borderstyle = 2."
  421. s = s & " Create controls on each page with an eye toward how they will be affected by resizing."
  422. s = s & " A dummy menu was added to the form to check the alignment of the tabs when the menu wraps."
  423. s = s & " The solution to this problem was sloppy (it simply resizes the form again) and if there is no better solution that can be implemented from within VB, there are at least 2 possible workarounds."
  424. s = s & nl & "     1. Use a message subclass control to intercept WM_GETMINMAXINFO."
  425. s = s & nl & "     2. Set the tb.minwidth to a size that accomodates all the menu text."
  426. t(1) = s
  427. s = " The code is similar to the code in the first sample with a few additions."
  428. s = s & nl & nl & "   1. Add the following lines to the general declarations section:"
  429. s = s & nl & nl & "       Dim page() As Control"
  430. s = s & nl & "       Dim tb As TabData"
  431. s = s & nl & nl & "   2. Add the following lines to the form_load procedure (note that in the samples this code is actually in the procedure 'Initialize()' called from form_load):"
  432. s = s & nl & nl & "       Redim page(0 To 6)"
  433. s = s & nl & "       For i = 0 to 6: Set page(i) = f3d(i): Next"
  434. s = s & nl & "       tb.num = 6"
  435. s = s & nl & "       tb.active = 0"
  436. s = s & nl & "       tb.cols = 4"
  437. s = s & nl & "       tb.orient = 0"
  438. s = s & nl & nl & "   (Note the following lines may be necessary if you have multiple instances of the tab control and the tb.structure is not being properly initialized to 0.  Note also that all 4 must be 0 or it will be assumed you are creating a 'nonaligned' tab and the form will not be fitted to the tab. See sample 3 for an example of this type.)"
  439. s = s & nl & "       tb.left = 0"
  440. s = s & nl & "       tb.top = 0"
  441. s = s & nl & "       tb.width = 0"
  442. s = s & nl & "       tb.height = 0"
  443. s = s & nl & "   (the following lines are optional but should be used if you have a menu and wish to prevent wrapping)"
  444. s = s & nl & "       tb.minwidth = (some value)"
  445. s = s & nl & "       tb.minheight = (some value)"
  446. s = s & nl & nl & "       DefineControl Me, tabbox, invbox, page(), tb"
  447. s = s & nl & nl & "   3. Add the following line to the form_resize event:"
  448. s = s & nl & "       If windowstate <> 1 then TabResize Me, -1, -1, tabbox, invbox, page(), tb"
  449. s = s & nl & nl & "   4. Add the following to tabbox_MouseUp:"
  450. s = s & nl & "       TabClick Button, X, Y, tabbox, page(), tb"
  451. s = s & nl & nl & "   5. Add the following to tabbox_Paint:"
  452. s = s & nl & "       DrawText tabbox, page(), tb"
  453. t(2) = s
  454. s = "   Size page(0) to the size to which you wish all the other page()s and the tab control to be initialized when the form is loaded."
  455. s = s & nl & nl & "   Again, set the Font properties of the tabbox to those you wish the captions to have."
  456. s = s & nl & nl & "   Add the following line to form_load before calling DefineControl() if you wish the tabs to be at the bottom of the pages:      "
  457. s = s & nl & "       tb.orient = 1"
  458. s = s & nl & nl & "   Add the following line to form_KeyDown if you wish to toggle through the pages:"
  459. s = s & nl & "       If KeyCode = (some value) Then PageNext"
  460. s = s & nl & "       If KeyCode = (some value) Then PagePrev"
  461. t(3) = s
  462. s = "   The resizing of the window is handled by TabResize(). It is not a good idea to manipulate the form size from within this event and the routine uses flags to keep from redrawing the tabs and text more than once."
  463. s = s & nl & nl & " The refresh rate is nontheless poor, and as mentioned previously, it must resize the form twice if a menu wraps."
  464. s = s & nl & nl & " I'm sure this section could be improved, but I just haven't hit on it. All in all, the resizable window is not the optimal use for this control."
  465. s = s & nl & nl & " That's it. The final sample includes some controls to manipulate the tabs at runtime."
  466. t(4) = s
  467. s = " The tab control assumes one pixel shading outline in white and dark grey around the inside of the container in which it sits."
  468. s = s & nl & nl & " The first sample uses line controls to shade the form's borders for convenience."
  469. s = s & nl & nl & " This sample omitted the shading to avoid having to write code to move and resize the line controls."
  470. s = s & nl & nl & " If you place the control in a 3d container such as a 3d panel, you may need to modify the DrawTabs routine to get the shading lines to match up."
  471. s = s & nl & nl & " The third sample uses a 3d panel, but the size of the tab control must be specified at designtime and it is not resizable."
  472. t(5) = s
  473. End Sub
  474. Sub ResizeTextboxes ()
  475. Dim w%, h%, rc As RECT
  476. w% = f3d(0).Width - 360
  477. h% = f3d(0).Height - 360
  478. For i = 0 To numpages: t(i).Visible = 0: Next
  479.     t(0).Move 120, 240, w, h
  480. w = w - 360: h = h - 480
  481. For i = 1 To numpages: t(i).Move 480, 720, w, h: Next
  482. 'this just buts the text in a little off the scroll bar
  483. r = SendMessage(t(0).hWnd, EM_GETRECT, 0, rc)
  484. rc.right = rc.right - 8
  485. r = SendMessage(t(0).hWnd, EM_SETRECT, 0, rc)
  486. r = SendMessage(t(1).hWnd, EM_GETRECT, 0, rc)
  487. rc.right = rc.right - 8
  488. For i = 1 To numpages
  489. r = SendMessage(t(i).hWnd, EM_SETRECT, 0, rc)
  490. For i = 0 To numpages: t(i).Visible = -1: Next
  491. End Sub
  492. Sub tabbox_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
  493. TabClick Button, X, Y, tabbox, page(), tb
  494. End Sub
  495. Sub tabbox_Paint ()
  496. DrawText tabbox, page(), tb
  497. Debug.Print "call DrawText   from tabbox_Paint========="
  498. End Sub
  499.