Some foundations: VC programming experience and errors

xiaoxiao2021-03-06  111

File operation

1, Unicode file start identification: 0xFeff;

#define setUnicode (Pfile) (FPUTWC (0xfeff, Pfile)

2, the text ("") function can convert the code value, not only to the wide character, for example:

Tchar Tzbuf [126];

Char czbuf [126];

Memset (TZBUF, 0, 126 * SIZEOF (TCHAR));

MEMSET (CZBUF, 0, 126);

WSPrintf (TZBUF, Text ("A San ASGA");

Sprintf (CZBUF, "ASGA");

or:

Tchar tzbuf [126] = text ("A San ASGA");

Char czbuf [126] = "A San ASGA";

in conclusion:

Address TZBUF: 963F, 4E09,0061,0073,0067,0061,0000

Address CZBUF: B0, A2, C8, FD, 61, 73, 67, 61, 00

3. Some equipment comes with the text editor unable to identify Chinese characters, whether it is ANSI or Unicode format;

4, when reading and writing Unicode text, you need to use "B" modifiers, such as "RB", "WB", not affected by FGETS and FGETWS;

5. Output format control description:

SINGLE-BYTE Character with Printf Functions H C OR C

SINGLE-BYTE Character with WPrintf Functions H C OR C

Wide Character with Printf Functions L C or C

Wide Character with WPRINTF Functions L C or C

SINGLE-BYTE - Character String with Printf Functions H s OR S

SINGLE-BYTE - Character String with WPrintf Functions H s OR S

Wide-Character String with Printf Functions L s OR S

Wide-Character String with WPrintf Functions L s OR S

Easy error 1:

SSCANF (BUF, Text ("% D"), var); // Forgetting "&"

SSCANF (BUF, Text ("% D"), & var);

Easy error 2:

When the Template Class MyTem is operated, if only Class MyClass is declared in the header file, then the following operation results in:

MyTem m_mytem;

Maybe error. I have encountered errors: MyClass uses Virtualalloc to allocate memory, and the value of SIZEOF (MyClass) is uncertain, resulting in allocating memory failed.

About ComboBox:

ComboBox has two types of DropDown and Droplist. For Droplist, Updatedata () can be used to get the user selected items in OnSelchange (), for Dropdown, you must use m_ctrlcombo.getsel (m_ctrlcombo.getsel) )), Then use Updatedata () to get the item selected. It is necessary to use the SHE handling problem, such as reading the file:

File * pfile = fopen (StrfileName, "R");

DO

{

__TRY

{

FGETS (CZBUF, LINENUM, PFILE);

// Do Your Things Here ...

}

__EXCEPT (Exception_execute_Handler)

{

// Continue or Break?

}

} while (! feof (pfile));

Fclose (pfile);

Use bitmap buffer drawing:

// Define bitmap:

CBITMAP M_BITMAP;

// Load bitmap or initialization bitmap:

// Load bitmap:

m_bitmap.loadbitmap (idb_bitmap1);

/ **** Initialization bit map **********

CClientDC ClientDC (this);

M_bitmap.createcompatibleBitmap (& ClientDC, 32, 32);

// ********************* /

// Initialize the memory device handle:

CClientDC ClientDC (this); // Display device handle

CDC MEMDC;

Memdc.createCompatibleDC (& ClientDC);

// Bit map is loaded into the memory device description table:

MEMDC.SELECTOBJECT (& M_Bitmap);

// Use a memory device to operate a bitmap:

MEMDC.PATBLT (0, 0, 32, 32, whitess); // Brush Wall

Memdc.ellipse (2, 2, 30, 30); //

// Display bitmap: OnDraw (CDC * PDC, ...)

Bitmap BM;

M_bitmap.getObject (Sizeof (BM), & BM);

PDC-> Bitblt

0,

0,

BM.BMWIDTH,

Bm.bmheight,

& MEMDC,

0,

0,

Srccopy);

// Other bitmap operation functions:

// PATBLT (int X, int y, int NWidth, int NHEIGHT, DWORD DWROP);

// Stretchblt (int X, int y, int nwidth, int nheight, cdc * psredc, int xsrc, int ysrc, int NSRCWIDTH, INT NSRCHEIGHT, DWORD DWROP);

Read the CF card ID number:

#include

Typedef struct _Storage_Identification {

DWORD DWSIZE;

DWORD DWFLAGS;

DWORD dwmanufactureidoffset;

DWORD DWSERIALNUMOFFSET;

} Storage_Identification, * pstorage_identification;

...

Tchar TzcfcardId [22];

Handle hcard = createfile ("DSK1:"), // Device Identifies Disk1 get generic_read | generic_write by query registry | generic_write,

0,

NULL,

Open_EXISTING,

0,

NULL);

IF (HCARD)

