Custom file types, and passing parameters to achieve (VB.NET) Author: wgscd Please respect copyright online a lot of people ask about custom file type and parameter passing problem, implement a custom file type well in .NET, a simple The method is to install the Wizard in the installation of the VS - the package custom file type, this is not to say, you will set it off (don't say you won't!) Next is a parameter transfer problem makes many problems People are troubled (I am annoyed). Not much to say, the parameters to get open programs in VB6.0 can use Command (). Specific example: Function getcommandline (Optional maxArgs) 'declared variables. DIM C, CMDLINE, CMDLNLEN, INARG, I, NUMARGS 'checks if the maxArgs parameter is provided. If ismissing (maxArgs) Then maxArgs = 10 'makes the size of the array appropriate. Redim ArgaRray (maxArgs) NUMARGS = 0: inarg = false 'acquisition command line parameters. CMDLINE = Command () cmdlnlen = len (cmdline) 'Remove command line parameters in a single character. For i = 1 to cmdlnlen c = mid (cmdline, i, 1) 'Detection is Space or Tab. If (c <> "and c <> vbtab) THEN 'If neither the Space key, it is not a TAB key, it is detected whether it is a character contained in the parameter. IF not inarg the 'new parameters. The detection parameter is too much. If Numargs = maxArgs Then EXIT for NUMARGS = NUMARGS 1 inarg = true end if 'adds characters to the current parameter. ArgaRray (NUMARGS) = Argarray (NUMARGS) C else 'Find space or TAB. Set the inARG flag to false. INARG = FALSE END IF NEXT I Redim Preserve Argarray (NUMARGS) 'Adjust the array size makes it just in line with the number of parameters. GetcommandLine = argarray () 'returns the array. END FUNCTION
-------------------------------------------------- -
What about VB.NET? In fact, it is almost, but just use system.environment.getCommandLineargs. Specific example: Sub main1 () 'detection passing parameters
DIM cmds as string () cmds = system.environment.getCommandLineArgs
IF cmds.length> 0 THEN DIM I as integer for i = 0 to cmds.length - 1
IF cmds (i) .tostring Like "* .ABC" the 'where ABC is the extension of the file for your custom file CMD = cmds (i) .tostring iscaseurl = trueEnd if Next
End if End Sub
DIM cmd as string = "" 'Used to save incoming parameters DIM ISCASEURL AS BOOLEAN = false' Judging whether it is the parameters you need
Private Sub Form1_Load (Byval Sender As System.Object, ByVal E AS System.EventArgs)
Handles mybase.load
Main1 () 'detection parameters
If iscaseurl = false kiln 'is not the parameters you need
'do your. . . . . . . . . . . . .
Else 'is the parameters that need to be processed
'Here the code added, CMD is the parameters you want
Msgbox ("The code added here, CMD is the parameters you want"))
IscaseURL = false
END IF
Catch exception
MSGBOX ("Erro")
END TRY
End Sub Of course, if you need it, you can call main1 () after the initializationComponent () call, you can detect and save the parameters of the open program.