VC common tips:
1: Get the system time dates (using getLocaltime) CString Stime, Syear, SMONTH, SDAY; SystemTime Curtime; getLocalTime (& Curtime); Syar.Format ("% D years", curtime.wyear); smonth.format ("% D Month) ", Curtime.wmonth; sday.format ("% d day ", curtime.wday; stime = syear smhood sday; // curtime.wHour // curtime.wminute // curtime.wsecond IBM AFXMESSAGEBOX (STIME) ; 2: Separation string
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", & x); a [i] = x;}
3: obtain 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 digital CString Strnum; CString STR ("test 125 countries 87kk"); strnum = getStr (STR); afxMessageBox (Strnum); 5: Create a modelless dialog CDLG_TEST * AA = New CDLG_Test; aa- > CREATE (IDD_DIALOG1, NULL); aa-> showwindow;
6: Get the absolute coordinates of the window
CSTRING STRNUM, STRNUM1; CRECT Rect; getClientRect (& Re); clienttoscreen (& Re); strnum.format ("x:% d", rect.top); strnum1.format ("Y:% D", Rect.Left); Strnum = Strnum Strnum1; AFXMessageBox (Strnum); 7: Copy 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 (& OP) == 0) MessageBox ("copy finished", "prompt", MB_OK | MB_ICONICONFORMATION); 8: Capture CTRL mouse left mouse combination case wm_lbuttondown: // mouse message wparam == IF ( WPARAM & 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; ;