C ++ common small function reference

Source: Internet
Author: User

1: Get the system time and date (using getlocaltime)
Cstring stime, syear, smonth, SDAY;
Systemtime curtime;
Getlocaltime (& amp; curtime );
Syear. Format ("% d Year", curtime. wyear );
Smonth. Format ("% d month", curtime. wmonth );
SDAY. Format ("% d", curtime. wday );
Stime = syear + smonth + SDAY;
// Curtime. whour
// Curtime. wminute
// Curtime. wsecond from IBM
Afxmessagebox (stime );

2: separating strings

Cstring STR = "4d3f0a2278 ";
Unsigned char a [12];
Long X;
For (INT I = 0; I <(Str. getlength ()/2); I ++)
{
Sscanf (Str. mid (2 * I, 2), "% x", & amp; x );
A [I] = X;
}

3: Get the current directory (getcurrentdirectory)
Char curpath [max_path];
DWORD size = max_path;
Getcurrentdirectory (size, curpath );
Afxmessagebox (curpath );

//
Cstring number;
Int Len = linelength (lineindex (0 ));
Lptstr P = number. getbuffer (LEN );
This-> Getline (0, P, Len );
Afxmessagebox (number );
Get the system directory (getsystemdirectory)

4: extract numbers from strings
Cstring strnum;
Cstring STR ("test 125 87kk ");
Strnum = getstr (STR );
Afxmessagebox (strnum );

5: Create a mode-free dialog box
Cdlg_test * AA = new cdlg_test;
Aa-> Create (idd_dialog1, null );
Aa-> showwindow (sw_show );

6. Obtain the absolute coordinates of the window.

Cstring strnum, strnum1;
Crect rect;
Getclientrect (& amp; rect );
Clienttoscreen (& amp; rect );
Strnum. Format ("X: % d", rect. Top );
Strnum1.format ("Y: % d", rect. Left );
Strnum = strnum + strnum1;
Afxmessagebox (strnum );

7. Copy a folder
Shfileopstruct op;

Char frombuf [] = "E: \ temp \ 0 ";
Char tobuf [] = "\\\\ sintekserver \ personal document \ CHEN Wei \ 0 ";;

Op. hwnd = NULL;
Op. wfunc = fo_copy;
Op. pfrom = frombuf;
Op. PTO = tobuf;
Op. fflags = fof_noconfirmation | fof_renameoncollision;
Op. fanyoperationsaborted = false;
Op. hnamemappings = NULL;
Op. lpszprogresstitle = NULL;

If (shfileoperation (& amp; OP) = 0)
MessageBox ("copied", "prompt", mb_ OK | mb_iconinformation );

8: capture Ctrl + left mouse button combination
Case wm_lbuttondown: // wparam =
If (wparam & amp; mk_control)
MessageBox (hwnd, "AAA", "BBB", mb_ OK );
Break;
Or
Case wm_lbuttondown:
If (getkeystate (vk_control) <0)
MessageBox (hwnd, "AAA", "BBB", mb_ OK );
Break;

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.