VC programming knowledge points (practical articles)

xiaoxiao2021-03-04  45

1. Run other programs

// 1, run email or URL

Char szmailaddress [80]; STRCPY (Szmailaddress, "Mailto: Netvc@21cn.com"); Shellexecute (Null, "Open", Szmailaddress, Null, NULL, SW_SHOWNORMAL);

// 2, run the executable Winexec ("notepad.exe", sw_show); // run the bill

LPCMDLINE

[in] Pointer TO a NULL-TERMINATED Character String That Contains The Command Line (File Name Plus Optional Parameters) for the application to be executed. if the name of the executable file in the application ivut

LPCMDLINE Parameter Does Not Contain A Directory Path, The System Searches for the Executable File In this sequence:

The directory from which the application loaded. The current directory. The Windows system directory. The tabindex = "0" keywords = "base.getsystemdirectory" errorurl = "../ common / badjump.htm" /> GetSystemDirectory function retrieves the path of this directory. The Windows directory. The tabindex = "0" keywords = "base.getwindowsdirectory" errorurl = "../ common / badjump.htm" /> GetWindowsDirectory function retrieves the path of this directory. The directories listed in the pATH environment Variable.

Ucmdshow

[in] for a list of the acceptable value value, see the description of the

Ncmdshow parameter of the Tabindex = "0" keywords = "_ win32_showwindow" erroorurl = "../ Common / badjump.htm" />

Showwindow function.

2 onSIZE () usage

Void CBaview :: Onsize (uint ntype, int cx, int cy) {cformview :: onsize (ntype, cx, cy); // Todo: add your message handler code hereiff ((cx> 0) && (cy> 0) )) {Create Rect; if (m_treedevice.m_hwnd! = Null) {m_treedevice.getWindowRect (Rect); ScreenToClient (Rect); m_treedevice.moveWindow (Rect.Left, Rect.top, CX / 4, CY);}}}} 3. Only one program instance is run once, if you have run, exit

IF (FindWindow (NULL, "Program Title")) EXIT (0);

// Only one instance of the application is allowed to run another professional method (QSSReadbot) DWORD DWERROR = 0;

// generates an error ERROR_ALREADY_EXISTS HANDLE hMutex = CreateMutex (NULL, TRUE, TEXT ( "QssReadBot")); if (hMutex == NULL) {MessageBox (NULL, "! Create Mutex error", NULL, MB_OK); return FALSE } Else {dwerror = getLastError (); if (error_already_exiss == dwerror) // will generate an error error_Already_exists {MessageBox (NULL, "program has been run!", "Tips", MB_OK; Return False;}

}

4. Add imagelist to the tree

// Load bitmap cimagelist * pimagelist; cbitmap bitmap; uint NID;

Pimagelist (); PimageList-> Create (20, 20, ILC_COLOR32, 0, 4);

for (nID = IDB_BITMAP1; nID <= IDB_BITMAP15; nID ) // load bitmaps for dog, bird and fish {bitmap.LoadBitmap (nID); pImageList-> Add (& bitmap, RGB (255,192,255)); bitmap.DeleteObject (); }

m_treedevice.setimagelist (pimagelist, tvsil_normal);

/ / Then add the Item of the tree control, the picture is 0, 1, 2, 3, etc.

5. Display the JPEG image DE function on the control

ShowPicture (CDC * PDC, CSTRING STRPATH, CRECT * RECT) // Displays the function {ISTREAM * PSTM; cfilestatus fstatus; cfilestatus fstatus; // open the file and detects the validity IF of the file and detects the file and detects the validity of the file and detects the file. strPath, CFile :: modeRead) && file.GetStatus (strPath, fstatus) && ((cb = fstatus.m_size) = -1)) {hGLOBAL hGlobal = GlobalAlloc (GMEM_MOVEABLE, cb);! LPVOID pvData = NULL; if (hGlobal ! = NULL) {pvData = GlobalLock (hGlobal); if (pvData = NULL) {file.ReadHuge (pvData, cb);! GlobalUnlock (hGlobal); CreateStreamOnHGlobal (hGlobal, TRUE, & pStm);}}} else {return false } // Open the file end // Display the image of the JPEG and GIF format, GIF can only display one frame, but also not display movies, // To display animation GIF, please use Active control //. Ipicture * ppic; // load image from File Stream

