Use the shell object in the VB and web page

zhaozj2021-02-08  262

Use the shell object in the VB and web page

Department of Electronic Engineering, Optoelectronic Engineering, Wuhan Surveying and Mapping University

---- What is a shell object? Specifically, Microsoft's package for some common shell operation functions. Like open or browse a folder, find a file, turn off the computer, etc., and also browse the entire file system, obtain various information of the file or folder. Since these packages are based on the OLE automation service, we can use them in VB and Web.

---- Use in VB

---- The function of the object or function provided by VB itself may be limited, but it can be extended with a variety of type libraries and automation objects. The specific practices are as follows (as examples in Chinese VB6):

---- New project, select "Reference" in the Project menu, you will see a "Reference Dialog", then select "Microsoft Shell Controls and Automation" in "available reference" so you will You can use the shell object in the program.

---- Let's try the method provided by the Shell object. Add a button (Button1) in the form (Form1), then add the following code in the Click event of Button1:

Dim myshell as shell

Set myshell = new shell

MyShell.FindFiles

---- When the MyShell variable becomes an instance of the shell object, you can see all methods of the shell object during editing. The above code is used by the FindFiles method, which will display the Find File dialog. The following table gives the methods commonly used in the Shell object for reference.

---- Method Description

---- BrowseForfolder Displays the browsing folder dialog, including 4 parameters:

---- HWND, Title, Options, [rootfolder]

---- HWND: The form handle (Handle) containing the dialog, is typically set to 0. Title: The instructions will be displayed in the dialog as a string.

---- Options: Use the special way to use the dialog, for long integers, usually set to 0.

---- [rootfolder]: Optional, used to set the top-level folder for browsing, is "Desktop" when default, you can set it to a path or "special file clamping regular".

---- This method returns a Folder object.

---- ControlPanelItem runs a specified control panel project, including a parameter:

---- SZDIR: Control Panel Project Name

--- Explore browses a specified folder with the Explorer: including a parameter:

---- VDIR: A path or "special file clamp regular"

---- Open Opens a specified folder, including a parameter:

---- VDIR: A path or "special file clamp regular"

---- Filerun Displays "Run" dialog

--- FindComputer Display "Find Computer" dialog

---- FindFiles Display "Find File" dialog

---- CascadeWindows laminated all windows on the desktop

---- Tilehorizontally horizontally arranged on the desktop all windows

---- TileVerticalLy portrait arrangement on the desktop all windows

---- MinimizeAll Minimizes all windows

---- UndominimizeAll restores the minimized window

---- EJECTPC logouts the current user

---- Suspend will hang your computer

---- ShutDownWindows Displays "Close Windows" dialog ---- Namespace Creates a folder object with the folder path (Folder object), using the Folder object, you can browse the entire file system, get files or folders Various information.

---- Table has a "special file clamp regular number", that is a special folder, like "My Computer", "Control Panel", etc. Desktop, "Favorites", etc. After some Windows installation, the folder generated after installation is also a special folder (0x representation 16).

Desktop: SSFDesktop = 0x0000 Document: SSFsendto = 0x0009 Favorites: SSFFAVORITES = 0x0006 Printer: SSFPrinters = 0x0004 My Computer: SSFDRIVES = 0x0011 Control Panel: SSFControls = 0x0003 Network Neighbor: SSFNetwork = 0x0012

---- With these tips and references, plus your imagination, it will make the VB to have a lot of color.

---- Use in the web page

---- Since IE4 and its later version can support ActiveX, you can insert all kinds of ActiveX on the web page, so you can use the shell object.

---- You can use the identifier in HTML4 to reference the shell object, and the specific HTML code is as follows:

shell object test </ title></p> <p><meta http-equiv = "content-type"</p> <p>Content = "text / html; charSet = GB2312"></p> <p></ hEAD></p> <p><body bgcolor = "# ffffff"></p> <p><Object ClassID = CLSID: 13709620-C279-11CE-</p> <p>A49E-444553540000 ID = shell></p> <p></ Object> shell object test</p> <p><p></p> <p><Input Type = "Button" name = "Button" value = "display"</p> <p>οnclick = "TEST.INNNERTEXT =</p> <p>Shell.BrowseForfolder (0, "Select a folder ', 0);">></p> <p></ p></p> <p><p> <span id = test> </ span> </ p></p> <p></ body></p> <p></ html></p> <p>---- You only need to create a new text file, write the above code into a new file, and then save the file that HTM is an extension. When you run the web page, you will see a button called "Show" and click the Browse Folder dialog box.</p> <p>---- The key to this section is <object classid = CLSID: 13709620-C279-11CE-A49E-444553540000 ID = shell>. Where ClassID is the CLSID number of the shell object, the ID is the name of the shell object instance, and the number of shell objects can be used through this name. ---- Folder object created by the shell object</p> <p>---- In the above examples and reference, there is always a Folder object, how do you use this object? A Folder object contains all information about a specified folder: subdirectory, files, etc. Using the Items method, you can return a folder item collection (FolderItems collection), which has all subdirectories and files in the specified directory in this collection.</p> <p>---- FolderItems collection has a count property, you can get the subdirectories and the total number of files, so you can use a "loop statement" all items in the directory. At the same time, you can use the Item method to return a FolderItem object. Operation of a folder or file, the ITEM method has an optional length integer parameter to use the project index in the collection. With a FolderItem object, you can get various information about folders and files. The FolderItem object has the following main properties:</p> <p>GetFolder: If the project is a folder, get a folder object isbrowsable: If you can browse, you are true, otherwise false isfilesystem: If you are a system folder or file is true, otherwise false isfolder: If it is a folder is true Otherwise, false modifydate: Visit or change the date name: file or directory name path: file or directory path size: file size Type: file type</p> <p>---- The following is an example of the Folder object.</p> <p>---- Use in VB: Add a new button (Button2) and a list box (List1) in the previous form, add the following code in the Button2 Click event:</p> <p>Dim myshell as shell</p> <p>Dim Myfolder, Myfolders</p> <p>Set myshell = new shell</p> <p>Set myfolder = myshell.browseforfolder</p> <p>(Form1.hWnd, "Please select a folder", 0)</p> <p>Set myfolders = myfolder.Items ()</p> <p>List1.clear</p> <p>For i = 0 to myfolders.count - 1</p> <p>List1.additem myfolders.Item (i) .name</p> <p>Next I</p> <p>---- Use the following code to join the following code Between <head> </ head>, then οnclick = "test.innerText = shell.browseforfolder (0, 'Please select a folder ', 0); "Change to οnclick =" TEST.INNNERHTML = ShowItem (); ", you can run!</p> <p><script language = "javascript"></p> <p>Function showItem ()</p> <p>{</p> <p>Var myfolder, myfolders;</p> <p>Var s = ""; myfolder = shell.browseforfolder (0, "Please select a folder", 0);</p> <p>myfolders = myfolder.Item.Items ();</p> <p>For (VAR i = 0; i <myfolders.count; i )</p> <p>S = myfolders.Item (i) .Name "<br>";</p> <p>Return (s)</p> <p>}</p> <p></ script></p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-2918.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="2918" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.047</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'JftMnbeUQqU61pq93vZGYHagCsudOMuRtg3FQcauV3IoiMEU0m3tffM5QSov89AR1Fy8HtyrIzJI0BxLRC2Kwg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>