当前位置:首页 > 芯闻号 > 充电吧
[导读]……21,程序只允许一个实例运行//在这个位置调用FirstInstance函数 BOOL CWindowsApp::InitInstance() { if (!FirstInstance()) re

……21,程序只允许一个实例运行
//在这个位置调用FirstInstance函数 
BOOL CWindowsApp::InitInstance() 

if (!FirstInstance()) 
return FALSE; //已经有实例存在了,退出 
AfxEnableControlContainer(); 

//FirstInstance函数 
BOOL FirstInstance() 

CWnd *pWndPrev; 
//根据主窗口类名和主窗口名判断是否已经有实例存在了 
if (pWndPrev = CWnd::FindWindow("#32770","Windows秘书"))//第二个参数为程序名 
{
//如果存在就将其激活,并显示出来 
pWndPrev->ShowWindow(SW_RESTORE); 
pWndPrev->SetForegroundWindow(); 
return FALSE; 
}else{
return TRUE; 

}

………22,取得系统时间及计算时间差
DWORD system_runtime; 
system_runtime=GetTickCount()/60000;//取得系统运行时间 
SYSTEMTIME sysTime; // Win32 time information 
GetLocalTime(&sysTime); 
COleDateTime now(sysTime); 
//COleDateTime now; 
//now=now.GetCurrentTime(); 
//GetCurrentTime()取得时间与time( time_t *timer );和struct tm *localtime( const time_t *timer );所得时间相同只能到2037年 
//而GetLocalTime(&sysTime);可到9999年 
m_zbyear=now.GetYear();//年 
m_zbmonth=now.GetMonth();//月 
m_zbday=now.GetDay();//日 
now.GetDayOfWeek();//weekday 
COleDateTimeSpan sub; 
sub.SetDateTimeSpan(m_howdaysafteris,0,0,0);//设定时间差为天数 
now+=sub; 
then.SetDateTime(,,,,,,,);//其它方式添加时保存的当时时间 
if(!now.SetDate(m_jsyear,m_jsmonth,m_jsday)//检查时间是否正确 &&!then.SetDate(m_jsyear2,m_jsmonth2,m_jsday2)) 

sub=then-now; 
CString cs; 
cs.Format("%d年%d月%d日 相距 %d年%d月%d日/n/n %.0f天",m_jsyear,m_jsmonth,m_jsday, 
m_jsyear2,m_jsmonth2,m_jsday2,sub.GetTotalDays()); 
MessageBox(cs); 

else 
MessageBox("您输入的时间有误,请重新输入!","Windows秘书",MB_OK|MB_ICONSTOP); 

………23,文件操作
//打开文件对话框 
CFileDialog dlg(TRUE, "mp3", NULL, OFN_FILEMUSTEXIST|OFN_NOCHANGEDIR, 
"音乐/电影文件(*.mp3,*.wav,*.avi,*.asf)|*.mp3;*.wav;*.avi;*.asf|"/ 
"mp3 文件(*.mp3)|*.mp3|" / 
"音频文件 (*.wav)|*.wav|" / 
"视频文件 (*.avi)|*.avi|" / 
"Window Media 文件(*.asf)|*.asf|" / 
"所有文件 (*.*)|*.*||"); 
if(dlg.DoModal()==IDOK) 

CString m_filename=dlg.GetPathName(); 

//读取文件 
CFile file; 
If (file.Open(m_filename,CFile::modeRead)) 

file.Read(zbpassword,sizeof(zbpassword)); 

file.Close(); 
//写入文件 
if (file.Open(m_zbfilename,CFile::modeCreate|CFile::modeWrite)) 

zbfile.Write(zbpassword,sizeof(zbpassword)); 

file.Close(); 

………24,进制转换
CString BinaryToDecimal(CString strBinary)//转换二进制为十进制 

int nLenth = strBinary.GetLength(); 
char* Binary = new char[nLenth]; 
Binary = strBinary.GetBuffer(0); 
int nDecimal = 0; 
for(int i=0;i<nLenth;i++) 

char h = Binary[nLenth-1-i]; 
char str[1]; 
str[0] = h; 
int j = atoi(str); 
for(int k=0;k<i;k++) j=j*2;  
nDecimal += j; 

CString strDecimal; 
strDecimal.Format("%d",nDecimal); 
return strDecimal; 

CString BinaryToHex(CString strBinary)//转换二进制为十六进制 

int nLength = strBinary.GetLength(); 
CString str = strBinary; 
//位数不是四的倍数时补齐 
switch(nLength%4) 

case 0: 
break; 
case 1: 
strBinary.Format("%d%d%d%s",0,0,0,str); 
break; 
case 2: 
strBinary.Format("%d%d%s",0,0,str); 
break; 
case 3: 
strBinary.Format("%d%s",0,str); 
break; 
default: 
return ""; 
break; 

CString strHex,str1; 
str1 = ""; 
nLength = strBinary.GetLength(); 
for(int i=1;i<=(nLength/4);i++) 

//每四位二进制数转换为一十六进制数 
str = strBinary.Left(4); 
CString strDecimal = BinaryToDecimal(str); 
int nDecimal = atoi(strDecimal.GetBuffer(0)); 
if (nDecimal<10) 
str1.Format("%d",nDecimal); 
else 

char c = 'A' + (nDecimal-10); 
str1.Format("%c",c); 

strHex += str1; 
strBinary = strBinary.Right(strBinary.GetLength()-str.GetLength()); 

return strHex; 

unsigned char BtoH(char ch)//将16进制的一个字符转换为十进制的数 

//0-9 
if (ch >= '0' && ch <= '9') 
return (ch - '0'); 
//9-15 
if (ch >= 'A' && ch <= 'F') 
return (ch - 'A' + 0xA); 
//9-15 
if (ch >= 'a' && ch <= 'f') 
return (ch - 'a' + 0xA); 
return(255); 

CString DecimalToBinary(CString strDecimal)//转换十进制为二进制 

int nDecimal = atoi(strDecimal.GetBuffer(0)); 
int nYushu; //余数 
int nShang; //商 
CString strBinary = ""; 
char buff[2]; 
CString str = ""; 
BOOL bContinue = TRUE; 
while(bContinue) 

nYushu = nDecimal%2; 
nShang = nDecimal/2; 
sprintf(buff,"%d",nYushu); 
str = strBinary; 
strBinary.Format("%s%s",buff,str); 
nDecimal = nShang; 
if(nShang==0) 
bContinue = FALSE; 

return strBinary; 


CString BinaryToDecimal(CString strBinary)//转换二进制为十进制 

int nLenth = strBinary.GetLength(); 
char* Binary = new char[nLenth]; 
Binary = strBinary.GetBuffer(0); 
int nDecimal = 0; 
for(int i=0;i<nLenth;i++) 

char h = Binary[nLenth-1-i]; 
char str[1]; 
str[0] = h; 
int j = atoi(str); 
for(int k=0;k<i;k++) j=j*2;  
nDecimal += j; 

CString strDecimal; 
strDecimal.Format("%d",nDecimal); 
return strDecimal; 


………25,数学函数
sin(); 
cos(); 
tan(); 
sqrt(); 
pow(x,y); 
log(); 
log10(); 

………26,递归法遍历磁盘目录
void CQt::BrowseDir(CString strDir) 

CFileFind ff; 
CString str,cs,inifile; 
inifile=regfilepath; 
inifile+="//Windows秘书.ini"; 
CString szDir = strDir; 
int index; 
char jjj,ppp,ggg; 
if(szDir.Right(1) != "//") 
szDir += "//"; 
szDir += "*.*"; 
BOOL res = ff.FindFile(szDir); 
while(res) 

res = ff.FindNextFile(); 
if(ff.IsDirectory() && !ff.IsDots()) 

//如果是一个子目录,用递归继续往深一层找 
BrowseDir(ff.GetFilePath()); 

else if(!ff.IsDirectory() && !ff.IsDots()) 

//显示当前访问的文件 
str=ff.GetFilePath(); 
/* index=str.GetLength(); 
//MessageBox(str); 
jjj=str.GetAt(index-3); 
ppp=str.GetAt(index-2); 
ggg=str.GetAt(index-1); 
if(((jjj=='J'||jjj=='j')&&(ppp=='P'||ppp=='p')&&(ggg=='G'||ggg=='g'))||((jjj=='B'||jjj=='b')&&(ppp=='M'||ppp=='m')&&(ggg=='P'||ggg=='p')))

intNumber++; 
cs.Format("%d",intNumber); 
WritePrivateProfileString("图片目录文件",cs,str,inifile);*/ 
//Sleep(3); 



ff.Close();//关闭 
//cs.Format("%d",intNumber); 
//WritePrivateProfileString("图片目录文件","total",cs,inifile); 
//WritePrivateProfileString("图片目录文件","turntowhich","1",inifile); 


//公用目录对话框**************************************************** 

//添加如下程序段 
LPITEMIDLIST pidlBeginAt, pidlDestination ; 
char szPath[ MAX_PATH] ; 
// 取得开始菜单或桌面的PIDL 
SHGetSpecialFolderLocation(AfxGetApp()->m_pMainWnd->m_hWnd,CSIDL_DESKTOP,&pidlBeginAt) ; 
// 取得新建文件夹的父文件夹 
if( !BrowseForFolder(pidlBeginAt , 
&pidlDestination, 
"请选择图片目录的位置:")) 

return ; 

// 把PIDL转换为路径名 
SHGetPathFromIDList( pidlDestination, szPath); 
//添加如下函数 
BOOL BrowseForFolder( 
LPITEMIDLIST pidlRoot,//浏览开始处的PIDL 
LPITEMIDLIST *ppidlDestination, 
//浏览结束时所选择的PIDL 
LPCSTR lpszTitle)//浏览对话框中的提示文字 

BROWSEINFO BrInfo ; 
ZeroMemory( &BrInfo, sizeof(BrInfo)) ; 
BrInfo.hwndOwner = HWND_DESKTOP ; 
BrInfo.pidlRoot = pidlRoot ; 
BrInfo.lpszTitle = lpszTitle ; 
//浏览文件夹 
*ppidlDestination= SHBrowseForFolder(&BrInfo); 
//用户选择了取消按钮 
if(NULL == *ppidlDestination) 
return FALSE ;/**/ 
return TRUE ; 


//读写INI/ini文件************************************************* 

//写入值 字段名 变量名 值 带目录文件名 
WritePrivateProfileString("目录","path",cs, regpath); 
//写入结构体 字段名 变量名 值 大小 带目录文件名 
WritePrivateProfileStruct("字体","font",&LF,sizeof(LOGFONT),regpath);//结构体 
//读入字符 字段名 变量名 默认值 字符缓冲区 长度 带目录文件名 
GetPrivateProfileString("目录","path","", buffer.GetBuffer(260),260,regpath); 
//读入整数值 字段名 变量名 默认值 带目录文件名 
GetPrivateProfileInt("colors","red",255, regpath); 
//读入结构体 字段名 变量名 值 大小 带目录文件名 
GetPrivateProfileStruct("字体","font",&LF,sizeof(LOGFONT),regpath); 

//位图操作,画图***************************************************** 

CClientDC client(this); 
BITMAP bmpInfo; 
CDC memdc; 
CBitmap picture; 
memdc.CreateCompatibleDC(pdc); 
memdc.SelectObject(&picture); 
CRect re; 
GetClientRect(&re); 
client.BitBlt(0,0,bmpInfo.bmWidth,bmpInfo.bmHeight,&memdc,0,0,SRCCOPY); 
client.SetBkMode(TRANSPARENT); 
client.SetTextColor(RGB(red,green,blue)); 
CFont font; 
CFont *oldfont; 
font.CreateFontIndirect(&LF); 
oldfont=client.SelectObject(&font); 
client.DrawText("",//注意这个字符串里如果只有一连串的字母或数字,没有空格或中文或标点符号,且总长度超过距形宽度,则不能自动换行!! 
&re,DT_CENTER |DT_WORDBREAK); 
client.SelectObject(oldfont); 

//打开EXE/exe文件********************************************** 

ShellExecute(GetSafeHwnd(), 
"open", 
"http://home.jlu.edu.cn/~ygsoft",//改这个文件名就可以了 
NULL, 
NULL,SW_SHOWNORMAL); 
//or 
LPITEMIDLIST pidlBeginAt; 
// 取得桌面的PIDL 
SHGetSpecialFolderLocation(AfxGetApp()->m_pMainWnd->m_hWnd, 
CSIDL_DRIVES//这个标志为我的电脑 
,&pidlBeginAt) ; 
SHELLEXECUTEINFO exe; 
ZeroMemory(&exe,sizeof(SHELLEXECUTEINFO)); 
exe.cbSize=sizeof(SHELLEXECUTEINFO); 
exe.fMask=SEE_MASK_IDLIST; 
exe.lpVerb="open"; 
exe.nShow=SW_SHOWNORMAL; 
exe.lpIDList=pidlBeginAt; 
ShellExecuteEx(&exe); 

//取得函数不能正常返回的原因字符*************************** 

LPVOID lpMsgBuf; 
FormatMessage( 
FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM | 
FORMAT_MESSAGE_IGNORE_InsertS, 
NULL, 
GetLastError(), 
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 
(LPTSTR) &lpMsgBuf, 
0, 
NULL 
); 
// Process any inserts in lpMsgBuf. 
// ... 
// Display the string. 
MessageBox((LPCTSTR)lpMsgBuf); 
// Free the buffer. 
LocalFree( lpMsgBuf ); 


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除。
换一批
延伸阅读

采用VC++的制瓶机微机控制系统的串口通信 制瓶机微机控制系统的基本功能是控制制瓶机的各个机械动作,使其按照设定程序进行工作。为了实现主机与下位机之间的控制操作和数据管理,需要通过串口连接具有数据采

关键字: vc 串口通信

【导读】:前谷歌风投技术合伙人张拓木接受了李开复抛出的橄榄枝,加入创新工场,将担任担纲探索数据、机器模型驱动的投资实践工作,也会参与AI和大数据方向的投资。 在AI侵袭千行百业

关键字: AI vc 创新工场 李开复

由于原文章没有转载链接,只好直接粘贴过来,附上原文地址:http://www.cnblogs.com/feiyangqingyun/p/3720777.html 既然QT也是C++,而且有个大名鼎鼎

关键字: QT vc

2008年,当同龄人还在中学乖乖念书的时候,15岁的Sahil已经实现了经济独立——他靠卖应用赚到10万美元。

关键字: vc 独角兽 风投

起因: 公司项目 服务器的nginx是使用的定制版,使用了concat、缩略图生成等模块,为了方便同事们在办公室环境下使用nginx,在Windows下编译nginx,并带上这两个模块。之前在 VC2

关键字: openssl vc

 1.只允许运行程序的一个实例MFC写在InitInstance函数中    HANDLE hMutex = CreateMutex(NULL, TRUE, _T("test")); //创建一个有名

关键字: vc

VC修改窗口属性 GetWindowLong(), SetWindowLong() 2015-07-01 19:06 425人阅读 评论(0) 收藏 举报分类:版权声明:本文为博主原创文章,未经

关键字: vc

早些年的创业公司取得成功,投资人收到回报助长了他们的信心,同时伴随着中国风投市场的趋于饱和,越来越多的中国 VC 开始来到南亚的印度寻找机会。

关键字: vc 移动互联 swarup 印度互联网圈

  步进电机是一种将电脉冲信号转换为线位移或角位移的电机,但步进电机的控制通常都采用汇编语言或C语言进行软件开发,本文结合SC3步进电机控制器及平移台的控制开发为例

关键字: vc 嵌入式开发 控制系统 步进电机
关闭
关闭