home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / message / msgboxmw / mbdmain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-04-03  |  19.9 KB  |  619 lines

  1. VERSION 2.00
  2. Begin Form MBDMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Message Box Designer"
  6.    ClientHeight    =   6315
  7.    ClientLeft      =   1065
  8.    ClientTop       =   510
  9.    ClientWidth     =   7770
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "MS Sans Serif"
  13.    FontSize        =   8.25
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   -1  'True
  16.    Height          =   6720
  17.    Icon            =   MBDMAIN.FRX:0000
  18.    Left            =   1005
  19.    LinkTopic       =   "Form1"
  20.    MaxButton       =   0   'False
  21.    ScaleHeight     =   6315
  22.    ScaleWidth      =   7770
  23.    Top             =   165
  24.    Width           =   7890
  25.    Begin SSFrame Frame3D5 
  26.       Caption         =   "Data"
  27.       Font3D          =   3  'Inset w/light shading
  28.       ForeColor       =   &H00000000&
  29.       Height          =   2985
  30.       Left            =   180
  31.       TabIndex        =   16
  32.       Top             =   180
  33.       Width           =   7395
  34.       Begin PictureBox Picture1 
  35.          BackColor       =   &H00C0C0C0&
  36.          BorderStyle     =   0  'None
  37.          Height          =   285
  38.          Left            =   6975
  39.          ScaleHeight     =   285
  40.          ScaleWidth      =   285
  41.          TabIndex        =   26
  42.          TabStop         =   0   'False
  43.          Top             =   2580
  44.          Width           =   285
  45.       End
  46.       Begin TextBox txtMessage 
  47.          BackColor       =   &H00FFFF00&
  48.          FontBold        =   -1  'True
  49.          FontItalic      =   0   'False
  50.          FontName        =   "System"
  51.          FontSize        =   9.75
  52.          FontStrikethru  =   0   'False
  53.          FontUnderline   =   0   'False
  54.          Height          =   1380
  55.          Left            =   180
  56.          MultiLine       =   -1  'True
  57.          ScrollBars      =   3  'Both
  58.          TabIndex        =   3
  59.          Top             =   1440
  60.          Width           =   7035
  61.       End
  62.       Begin CommandButton btnClear 
  63.          Caption         =   "&Wipe"
  64.          Height          =   375
  65.          Left            =   6300
  66.          TabIndex        =   4
  67.          Top             =   630
  68.          Width           =   915
  69.       End
  70.       Begin TextBox txtTitle 
  71.          BackColor       =   &H00FFFF00&
  72.          FontBold        =   -1  'True
  73.          FontItalic      =   0   'False
  74.          FontName        =   "System"
  75.          FontSize        =   9.75
  76.          FontStrikethru  =   0   'False
  77.          FontUnderline   =   0   'False
  78.          Height          =   360
  79.          Left            =   180
  80.          TabIndex        =   1
  81.          Text            =   "{application name}"
  82.          Top             =   630
  83.          Width           =   5955
  84.       End
  85.       Begin Label NumLines 
  86.          Alignment       =   1  'Right Justify
  87.          BackColor       =   &H00C0C0C0&
  88.          Caption         =   "0"
  89.          ForeColor       =   &H00808080&
  90.          Height          =   195
  91.          Left            =   6210
  92.          TabIndex        =   24
  93.          Top             =   1170
  94.          Width           =   330
  95.       End
  96.       Begin Label Label3 
  97.          BackColor       =   &H00C0C0C0&
  98.          Caption         =   "&Title"
  99.          Height          =   195
  100.          Left            =   180
  101.          TabIndex        =   0
  102.          Top             =   360
  103.          Width           =   1005
  104.       End
  105.       Begin Label Label4 
  106.          BackColor       =   &H00C0C0C0&
  107.          Caption         =   "&Message"
  108.          Height          =   195
  109.          Left            =   180
  110.          TabIndex        =   2
  111.          Top             =   1170
  112.          Width           =   765
  113.       End
  114.       Begin Label Label8 
  115.          BackColor       =   &H00C0C0C0&
  116.          Caption         =   "Line(s)"
  117.          ForeColor       =   &H00808080&
  118.          Height          =   195
  119.          Left            =   6570
  120.          TabIndex        =   25
  121.          Top             =   1170
  122.          Width           =   585
  123.       End
  124.    End
  125.    Begin SSFrame Frame3D4 
  126.       ForeColor       =   &H00000000&
  127.       Height          =   915
  128.       Left            =   180
  129.       TabIndex        =   23
  130.       Top             =   5220
  131.       Width           =   7395
  132.       Begin CommandButton btnHelp 
  133.          Caption         =   "&Help"
  134.          Height          =   465
  135.          Left            =   3960
  136.          TabIndex        =   14
  137.          Top             =   270
  138.          Width           =   1275
  139.       End
  140.       Begin CommandButton btnExit 
  141.          Caption         =   "E&xit"
  142.          Height          =   465
  143.          Left            =   5760
  144.          TabIndex        =   15
  145.          Top             =   270
  146.          Width           =   1275
  147.       End
  148.       Begin CommandButton btnTest 
  149.          Caption         =   "&Preview"
  150.          Enabled         =   0   'False
  151.          Height          =   465
  152.          Left            =   2160
  153.          TabIndex        =   13
  154.          Top             =   270
  155.          Width           =   1275
  156.       End
  157.       Begin CommandButton btnExport 
  158.          Caption         =   "&Export"
  159.          Enabled         =   0   'False
  160.          Height          =   465
  161.          Left            =   360
  162.          TabIndex        =   12
  163.          Top             =   270
  164.          Width           =   1275
  165.       End
  166.    End
  167.    Begin SSFrame Frame3D3 
  168.       Caption         =   "Modal State"
  169.       Font3D          =   3  'Inset w/light shading
  170.       ForeColor       =   &H00000000&
  171.       Height          =   1905
  172.       Left            =   5940
  173.       TabIndex        =   20
  174.       Top             =   3240
  175.       Width           =   1635
  176.       Begin SSOption MState1 
  177.          Caption         =   "&Application"
  178.          Height          =   465
  179.          Index           =   1
  180.          Left            =   180
  181.          TabIndex        =   11
  182.          Top             =   1170
  183.          Value           =   -1  'True
  184.          Width           =   1185
  185.       End
  186.       Begin SSOption MState1 
  187.          Caption         =   "&System"
  188.          Height          =   465
  189.          Index           =   0
  190.          Left            =   180
  191.          TabIndex        =   10
  192.          TabStop         =   0   'False
  193.          Top             =   720
  194.          Width           =   1185
  195.       End
  196.    End
  197.    Begin SSFrame Frame3D2 
  198.       Caption         =   "Icon"
  199.       Font3D          =   3  'Inset w/light shading
  200.       ForeColor       =   &H00000000&
  201.       Height          =   1905
  202.       Left            =   3960
  203.       TabIndex        =   18
  204.       Top             =   3240
  205.       Width           =   1815
  206.       Begin VScrollBar VScroll1 
  207.          Height          =   1005
  208.          Left            =   180
  209.          Max             =   3
  210.          TabIndex        =   9
  211.          Top             =   720
  212.          Width           =   285
  213.       End
  214.       Begin PictureBox DisplayIcon 
  215.          BackColor       =   &H00C0C0C0&
  216.          BorderStyle     =   0  'None
  217.          Height          =   540
  218.          Left            =   870
  219.          ScaleHeight     =   38.118
  220.          ScaleMode       =   0  'User
  221.          ScaleWidth      =   38.118
  222.          TabIndex        =   21
  223.          TabStop         =   0   'False
  224.          Top             =   810
  225.          Width           =   540
  226.       End
  227.       Begin Label Label5 
  228.          BackColor       =   &H00C0C0C0&
  229.          Caption         =   "Sele&ct"
  230.          Height          =   195
  231.          Left            =   180
  232.          TabIndex        =   19
  233.          Top             =   450
  234.          Width           =   1005
  235.       End
  236.       Begin Label Label1 
  237.          Alignment       =   2  'Center
  238.          BackColor       =   &H00C0C0C0&
  239.          Caption         =   "Stop"
  240.          Height          =   285
  241.          Left            =   540
  242.          TabIndex        =   22
  243.          Top             =   1440
  244.          Width           =   1185
  245.       End
  246.    End
  247.    Begin SSFrame Frame3D1 
  248.       Caption         =   "Buttons"
  249.       Font3D          =   3  'Inset w/light shading
  250.       Height          =   1905
  251.       Left            =   180
  252.       TabIndex        =   17
  253.       Top             =   3240
  254.       Width           =   3615
  255.       Begin ComboBox MBbtnStyle 
  256.          BackColor       =   &H00FFFF00&
  257.          Height          =   300
  258.          Left            =   180
  259.          Style           =   2  'Dropdown List
  260.          TabIndex        =   6
  261.          Top             =   720
  262.          Width           =   3255
  263.       End
  264.       Begin ComboBox MBbtnDefault 
  265.          BackColor       =   &H00FFFF00&
  266.          Enabled         =   0   'False
  267.          Height          =   300
  268.          Left            =   180
  269.          Style           =   2  'Dropdown List
  270.          TabIndex        =   8
  271.          Top             =   1440
  272.          Width           =   3255
  273.       End
  274.       Begin Label Label2 
  275.          BackColor       =   &H00C0C0C0&
  276.          Caption         =   "&Default"
  277.          Height          =   195
  278.          Index           =   0
  279.          Left            =   180
  280.          TabIndex        =   7
  281.          Top             =   1170
  282.          Width           =   1245
  283.       End
  284.       Begin Label Label2 
  285.          BackColor       =   &H00C0C0C0&
  286.          Caption         =   "&Layout"
  287.          Height          =   195
  288.          Index           =   1
  289.          Left            =   180
  290.          TabIndex        =   5
  291.          Top             =   450
  292.          Width           =   1245
  293.       End
  294.    End
  295.    Begin Image Image2 
  296.       Height          =   540
  297.       Index           =   3
  298.       Left            =   2790
  299.       Picture         =   MBDMAIN.FRX:0302
  300.       Top             =   6840
  301.       Width           =   540
  302.    End
  303.    Begin Image Image2 
  304.       Height          =   540
  305.       Index           =   2
  306.       Left            =   2160
  307.       Picture         =   MBDMAIN.FRX:064C
  308.       Top             =   6840
  309.       Width           =   540
  310.    End
  311.    Begin Image Image2 
  312.       Height          =   540
  313.       Index           =   1
  314.       Left            =   1530
  315.       Picture         =   MBDMAIN.FRX:0996
  316.       Top             =   6840
  317.       Width           =   540
  318.    End
  319.    Begin Image Image2 
  320.       Height          =   540
  321.       Index           =   0
  322.       Left            =   900
  323.       Picture         =   MBDMAIN.FRX:0CE0
  324.       Top             =   6840
  325.       Width           =   540
  326.    End
  327. Option Explicit
  328. Dim IconArr(4) As String    'msgbox icon descriptions
  329. Dim MBValue As Integer      'msgbox type value
  330. Sub btnClear_Click ()
  331. 'clear title and message text boxes
  332. txtTitle = "{application name}"
  333. txtMessage = ""
  334. txtTitle.SetFocus
  335. NumLines = 0
  336. 'hilite contents of title textbox
  337. txtTitle.SelStart = 0
  338. txtTitle.SelLength = Len(txtTitle)
  339. End Sub
  340. Sub btnExit_Click ()
  341. 'unload all forms and terminate
  342. Unload Me
  343. End Sub
  344. Sub btnExport_Click ()
  345. 'export code for creating message box to clipboard
  346. 'if VB code window open paste into window at current
  347. 'caret position
  348. 'linefeed
  349. Const LF = " & Chr$(10)"
  350. 'variable declarations
  351. Dim CR As String * 1        'carriage return
  352. Dim QT As String * 1        'quote
  353. Dim temp As String          'scratch string
  354. Dim MBD_Title As String     'message box title
  355. Dim MBD_MsgText As String   'message box text
  356. Dim VBLine As String        'command line in VB format
  357. Dim message As String       'scratch string
  358. Dim loopcount As Integer    'loop counter
  359. Dim linecount As Integer    'number of lines in textbox
  360. 'carriage return and quote characters
  361. CR = Chr$(13)
  362. QT = Chr$(34)
  363. 'get function/statement option from user
  364. ExOption.Show MODAL
  365. 'abort paste to clipboard on user request
  366. If MBD_BtnReturned = IDCANCEL Then Exit Sub
  367. 'get number of lines in textbox
  368. linecount = SendMessageBynum(txtMessage.hWnd, EM_GETLINECOUNT, 0, 0&)
  369. 'get first line
  370. temp = GetTextLine(txtMessage, 0)
  371. 'build message text of message box
  372. 'allow for empty first line
  373. If temp = "" Then
  374.     message = "MBD_MsgText = Chr$(10)"
  375.     message = "MBD_MsgText = " & QT & temp & QT
  376.     If linecount > 1 Then message = message & LF
  377. End If
  378. 'get each remaining line and add to message text
  379. 'of message box
  380. For loopcount = 1 To linecount - 1
  381.     temp = GetTextLine(txtMessage, loopcount)
  382.     If temp = "" Then   'empty line
  383.     If loopcount < linecount - 1 Then message = message & LF
  384.     Else                'line with text
  385.     message = message & CR & "MBD_MsgText = MBD_MsgText & " & QT & temp & QT
  386.     'append linefeed if not last line
  387.     If loopcount < linecount - 1 Then message = message & LF
  388.     End If
  389. 'start of function/statement call
  390. If MBD_BtnReturned = IDYES Then
  391.     VBLine = "MBD_BtnReturned = MsgBox(MBD_MsgText" 'function
  392.     VBLine = "MsgBox MBD_MsgText"                   'statement
  393. End If
  394. 'place type value in call
  395. Calc_MBValue
  396. VBLine = VBLine & ", " & MBValue
  397. 'allow for default title
  398. If UCase(txtTitle) = "{APPLICATION NAME}" Then
  399.     MBD_Title = ""          'no title given - use default
  400.     MBD_Title = txtTitle    'title supplied
  401. End If
  402. 'place title text in call (if title exists)
  403. If MBD_Title > "" Then
  404.     VBLine = VBLine & ", " & QT & MBD_Title & QT
  405. End If
  406. 'terminate function call
  407. If MBD_BtnReturned = IDYES Then VBLine = VBLine & ")"
  408. clipcopy:
  409. 'copy call to clipboard
  410. Clipboard.Clear
  411. Clipboard.SetText message & CR & VBLine
  412. 'switch to VB - if VB not running signal error
  413. On Error GoTo err_handler
  414. AppActivate "Microsoft Visual Basic"
  415. On Error GoTo 0
  416. DoEvents
  417. 'paste clipboard contents into VB code window
  418. SendKeys "%EP"
  419. DoEvents
  420. Exit Sub
  421. 'handle error in switching to VB
  422. err_handler:
  423. On Error GoTo 0
  424. MBD_MsgText = "Microsoft Visual Basic not running. Unable to export directly to "
  425. MBD_MsgText = MBD_MsgText & "Visual Basic code window. Code copied to Clipboard only."
  426. MBD_BtnReturned = MsgBox(MBD_MsgText, 69, "Message Box Designer")
  427. If MBD_BtnReturned = IDRETRY Then
  428.     Resume clipcopy
  429.     Exit Sub
  430. End If
  431. End Sub
  432. Sub btnHelp_Click ()
  433. Dim result As Integer
  434. 'load help file
  435. MBDMain.MousePointer = 11   'hourglass pointer
  436. result = WinHelp(Me.hWnd, App.HelpFile, HELP_INDEX, "")
  437. MBDMain.MousePointer = 0    'default pointer
  438. End Sub
  439. Sub btnTest_Click ()
  440. 'display a sample message box using currently selected
  441. 'values
  442. Dim message As String
  443. Dim i As Integer
  444. Dim char As String * 1
  445. 'calculate selected type values
  446. Calc_MBValue
  447. 'strip out CR characters (upsets system modal MB's)
  448. For i = 1 To Len(txtMessage)
  449.     char = Mid(txtMessage, i, 1)
  450.     If char <> Chr$(13) Then message = message & char
  451. 'display message box using selected values
  452. MsgBox message, MBValue, txtTitle
  453. End Sub
  454. Sub Calc_MBValue ()
  455. 'calculate message box type value from MDBMain
  456. 'control settings
  457. 'icon
  458. MBValue = VScroll1.Value * 16 + 16
  459. 'modal state
  460. If MState1(0).Value Then MBValue = MBValue + 4096
  461. 'number/type of buttons
  462. MBValue = MBValue + MBbtnStyle.ListIndex
  463. 'default button
  464. MBValue = MBValue + MBbtnDefault.ListIndex * 256
  465. End Sub
  466. Sub Form_Load ()
  467. Dim result As Integer
  468. Dim SaveAppTitle As String
  469. 'allow only one copy of application to run
  470. 'switch to previous instance if it exists
  471. If App.PrevInstance Then
  472.     SaveAppTitle = App.Title
  473.     App.Title = "... duplicate instance."
  474.     MBDMain.Caption = "... duplicate instance."
  475.     AppActivate SaveAppTitle
  476.     SendKeys "% R", True
  477.     End
  478. End If
  479. 'initialise style combo box
  480. 'ItemData property = number of buttons in each style
  481. MBbtnStyle.AddItem "OK button only."
  482. MBbtnStyle.ItemData(MBbtnStyle.NewIndex) = 1
  483. MBbtnStyle.AddItem "OK and Cancel buttons."
  484. MBbtnStyle.ItemData(MBbtnStyle.NewIndex) = 2
  485. MBbtnStyle.AddItem "Abort, Retry, and Ignore buttons."
  486. MBbtnStyle.ItemData(MBbtnStyle.NewIndex) = 3
  487. MBbtnStyle.AddItem "Yes, No, and Cancel buttons."
  488. MBbtnStyle.ItemData(MBbtnStyle.NewIndex) = 3
  489. MBbtnStyle.AddItem "Yes and No buttons."
  490. MBbtnStyle.ItemData(MBbtnStyle.NewIndex) = 2
  491. MBbtnStyle.AddItem "Retry and Cancel buttons."
  492. MBbtnStyle.ItemData(MBbtnStyle.NewIndex) = 2
  493. MBbtnStyle.ListIndex = 0
  494. 'initialise default button combo box
  495. MBbtnDefault.AddItem "First button"
  496. MBbtnDefault.ListIndex = 0
  497. 'initialise string array of icon descriptions
  498. IconArr(0) = "Stop"
  499. IconArr(1) = "Question"
  500. IconArr(2) = "Exclamation"
  501. IconArr(3) = "Information"
  502. 'show banner
  503. About.Show MODAL
  504. 'load user option form
  505. Load ExOption
  506. 'center form on screen
  507. Center_Form Me
  508. 'show default icon
  509. DisplayIcon.Picture = image2(0).Picture
  510. 'hilite title
  511. txtTitle.SelStart = 0
  512. txtTitle.SelLength = Len(txtTitle)
  513. Me.Refresh
  514. End Sub
  515. Sub Form_QueryUnload (Cancel As Integer, UnloadMode As Integer)
  516. Dim result As Integer
  517. 'unload help file if open
  518. result = WinHelp(Me.hWnd, App.HelpFile, HELP_QUIT, 0&)
  519. 'clear preloaded form
  520. Unload ExOption
  521. End Sub
  522. Sub Form_Unload (Cancel As Integer)
  523. End Sub
  524. Function GetTextLine (TB As TextBox, nLine As Integer) As String
  525. 'retrieve a line (nLine) of text from textbox (TB)
  526. Dim start As Integer
  527. Dim lSize As Long
  528. Dim buffer As String
  529. Dim result As Long
  530. 'get offset to first character in line nLine
  531. start = SendMessageBynum(TB.hWnd, EM_LINEINDEX, nLine, 0&)
  532. 'get length of line nLine
  533. lSize = SendMessageBynum(TB.hWnd, EM_LINELENGTH, start, 0&) + 1
  534. 'allocate string to contain result
  535. buffer = String$(lSize + 2, 0)
  536. 'prepare string for API call
  537. Mid$(buffer, 1, 1) = Chr$(lSize And &HFF)
  538. Mid$(buffer, 2, 1) = Chr$(lSize \ &H100)
  539. 'get the line
  540. result = SendMessageBystring(TB.hWnd, EM_GETLINE, nLine, buffer)
  541. 'return result to caller
  542. GetTextLine = Left(buffer, result)
  543. End Function
  544. Sub MBbtnStyle_Click ()
  545. Static old_value As Integer 'saved value
  546. 'present available default buttons based on message box style
  547. 'skip if new style has same default as previous selection
  548. If MBbtnStyle.ItemData(MBbtnStyle.ListIndex) <> old_value Then
  549.     'clear combo
  550.     MBbtnDefault.Clear
  551.     'add available defaults based on itemdata property of style
  552.     MBbtnDefault.AddItem "First button"
  553.     Select Case MBbtnStyle.ItemData(MBbtnStyle.ListIndex)
  554.     Case 2
  555.         MBbtnDefault.AddItem "Second button"
  556.     Case 3
  557.         MBbtnDefault.AddItem "Second button"
  558.         MBbtnDefault.AddItem "Third button"
  559.     End Select
  560.     'show first available default
  561.     MBbtnDefault.ListIndex = 0
  562.     MBbtnDefault.Refresh
  563.     'save value for next call
  564.     old_value = MBbtnStyle.ItemData(MBbtnStyle.ListIndex)
  565.     'disable defaults if only one available
  566.     If old_value = 1 Then
  567.     MBbtnDefault.Enabled = False
  568.     Else
  569.     MBbtnDefault.Enabled = True
  570.     End If
  571. End If
  572. End Sub
  573. Function TotalLines (TB As TextBox) As Integer
  574. 'get total number of lines in textbox TB
  575. TotalLines = SendMessageBynum(TB.hWnd, EM_GETLINECOUNT, 0, 0&)
  576. End Function
  577. Sub txtMessage_Change ()
  578. Dim tlnew As Integer
  579. Static tlold As Integer 'saved value
  580. 'disable Export and Preview buttons if no message text
  581. If Len(txtMessage) > 0 Then
  582.     btnExport.Enabled = True
  583.     btnTest.Enabled = True
  584.     btnExport.Enabled = False
  585.     btnTest.Enabled = False
  586.     NumLines = 0
  587.     tlold = 0
  588.     Exit Sub
  589. End If
  590. 'display number of lines in message textbox
  591. 'skip if no change
  592. tlnew = TotalLines(txtMessage)
  593. If tlnew <> tlold Then
  594.     NumLines = tlnew
  595.     tlold = tlnew
  596. End If
  597. End Sub
  598. Sub txtTitle_KeyPress (KeyAscii As Integer)
  599. 'allow Enter key to terminate Title entry
  600. If KeyAscii = 13 Then
  601.     KeyAscii = 0        'prevent beep
  602.     txtMessage.SetFocus 'move caret to message entry textbox
  603. End If
  604. End Sub
  605. Sub txtTitle_LostFocus ()
  606. 'if Title entry text box empty replace default
  607. If txtTitle = "" Then txtTitle = "{application name}"
  608. End Sub
  609. Sub VScroll1_Change ()
  610. 'display icon and descriptor based on scrollbar position
  611. DisplayIcon.Picture = image2(VScroll1.Value).Picture
  612. Label1.Caption = IconArr(VScroll1.Value)
  613. End Sub
  614. Sub VScroll1_Scroll ()
  615. 'display icon and descriptor based on scrollbar position
  616. DisplayIcon.Picture = image2(VScroll1.Value).Picture
  617. Label1.Caption = IconArr(VScroll1.Value)
  618. End Sub
  619.