當前位置:首頁 > 芯聞號 > 充電吧
[導讀]……21,程序只允許一個實例運行//在這個位置調(diào)用FirstInstance函數(shù)?BOOL CWindowsApp::InitInstance()?{?if (!FirstInstance())?re

……21,程序只允許一個實例運行
//在這個位置調(diào)用FirstInstance函數(shù)?
BOOL CWindowsApp::InitInstance()?
{?
if (!FirstInstance())?
return FALSE; //已經(jīng)有實例存在了,退出?
AfxEnableControlContainer();?
}?
//FirstInstance函數(shù)?
BOOL FirstInstance()?
{?
CWnd *pWndPrev;?
//根據(jù)主窗口類名和主窗口名判斷是否已經(jīng)有實例存在了?
if (pWndPrev = CWnd::FindWindow("#32770","Windows秘書"))//第二個參數(shù)為程序名?
{
//如果存在就將其激活,并顯示出來?
pWndPrev->ShowWindow(SW_RESTORE);?
pWndPrev->SetForegroundWindow();?
return FALSE;?
}else{
return TRUE;?
}?
}

………22,取得系統(tǒng)時間及計算時間差
DWORD system_runtime;?
system_runtime=GetTickCount()/60000;//取得系統(tǒng)運行時間?
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);//設(shè)定時間差為天數(shù)?
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,進制轉(zhuǎn)換
CString BinaryToDecimal(CString strBinary)//轉(zhuǎn)換二進制為十進制?
{?
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)//轉(zhuǎn)換二進制為十六進制?
{?
int nLength = strBinary.GetLength();?
CString str = strBinary;?
//位數(shù)不是四的倍數(shù)時補齊?
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++)?
{?
//每四位二進制數(shù)轉(zhuǎn)換為一十六進制數(shù)?
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進制的一個字符轉(zhuǎn)換為十進制的數(shù)?
{?
//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)//轉(zhuǎn)換十進制為二進制?
{?
int nDecimal = atoi(strDecimal.GetBuffer(0));?
int nYushu; //余數(shù)?
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)//轉(zhuǎn)換二進制為十進制?
{?
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,數(shù)學函數(shù)
sin();?
cos();?
tan();?
sqrt();?
pow(x,y);?
log();?
log10();?

………26,遞歸法遍歷磁盤目錄
void CQt::BrowseDir(CString strDir)?
{?
CFileFind ff;?
CString str,cs,inifile;?
inifile=regfilepath;?
inifile+="http://Windows秘書.ini";?
CString szDir = strDir;?
int index;?
char jjj,ppp,ggg;?
if(szDir.Right(1) != "http://")?
szDir += "http://";?
szDir += "*.*";?
BOOL res = ff.FindFile(szDir);?
while(res)?
{?
res = ff.FindNextFile();?
if(ff.IsDirectory() && !ff.IsDots())?
{?
//如果是一個子目錄,用遞歸繼續(xù)往深一層找?
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();//關(guān)閉?
//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轉(zhuǎn)換為路徑名?
SHGetPathFromIDList( pidlDestination, szPath);?
//添加如下函數(shù)?
BOOL BrowseForFolder(?
LPITEMIDLIST pidlRoot,//瀏覽開始處的PIDL?
LPITEMIDLIST *ppidlDestination,?
//瀏覽結(jié)束時所選擇的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);?
//寫入結(jié)構(gòu)體 字段名 變量名 值 大小 帶目錄文件名?
WritePrivateProfileStruct("字體","font",&LF,sizeof(LOGFONT),regpath);//結(jié)構(gòu)體?
//讀入字符 字段名 變量名 默認值 字符緩沖區(qū) 長度 帶目錄文件名?
GetPrivateProfileString("目錄","path","", buffer.GetBuffer(260),260,regpath);?
//讀入整數(shù)值 字段名 變量名 默認值 帶目錄文件名?
GetPrivateProfileInt("colors","red",255, regpath);?
//讀入結(jié)構(gòu)體 字段名 變量名 值 大小 帶目錄文件名?
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("",//注意這個字符串里如果只有一連串的字母或數(shù)字,沒有空格或中文或標點符號,且總長度超過距形寬度,則不能自動換行!!?
&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);?

//取得函數(shù)不能正常返回的原因字符***************************?

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


本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫毥谦F公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

加利福尼亞州圣克拉拉縣2024年8月30日 /美通社/ -- 數(shù)字化轉(zhuǎn)型技術(shù)解決方案公司Trianz今天宣布,該公司與Amazon Web Services (AWS)簽訂了...

關(guān)鍵字: AWS AN BSP 數(shù)字化

倫敦2024年8月29日 /美通社/ -- 英國汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開發(fā)耗時1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動 BSP

北京2024年8月28日 /美通社/ -- 越來越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運行,同時企業(yè)卻面臨越來越多業(yè)務(wù)中斷的風險,如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報道,騰訊和網(wǎng)易近期正在縮減他們對日本游戲市場的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會開幕式在貴陽舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導體

8月28日消息,在2024中國國際大數(shù)據(jù)產(chǎn)業(yè)博覽會上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機 衛(wèi)星通信

要點: 有效應(yīng)對環(huán)境變化,經(jīng)營業(yè)績穩(wěn)中有升 落實提質(zhì)增效舉措,毛利潤率延續(xù)升勢 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競爭力 堅持高質(zhì)量發(fā)展策略,塑強核心競爭優(yōu)勢...

關(guān)鍵字: 通信 BSP 電信運營商 數(shù)字經(jīng)濟

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺與中國電影電視技術(shù)學會聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會上宣布正式成立。 活動現(xiàn)場 NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會上,軟通動力信息技術(shù)(集團)股份有限公司(以下簡稱"軟通動力")與長三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