日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

Visual C++ 2011-5-20

發布時間:2023/12/10 c/c++ 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Visual C++ 2011-5-20 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

一.LockFile和UnlockFile

鎖定文件部分區域,防止其他程序進行該部分區域的讀寫

#include <windows.h> #include <stdio.h>void main() {HANDLE hFile;HANDLE hAppend;DWORD dwBytesRead, dwBytesWritten, dwPos;BYTE buff[4096];// Open the existing file.hFile = CreateFile(TEXT("one.txt"), // open One.txtGENERIC_READ, // open for reading0, // do not shareNULL, // no securityOPEN_EXISTING, // existing file onlyFILE_ATTRIBUTE_NORMAL, // normal fileNULL); // no attr. templateif (hFile == INVALID_HANDLE_VALUE){printf("Could not open One.txt."); return;}// Open the existing file, or if the file does not exist,// create a new file.hAppend = CreateFile(TEXT("two.txt"), // open Two.txtFILE_APPEND_DATA, // open for writingFILE_SHARE_READ, // allow multiple readersNULL, // no securityOPEN_ALWAYS, // open or createFILE_ATTRIBUTE_NORMAL, // normal fileNULL); // no attr. templateif (hAppend == INVALID_HANDLE_VALUE){printf("Could not open Two.txt."); return;}// Append the first file to the end of the second file.// Lock the second file to prevent another process from// accessing it while writing to it. Unlock the// file when writing is complete.while (ReadFile(hFile, buff, sizeof(buff), &dwBytesRead, NULL)&& dwBytesRead > 0){dwPos = SetFilePointer(hAppend, 0, NULL, FILE_END);LockFile(hAppend, dwPos, 0, dwBytesRead, 0);WriteFile(hAppend, buff, dwBytesRead, &dwBytesWritten, NULL);UnlockFile(hAppend, dwPos, 0, dwBytesRead, 0);}// Close both files.CloseHandle(hFile);CloseHandle(hAppend); }

二.GetOverlappedResult

此函數可以查詢I/O處理過程中的傳輸狀態.如下代碼示例,可以通過以下方式查看狀態,見SDK示例(Testing for the End of a File)

// Check the result of the asynchronous read // without waiting (forth parameter FALSE). bResult = GetOverlappedResult(hFile,&stOverlapped,&dwBytesRead,FALSE) ; if (bResult) { float floatOffset=(float)stOverlapped.Offset;printf("ReadFile operation completed (%f)\n",floatOffset/dwFileSize);// Manual-reset event should be reset since it is now signaled.ResetEvent(stOverlapped.hEvent); }

三.Dialog消息循環

Dialog有著自己的消息循環,見下示例代碼,About消息循環在DialogBox函數中創建

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {int wmId, wmEvent;PAINTSTRUCT ps;HDC hdc;switch (message){case WM_COMMAND:wmId = LOWORD(wParam);wmEvent = HIWORD(wParam);// Parse the menu selections:switch (wmId){case IDM_ABOUT:DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);break;case IDM_EXIT:DestroyWindow(hWnd);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}break;case WM_PAINT:hdc = BeginPaint(hWnd, &ps);// TODO: Add any drawing code here...EndPaint(hWnd, &ps);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hWnd, message, wParam, lParam);}return 0; }// Message handler for about box. INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {UNREFERENCED_PARAMETER(lParam);switch (message){case WM_INITDIALOG:return (INT_PTR)TRUE;case WM_COMMAND:if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL){EndDialog(hDlg, LOWORD(wParam));return (INT_PTR)TRUE;}break;}return (INT_PTR)FALSE; }

四.對話框參數

DialogBoxParam 方法多了一個參數,可以在WM_INITDIALOG消息中傳遞一個參數,同理CreateDialog和CreateDialogParam也是如此

五.ATL窗體類介紹

很好的一篇文章
http://msdn.microsoft.com/en-us/library/aa260759(VS.60).aspx

http://www.vckbase.com/document/viewdoc/?id=1119

總結

以上是生活随笔為你收集整理的Visual C++ 2011-5-20的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。