URL文字列のパーツを取得 <TOP>
URL文字列をパーツに分解します。
UrlGetPart 指定のURLのパーツを取得
'================================================================ '= URL文字列のパーツを取得 '= (UrlGetPart.bas) '================================================================ #include "Windows.bi" #define MAX_PATH 260 #define ERROR_SUCCESS 0 '正常終了の戻り値を示す #define URL_PART_SCHEME 1 'スキーム #define URL_PART_HOSTNAME 2 'ホストネーム #define URL_PART_USERNAME 3 'ユーザーネーム #define URL_PART_PASSWORD 4 'パスワード #define URL_PART_PORT 5 'ポート #define URL_PART_QUERY 6 'クエリ #define URL_PARTFLAG_KEEPSCHEME &H1 ' 指定のURLのパーツを取得 Declare Function Api_UrlGetPart& Lib "shlwapi" Alias "UrlGetPartA" (ByVal pszIn$, ByVal pszOut$, pcchOut&, ByVal dwPart&, ByVal dwFlags&) Var Shared strURL As String Var Shared Text1 As Object Var Shared Text2 As Object Var Shared Edit1 As Object Var Shared List1 As Object Var Shared Button1 As Object Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 Text2.Attach GetDlgItem("Text2") : Text2.SetFontSize 14 Edit1.Attach GetDlgItem("Edit1") : Edit1.SetFontSize 14 List1.Attach GetDlgItem("List1") : List1.SetFontSize 14 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Function GetUrlParts(sUrl As String, dwPart As Long, dwFlags As Long) As String Function GetUrlParts(sUrl As String, dwPart As Long, dwFlags As Long) As String Var sPart As String Var dwSize As Long If Len(sUrl) > 0 Then sPart = Space$(MAX_PATH) dwSize = Len(sPart) If Api_UrlGetPart(sUrl, sPart, dwSize, dwPart, dwFlags) = ERROR_SUCCESS Then GetUrlParts = Left$(sPart, dwSize) End If End If End Function '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() strURL = Edit1.GetWindowText List1.ResetContent List1.AddString "【dwFlags=0】" List1.AddString "SCHEME : " & GetUrlParts(strURL, URL_PART_SCHEME, 0) List1.AddString "HOSTNAME : " & GetUrlParts(strURL, URL_PART_HOSTNAME, 0) List1.AddString "USERNAME : " & GetUrlParts(strURL, URL_PART_USERNAME, 0) List1.AddString "PASSWORD : " & GetUrlParts(strURL, URL_PART_PASSWORD, 0) List1.AddString "PORT : " & GetUrlParts(strURL, URL_PART_PORT, 0) List1.AddString "QUERY : " & GetUrlParts(strURL, URL_PART_QUERY, 0) List1.AddString String$(50, "-") List1.AddString "【dwFlags=URL_PARTFLAG_KEEPSCHEME】" List1.AddString "SCHEME : " & GetUrlParts(strURL, URL_PART_SCHEME, URL_PARTFLAG_KEEPSCHEME) List1.AddString "HOSTNAME : " & GetUrlParts(strURL, URL_PART_HOSTNAME, URL_PARTFLAG_KEEPSCHEME) List1.AddString "USERNAME : " & GetUrlParts(strURL, URL_PART_USERNAME, URL_PARTFLAG_KEEPSCHEME) List1.AddString "PASSWORD : " & GetUrlParts(strURL, URL_PART_PASSWORD, URL_PARTFLAG_KEEPSCHEME) List1.AddString "PORT : " & GetUrlParts(strURL, URL_PART_PORT, URL_PARTFLAG_KEEPSCHEME) List1.AddString "QUERY : " & GetUrlParts(strURL, URL_PART_QUERY, URL_PARTFLAG_KEEPSCHEME) End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End