VC编程技巧

1.得到程序路径
 TCHAR exeFullPath[MAX_PATH];
 GetModuleFileName(NULL,exeFullPath,MAX_PATH)
2.从对话框得到一个文件夹
 char szDir[MAX_PATH];
 BROWSEINFO bi;
 ITEMIDLIST *pidl;

 bi.hwndOwner = this->m_hWnd;
 bi.pidlRoot = NULL;
 bi.pszDisplayName = szDir;
 bi.lpszTitle = "请选择受控的目录";//strDlgTitle;
 bi.ulFlags = BIF_RETURNONLYFSDIRS;
 bi.lpfn = NULL;
 bi.lParam = 0;
 bi.iImage = 0;

 pidl = SHBrowseForFolder(&bi);
 if(pidl == NULL) 
    return;
 if(!SHGetPathFromIDList(pidl, szDir))
  return;
3.分割字符串

 CString s="aaa,bbb,ccc,ddd";
 char a1[4],a2[4],a3[4],a4[4];
 sscanf(s,"%[^,],%[^,],%[^,],%[^,]",a1,a2,a3,a4);
 AfxMessageBox(a4);//显示ddd
4.关闭显示器:
 ::SendMessage(GetSafeHwnd(), WM_SYSCOMMAND, SC_MONITORPOWER, 1);
5.  打开显示器:
 ::SendMessage(GetSafeHwnd(), WM_SYSCOMMAND, SC_MONITORPOWER, -1);
6.得到系统时间、语言等的设置
 GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_ITIME, lpLCData, cchData);
7.计算windows的运行时间
 ULONG Time_mm  =GetTickCount();
 ULONG Time_sec =(Time_mm/1000)%60;
 int  Time_min =(Time_mm/(1000*60))%60;
 int  Time_hour =(Time_mm/(1000*60*60))%24;
 int  Time_day =(Time_mm/(1000*60*60*24));
 cout<<Time_day<<" day(s) "<<Time_hour<<" hour(s) "<<Time_min<<" minute(s) "<<Time_sec<<"second(s)./n";
8.文件是否存在(头文件io.h)
 if(_access("c://somefile.file",0)!=-1)
  //存在

 else
  //不存在
9.得到剪贴板数据
if ( OpenClipboard() )                      
 {
  HANDLE hData = GetClipboardData(CF_TEXT);
        char * buffer = (char*)GlobalLock(hData);
        fromClipboard = buffer;
        GlobalUnlock(hData);
        CloseClipboard();
}
10.在CStatic上面关联图片

CStatic* pWnd = (CStatic*)GetDlgItem(IDC_STATIC);
 pWnd->ModifyStyle(0, SS_BITMAP);
 pWnd->SetBitmap((HBITMAP)::LoadImage(0,
      "c://zzzzz.bmp",
      IMAGE_BITMAP,
      0,0,LR_CREATEDIBSECTION |LR_DEFAULTSIZE |LR_LOADFROMFILE));

你可能感兴趣的:(编程,null,BI,buffer,Access,Path)