VC ++ common API 2

Source: Internet
Author: User

1. Create a desktop shortcut

# Include <atlconv. h> void createshortcut (lpctstr lpszexe, lpctstr lpszlnk) {// create a blockchain method // parameter lpszexe: full path name of the EXE file // parameter lpszlnk: full path name of the shortcut file :: coinitialize (null); ishelllink * PSL = NULL; ipersistfile * PPF = NULL; hresult hR =: cocreateinstance (// start component clsid_shelllink, // shortcut clsidnull, // for aggregation (note 4) clsctx_inproc_server, // The iid_ishelllink and the iid (lpvoid *) of the shell32.dll service in the process. & PSL ); // obtain the interface pointer if (succeeded (HR) {PSL-> setpath (lpszexe); // full path Program Name // PSL-> setarguments (); // command line parameter // PSL-> setdescription (); // remarks // PSL-> sethotkey (); // shortcut // PSL-> seticonlocation (); // icon // PSL-> setshowcmd (); // window size // according to the EXE file name, obtain the directory name tchar szworkpath [max_path];: lstrcpy (szworkpath, lpszexe); lptstr Lp = szworkpath; while (* LP) LP ++; while ('//'! = * LP) LP --; * Lp = 0; // set the default working directory of the EXE program, PSL-> setworkingdirectory (szworkpath ); hR = PSL-> QueryInterface (// persistence file query interface pointer iid_ipersistfile, // persistence interface IID (lpvoid *) & PPF ); // obtain the interface pointer if (succeeded (HR) {uses_conversion; // convert it to the Unicode string PPF-> Save (t2cole (lpszlnk), true ); // save} If (PPF) PPF-> release (); If (PSL) PSL-> release ();: couninitialize ();}
 
 

2. display a jpg image in the window.

Void cxxxview: ondraw (CDC * PDC) {: coinitialize (null); // com initializes hresult hr; cfile file; file. open ("C: // aa.jpg", cfile: moderead | cfile: sharedenynone); // read the file content DWORD dwsize = file. getlength (); hglobal hmem =: globalalloc (gmem_moveable, dwsize); lpvoid lpbuf =: globallock (hmem); file. readhuge (lpbuf, dwsize); file. close ();: globalunlock (hmem); istream * pstream = NULL; ipicture * ppicture = NULL; // get istream from hglobal. If the parameter is true, istream is released, release memory hR =: createstreamonhglobal (hmem, true, & pstream); Assert (succeeded (HR); HR =: oleloadpicture (pstream, dwsize, true, iid_ipicture, (lpvoid *) & ppicture); Assert (hR = s_ OK); long nwidth, nheight; // width/height, mm_himetric mode, unit: 0.01mm ppicture-> get_width (& nwidth); // width: ppicture-> get_height (& nheight ); /// high ////// original large display ///// csize SZ (nwidth, nheight); PDC-> himetrictodp (& sz ); // The mm_himetric conversion mode is measured in mm_text pixels. The unit is ppicture-> render (PDC-> m_hdc, 0, 0, Sz. CX, Sz. cy, 0, nheight, nwidth,-nheight, null); // display by window size // crect rect; getclientrect (& rect); // ppicture-> render (PDC-> m_hdc, 0, 0, rect. width (), rect. height (), // 0, nheight, nwidth,-nheight, null); If (ppicture) ppicture-> release (); // release ipicture pointer if (pstream) pstream-> release (); // release the istream pointer and release hmem: couninitialize ();}

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.