if (SUCCEEDED (OleLoadPicture (pStm, fstatus.m_size, FALSE, IID_IPicture, (LPVOID *) & pPic))) {OLE_XSIZE_HIMETRIC hmWidth; OLE_YSIZE_HIMETRIC hmHeight; pPic-> get_Width (& hmWidth); pPic-> get_Height (& hmHeight); // in Rip-pull display image if (failed (ppic-> render (* PDC, RECT-> LEFT, RECT-> TOP, RECT-> Right, Rect-> Bottom, 0, hmheight, hmwidth, -hmheight, null) ) {Ppic-> release (); return false;} ppic-> release ();} else {returnaf false;} return true;

As follows:

CRECT RECT; // spath = _t ("c: // Documents and settings // all users // sample picture //sunset.jpg"); m_static1.getClientRect (Rect); // m_static1 Control

ShowPicture (PDC, _T ("RES // Stadium .jpg"), & Rect);

, _T ("res // stadium .jpg") can be replaced with spath, display the image of the fixed position, _t ("res // stadium .jpg"), it is possible to write, _t ("..// RES // Stadium .jpg ")?

6 control effects of tree control

void CBAView :: OnSelchangedTreeDevice (NMHDR * pNMHDR, LRESULT * pResult) {NM_TREEVIEW * pNMTreeView = (NM_TREEVIEW *) pNMHDR; // TODO: Add your control notification handler code here // if (m_treeDevice.GetSelectedItem () == hFan [1 ]) MessageBox (m_treedevice.getitemtext (m_treedevice.getSelectedItem ()), NULL, MB_OK; * PRESULT = 0;}

Reflect the selection of trees through the Handle of the global variable node

7 use ADO components

First put the #import "c: / program files / common files / system / ado / msado15.dll" No_namespace rename, "AdoEOF") Add to Stdafx.h

Then add it in the main .cpp file

_ConnectionPtr M_PCONNECTION; _RecordSetPtr M_PRecordset;

And in onnitial (), COM components

:: Coinitialize (NULL); // Initialization COM library environment

Initialization pointer when applied

M_PConnection.createInstance (_UUIDOF (Connection)); // Initializes Pointer M_PRecordSet.createInstance (_UUIDOF (Recordset);

Then open M_PConnection

m_pConnection-> Open ("driver = {SQL Server}; server = 192.168.1.158; uid = sa; pwd = sa; database = anyview", ",", "", null);

use

// m_precordset-> Open ("Select * from device", (idispatch *) m_pconnection, adomentynamic, adlockoptimistic, adcmdtext); or

m_precordset = m_pconnection-> execute ("Select Count (Distinct Buildingno from Device", & Recordsaffected, AdcmdText); Received Record

At the end of the app

Void CBAView :: ONDESTROY () {cFormview :: Ondestroy () ;:: couninitialize (); // TODO: add your message handler code here} 8.sql statement connection

A.char tempStr [10]; itoa (i 1, tempStr, 10); _bstr_t sqlStr; sqlStr = "SELECT COUNT (DISTINCT FloorNO) FROM Device"; sqlStr = sqlStr "WHERE BuildingNO ="; sqlStr = sqlStr tempStr ; m_pRecordset = m_pConnection-> Execute (sqlStr, & RecordsAffected, adCmdText); _variant_t vCountF = m_pRecordset-> GetCollect ((_ variant_t) ((long) 0)); floors = vCountF.lVal; B.SqlStr = "delete from" this -> m_curtblname "where" fldname "= '" value ""; sqlstr = "INSERT INTO" TBLNAME "(" FLDLIST ") VALUES (" Valuelist ")"

9. Get system time and format

char szYear ​​[5], szMonth [5], szDay [5], szHour [5], szMinute [5], szSecond [5], szTemp [5]; CString strDateTime; CString strAirConditonID; CString strAirConSwitch_ID, strLX_datetime; CString strRunStatus, Strwd, strsnwd, strpzfkd, stryxfs, strequipeid; cstring strerror;

Cstring strsql; cstring strqconnection; cstring strqssnumber, strbh, strname

/// Get the current system local time SystemTime StsystemDatetime; Memset (& StsystemDateTime, 0, Sizeof (SystemTime));

GetLocalTime (& StsystemDateTime);

ITOA (StsystemDatetime.wyear, Szyear, 10); // year

IF (stsystemdatetime.wmonth <10) / month {ITOA (StsystemDatetime.wmonth, Sztemp, 10); Strcpy (Szmonth, "0"); strcat (szmonth, sztemp);} else {ketime.wmonth, szmonth, 10);

IF (StsystemDatetime.wday <10) // 日 {ITOA (StsystemDatetime.wday, SZTEMP, 10); STRCPY (SZDAY, "0"); strcat (szday, sztemp);} else {ketime.wday, szday, 10);

IF (StsystemDatetime.WHOUR <10) // hour {ITOA (SZTEMDATETIME.WHOUR, SZTEMP, 10); STRCPY (SZHOUR, "0"); STRCAT (SZHOUR, SZTEMP);} else {Itoa (stsystemdatetime.whour, szhour, 10);}} (stsystemdatetime.wminute <10) // minute {ITOA (SZTEMDATETIME.WMINUTE, SZTEMDATETIME.WMINUTE, SZTEMP, 10); STRCPY (Szminute, "0"); Strcat (Szminute, SzTemp);} else {Itoa (STSystemDateTime. WMINUTE, SZMINUTE, 10);

if (stSystemDateTime.wSecond <10) // sec {itoa (stSystemDateTime.wSecond, szSecond, 10); strcpy (szSecond, "0"); strcat (szSecond, szTemp);} else {itoa (stSystemDateTime.wSecond, szSecond, 10);

strDateTime = szYear; strDateTime = "-"; strDateTime = szMonth; strDateTime = "-"; strDateTime = szDay; strDateTime = ""; strDateTime = szHour; strDateTime = ":"; strDateTime = szMinute StRDATETIME = ":"; strdatetime = szsecond;

转载请注明原文地址:https://www.9cbs.com/read-31691.html

New Post(0)