1. 程式人生 > >筆記(執行緒、檔案、當前時間)

筆記(執行緒、檔案、當前時間)

FILE* out_num;
FILE* out_pic;

 HANDLE hThread;
// DWORD dwThread;
 HANDLE hThread2;

 
DWORD WINAPI NumSaveFile_proc(LPVOID lpParam);
DWORD WINAPI PicSaveFile_proc(LPVOID lpParam);

DWORD WINAPI NumSaveFile_proc(LPVOID lpParam)
{
 AfxMessageBox("num file proc");
 out_num = fopen("num_saveFile", "w");
 CTime ctime=CTime::GetCurrentTime(); //得到當前系統時間
 CString AimTime = ctime.Format("%H:%M:%S");
 while(1)
 {
  Sleep(30);
//  fprintf(out_num, "%s %d\n", AimTime, v_gps);
 }
 
 return 0;
}

DWORD WINAPI PicSaveFile_proc(LPVOID lpParam)
{
 AfxMessageBox("pic file proc");
 out_pic = fopen("pic_saveFile", "w");
 CTime ctime=CTime::GetCurrentTime(); //得到當前系統時間
// AimTime = ctime.Format("%H:%M:%S");
 while(1)
 {
  Sleep(30);
//  fprintf(out_pic, "%s %d\n", AimTime, v_gps);
 }
 return 0;
}
/*
 hThread = ::CreateThread(NULL,0,num_proc, NULL, CREATE_SUSPENDED, NULL);
 hThread2 = ::CreateThread(NULL,0,pic_proc, NULL, CREATE_SUSPENDED, NULL);
 // 開始執行緒/
 AfxMessageBox("開始任務,啟動執行緒");
 ::ResumeThread (hThread);   // 執行緒控制代碼
 ::ResumeThread (hThread2);   // 執行緒控制代碼
  // 結束執行緒/
 ::CloseHandle(hThread);
 ::CloseHandle(hThread2);

//  static成員函式只能呼叫靜態的或者全全域性的;舉例說明:類中宣告執行緒函式
//  class Cxxx : public CDialog{ static UINT Doxxx(LPVOID pParam);}
//  建立執行緒
//  AfxBeginThread(DoDBServer,this);\\傳入this指標執行緒函式體:
//  UINT Cxxx::Doxxx(LPVOID pParam){ Cxxx* p=(Cxxx*)pParam;
//  使用指標呼叫類成員即可。}

*/

CopyFile(原始檔名,目標檔名,引數); 

說明:

“引數”如果設為TRUE(非零),那麼一旦目標檔案已經存在,則函式呼叫會失敗。否則目標檔案被改寫。

返回值 Long,非零表示成功,零表示失敗。

例:

CopyFile(".\\A.html","..\\B.html",FALSE);