| 订阅 | 在线投稿
分享
 
 
 

编程必备:VC常用知识重温

来源:互联网网民  宽屏版  评论
2006-12-16 17:27:41

这次我们将会带大家再次回顾一下VC的常用知识,包括得到系统时间日期(使用GetLocalTime)、分离字串等。

1: 得到系统时间日期(使用GetLocalTime)

BR clear=all>

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);

||||||6: 得到窗口绝对坐标

CString strNum,strNum1;

CRect rect;

GetClientRect(&rect);

ClientToScreen(&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(&Op) == 0)

MessageBox("复制完毕","提示",MB_OK|MB_ICONINFORMATION);

8: 捕获 Ctrl+鼠标左键 组合

case WM_LBUTTONDOWN://鼠标消息wParam ==

if (wParam & MK_CONTROL)

MessageBox(hwnd,"aaa","bbb",MB_OK);

break;

case WM_LBUTTONDOWN:

if(GetKeyState(VK_CONTROL)<0)

MessageBox(hwnd,"aaa","bbb",MB_OK);

break;

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",&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);

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
  这次我们将会带大家再次回顾一下VC的常用知识,包括得到系统时间日期(使用GetLocalTime)、分离字串等。      1: 得到系统时间日期(使用GetLocalTime) BR clear=all>   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); |||||| 6: 得到窗口绝对坐标   CString strNum,strNum1;   CRect rect;   GetClientRect(&rect);   ClientToScreen(&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(&Op) == 0)   MessageBox("复制完毕","提示",MB_OK|MB_ICONINFORMATION);   8: 捕获 Ctrl+鼠标左键 组合   case WM_LBUTTONDOWN://鼠标消息wParam ==   if (wParam & MK_CONTROL)   MessageBox(hwnd,"aaa","bbb",MB_OK);   break;   或   case WM_LBUTTONDOWN:   if(GetKeyState(VK_CONTROL)<0)   MessageBox(hwnd,"aaa","bbb",MB_OK);   break;      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",&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);
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有