Accidentally saw a cell phone number attribution to the database, more than 9,000 pages of content is really stunned, think of it into C + +, but the UI is really not how, simply with Visual Basic wrote a web-based mobile phone attribution query.
The structure is simple, use a picture to do the background, add a textbox, three labels (one output, one as a drag window, one as the Close button) and an image (which is responsible for the effect of the command Class).
The database is network-based, which means it must be networked.
The network interface API is found online, "http://www.096.me/api.php?phone=" + Phone + "&mode=txt", where phone is the mobile number.
Use two functions to get the source of the Web page to extract the information of the cell phone attribution, and use the label. Caption show up.
Get the Web page source code function:
Function gethttppage (URL) ' Gets the website source on Error Resume Nextdim Httpset http = CreateObject ("MSXML2. XMLHTTP ") http. Open "GET", url, falsegethttppage = http. Send () If http. ReadyState <> 4 Thendebug.print "Unable to connect to server" Gethttppage = "Unable to connect to server" Exit functionend ifgethttppage = Bytestobstr ( Http.responsebody, "GB2312") Set http = nothingend functionfunction bytestobstr (body, Cset) ' transcoding Dim Objstreamset objstream = CreateObject ("ADODB.stream") objstream. Type = 1objstream. Mode = 3objstream. Openobjstream.write bodyobjstream.position = 0objstream. Type = 2objstream. Charset = Csetbytestobstr = objstream. Readtextobjstream.closeset objstream = NothingEnd Function
How to drag a window:
using the label, backstyle=0 the property of the label, changing the name to: Labformtitle Add Source:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd as Long, _byval wmsg as Long, ByVal wPa Ram as Long, LParam as any) as Longprivate Declare Function releasecapture Lib "user32" () as Longprivate Const Wm_syscomm and = &h112private Const SC_MOVE = &hf010&private Const Htcaptio = 2
Private Sub labformtitle_mousedown (Button As Integer, Shift As Integer, X as single, Y as single) releasecapture ' wm_s Ys sends a mobile form command to a form call SendMessage (Me.hwnd, Wm_syscommand, Sc_move + htcaptio, 0) ' sc_move+ htcaptio means left-click to move the form end Sub
To obtain a specific two-character method in the source code:
Function Getbydiv (ByVal code As String, ByVal Divbegin as String, Divend as String) ' gets the contents of the delimiter clip Dim Lgstart as Lon G Dim lens As Long Dim lgend as long lens = Len (divbegin) Lgstart = InStr (1, code, Divbegin) + CLng (lens) C10/>lgend = INSTR (Lgstart, Code, divend) getbydiv = Mid (code, Lgstart, Lgend-lgstart) End Function
Therefore, the total source code:
/span>
Option explicitprivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd as Long, _byval wmsg as Long, ByVal WParam as Long, LParam as any) as Longprivate Declare Function releasecapture Lib "user32" () as Longprivate C Onst Wm_syscommand = &h112private Const SC_MOVE = &hf010&private Const Htcaptio = 2Private Sub image1_click () D Im Phonedim web as StringDim tem as Stringphone = Text1.textweb = "Http://www.096.me/api.php?phone=" + Phone + "&mode= TXT "' text2.text = Webtem = Gethttppage (web) Label1.Caption = getbydiv (tem," | | "," | | ") End subfunction gethttppage (URL) ' Get website source on Error Resume Nextdim Httpset http = CreateObject ("MSXML2. XMLHTTP ") http. Open "GET", url, falsegethttppage = http. Send () If http. ReadyState <> 4 Thendebug.print "Unable to connect to server" Gethttppage = "Unable to connect to server" Exit functionend ifgethttppage = Bytestobstr ( Http.responsebody, "GB2312") Set http = nothingend functionfunction bytestobstr (body, Cset) ' transcoding Dim Objstreamset objstream = CreateObject ("ADODB.Stream ") objstream. Type = 1objstream. Mode = 3objstream. Openobjstream.write bodyobjstream.position = 0objstream. Type = 2objstream. Charset = Csetbytestobstr = objstream. Readtextobjstream.closeset objstream = NothingEnd functionfunction getbydiv (ByVal code As String, ByVal Divbegin As String , divend as String) ' Gets the contents of the delimiter clip Dim lgstart As Long Dim lens As Long Dim lgend As Long Lens = Len (Divbegin) Lgstart = INSTR (1, code, Divbegin) + CLng (lens) Lgend = INSTR (Lgstart, Code, divend) Getbydiv = Mid (code, Lgstart, Lgend-lgstart) End functionprivate Sub labformtitle_mousedown (Button As Integer, Shift As Integer, X as single, Y as Sin GLE) releasecapture ' Wm_sys send a mobile form command to the form call SendMessage (Me.hwnd, Wm_syscommand, Sc_move + htcaptio, 0) ' sc_move+ HT Captio means left-click to move the form End SubPrivate Sub Label2_click () EndEnd SubPrivate Sub Picture1_click () End Sub
Operation Result:
GUI relatively single, with the simplest structure, the effect is General bar.
Although there are many similar softwares on the Internet, the process of production is happy.
@ Mayuko
Visual basic-Phone Attribution query