{

INT i = 0;

PSTORAGE_IDENTIFICATION PSTOREINFO;

PstoreInfo = (Storage_Identification *) Localalloc (LMEM_ZEROINIT, 3000);

DWORD DWGETBYTES;

IF (DeviceIocontrol (Hcard,

CTL_CODE (0x0007, 0x0709, method_buffered, file_any_access), // Key line: Specify IOCTL

NULL,

0,

(Lpvoid) PStoreInfo,

3000,

& dwgetBytes,

NULL)

! = False)

{

IF (dWgetBytes> 0)

{

i = 0;

INT j = 0;

IF (PstoreInfo-> DWSerialnumoffset

{

Byte * serialno = ((Byte *) pstoreInfo pstoreInfo-> dwserialnumoffset;

While (Serialno [I]! = 0 && i <(int) (dwgetbytes-pstoreinfo-> dwserialnumoffset) && i <22)

{

IF (Serialno [i] <'0' || serialno [i]> 'Z')

{

J ;

}

Else

{

TzcfCardId [i - j] = (tchar) Serialno [i];

}

i ;

}

}

TzcfcardId [i - j] = 0;

}

}

Else

{

WSPrintf (Tzerror, Text ("Query Storage Card ID Failed, Error Number% Lu!"), getLastError ());

AfxMessageBox (Tzerror);

Localfree (PstoreInfo);

CloseHandle (HCARD);

Return False;

}

Localfree (PstoreInfo);

CloseHandle (HCARD);

...

// Description: Some cards are not a card number, I got it for a long time :)

Key code segment runtime test

__INT64 FILETITOQUADWORD (PfileTime PFT)

{

Return (INT64SHLLMOD32 (PFT-> DWHighDateTime, 32) | PFT-> DWLOWDATETIME);

}

Union LTIME

{

int NTIME [2];

__INT64 LTIME;

}

Filetime ftkerneltimestart, ftkerneltimend;

Filetime FTUSERTIMESTART, FTUSERTIMEEND;

Filetime ftdummy;

__int64 qwkerneltimeelapsed, qwusertimelapsed,

QWTOTALTIMEELAPSED;

Int nTimes;

LTIME KERNELTIME, USERTIME, TOTALTIME

void timestart ()

{

GetThreadTimes (GetCurrentThread (), & ftdummy, & ftdummy, & ftkerneltimestart, & ftusertimeStart;

}

void timeend ()

{

GetThreadTimes (GetCurrentThread (), & ftdummy, & ftdummy,

& ftkerneltimeEnd, & fTusertimeEnd;

QwkernelTimeElapsed = filetimetoquadword (& ftkernelTimeEnd) -

Filetimetoquadword (& ftkernelTimeStart);

QwusertimeElapsed = filetimetoquadword (& fTusertimeEnd) -

Filetimetoquadword (& fTusertimeStart);

/ *

Large_integer listart, liend;

Listart.highpart = fTusertimeStart.dwhightatetime;

Listart.lowpart = ftusertimestart.dwlowdatetime;

LiEND.HIGHPART = fTusertimeEnd.dwhighdatetime;

LiEND.LOWPART = fTusertimeEnd.dwlowDatetime;

QwusertimeLapsed = liend.quadpart - listart.quadpart;

// * /

QWTOTALTIMEELAPSED = QWKERNELTIMEELAPSED QwusertimeLapsed;

NTIMES ;

KernelTime.lti = kernelTime.ltime (QWkernelTimeLapsed - kernelTime.ltime) / NTIMES

Usertime.ltime = useertime.ltime (qwusertimelapsed - usertime.ltime) / ntimes;

TotalTime.ltime = TotalTime.ltime (qwtotaltimeLapsed - Totaltime.ltime) / NTIMES

}

void timereport ()

{

File * pfile = fopen ("TestTime.txt", "A ");

FPRINTF (Pfile, "Test Description: / N");

FPRINTF (Pfile, "Total Times:% D / N", NTIMES);

FPrintf (Pfile, "Kernel Time Elapsed:% D,% D / N", kerneltime.ntime [1], kerneltime.ntime [0]);

FPRINTF (Pfile, "User Time Elapsed:% D,% D / N", useertime.ntime [1], useertime.ntime [0]);

FPRINTF (Pfile, "Total Time Elapsed:% D,% D / N / N", Totaltime.ntime [1], Totaltime.ntime [0]);

Fclose (pfile);

}

Void inittesttime ()

{

NTIMES = 0;

KernelTime.lti = 0;

UserTime.ltime = 0;

Totaltime.ltime = 0;}

Code replacement link

#pragma comment (Lib, "OpenGL32.LIB") // Use OpenGL32.LIB when link

List operation

Icon settings

M_atttypeImagelist.create (idb_attributetype, 16, 0, false);

M_CTRLLSTPOS.SetImageList (& m_atttypelist, lvsil_small);

Column operation

LV_COLUMN LVC;

Lvc.mask = (LVCF_FMT | LVCF_WIDTH | LVCF_Text | LVCF_SUBITEM);

LVC.fmt = lvcfmt_left;

TCHAR * CAPTION [6] = {Text ("Dista"),

Text ("Engineering X"), Text ("Project Y"),

Text ("Engineering H"), Text ("High"),

TEXT ("Description")};

For (int i = 0; i <6; i )

{

Lvc.psztext = CAPTION [I];

IF (i == 0) lvc.cx = 60;

Else LVC.cx = 100;

Lvc.isubitem = i;

m_ctrllistpos.insertcolumn (i, & lvc);

}

Record operation

LV_Item LVI;

Lvi.mask = lvif_text | LVIF_IMAGE;

Lvi.psztext = PDPOS-> M_TZNAME;

LVI.IITEM = i;

Lvi.isubitem = 0;

IF (...)

LVI.IMAGE = 0;

Else

LVI.IMAGE = 1;

M_CtrllistPos.SetItem (& lvi);

TCHAR CC [20];

_stprintf (CC, Text ("%. 3LF"), PDPOS-> M_x);

m_ctrllistpos.setitemtext (LVI.IITEM, 1, CC);

_stprintf (cc, text ("%. 3LF"), PDPOS-> M_Y);

m_ctrllistpos.setitemtext (i, 2, cc);

_stprintf (CC, Text ("%. 3LF"), PDPOS-> M_Z);

m_ctrllistpos.setitemtext (i, 3, cc);

_Stprintf (CC, Text ("%. 3LF"), PDPOS-> M_DANTH);

m_ctrllistpos.setitemtext (i, 4, cc);

m_ctrllistpos.setitemtext (i, 5, pdpos-> m_tzattribute);

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

New Post(0)