C++常用小功能參考

來源:互聯網
上載者:User

1: 得到系統時間日期(使用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 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: 得到目前的目錄 (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);
得到系統目錄 (GetSystemDirectory)

4: 從字串中提取數字
CString strNum;
CString str("測試125各國87kk");
strNum = GetStr(str);
AfxMessageBox(strNum);

5: 建立無模對話方塊
CDlg_Test *aa = new CDlg_Test;
aa->Create(IDD_DIALOG1,NULL);
aa->ShowWindow(SW_SHOW);

6: 得到視窗絕對座標

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: 複製檔案夾
SHFILEOPSTRUCT Op;

char FromBuf[]="E:\\temp\0";
char ToBuf[]="\\\\SINTEKSERVER\\個人文檔\\陳 偉\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("複製完畢","提示",MB_OK|MB_ICONINFORMATION);

8: 捕獲 Ctrl+滑鼠左鍵 組合
case WM_LBUTTONDOWN://滑鼠訊息wParam ==
if (wParam &amp; MK_CONTROL)
MessageBox(hwnd,"aaa","bbb",MB_OK);
break;

case WM_LBUTTONDOWN:
if(GetKeyState(VK_CONTROL)<0)
MessageBox(hwnd,"aaa","bbb",MB_OK);
break;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.