📄 frmmain.frm
字号:
'Clears the text from both C and VB text boxes
Private Sub cmdClear_Click()
txtC.Text = ""
txtBas.Text = ""
End Sub
'Copies the contents of the VB text box to the Clipboard
Private Sub cmdCopy_Click()
Clipboard.SetText txtBas.Text 'You can also set pictures, check the help file.
End Sub
'Calls the Common Dialog control and retrieves the filenames selected by
'the user.
'If you don't like the limitations set by this control, you should check
'out The Common Controls Replacement Project (CCRP) home page at
' http://www.mvps.org/ccrp
'
Private Sub GetFilenames(strHfile As String, strBASfile As String)
'Set the properties and call it
With cdlg
.Filter = "C header files|*.h|All files|*.*"
.DialogTitle = "Choose .h file"
.Flags = cdlOFNFileMustExist Or cdlOFNPathMustExist Or cdlOFNHideReadOnly
.ShowOpen
'Okay, we got the .h file, now to get the VB file.
strHfile = .FileName
.FileName = ""
.Filter = "VB modules|*.bas|All files|*.*"
.DefaultExt = ".bas"
.Flags = cdlOFNOverwritePrompt Or cdlOFNPathMustExist Or cdlOFNHideReadOnly
.DialogTitle = "Select target file"
.ShowSave
strBASfile = .FileName
End With
End Sub
'Do all the work required prior to processing.
Private Sub cmdProcess_Click()
Dim dummy As String
'Lets the user know something is going on.
Me.MousePointer = vbHourglass
'Get the library name (a.k.a. DLL name)
txtLibraryName.Text = Trim(txtLibraryName.Text)
LibraryName = IIf(txtLibraryName.Text = "", "libname", txtLibraryName.Text)
'Ok, are we working with files or with user input?
If frFile.Enabled Then 'files
hFilename = txtHFile.Text
basFilename = txtBASfile.Text
'make sure we have files to work with
If (txtHFile.Text = "") And (txtBASfile.Text = "") Then
GetFilenames hFilename, basFilename
If (hFilename = "") Or (basFilename = "") Then
Me.MousePointer = vbDefault
Exit Sub
End If
Else
If txtHFile.Text = "" Then
MsgBox "You have to provide an input file", vbExclamation
Me.MousePointer = vbDefault
Exit Sub
End If
If txtBASfile.Text = "" Then
MsgBox "You have to provide an output file", vbExclamation
Me.MousePointer = vbDefault
Exit Sub
End If
'See if it exists. Although Dir() is not perfect, it works.
'If you want to optimize this piece of code, try the API function
'FindFirstFile()
If Dir(txtHFile.Text) = "" Then
MsgBox "File: " & txtHFile.Text & " does not exist!", vbExclamation
Me.MousePointer = vbDefault
Exit Sub
End If
End If
txtHFile.Text = hFilename
txtBASfile.Text = basFilename
'Process the files
Process hFilename, , True, basFilename
MsgBox "Conversion complete", vbOKOnly, "Done"
Else 'User input
Process txtC.Text, dummy
txtBas.Text = dummy
txtBas.SelStart = Len(txtBas.Text)
End If
'Restore the mouse pointer.
Me.MousePointer = vbDefault
End Sub
'Retrieve the source and target files
Private Sub cmdSelectFiles_Click()
GetFilenames hFilename, basFilename
If (hFilename = "") Or (basFilename = "") Then Exit Sub
txtHFile.Text = hFilename
txtBASfile.Text = basFilename
End Sub
Private Sub Form_Load()
Dim Args As String
'Initialize the local and global variables.
IsPublic = True
LibraryName = "libname"
'See if we got any command line arguments
Args = Command()
If Args <> "" Then 'if we did then...
Dim fparts() As String
txtHFile.Text = Args
fparts = Split(Args, ".")
fparts(UBound(fparts)) = "bas"
Args = Join(fparts, ".")
txtBASfile.Text = Args
frFile.Enabled = True
frMain.Enabled = False
optWhat(0).Value = True
hFilename = txtHFile.Text
basFilename = txtBASfile.Text
End If
pcntSep = 0.5 'Set the ratio for the splitter
End Sub
'Here is the magic for the form...
Private Sub Form_Resize()
Dim frmWidth As Long
Dim frmHeight As Long
'if the form was minimized, ignore this stuff
If Me.WindowState = vbMinimized Then Exit Sub
'Store the "perfect" width in a variable, easier to access.
frmWidth = Me.ScaleWidth - cmdProcess.Width - 200
'Set .Top and .Left for buttons and options
frOptions.Top = 0
frOptions.Left = frmWidth + 100
cmdProcess.Left = frmWidth + 100
cmdProcess.Top = frOptions.Top + frOptions.Height + 100
cmdClear.Left = cmdProcess.Left
cmdClear.Top = cmdProcess.Top + cmdProcess.Height + 50
cmdCopy.Left = cmdProcess.Left
cmdCopy.Top = cmdClear.Top + cmdClear.Height + 50
'Set coordinates for the 2 main frames
With frFile
.Left = 0
.Top = 0
.Width = frmWidth
End With
frmHeight = Me.ScaleHeight - frFile.Height
With frMain
.Left = 0
.Top = frFile.Top + frFile.Height
.Width = frmWidth
.Height = IIf(frmHeight < 0, 0, frmHeight)
End With
frmWidth = (frMain.Width - 100)
'Set the separator's position on the form (actually in the frame)
Sep.Left = 50
Sep.Width = frMain.Width - 100
'This will make sure that the textboxes will occupy the same ratio of the
'frame whatever the size of the frame itself.
Sep.Top = IIf(frMain.Height < lblLabels(0).Height * 5, Sep.Top, frMain.Height * pcntSep)
'Set the label positions
lblLabels(0).Top = 250
lblLabels(0).Left = 50
lblLabels(0).Width = frmWidth
lblLabels(1).Top = Sep.Top + Sep.Height
lblLabels(1).Left = 50
lblLabels(1).Width = frmWidth
'This is where the textboxes (which are contained in pictureboxes) get resized.
Upper.Left = 50
Lower.Left = 50
Upper.Top = lblLabels(0).Top + lblLabels(0).Height
Lower.Top = lblLabels(1).Top + lblLabels(1).Height
Upper.Width = frmWidth
Lower.Width = frmWidth
'Call the pane resize function
Sep_MouseMove vbLeftButton, 0, 0, 0
'This takes care of the upper frame that holds the filenames
txtHFile.Width = IIf(txtC.Width < (lblLabels(3).Width + lblLabels(3).Left + _
cmdSelectFiles.Width), 0, txtC.Width - lblLabels(3).Width - lblLabels(3).Left - _
cmdSelectFiles.Width)
txtBASfile.Width = txtHFile.Width
cmdSelectFiles.Left = txtHFile.Left + txtHFile.Width + 50
cmdSelectFiles.Top = txtHFile.Top
optWhat(0).Left = frFile.Left + 200
optWhat(1).Left = optWhat(0).Left
optWhat(0).Top = frFile.Top
optWhat(1).Top = frMain.Top
End Sub
'Sets the size of the VB textbox
Private Sub Lower_Resize()
txtBas.Top = 0
txtBas.Left = 0
txtBas.Width = Lower.ScaleWidth
txtBas.Height = Lower.ScaleHeight
End Sub
Private Sub optOptions_Click(Index As Integer)
IsPublic = optOptions(0).Value
End Sub
Private Sub optWhat_Click(Index As Integer)
frFile.Enabled = optWhat(0).Value
frMain.Enabled = optWhat(1).Value
If Not Me.Visible Then Exit Sub
If frFile.Enabled Then
txtHFile.SetFocus
Else
txtC.SetFocus
End If
End Sub
'This is where the "splitting" occurs.
'
'I am using picture boxes for the panes. One for each one.
'The reason I chose to use picture boxes, is because I can manipulate them
'the same way I can a form. Most importantly, it's got a resize event
'which can be used to resize its contained controls.
Private Sub Sep_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button <> vbLeftButton Then Exit Sub 'We only care about the left button
'Make sure that the separator doesn't get out of bounds
Sep.Top = IIf(Sep.Top + Y < lblLabels(0).Top + lblLabels(0).Height + 450, lblLabels(0).Top + lblLabels(0).Height + 450, Sep.Top + Y)
Sep.Top = IIf(Sep.Top > frMain.Height - lblLabels(1).Height - Sep.Height - 470, frMain.Height - lblLabels(1).Height - Sep.Height - 470, Sep.Top)
'Check the size of the frame (see if we fit)
If frMain.Height < lblLabels(0).Height * 5 Then Exit Sub
'Resize the top part
Upper.Height = Sep.Top - Upper.Top - 50
'Set the vertical coordinate of the label box "VB Declaration"
lblLabels(1).Top = Sep.Top + Sep.Height
'Place and resize the lower part
Lower.Top = lblLabels(1).Top + lblLabels(1).Height
Lower.Height = frMain.Height - Lower.Top - 100
'Store the new ratio
pcntSep = Sep.Top / frMain.Height
End Sub
'Resize the C textbox
Private Sub Upper_Resize()
txtC.Top = 0
txtC.Left = 0
txtC.Width = Upper.ScaleWidth
txtC.Height = Upper.ScaleHeight
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -