How to pin a program to the Windows7 taskbar (fixed version)

Source: Internet
Author: User

Source: How to pin the program to the Windows7 taskbar (fixed version)

In the CSDN forum to see a netizen asked how to pin the program to WINDOWS7 task bar, Ccrun (demon elder brother) is interested in this issue, so Google a bit, did not find the relevant API information, But in a foreign site to see the Folderitemverb object to achieve the method, about the specific information, you can refer to msdn:http://msdn.microsoft.com/en-us/library/windows/desktop/ bb774172 (v=vs.85). aspx

The code implemented in Delphi is as follows. Compilation environment: Delphi7 and XE2, test operating system for Chinese and English Windows7

usescomobj;procedureCrnpinapptowin7taskbar (strpath, Strapp:string);varVshell, Vfolder, Vfolderitem, vitemverbs:variant;  VPath, Vapp:variant;  I:integer;  str:string;  H:hinst; Szpinname:Array[0..255] ofChar;beginVshell:= Createoleobject ('shell.application'); VPath:=strpath; Vfolder:=Vshell.namespace (VPath); VAPP:=Strapp; Vfolderitem:=Vfolder.parsename (VAPP); Vitemverbs:=Vfolderitem.verbs; H:= LoadLibrary ('Shell32.dll'); LoadString (H,5386, Szpinname, the);  FreeLibrary (h);  forI: =1  toVitemverbs.count Do  beginStr:=Vitemverbs.item (i).    Name; ifSametext (str, szpinname) Then    begin      //6E 2E 6F 6DVitemverbs.item (i).    DoIt; End; End;End;procedureTform1.button1click (sender:tobject);beginCrnpinapptowin7taskbar ('C:\windows','Regedit.exe');End;

The implementation code in C++builder is as follows. Compilation environment: C++BUILDER6 and XE2, test operating system: Chinese and English Windows7

#include <comobj.hpp>void__fastcall Crnpinapptowin7taskbar (String strpath, String strapp) {Variant Vshell= Createoleobject ("shell.application"); Variant Vfolder= Vshell.olefunction ("NameSpace", Widestring (strpath)); Variant Vfolderitem= Vfolder.olefunction ("ParseName", Widestring (Strapp)); Variant Vitemverbs= Vfolderitem.olefunction ("Verbs"); //get pin to taskbar verb string, thanks titilimaHInstance HInst =:: LoadLibrary (TEXT ("Shell32.dll")); TCHAR szpinname[ the] = {0 }; :: LoadString (HInst,5386, Szpinname, the);    :: FreeLibrary (HInst);    String str; intncount = Vitemverbs.olepropertyget ("Count");  for(inti =0; i < ncount; i++) {str= Vitemverbs.olefunction ("Item", i). Olepropertyget ("Name"); if(Sametext (str, szpinname)) {//6E 2E 6F 6DVitemverbs.olefunction ("Item", i). Olefunction ("DoIt"); }    }}void__fastcall Tform1::button1click (TObject *Sender) {Crnpinapptowin7taskbar ("c:\\windows\\","notepad.exe");}

Also, thanks to Titilima Daniel, pinning the. lnk file to the Win7 taskbar is a much easier way to do this:

C + + code:

:: ShellExecute (NULL, text ("taskbarpin"), Text ("e:\\temp\\ Notepad.lnk"), NULL, NULL, SW_SHOW);

Delphi Code:

ShellExecute (nil'taskbarpin'E:\Temp\Notepad.lnk'  Nilnil, sw_show);

How to pin a program to the Windows7 taskbar (fixed version)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.