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 ();}