二級(jí)考試C語(yǔ)言輔導(dǎo):VC常用知識(shí)重溫

字號(hào):

這次我們將會(huì)帶大家再次回顧一下VC的常用知識(shí),包括得到系統(tǒng)時(shí)間日期(使用GetLocalTime)、分離字串等。
    1: 得到系統(tǒng)時(shí)間日期(使用GetLocalTime)
    CString sTime,sYear,sMonth,sDay;
    SYSTEMTIME CurTime;
    GetLocalTime(&CurTime);
    sYear.Format(%d年,CurTime.wYear);
    sMonth.Format(%d月,CurTime.wMonth);
    sDay.Format(%d日,CurTime.wDay);
    sTime = sYear+ sMonth + sDay;
    // CurTime.wHour
    // CurTime.wMinute
    // CurTime.wSecond IBM的
    AfxMessageBox(sTime);
    2: 分離字串
    CString str = 4d3f0a2278;
    unsigned char a12;
    long x;
    for(int i = 0;i< (str.GetLength()/2);i++)
    {
    sscanf(str.Mid(2*i,2),%x,&x);
    a[i] = x;
    }
    3: 得到當(dāng)前目錄 (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);
    得到系統(tǒng)目錄 (GetSystemDirectory)
    4: 從字符串中提取數(shù)字
    CString strNum;
    CString str(測(cè)試125各國(guó)87kk);
    strNum = GetStr(str);
    AfxMessageBox(strNum);
    5: 創(chuàng)建無(wú)模對(duì)話框
    CDlg_Test *aa = new CDlg_Test;
    aa->Create(IDD_DIALOG1,NULL);
    aa->ShowWindow(SW_SHOW);1
    6: 得到窗口絕對(duì)坐標(biāo)
    CString strNum,strNum1;
    CRect rect;
    GetClientRect(&rect);
    ClientToScreen(&rect);
    strNum.Format(X: %d,rect.top);
    strNum1.Format( Y: %d,rect.center);
    strNum = strNum + strNum1;
    AfxMessageBox(strNum);
    7: 復(fù)制文件夾
    SHFILEOPSTRUCT Op;
    char FromBuf[]=E:temp;
    char ToBuf[]=SINTEKSERVER個(gè)人文檔陳 偉;;
    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;
    MessageBox(復(fù)制完畢,提示,MB_OK|MB_ICONINFORMATION);
    8: 捕獲 Ctrl+鼠標(biāo)左鍵 組合
    case WM_LBUTTONDOWN://鼠標(biāo)消息wParam ==
    if (wParam & MK_CONTROL)
    MessageBox(hwnd,aaa,bbb,MB_OK);
    break;
    或
    case WM_LBUTTONDOWN:
    MessageBox(hwnd,aaa,bbb,MB_OK);
    break;