├── .gitignore ├── BIOS └── GetBIOSInfo │ ├── GetBIOSInfo.cpp │ └── GetBIOSInfo.vcxproj ├── BypassUAC ├── ByPassUAC_COM_Demo │ ├── ByPassUAC_COM_Demo.cpp │ └── ByPassUAC_COM_Demo.vcxproj └── ByPassUAC_COM_LIB │ ├── ByPassUAC_COM_LIB.vcxproj │ ├── BypassUAC.cpp │ ├── BypassUAC.h │ ├── BypassUACLib.cpp │ ├── Source.def │ ├── dllmain.cpp │ └── framework.h ├── COM ├── ComPtr │ ├── ComPtrInitialization │ │ ├── ComPtrInitialization.cpp │ │ └── ComPtrInitialization.vcxproj │ ├── ComPtrQueryInterface │ │ ├── ComPtrQueryInterface.cpp │ │ ├── ComPtrQueryInterface.vcxproj │ │ └── explorer_back.png │ └── ComPtrReset │ │ ├── ComPtrReset.cpp │ │ └── ComPtrReset.vcxproj └── Create │ ├── COM.cpp │ └── COM.vcxproj ├── ClassFeature ├── ClassFeature.cpp └── ClassFeature.vcxproj ├── ClipBoard ├── CClipBoardDialog.cpp ├── CClipBoardDialog.h ├── ClipBoard.cpp ├── ClipBoard.h ├── ClipBoard.rc ├── ClipBoard.vcxproj ├── ClipBoard.vcxproj.filters ├── ClipBoardDlg.cpp ├── ClipBoardDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── ClipBoard.ico │ └── ClipBoard.rc2 ├── resource.h └── targetver.h ├── CommonDlg ├── CommonDlg.cpp ├── CommonDlg.h ├── CommonDlg.rc ├── CommonDlg.vcxproj ├── CommonDlg.vcxproj.filters ├── CommonDlgDlg.cpp ├── CommonDlgDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── CommonDlg.ico │ └── CommonDlg.rc2 ├── resource.h └── targetver.h ├── CreateWindowDemo ├── CreateWindowDemo.cpp ├── CreateWindowDemo.h ├── CreateWindowDemo.ico ├── CreateWindowDemo.rc ├── CreateWindowDemo.vcxproj ├── Resource.h ├── framework.h ├── small.ico └── targetver.h ├── DWM └── GetSystemGlassColor │ ├── GetSystemGlassColor.cpp │ └── GetSystemGlassColor.vcxproj ├── Desktop ├── Desktop.cpp ├── Desktop.h ├── Desktop.rc ├── Desktop.vcxproj ├── Desktop.vcxproj.filters ├── DesktopDlg.cpp ├── DesktopDlg.h ├── Resource.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── Desktop.ico │ └── Desktop.rc2 └── targetver.h ├── Disk ├── Disk.vcxproj ├── Disk.vcxproj.filters ├── disk.cpp ├── disk.h └── main.cpp ├── Drawing ├── BeginPaintStartup │ ├── BeginPaintStartup.cpp │ ├── BeginPaintStartup.h │ ├── BeginPaintStartup.ico │ ├── BeginPaintStartup.rc │ ├── BeginPaintStartup.vcxproj │ ├── Resource.h │ ├── framework.h │ ├── small.ico │ └── targetver.h ├── InvalidateArea │ ├── InvalidateArea.cpp │ ├── InvalidateArea.h │ ├── InvalidateArea.ico │ ├── InvalidateArea.rc │ ├── InvalidateArea.vcxproj │ ├── Resource.h │ ├── framework.h │ ├── small.ico │ └── targetver.h ├── MousePaint │ ├── MousePaint.cpp │ ├── MousePaint.h │ ├── MousePaint.ico │ ├── MousePaint.rc │ ├── MousePaint.vcxproj │ ├── Resource.h │ ├── framework.h │ ├── small.ico │ └── targetver.h ├── TextColor │ ├── Resource.h │ ├── TextColor.cpp │ ├── TextColor.h │ ├── TextColor.ico │ ├── TextColor.rc │ ├── TextColor.vcxproj │ ├── framework.h │ ├── small.ico │ └── targetver.h └── TimerDrawer │ ├── Resource.h │ ├── TimerDrawer.cpp │ ├── TimerDrawer.h │ ├── TimerDrawer.ico │ ├── TimerDrawer.rc │ ├── TimerDrawer.vcxproj │ ├── framework.h │ ├── small.ico │ └── targetver.h ├── EnumFile ├── EnumFile.cpp └── EnumFile.vcxproj ├── ErrorHandler ├── ErrorHandler.cpp └── ErrorHandler.vcxproj ├── Exception ├── Exception.cpp └── Exception.vcxproj ├── Hook ├── Hook.cpp ├── Hook.h ├── Hook.rc ├── Hook.vcxproj ├── Hook.vcxproj.filters ├── HookDlg.cpp ├── HookDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── Hook.ico │ └── Hook.rc2 ├── resource.h ├── targetver.h └── 注入技术介绍.md ├── Hook_lib ├── Hook_lib.cpp ├── Hook_lib.h ├── Hook_lib.vcxproj ├── Hook_lib.vcxproj.filters ├── Source.def ├── cpp.hint ├── dllmain.cpp ├── framework.h ├── pch.cpp └── pch.h ├── IO ├── IO.cpp ├── IO.h ├── IO.rc ├── IO.vcxproj ├── IO.vcxproj.filters ├── IODlg.cpp ├── IODlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── IO.ico │ └── IO.rc2 ├── resource.h └── targetver.h ├── IPC ├── Mailslots_CreateAndWrite │ ├── Mailslots_CreateAndWrite.cpp │ └── Mailslots_CreateAndWrite.vcxproj └── Mailslots_Reading │ ├── Mailslots_Reading.cpp │ └── Mailslots_Reading.vcxproj ├── KeyBoard ├── KeyBoard.cpp ├── KeyBoard.h ├── KeyBoard.rc ├── KeyBoard.vcxproj ├── KeyBoard.vcxproj.filters ├── KeyBoardDlg.cpp ├── KeyBoardDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── KeyBoard.ico │ └── KeyBoard.rc2 ├── resource.h └── targetver.h ├── KeyBoardRecord ├── KeyBoardRecord.cpp ├── KeyBoardRecord.h ├── KeyBoardRecord.rc ├── KeyBoardRecord.vcxproj ├── KeyBoardRecord.vcxproj.filters ├── KeyBoardRecordDlg.cpp ├── KeyBoardRecordDlg.h ├── VirtualKeyMapString.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── KeyBoardRecord.ico │ └── KeyBoardRecord.rc2 ├── resource.h └── targetver.h ├── LICENSE ├── Lambda ├── Lambda.cpp ├── Lambda.vcxproj └── Lambda.vcxproj.filters ├── Message ├── Message.cpp ├── Message.h ├── Message.rc ├── Message.vcxproj ├── Message.vcxproj.filters ├── MessageDlg.cpp ├── MessageDlg.h ├── Resource.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── Message.ico │ └── Message.rc2 └── targetver.h ├── Mouse ├── Mouse.cpp ├── Mouse.h ├── Mouse.rc ├── Mouse.vcxproj ├── Mouse.vcxproj.filters ├── MouseDlg.cpp ├── MouseDlg.h ├── Resource.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── Mouse.ico │ └── Mouse.rc2 ├── resource.h └── targetver.h ├── Process ├── Process.cpp ├── Process.vcxproj └── Process.vcxproj.filters ├── ProcessMonitor ├── ProcessMonitor.cpp ├── ProcessMonitor.h ├── ProcessMonitor.rc ├── ProcessMonitor.vcxproj ├── ProcessMonitorDlg.cpp ├── ProcessMonitorDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── ProcessMonitor.ico │ └── ProcessMonitor.rc2 ├── resource.h └── targetver.h ├── Process_EnumProcesses ├── Process_EnumProcesses.cpp └── Process_EnumProcesses.vcxproj ├── Process_WMI ├── Process_WMI.cpp └── Process_WMI.vcxproj ├── Process_ZwQuerySystemInformation ├── Process_ZwQuerySystemInformation.cpp ├── Process_ZwQuerySystemInformation.vcxproj └── SYSTEM_INFORMATION_CLASS.h ├── README.md ├── Registry ├── Registry.cpp └── Registry.vcxproj ├── RemoteThreadDemo ├── RemoteThreadDemo.cpp ├── RemoteThreadDemo.vcxproj ├── inject.cpp └── inject.h ├── RemoteThread_lib ├── RemoteThread_lib.vcxproj ├── dllmain.cpp └── framework.h ├── Screenshot ├── Resource.h ├── Screenshot.cpp ├── Screenshot.h ├── Screenshot.rc ├── Screenshot.vcxproj ├── Screenshot.vcxproj.filters ├── ScreenshotDlg.cpp ├── ScreenshotDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── Screenshot.ico │ └── Screenshot.rc2 ├── resource.h └── targetver.h ├── Self-starting ├── Self-starting.cpp ├── Self-starting.h ├── Self-starting.vcxproj ├── Self-starting.vcxproj.filters ├── Self-startingDlg.cpp ├── Self-startingDlg.h ├── Selfstarting.rc ├── Session 0 Isolation.txt ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── Self-starting.ico │ └── Selfstarting.rc2 ├── resource.h └── targetver.h ├── SingleInstance ├── Resource.h ├── SingleInstance.cpp ├── SingleInstance.h ├── SingleInstance.rc ├── SingleInstance.vcxproj ├── SingleInstance.vcxproj.filters ├── SingleInstanceDlg.cpp ├── SingleInstanceDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── res │ ├── SingleInstance.ico │ └── SingleInstance.rc2 └── targetver.h ├── StringLiteral ├── StringLiteral.cpp ├── StringLiteral.vcxproj └── StringLiteral.vcxproj.filters ├── TaskbarHookLib ├── HBitmapEx.cpp ├── HBitmapEx.h ├── TaskbarHook.cpp ├── TaskbarHook.h ├── TaskbarHookLib.vcxproj ├── dllmain.cpp └── framework.h ├── Thread ├── ProcessState.jpg ├── Thread.cpp ├── Thread.h ├── Thread.md ├── Thread.rc ├── Thread.vcxproj ├── ThreadDlg.cpp ├── ThreadDlg.h ├── framework.h ├── pch.cpp ├── pch.h ├── priority_table.png ├── res │ ├── Thread.ico │ └── Thread.rc2 ├── resource.h └── targetver.h ├── UniformInitialization ├── UniformInitialization.cpp ├── UniformInitialization.vcxproj └── UniformInitialization.vcxproj.filters ├── WMI ├── QuerySink.h ├── WMI.cpp └── WMI.vcxproj └── WindowsProgramming.sln /BypassUAC/ByPassUAC_COM_Demo/ByPassUAC_COM_Demo.cpp: -------------------------------------------------------------------------------- 1 | // BypassUAC_Test.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | TCHAR szCmdLine[MAX_PATH] = { 0 }; 11 | TCHAR szRundll32Path[MAX_PATH] = L"C:\\Windows\\System32\\rundll32.exe"; 12 | TCHAR szDllPath[MAX_PATH] = L"E:\\WindowsProgramming\\x64\\Debug\\ByPassUAC_COM_LIB.dll";//替换为编译的dll路径 13 | wsprintf(szCmdLine, L"%s \"%s\" %s", szRundll32Path, szDllPath, L"BypassUAC"); 14 | STARTUPINFO si{}; 15 | si.cb = sizeof(STARTUPINFO); 16 | PROCESS_INFORMATION pi{}; 17 | CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); 18 | CloseHandle(pi.hProcess); 19 | CloseHandle(pi.hThread); 20 | return 0; 21 | } -------------------------------------------------------------------------------- /BypassUAC/ByPassUAC_COM_LIB/BypassUAC.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/BypassUAC/ByPassUAC_COM_LIB/BypassUAC.cpp -------------------------------------------------------------------------------- /BypassUAC/ByPassUAC_COM_LIB/BypassUACLib.cpp: -------------------------------------------------------------------------------- 1 | #include "BypassUAC.h" 2 | 3 | void CALLBACK BypassUAC(HWND hWnd, HINSTANCE hInstance, LPSTR lpszCmdLine, int iCmdShow) 4 | { 5 | CMLuaUtilBypassUAC(L"C:\\Windows\\System32\\cmd.exe"); 6 | } -------------------------------------------------------------------------------- /BypassUAC/ByPassUAC_COM_LIB/Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | BypassUAC 4 | -------------------------------------------------------------------------------- /BypassUAC/ByPassUAC_COM_LIB/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : 定义 DLL 应用程序的入口点。 2 | #include "framework.h" 3 | 4 | BOOL APIENTRY DllMain( HMODULE hModule, 5 | DWORD ul_reason_for_call, 6 | LPVOID lpReserved 7 | ) 8 | { 9 | switch (ul_reason_for_call) 10 | { 11 | case DLL_PROCESS_ATTACH: 12 | case DLL_THREAD_ATTACH: 13 | case DLL_THREAD_DETACH: 14 | case DLL_PROCESS_DETACH: 15 | break; 16 | } 17 | return TRUE; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /BypassUAC/ByPassUAC_COM_LIB/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 8 | // Windows 头文件 9 | #include 10 | -------------------------------------------------------------------------------- /COM/ComPtr/ComPtrInitialization/ComPtrInitialization.cpp: -------------------------------------------------------------------------------- 1 | // ComPtrInitialization.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using Microsoft::WRL::ComPtr; 11 | 12 | int main() 13 | { 14 | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 15 | COINIT_DISABLE_OLE1DDE); 16 | 17 | //ComPtr 18 | Microsoft::WRL::ComPtr m_pFileDialog; 19 | hr = CoCreateInstance( 20 | __uuidof(FileOpenDialog), 21 | NULL, 22 | CLSCTX_INPROC_SERVER, 23 | IID_PPV_ARGS(&m_pFileDialog) 24 | ); 25 | auto rt = m_pFileDialog.Get(); 26 | rt->Show(NULL); 27 | 28 | //CComPtr 29 | CComPtr pFileOpen; 30 | // Create the FileOpenDialog object. 31 | hr = pFileOpen.CoCreateInstance(__uuidof(FileOpenDialog)); 32 | 33 | return 0; 34 | } 35 | 36 | // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 37 | // 调试程序: F5 或调试 >“开始调试”菜单 38 | 39 | // 入门使用技巧: 40 | // 1. 使用解决方案资源管理器窗口添加/管理文件 41 | // 2. 使用团队资源管理器窗口连接到源代码管理 42 | // 3. 使用输出窗口查看生成输出和其他消息 43 | // 4. 使用错误列表窗口查看错误 44 | // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 45 | // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 46 | -------------------------------------------------------------------------------- /COM/ComPtr/ComPtrQueryInterface/ComPtrQueryInterface.cpp: -------------------------------------------------------------------------------- 1 | // ComPtrQueryInterface.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int main() 12 | { 13 | 14 | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 15 | COINIT_DISABLE_OLE1DDE); 16 | 17 | Microsoft::WRL::ComPtr m_pIWICFactory; 18 | 19 | hr = CoCreateInstance( 20 | CLSID_WICImagingFactory, 21 | NULL, 22 | CLSCTX_INPROC_SERVER, 23 | IID_PPV_ARGS(&m_pIWICFactory) 24 | ); 25 | 26 | if (FAILED(hr)) 27 | return 0; 28 | 29 | Microsoft::WRL::ComPtr pDecoder; 30 | 31 | hr = m_pIWICFactory->CreateDecoderFromFilename( 32 | L"explorer_back.png", // Image to be decoded 33 | NULL, // Do not prefer a particular vendor 34 | GENERIC_READ, // Desired read access to the file 35 | WICDecodeMetadataCacheOnDemand, // Cache metadata when needed 36 | &pDecoder // Pointer to the decoder 37 | ); 38 | 39 | Microsoft::WRL::ComPtr pFrame; 40 | 41 | // Retrieve the first frame of the image from the decoder 42 | if (SUCCEEDED(hr)) 43 | { 44 | hr = pDecoder->GetFrame(0, &pFrame); 45 | } 46 | 47 | Microsoft::WRL::ComPtr m_pOriginalBitmapSource; 48 | // Retrieve IWICBitmapSource from the frame 49 | if (SUCCEEDED(hr)) 50 | { 51 | //ComPtr provides a much simpler syntax for doing QueryInterface calls on COM Objects 52 | //You can also use CopyTo to perform similar operations to As. 53 | hr = pFrame.As(&m_pOriginalBitmapSource); 54 | 55 | //QueryInterface 56 | /* 57 | * hr = pFrame->QueryInterface( 58 | * IID_IWICBitmapSource, 59 | * reinterpret_cast(&m_pOriginalBitmapSource)); 60 | */ 61 | 62 | //... 63 | } 64 | return 0; 65 | } -------------------------------------------------------------------------------- /COM/ComPtr/ComPtrQueryInterface/explorer_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/COM/ComPtr/ComPtrQueryInterface/explorer_back.png -------------------------------------------------------------------------------- /COM/ComPtr/ComPtrReset/ComPtrReset.cpp: -------------------------------------------------------------------------------- 1 | // ComPtrInitialization.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using Microsoft::WRL::ComPtr; 11 | 12 | int main() 13 | { 14 | HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 15 | COINIT_DISABLE_OLE1DDE); 16 | 17 | //ComPtr 18 | Microsoft::WRL::ComPtr m_pFileDialog; 19 | hr = CoCreateInstance( 20 | __uuidof(FileOpenDialog), 21 | NULL, 22 | CLSCTX_INPROC_SERVER, 23 | IID_PPV_ARGS(&m_pFileDialog) 24 | ); 25 | auto rt = m_pFileDialog.Get(); 26 | rt->Show(NULL); 27 | 28 | //Clearing 29 | m_pFileDialog.Reset(); //or m_pFileDialog = nullptr; 30 | 31 | 32 | return 0; 33 | } 34 | 35 | // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 36 | // 调试程序: F5 或调试 >“开始调试”菜单 37 | 38 | // 入门使用技巧: 39 | // 1. 使用解决方案资源管理器窗口添加/管理文件 40 | // 2. 使用团队资源管理器窗口连接到源代码管理 41 | // 3. 使用输出窗口查看生成输出和其他消息 42 | // 4. 使用错误列表窗口查看错误 43 | // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 44 | // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 45 | -------------------------------------------------------------------------------- /COM/Create/COM.cpp: -------------------------------------------------------------------------------- 1 | // COM.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | VOID CreateComObj() 10 | { 11 | IVirtualDesktopManager* pDesktopManager = NULL; 12 | HRESULT hr = CoInitialize(NULL); 13 | 14 | if (SUCCEEDED(hr)) 15 | { 16 | hr = CoCreateInstance( 17 | CLSID_VirtualDesktopManager, 18 | NULL, 19 | CLSCTX_INPROC_SERVER, 20 | IID_IVirtualDesktopManager, (void**)&pDesktopManager); 21 | 22 | if (SUCCEEDED(hr)) 23 | { 24 | pDesktopManager->Release(); 25 | } 26 | } 27 | 28 | CoUninitialize(); 29 | } 30 | 31 | int main() 32 | { 33 | std::cout << "Hello World!\n"; 34 | } 35 | -------------------------------------------------------------------------------- /ClassFeature/ClassFeature.cpp: -------------------------------------------------------------------------------- 1 | // ClassFeature.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | 6 | int main() 7 | { 8 | std::cout << "Hello World!\n"; 9 | } 10 | 11 | 12 | /* 13 | * default 14 | * C++11 provides more control over which methods are used. 15 | * Suppose that you wish to use a defaulted function that, 16 | * due to circumstances, isn’t created automatically. For example, 17 | * if you provide a move constructor, then the default constructor, 18 | * the copy constructor, and the copy assignment operator are not provided. 19 | * In that case, you can use the keyword default to explicitly declare the defaulted versions of these methods: 20 | */ 21 | class Animal 22 | { 23 | public: 24 | Animal() = default; 25 | Animal(const Animal& animal) = default; 26 | Animal& operator=(const Animal& animal) = default; 27 | }; 28 | 29 | /* 30 | * The compiler provides the same constructor that it would have provided automatically had you not provided the move constructor. 31 | * The delete keyword, on the other hand, can be used to prevent the compiler from using a particular method. For example, to prevent an object from being copied, you can disable the copy constructor and copy assignment operator: 32 | */ 33 | 34 | class Animal 35 | { 36 | public: 37 | Animal() = delete; 38 | Animal(const Animal& animal) = delete; 39 | }; -------------------------------------------------------------------------------- /ClipBoard/CClipBoardDialog.cpp: -------------------------------------------------------------------------------- 1 | // CClipBoardDialog.cpp: 实现文件 2 | // 3 | 4 | #include "pch.h" 5 | #include "ClipBoard.h" 6 | #include "CClipBoardDialog.h" 7 | #include "afxdialogex.h" 8 | 9 | 10 | // CClipBoardDialog 对话框 11 | 12 | IMPLEMENT_DYNAMIC(CClipBoardDialog, CDialogEx) 13 | 14 | CClipBoardDialog::CClipBoardDialog(CWnd* pParent /*=nullptr*/) 15 | : CDialogEx(IDD_CLIPBOARD_DIALOG, pParent) 16 | { 17 | 18 | } 19 | 20 | CClipBoardDialog::~CClipBoardDialog() 21 | { 22 | } 23 | 24 | void CClipBoardDialog::DoDataExchange(CDataExchange* pDX) 25 | { 26 | CDialogEx::DoDataExchange(pDX); 27 | } 28 | 29 | 30 | BEGIN_MESSAGE_MAP(CClipBoardDialog, CDialogEx) 31 | END_MESSAGE_MAP() 32 | 33 | 34 | // CClipBoardDialog 消息处理程序 35 | -------------------------------------------------------------------------------- /ClipBoard/CClipBoardDialog.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | 4 | // CClipBoardDialog 对话框 5 | 6 | class CClipBoardDialog : public CDialogEx 7 | { 8 | DECLARE_DYNAMIC(CClipBoardDialog) 9 | 10 | public: 11 | CClipBoardDialog(CWnd* pParent = nullptr); // 标准构造函数 12 | virtual ~CClipBoardDialog(); 13 | 14 | // 对话框数据 15 | #ifdef AFX_DESIGN_TIME 16 | enum { IDD = IDD_CLIPBOARD_DIALOG }; 17 | #endif 18 | 19 | protected: 20 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 21 | 22 | DECLARE_MESSAGE_MAP() 23 | }; 24 | -------------------------------------------------------------------------------- /ClipBoard/ClipBoard.cpp: -------------------------------------------------------------------------------- 1 |  2 | // ClipBoard.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "ClipBoard.h" 8 | #include "ClipBoardDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CClipBoardApp 16 | 17 | BEGIN_MESSAGE_MAP(CClipBoardApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CClipBoardApp 构造 23 | 24 | CClipBoardApp::CClipBoardApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CClipBoardApp 对象 35 | 36 | CClipBoardApp theApp; 37 | 38 | 39 | // CClipBoardApp 初始化 40 | 41 | BOOL CClipBoardApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CClipBoardDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /ClipBoard/ClipBoard.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * 剪贴板相关 * 4 | * Copyright (C) 2020 https://github.com/zhaotianff * 5 | * All rights reserved. * 6 | * Licensed under the MIT License. * 7 | * * 8 | *****************************************************************************/ 9 | 10 | #pragma once 11 | 12 | #ifndef __AFXWIN_H__ 13 | #error "include 'pch.h' before including this file for PCH" 14 | #endif 15 | 16 | #include "resource.h" // 主符号 17 | 18 | 19 | // CClipBoardApp: 20 | // 有关此类的实现,请参阅 ClipBoard.cpp 21 | // 22 | 23 | class CClipBoardApp : public CWinApp 24 | { 25 | public: 26 | CClipBoardApp(); 27 | 28 | // 重写 29 | public: 30 | virtual BOOL InitInstance(); 31 | 32 | // 实现 33 | 34 | DECLARE_MESSAGE_MAP() 35 | }; 36 | 37 | extern CClipBoardApp theApp; 38 | -------------------------------------------------------------------------------- /ClipBoard/ClipBoard.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/ClipBoard/ClipBoard.rc -------------------------------------------------------------------------------- /ClipBoard/ClipBoard.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /ClipBoard/ClipBoardDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // ClipBoardDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CClipBoardDlg 对话框 9 | class CClipBoardDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CClipBoardDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_CLIPBOARD_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedOk(); 36 | CListBox m_list; 37 | afx_msg void OnBnClickedButton1(); 38 | 39 | public: 40 | CString GetClipBoardFormat(int index); 41 | afx_msg void OnBnClickedButton2(); 42 | CButton m_picture; 43 | }; 44 | -------------------------------------------------------------------------------- /ClipBoard/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /ClipBoard/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /ClipBoard/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | #include 13 | 14 | #endif //PCH_H 15 | -------------------------------------------------------------------------------- /ClipBoard/res/ClipBoard.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/ClipBoard/res/ClipBoard.ico -------------------------------------------------------------------------------- /ClipBoard/res/ClipBoard.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/ClipBoard/res/ClipBoard.rc2 -------------------------------------------------------------------------------- /ClipBoard/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 ClipBoard.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_CLIPBOARD_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_LIST1 1000 11 | #define IDC_BUTTON1 1001 12 | #define IDC_BUTTON2 1002 13 | 14 | // Next default values for new objects 15 | // 16 | #ifdef APSTUDIO_INVOKED 17 | #ifndef APSTUDIO_READONLY_SYMBOLS 18 | #define _APS_NEXT_RESOURCE_VALUE 130 19 | #define _APS_NEXT_COMMAND_VALUE 32771 20 | #define _APS_NEXT_CONTROL_VALUE 1003 21 | #define _APS_NEXT_SYMED_VALUE 101 22 | #endif 23 | #endif 24 | -------------------------------------------------------------------------------- /ClipBoard/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /CommonDlg/CommonDlg.cpp: -------------------------------------------------------------------------------- 1 |  2 | // CommonDlg.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "CommonDlg.h" 8 | #include "CommonDlgDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CCommonDlgApp 16 | 17 | BEGIN_MESSAGE_MAP(CCommonDlgApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CCommonDlgApp 构造 23 | 24 | CCommonDlgApp::CCommonDlgApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CCommonDlgApp 对象 35 | 36 | CCommonDlgApp theApp; 37 | 38 | 39 | // CCommonDlgApp 初始化 40 | 41 | BOOL CCommonDlgApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CCommonDlgDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /CommonDlg/CommonDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // CommonDlg.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CCommonDlgApp: 15 | // 有关此类的实现,请参阅 CommonDlg.cpp 16 | // 17 | 18 | class CCommonDlgApp : public CWinApp 19 | { 20 | public: 21 | CCommonDlgApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CCommonDlgApp theApp; 33 | -------------------------------------------------------------------------------- /CommonDlg/CommonDlg.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/CommonDlg/CommonDlg.rc -------------------------------------------------------------------------------- /CommonDlg/CommonDlg.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /CommonDlg/CommonDlgDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // CommonDlgDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CCommonDlgDlg 对话框 9 | class CCommonDlgDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CCommonDlgDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_COMMONDLG_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | 37 | public: 38 | afx_msg void OnBnClickedButton2(); 39 | afx_msg void OnBnClickedButton3(); 40 | afx_msg void OnBnClickedButton4(); 41 | afx_msg void OnBnClickedButton5(); 42 | }; 43 | -------------------------------------------------------------------------------- /CommonDlg/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /CommonDlg/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /CommonDlg/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /CommonDlg/res/CommonDlg.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/CommonDlg/res/CommonDlg.ico -------------------------------------------------------------------------------- /CommonDlg/res/CommonDlg.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/CommonDlg/res/CommonDlg.rc2 -------------------------------------------------------------------------------- /CommonDlg/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 CommonDlg.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_COMMONDLG_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | #define IDC_BUTTON3 1002 13 | #define IDC_BUTTON4 1003 14 | #define IDC_BUTTON5 1004 15 | 16 | // Next default values for new objects 17 | // 18 | #ifdef APSTUDIO_INVOKED 19 | #ifndef APSTUDIO_READONLY_SYMBOLS 20 | #define _APS_NEXT_RESOURCE_VALUE 130 21 | #define _APS_NEXT_COMMAND_VALUE 32771 22 | #define _APS_NEXT_CONTROL_VALUE 1005 23 | #define _APS_NEXT_SYMED_VALUE 101 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /CommonDlg/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /CreateWindowDemo/CreateWindowDemo.cpp: -------------------------------------------------------------------------------- 1 | #ifndef UNICODE 2 | #define UNICODE 3 | #endif 4 | 5 | #include 6 | 7 | LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 8 | 9 | int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow) 10 | { 11 | 12 | // Register the window class. 13 | const wchar_t CLASS_NAME[] = L"Sample Window Class"; 14 | 15 | WNDCLASS wc = { }; 16 | 17 | wc.lpfnWndProc = WindowProc; 18 | wc.hInstance = hInstance; 19 | wc.lpszClassName = CLASS_NAME; 20 | 21 | RegisterClass(&wc); 22 | 23 | // 创建窗口. 24 | HWND hwnd = CreateWindow( 25 | CLASS_NAME, //窗口类名 26 | L"Demo Window", //窗口标题 27 | WS_OVERLAPPEDWINDOW, //窗口样式 28 | CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, //窗口位置和大小 29 | NULL, //父窗口 30 | NULL, //菜单 31 | hInstance, //Instance句柄 32 | NULL //额外的程序数据 33 | ); 34 | 35 | if (hwnd == NULL) 36 | { 37 | return 0; 38 | } 39 | 40 | ShowWindow(hwnd, nCmdShow); 41 | 42 | // 消息循环. 43 | MSG msg = { }; 44 | while (GetMessage(&msg, NULL, 0, 0)) 45 | { 46 | TranslateMessage(&msg); 47 | DispatchMessage(&msg); 48 | } 49 | 50 | return 0; 51 | } 52 | 53 | LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 54 | { 55 | switch (uMsg) 56 | { 57 | case WM_DESTROY: 58 | PostQuitMessage(0); 59 | return 0; 60 | 61 | case WM_PAINT: 62 | { 63 | PAINTSTRUCT ps; 64 | HDC hdc = BeginPaint(hwnd, &ps); 65 | 66 | //在此处添加使用 hdc 的任何绘图代码... 67 | FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1)); 68 | EndPaint(hwnd, &ps); 69 | } 70 | return 0; 71 | } 72 | 73 | return DefWindowProc(hwnd, uMsg, wParam, lParam); 74 | } -------------------------------------------------------------------------------- /CreateWindowDemo/CreateWindowDemo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /CreateWindowDemo/CreateWindowDemo.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/CreateWindowDemo/CreateWindowDemo.ico -------------------------------------------------------------------------------- /CreateWindowDemo/CreateWindowDemo.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/CreateWindowDemo/CreateWindowDemo.rc -------------------------------------------------------------------------------- /CreateWindowDemo/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 使用者 CreateWindowDemo.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_CREATEWINDOWDEMO_DIALOG 102 9 | #define IDD_ABOUTBOX 103 10 | #define IDM_ABOUT 104 11 | #define IDM_EXIT 105 12 | #define IDI_CREATEWINDOWDEMO 107 13 | #define IDI_SMALL 108 14 | #define IDC_CREATEWINDOWDEMO 109 15 | #define IDC_MYICON 2 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC -1 18 | #endif 19 | // 新对象的下一组默认值 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | 24 | #define _APS_NO_MFC 130 25 | #define _APS_NEXT_RESOURCE_VALUE 129 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1000 28 | #define _APS_NEXT_SYMED_VALUE 110 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /CreateWindowDemo/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 9 | // Windows 头文件 10 | #include 11 | // C 运行时头文件 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /CreateWindowDemo/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/CreateWindowDemo/small.ico -------------------------------------------------------------------------------- /CreateWindowDemo/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。 4 | // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并 5 | // 将 _WIN32_WINNT 宏设置为想要支持的平台。 6 | #include 7 | -------------------------------------------------------------------------------- /DWM/GetSystemGlassColor/GetSystemGlassColor.cpp: -------------------------------------------------------------------------------- 1 | // GetSystemGlassColor.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #define SYS_VER_GREATER_THAN_WIN8 5 | 6 | #include 7 | #include 8 | 9 | //from https://github.com/Open-Shell/Open-Shell-Menu.git 10 | //SkinManager.cpp 11 | 12 | struct DWMCOLORIZATIONPARAMS 13 | { 14 | DWORD ColorizationColor; 15 | DWORD ColorizationAfterglow; 16 | DWORD ColorizationColorBalance; 17 | DWORD ColorizationAfterglowBalance; 18 | DWORD ColorizationBlurBalance; 19 | DWORD ColorizationGlassReflectionIntensity; 20 | DWORD ColorizationOpaqueBlend; 21 | DWORD extra; // Win8 has extra parameter 22 | }; 23 | 24 | BOOL GetSkinColorizationParameters(DWMCOLORIZATIONPARAMS* params) 25 | { 26 | typedef HRESULT(WINAPI* tGetColorizationParameters)(DWMCOLORIZATIONPARAMS* params); 27 | 28 | // HACK: the system function DwmGetColorizationColor is buggy on Win 7. its calculations can overflow and return a totally wrong value 29 | // (try orange color with full intensity and no transparency - you'll get alpha=0 and green color). so here we use the undocumented 30 | // function GetColorizationParameters exported by dwmapi.dll, ordinal 127 and then compute the colors manually using integer math 31 | HMODULE hMod = LoadLibrary(L"dwmapi.dll"); 32 | if (!hMod) return false; 33 | tGetColorizationParameters GetColorizationParameters = (tGetColorizationParameters)GetProcAddress(hMod, MAKEINTRESOURCEA(127)); 34 | if (!GetColorizationParameters || FAILED(GetColorizationParameters(params))) 35 | return false; 36 | #ifdef SYS_VER_GREATER_THAN_WIN8 37 | params->ColorizationOpaqueBlend = 0; // Win8 has no transparency 38 | #endif 39 | 40 | if (hMod) 41 | FreeLibrary(hMod); 42 | return true; 43 | } 44 | 45 | COLORREF GetSystemGlassColor8(void) 46 | { 47 | COLORREF color = 0; 48 | DWMCOLORIZATIONPARAMS params; 49 | if (GetSkinColorizationParameters(¶ms)) 50 | { 51 | int r = (params.ColorizationColor >> 16) & 255; 52 | int g = (params.ColorizationColor >> 8) & 255; 53 | int b = (params.ColorizationColor) & 255; 54 | int gray = 217 * (100 - params.ColorizationColorBalance) + 50; 55 | r = (r * params.ColorizationColorBalance + gray) / 100; 56 | g = (g * params.ColorizationColorBalance + gray) / 100; 57 | b = (b * params.ColorizationColorBalance + gray) / 100; 58 | r = (r * 200 + 127) / 255; 59 | g = (g * 200 + 127) / 255; 60 | b = (b * 200 + 127) / 255; 61 | color = (r << 16) | (g << 8) | b | (params.ColorizationColor & 0xFF000000); 62 | } 63 | return color; 64 | } 65 | 66 | int main() 67 | { 68 | COLORREF color = GetSystemGlassColor8(); 69 | } 70 | -------------------------------------------------------------------------------- /Desktop/Desktop.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Desktop.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Desktop.h" 8 | #include "DesktopDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CDesktopApp 16 | 17 | BEGIN_MESSAGE_MAP(CDesktopApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CDesktopApp 构造 23 | 24 | CDesktopApp::CDesktopApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CDesktopApp 对象 35 | 36 | CDesktopApp theApp; 37 | 38 | 39 | // CDesktopApp 初始化 40 | 41 | BOOL CDesktopApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CDesktopDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Desktop/Desktop.h: -------------------------------------------------------------------------------- 1 |  2 | // Desktop.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'pch.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CDesktopApp: 15 | // 有关此类的实现,请参阅 Desktop.cpp 16 | // 17 | 18 | class CDesktopApp : public CWinApp 19 | { 20 | public: 21 | CDesktopApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CDesktopApp theApp; 33 | -------------------------------------------------------------------------------- /Desktop/Desktop.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Desktop/Desktop.rc -------------------------------------------------------------------------------- /Desktop/Desktop.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /Desktop/DesktopDlg.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * * 3 | * 桌面相关 * 4 | * Copyright (C) 2020 https://github.com/zhaotianff * 5 | * All rights reserved. * 6 | * Licensed under the MIT License. * 7 | * * 8 | *****************************************************************************/ 9 | #pragma once 10 | 11 | 12 | // CDesktopDlg 对话框 13 | class CDesktopDlg : public CDialogEx 14 | { 15 | // 构造 16 | public: 17 | CDesktopDlg(CWnd* pParent = nullptr); // 标准构造函数 18 | 19 | // 对话框数据 20 | #ifdef AFX_DESIGN_TIME 21 | enum { IDD = IDD_DESKTOP_DIALOG }; 22 | #endif 23 | 24 | protected: 25 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 26 | 27 | 28 | // 实现 29 | protected: 30 | HICON m_hIcon; 31 | 32 | // 生成的消息映射函数 33 | virtual BOOL OnInitDialog(); 34 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 35 | afx_msg void OnPaint(); 36 | afx_msg HCURSOR OnQueryDragIcon(); 37 | DECLARE_MESSAGE_MAP() 38 | public: 39 | afx_msg void OnBnClickedButton1(); 40 | afx_msg void OnBnClickedButton2(); 41 | afx_msg void OnBnClickedButton3(); 42 | afx_msg void OnBnClickedButton4(); 43 | afx_msg void OnBnClickedButton5(); 44 | afx_msg void OnBnClickedButton6(); 45 | afx_msg void OnBnClickedButton7(); 46 | afx_msg void OnBnClickedButton8(); 47 | afx_msg void OnBnClickedButton9(); 48 | }; 49 | -------------------------------------------------------------------------------- /Desktop/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Desktop.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_DESKTOP_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | #define IDC_BUTTON3 1002 13 | #define IDC_BUTTON4 1003 14 | #define IDC_BUTTON5 1004 15 | #define IDC_BUTTON6 1005 16 | #define IDC_BUTTON7 1006 17 | #define IDC_BUTTON8 1007 18 | #define IDC_BUTTON9 1008 19 | 20 | // Next default values for new objects 21 | // 22 | #ifdef APSTUDIO_INVOKED 23 | #ifndef APSTUDIO_READONLY_SYMBOLS 24 | #define _APS_NEXT_RESOURCE_VALUE 130 25 | #define _APS_NEXT_COMMAND_VALUE 32771 26 | #define _APS_NEXT_CONTROL_VALUE 1009 27 | #define _APS_NEXT_SYMED_VALUE 101 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /Desktop/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Desktop/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Desktop/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Desktop/res/Desktop.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Desktop/res/Desktop.ico -------------------------------------------------------------------------------- /Desktop/res/Desktop.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Desktop/res/Desktop.rc2 -------------------------------------------------------------------------------- /Desktop/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Disk/Disk.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 23 | 24 | 源文件 25 | 26 | 27 | 源文件 28 | 29 | 30 | -------------------------------------------------------------------------------- /Disk/disk.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Disk/disk.cpp -------------------------------------------------------------------------------- /Disk/disk.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Disk/disk.h -------------------------------------------------------------------------------- /Disk/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include"disk.h" 4 | 5 | using namespace std; 6 | 7 | int main() 8 | { 9 | GetDiskDriverVolumnName(); 10 | 11 | GetDiskDriverSpaceByDriverName(L"C:\\"); 12 | 13 | //格式化磁盘 谨慎操作 14 | //FormatDriverByDriverName(L"G:\\"); 15 | 16 | //监控磁盘文件变化 17 | //MonitorDiskFile(TEXT("D:\\")); 18 | 19 | EjectCD(); 20 | } 21 | -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/BeginPaintStartup.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/BeginPaintStartup.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/BeginPaintStartup/BeginPaintStartup.ico -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/BeginPaintStartup.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/BeginPaintStartup/BeginPaintStartup.rc -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 使用者 BeginPaintStartup.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_BEGINPAINTSTARTUP_DIALOG 102 9 | #define IDD_ABOUTBOX 103 10 | #define IDM_ABOUT 104 11 | #define IDM_EXIT 105 12 | #define IDI_BEGINPAINTSTARTUP 107 13 | #define IDI_SMALL 108 14 | #define IDC_BEGINPAINTSTARTUP 109 15 | #define IDC_MYICON 2 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC -1 18 | #endif 19 | // 新对象的下一组默认值 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | 24 | #define _APS_NO_MFC 130 25 | #define _APS_NEXT_RESOURCE_VALUE 129 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1000 28 | #define _APS_NEXT_SYMED_VALUE 110 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 9 | // Windows 头文件 10 | #include 11 | // C 运行时头文件 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/BeginPaintStartup/small.ico -------------------------------------------------------------------------------- /Drawing/BeginPaintStartup/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。 4 | // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并 5 | // 将 _WIN32_WINNT 宏设置为想要支持的平台。 6 | #include 7 | -------------------------------------------------------------------------------- /Drawing/InvalidateArea/InvalidateArea.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /Drawing/InvalidateArea/InvalidateArea.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/InvalidateArea/InvalidateArea.ico -------------------------------------------------------------------------------- /Drawing/InvalidateArea/InvalidateArea.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/InvalidateArea/InvalidateArea.rc -------------------------------------------------------------------------------- /Drawing/InvalidateArea/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 使用者 InvalidateArea.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_INVALIDATEAREA_DIALOG 102 9 | #define IDD_ABOUTBOX 103 10 | #define IDM_ABOUT 104 11 | #define IDM_EXIT 105 12 | #define IDI_INVALIDATEAREA 107 13 | #define IDI_SMALL 108 14 | #define IDC_INVALIDATEAREA 109 15 | #define IDC_MYICON 2 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC -1 18 | #endif 19 | // 新对象的下一组默认值 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | 24 | #define _APS_NO_MFC 130 25 | #define _APS_NEXT_RESOURCE_VALUE 129 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1000 28 | #define _APS_NEXT_SYMED_VALUE 110 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /Drawing/InvalidateArea/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 9 | // Windows 头文件 10 | #include 11 | // C 运行时头文件 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /Drawing/InvalidateArea/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/InvalidateArea/small.ico -------------------------------------------------------------------------------- /Drawing/InvalidateArea/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。 4 | // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并 5 | // 将 _WIN32_WINNT 宏设置为想要支持的平台。 6 | #include 7 | -------------------------------------------------------------------------------- /Drawing/MousePaint/MousePaint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /Drawing/MousePaint/MousePaint.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/MousePaint/MousePaint.ico -------------------------------------------------------------------------------- /Drawing/MousePaint/MousePaint.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/MousePaint/MousePaint.rc -------------------------------------------------------------------------------- /Drawing/MousePaint/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 使用者 MousePaint.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_MOUSEPAINT_DIALOG 102 9 | #define IDD_ABOUTBOX 103 10 | #define IDM_ABOUT 104 11 | #define IDM_EXIT 105 12 | #define IDI_MOUSEPAINT 107 13 | #define IDI_SMALL 108 14 | #define IDC_MOUSEPAINT 109 15 | #define IDC_MYICON 2 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC -1 18 | #endif 19 | // 新对象的下一组默认值 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | 24 | #define _APS_NO_MFC 130 25 | #define _APS_NEXT_RESOURCE_VALUE 129 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1000 28 | #define _APS_NEXT_SYMED_VALUE 110 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /Drawing/MousePaint/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 9 | // Windows 头文件 10 | #include 11 | // C 运行时头文件 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /Drawing/MousePaint/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/MousePaint/small.ico -------------------------------------------------------------------------------- /Drawing/MousePaint/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。 4 | // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并 5 | // 将 _WIN32_WINNT 宏设置为想要支持的平台。 6 | #include 7 | -------------------------------------------------------------------------------- /Drawing/TextColor/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 使用者 TextColor.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_TEXTCOLOR_DIALOG 102 9 | #define IDD_ABOUTBOX 103 10 | #define IDM_ABOUT 104 11 | #define IDM_EXIT 105 12 | #define IDI_TEXTCOLOR 107 13 | #define IDI_SMALL 108 14 | #define IDC_TEXTCOLOR 109 15 | #define IDC_MYICON 2 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC -1 18 | #endif 19 | // 新对象的下一组默认值 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | 24 | #define _APS_NO_MFC 130 25 | #define _APS_NEXT_RESOURCE_VALUE 129 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1000 28 | #define _APS_NEXT_SYMED_VALUE 110 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /Drawing/TextColor/TextColor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /Drawing/TextColor/TextColor.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/TextColor/TextColor.ico -------------------------------------------------------------------------------- /Drawing/TextColor/TextColor.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/TextColor/TextColor.rc -------------------------------------------------------------------------------- /Drawing/TextColor/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 9 | // Windows 头文件 10 | #include 11 | // C 运行时头文件 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /Drawing/TextColor/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/TextColor/small.ico -------------------------------------------------------------------------------- /Drawing/TextColor/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。 4 | // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并 5 | // 将 _WIN32_WINNT 宏设置为想要支持的平台。 6 | #include 7 | -------------------------------------------------------------------------------- /Drawing/TimerDrawer/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 使用者 TimerDrawer.rc 4 | 5 | #define IDS_APP_TITLE 103 6 | 7 | #define IDR_MAINFRAME 128 8 | #define IDD_TIMERDRAWER_DIALOG 102 9 | #define IDD_ABOUTBOX 103 10 | #define IDM_ABOUT 104 11 | #define IDM_EXIT 105 12 | #define IDI_TIMERDRAWER 107 13 | #define IDI_SMALL 108 14 | #define IDC_TIMERDRAWER 109 15 | #define IDC_MYICON 2 16 | #ifndef IDC_STATIC 17 | #define IDC_STATIC -1 18 | #endif 19 | // 新对象的下一组默认值 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | 24 | #define _APS_NO_MFC 130 25 | #define _APS_NEXT_RESOURCE_VALUE 129 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1000 28 | #define _APS_NEXT_SYMED_VALUE 110 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /Drawing/TimerDrawer/TimerDrawer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "resource.h" 4 | -------------------------------------------------------------------------------- /Drawing/TimerDrawer/TimerDrawer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/TimerDrawer/TimerDrawer.ico -------------------------------------------------------------------------------- /Drawing/TimerDrawer/TimerDrawer.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/TimerDrawer/TimerDrawer.rc -------------------------------------------------------------------------------- /Drawing/TimerDrawer/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #include "targetver.h" 8 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 9 | // Windows 头文件 10 | #include 11 | // C 运行时头文件 12 | #include 13 | #include 14 | #include 15 | #include 16 | -------------------------------------------------------------------------------- /Drawing/TimerDrawer/small.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Drawing/TimerDrawer/small.ico -------------------------------------------------------------------------------- /Drawing/TimerDrawer/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。 4 | // 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并 5 | // 将 _WIN32_WINNT 宏设置为想要支持的平台。 6 | #include 7 | -------------------------------------------------------------------------------- /EnumFile/EnumFile.cpp: -------------------------------------------------------------------------------- 1 | // EnumFile.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | VOID SearchFile(LPCTSTR pszDirectory) 8 | { 9 | // 搜索指定类型文件 10 | DWORD dwBufferSize = 2048; 11 | TCHAR* pszFileName = NULL; 12 | TCHAR* pTempSrc = NULL; 13 | WIN32_FIND_DATA findData{}; 14 | BOOL bRet = FALSE; 15 | 16 | // 申请动态内存 17 | pszFileName = new TCHAR[dwBufferSize]; 18 | pTempSrc = new TCHAR[dwBufferSize]; 19 | 20 | // 构造搜索文件类型字符串, *.*表示搜索所有文件类型 21 | wsprintf(pszFileName, L"%s\\*.*", pszDirectory); 22 | 23 | // 搜索第一个文件 24 | HANDLE hFile = FindFirstFile(pszFileName, &findData); 25 | if (INVALID_HANDLE_VALUE != hFile) 26 | { 27 | do 28 | { 29 | // 要过滤掉 当前目录"." 和 上一层目录"..", 否则会不断进入死循环遍历 30 | if ('.' == findData.cFileName[0]) 31 | { 32 | continue; 33 | } 34 | // 拼接文件路径 35 | wsprintf(pTempSrc, L"%s\\%s", pszDirectory, findData.cFileName); 36 | // 判断是否是目录还是文件 37 | if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) 38 | { 39 | // 目录, 则继续往下递归遍历文件 40 | SearchFile(pTempSrc); 41 | } 42 | else 43 | { 44 | // 文件 45 | wprintf_s(L"%s\n", pTempSrc); 46 | } 47 | 48 | // 搜索下一个文件 49 | } while (FindNextFile(hFile, &findData)); 50 | } 51 | 52 | // 关闭文件句柄 53 | FindClose(hFile); 54 | // 释放内存 55 | delete[]pTempSrc; 56 | pTempSrc = NULL; 57 | delete[]pszFileName; 58 | pszFileName = NULL; 59 | } 60 | 61 | int main() 62 | { 63 | SearchFile(L"C:\\"); 64 | } 65 | 66 | // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 67 | // 调试程序: F5 或调试 >“开始调试”菜单 68 | 69 | // 入门使用技巧: 70 | // 1. 使用解决方案资源管理器窗口添加/管理文件 71 | // 2. 使用团队资源管理器窗口连接到源代码管理 72 | // 3. 使用输出窗口查看生成输出和其他消息 73 | // 4. 使用错误列表窗口查看错误 74 | // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 75 | // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 76 | -------------------------------------------------------------------------------- /ErrorHandler/ErrorHandler.cpp: -------------------------------------------------------------------------------- 1 | // ErrorHandler.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | BOOL ShowErrorInfo(DWORD errorCode); 10 | int main() 11 | { 12 | //当Windows 函数检测到错误时,会使用一种名为“线程本地存储区”(thread-local storeage)的机制将相应的错误代码与 13 | //调用线程关联到一起 14 | //这种机制使不同的线程能独立运行,不会出现相互干扰对方的错误代码的情况 15 | //使用GetLastError()函数来获取函数执行的错误 16 | //需要注意的时,由于是所有的线程错误都存储在一个位置,所以当发生错误后,要马上调用GetLastError()函数来获取错误码,否则结果可能不对了 17 | 18 | 19 | //使用监视窗口的$err,hr可以查看错误代码具体代表什么意思 20 | 21 | DWORD dwErrorCode = 0x02; 22 | ShowErrorInfo(dwErrorCode); 23 | 24 | } 25 | 26 | BOOL ShowErrorInfo(DWORD errorCode) 27 | { 28 | 29 | PCTSTR lpszErrorInfo = NULL; 30 | 31 | HLOCAL hlocal = NULL; //存储错误信息字符串的缓冲区 32 | DWORD systemLocale = MAKELANGID(LANG_NEUTRAL,SUBLANG_NEUTRAL); //使用操作系统默认的语言 33 | 34 | BOOL fOK = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, 35 | NULL,errorCode,systemLocale, 36 | (PTSTR)&hlocal, 0, NULL); 37 | 38 | if (!fOK) 39 | { 40 | //网络相关的错误 41 | HMODULE hDll = LoadLibraryEx(L"netmsg.dll", NULL, DONT_RESOLVE_DLL_REFERENCES); 42 | 43 | if (hDll) 44 | { 45 | fOK = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, 46 | hDll, errorCode, systemLocale, 47 | (PTSTR)&hlocal, 0, NULL); 48 | } 49 | } 50 | 51 | if (fOK && (hlocal != NULL)) 52 | { 53 | lpszErrorInfo = (PCTSTR)LocalLock(hlocal); 54 | 55 | //测试输出 56 | //打印中文须先设置本地语言为中文 57 | setlocale(LC_ALL, "chs"); 58 | std::wcout << lpszErrorInfo << std::endl; 59 | 60 | LocalFree(hlocal); 61 | return TRUE; 62 | } 63 | else 64 | { 65 | lpszErrorInfo = L""; 66 | return FALSE; 67 | } 68 | } -------------------------------------------------------------------------------- /Exception/Exception.cpp: -------------------------------------------------------------------------------- 1 | // Exception.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | template 12 | void processCodeException(const T& e) 13 | { 14 | using namespace std; 15 | auto c = e.code(); 16 | cerr << "-category : " << c.category().name() << endl; 17 | cerr << "-value: " << c.value() << endl; 18 | cerr << "-msg: " << c.message() << endl; 19 | cerr << "-def category: " << c.default_error_condition().category().name() << endl; 20 | cerr << "-def value: " << c.default_error_condition().value() << endl; 21 | cerr << "-def msg: " << c.default_error_condition().message() << endl; 22 | } 23 | 24 | void processException() 25 | { 26 | using namespace std; 27 | 28 | try 29 | { 30 | throw; 31 | } 32 | catch (const ios_base::failure& e) 33 | { 34 | cerr << "I/O exception" << e.what() << endl; 35 | processCodeException(e); 36 | } 37 | } 38 | 39 | int main() 40 | { 41 | processException(); 42 | } -------------------------------------------------------------------------------- /Hook/Hook.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Hook.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Hook.h" 8 | #include "HookDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CHookApp 16 | 17 | BEGIN_MESSAGE_MAP(CHookApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CHookApp 构造 23 | 24 | CHookApp::CHookApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CHookApp 对象 35 | 36 | CHookApp theApp; 37 | 38 | 39 | // CHookApp 初始化 40 | 41 | BOOL CHookApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CHookDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Hook/Hook.h: -------------------------------------------------------------------------------- 1 |  2 | // Hook.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'pch.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CHookApp: 15 | // 有关此类的实现,请参阅 Hook.cpp 16 | // 17 | 18 | class CHookApp : public CWinApp 19 | { 20 | public: 21 | CHookApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CHookApp theApp; 33 | -------------------------------------------------------------------------------- /Hook/Hook.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Hook/Hook.rc -------------------------------------------------------------------------------- /Hook/Hook.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {6c255407-a220-4360-9129-da3474a97ebe} 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 52 | 53 | 资源文件 54 | 55 | 56 | 57 | 58 | 资源文件 59 | 60 | 61 | 62 | 63 | 资源文件 64 | 65 | 66 | 67 | 68 | 资料 69 | 70 | 71 | -------------------------------------------------------------------------------- /Hook/HookDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // HookDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | typedef BOOL (*SetHook)(); 8 | typedef BOOL(*UnSetHook)(); 9 | 10 | 11 | // CHookDlg 对话框 12 | class CHookDlg : public CDialogEx 13 | { 14 | // 构造 15 | public: 16 | CHookDlg(CWnd* pParent = nullptr); // 标准构造函数 17 | 18 | // 对话框数据 19 | #ifdef AFX_DESIGN_TIME 20 | enum { IDD = IDD_HOOK_DIALOG }; 21 | #endif 22 | 23 | protected: 24 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 25 | 26 | 27 | // 实现 28 | protected: 29 | HICON m_hIcon; 30 | 31 | // 生成的消息映射函数 32 | virtual BOOL OnInitDialog(); 33 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 34 | afx_msg void OnPaint(); 35 | afx_msg HCURSOR OnQueryDragIcon(); 36 | DECLARE_MESSAGE_MAP() 37 | public: 38 | afx_msg void OnBnClickedOk(); 39 | afx_msg void OnBnClickedButton1(); 40 | 41 | private: 42 | SetHook m_fSetHook; 43 | UnSetHook m_fUnSetHook; 44 | public: 45 | afx_msg void OnBnClickedButton2(); 46 | }; 47 | -------------------------------------------------------------------------------- /Hook/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Hook/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Hook/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Hook/res/Hook.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Hook/res/Hook.ico -------------------------------------------------------------------------------- /Hook/res/Hook.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Hook/res/Hook.rc2 -------------------------------------------------------------------------------- /Hook/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Hook.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_HOOK_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 130 18 | #define _APS_NEXT_COMMAND_VALUE 32771 19 | #define _APS_NEXT_CONTROL_VALUE 1002 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /Hook/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Hook/注入技术介绍.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Hook/注入技术介绍.md -------------------------------------------------------------------------------- /Hook_lib/Hook_lib.h: -------------------------------------------------------------------------------- 1 |  2 | #ifdef HOOKLIB_EXPORTS 3 | #define HOOKLIB_API __declspec(dllexport) 4 | #else 5 | #define HOOKLIB_API __declspec(dllimport) 6 | #endif 7 | 8 | HOOKLIB_API BOOL SetHook(); 9 | HOOKLIB_API BOOL UnsetHook(); 10 | -------------------------------------------------------------------------------- /Hook_lib/Hook_lib.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 源文件 21 | 22 | 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | -------------------------------------------------------------------------------- /Hook_lib/Source.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | EXPORTS 3 | 4 | SetHook 5 | UnsetHook 6 | -------------------------------------------------------------------------------- /Hook_lib/cpp.hint: -------------------------------------------------------------------------------- 1 | #define HOOKLIB_API __declspec(dllexport) 2 | #define HOOKLIB_API __declspec(dllimport) 3 | -------------------------------------------------------------------------------- /Hook_lib/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : 定义 DLL 应用程序的入口点。 2 | #include "pch.h" 3 | 4 | HMODULE g_hDllModule = NULL; 5 | 6 | BOOL APIENTRY DllMain(HMODULE hModule, 7 | DWORD ul_reason_for_call, 8 | LPVOID lpReserved 9 | ) 10 | { 11 | switch (ul_reason_for_call) 12 | { 13 | case DLL_PROCESS_ATTACH: 14 | { 15 | g_hDllModule = hModule; 16 | break; 17 | } 18 | case DLL_THREAD_ATTACH: 19 | case DLL_THREAD_DETACH: 20 | case DLL_PROCESS_DETACH: 21 | break; 22 | } 23 | return TRUE; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Hook_lib/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 4 | // Windows 头文件 5 | #include 6 | 7 | #include 8 | 9 | #pragma comment(lib,"Comctl32.lib") 10 | -------------------------------------------------------------------------------- /Hook_lib/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Hook_lib/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /IO/IO.cpp: -------------------------------------------------------------------------------- 1 |  2 | // IO.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "IO.h" 8 | #include "IODlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CIOApp 16 | 17 | BEGIN_MESSAGE_MAP(CIOApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CIOApp 构造 23 | 24 | CIOApp::CIOApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CIOApp 对象 35 | 36 | CIOApp theApp; 37 | 38 | 39 | // CIOApp 初始化 40 | 41 | BOOL CIOApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CIODlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /IO/IO.h: -------------------------------------------------------------------------------- 1 |  2 | // IO.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CIOApp: 15 | // 有关此类的实现,请参阅 IO.cpp 16 | // 17 | 18 | class CIOApp : public CWinApp 19 | { 20 | public: 21 | CIOApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CIOApp theApp; 33 | -------------------------------------------------------------------------------- /IO/IO.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/IO/IO.rc -------------------------------------------------------------------------------- /IO/IO.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /IO/IODlg.h: -------------------------------------------------------------------------------- 1 |  2 | // IODlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CIODlg 对话框 9 | class CIODlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CIODlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_IO_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | 37 | public: 38 | LPTSTR OpenFile(); 39 | afx_msg void OnBnClickedButton2(); 40 | afx_msg void OnBnClickedButton4(); 41 | afx_msg void OnBnClickedButton5(); 42 | afx_msg void OnBnClickedButton6(); 43 | afx_msg void OnBnClickedButton7(); 44 | afx_msg void OnBnClickedButton3(); 45 | }; 46 | -------------------------------------------------------------------------------- /IO/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /IO/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /IO/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /IO/res/IO.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/IO/res/IO.ico -------------------------------------------------------------------------------- /IO/res/IO.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/IO/res/IO.rc2 -------------------------------------------------------------------------------- /IO/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 IO.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_IO_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_EDIT1 1001 11 | #define IDC_BUTTON1 1002 12 | #define IDC_BUTTON2 1003 13 | #define IDC_BUTTON3 1004 14 | #define IDC_BUTTON4 1005 15 | #define IDC_EDIT2 1006 16 | #define IDC_BUTTON5 1007 17 | #define IDC_BUTTON6 1008 18 | #define IDC_BUTTON7 1009 19 | 20 | // Next default values for new objects 21 | // 22 | #ifdef APSTUDIO_INVOKED 23 | #ifndef APSTUDIO_READONLY_SYMBOLS 24 | #define _APS_NEXT_RESOURCE_VALUE 130 25 | #define _APS_NEXT_COMMAND_VALUE 32771 26 | #define _APS_NEXT_CONTROL_VALUE 1010 27 | #define _APS_NEXT_SYMED_VALUE 101 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /IO/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /IPC/Mailslots_CreateAndWrite/Mailslots_CreateAndWrite.cpp: -------------------------------------------------------------------------------- 1 | // Mailslots_CreateAndWrite.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | 7 | #define DEMO_SLOT_NAME L"\\\\.\\mailslot\\demo_slot" 8 | 9 | BOOL WriteSlot(LPCTSTR lpszSlotName, LPCTSTR lpszMessage) 10 | { 11 | HANDLE hFile = CreateFile(lpszSlotName, GENERIC_WRITE, 12 | FILE_SHARE_READ, NULL, OPEN_EXISTING, 13 | FILE_ATTRIBUTE_NORMAL, NULL); 14 | 15 | if (hFile == INVALID_HANDLE_VALUE) 16 | { 17 | std::cout << "CreateFile failed with " << GetLastError() << std::endl; 18 | return FALSE; 19 | } 20 | 21 | DWORD cbWritten = 0; 22 | BOOL bResult = WriteFile(hFile,lpszMessage, (DWORD)(lstrlen(lpszMessage) * sizeof(TCHAR)), 23 | &cbWritten, NULL); 24 | 25 | if (!bResult) 26 | { 27 | std::cout << "WriteFile failed with " << GetLastError() << std::endl; 28 | CloseHandle(hFile); 29 | return FALSE; 30 | } 31 | else 32 | { 33 | std::wcout << L"Slot written to [" << lpszMessage << L"] successfully." << std::endl; 34 | CloseHandle(hFile); 35 | return TRUE; 36 | } 37 | } 38 | 39 | BOOL CloseSlot(HANDLE hSlot) 40 | { 41 | if (hSlot) 42 | { 43 | return CloseHandle(hSlot); 44 | } 45 | 46 | return FALSE; 47 | } 48 | 49 | int main() 50 | { 51 | WriteSlot(DEMO_SLOT_NAME, L"HelloWorld"); 52 | 53 | // A mailslot exists until the CloseHandle function is called for all open server handles or 54 | // until all server processes that own a mailslot handle exit. 55 | // In both cases, any unread messages are deleted from the mailslot, 56 | // all client handles to the mailslot are closed, 57 | // and the mailslot itself is deleted from memory. 58 | //CloseHandle(hSlot); 59 | 60 | // 61 | //Caution: 62 | // 63 | //Q:Why mailslot is called one directional ? While there can be multiple client / servers? 64 | // 65 | //A:It really is one - directional.The process who creates a mailslot can only read from it, not to write to it. 66 | //The process that opens the mailslot can only write to it, not read from it.A mailslot is not like a named pipe or a socket, 67 | //where data can flow in both directions over a single connection. 68 | //If the process that creates the mailslot wants to send a reply, 69 | //it has to write to a different mailslot or other IPC mechanism. 70 | // 71 | return 0; 72 | } -------------------------------------------------------------------------------- /KeyBoard/KeyBoard.cpp: -------------------------------------------------------------------------------- 1 |  2 | // KeyBoard.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "KeyBoard.h" 8 | #include "KeyBoardDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CKeyBoardApp 16 | 17 | BEGIN_MESSAGE_MAP(CKeyBoardApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CKeyBoardApp 构造 23 | 24 | CKeyBoardApp::CKeyBoardApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CKeyBoardApp 对象 35 | 36 | CKeyBoardApp theApp; 37 | 38 | 39 | // CKeyBoardApp 初始化 40 | 41 | BOOL CKeyBoardApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CKeyBoardDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /KeyBoard/KeyBoard.h: -------------------------------------------------------------------------------- 1 |  2 | // KeyBoard.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'pch.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CKeyBoardApp: 15 | // 有关此类的实现,请参阅 KeyBoard.cpp 16 | // 17 | 18 | class CKeyBoardApp : public CWinApp 19 | { 20 | public: 21 | CKeyBoardApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | // virtual BOOL PreTranslateMessage(MSG* pMsg); 31 | }; 32 | 33 | extern CKeyBoardApp theApp; 34 | -------------------------------------------------------------------------------- /KeyBoard/KeyBoard.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/KeyBoard/KeyBoard.rc -------------------------------------------------------------------------------- /KeyBoard/KeyBoard.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /KeyBoard/KeyBoardDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // KeyBoardDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CKeyBoardDlg 对话框 9 | class CKeyBoardDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CKeyBoardDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_KEYBOARD_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedOk(); 36 | virtual BOOL PreTranslateMessage(MSG* pMsg); 37 | 38 | void ShowLockStatus(); 39 | void EmuKeyStroke(WORD wVk,WORD wScan); 40 | afx_msg void OnBnClickedButton1(); 41 | afx_msg void OnBnClickedButton2(); 42 | afx_msg void OnBnClickedButton3(); 43 | afx_msg void OnBnClickedButton4(); 44 | }; 45 | -------------------------------------------------------------------------------- /KeyBoard/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /KeyBoard/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /KeyBoard/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /KeyBoard/res/KeyBoard.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/KeyBoard/res/KeyBoard.ico -------------------------------------------------------------------------------- /KeyBoard/res/KeyBoard.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/KeyBoard/res/KeyBoard.rc2 -------------------------------------------------------------------------------- /KeyBoard/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 KeyBoard.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_KEYBOARD_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_EDIT1 1000 11 | #define IDC_EDIT2 1001 12 | #define IDC_EDIT3 1002 13 | #define IDC_RADIO1 1003 14 | #define IDC_RADIO2 1004 15 | #define IDC_RADIO3 1005 16 | #define IDC_BUTTON1 1006 17 | #define IDC_BUTTON2 1007 18 | #define IDC_BUTTON3 1008 19 | #define IDC_BUTTON4 1009 20 | 21 | // Next default values for new objects 22 | // 23 | #ifdef APSTUDIO_INVOKED 24 | #ifndef APSTUDIO_READONLY_SYMBOLS 25 | #define _APS_NEXT_RESOURCE_VALUE 130 26 | #define _APS_NEXT_COMMAND_VALUE 32771 27 | #define _APS_NEXT_CONTROL_VALUE 1010 28 | #define _APS_NEXT_SYMED_VALUE 101 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /KeyBoard/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /KeyBoardRecord/KeyBoardRecord.h: -------------------------------------------------------------------------------- 1 |  2 | // KeyBoardRecord.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CKeyBoardRecordApp: 15 | // 有关此类的实现,请参阅 KeyBoardRecord.cpp 16 | // 17 | 18 | class CKeyBoardRecordApp : public CWinApp 19 | { 20 | public: 21 | CKeyBoardRecordApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CKeyBoardRecordApp theApp; 33 | -------------------------------------------------------------------------------- /KeyBoardRecord/KeyBoardRecord.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/KeyBoardRecord/KeyBoardRecord.rc -------------------------------------------------------------------------------- /KeyBoardRecord/KeyBoardRecord.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 52 | 53 | 资源文件 54 | 55 | 56 | 57 | 58 | 资源文件 59 | 60 | 61 | 62 | 63 | 资源文件 64 | 65 | 66 | -------------------------------------------------------------------------------- /KeyBoardRecord/KeyBoardRecordDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // KeyBoardRecordDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CKeyBoardRecordDlg 对话框 9 | class CKeyBoardRecordDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CKeyBoardRecordDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_KEYBOARDRECORD_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | afx_msg void OnBnClickedButton2(); 37 | afx_msg void OnRawInput(UINT nInputcode, HRAWINPUT hRawInput); 38 | 39 | public: 40 | BOOL SaveKeyToFile(USHORT usVkey); 41 | BOOL SaveKeyToFile(LPTSTR szWindowText, UINT nType); 42 | afx_msg void OnBnClickedButton3(); 43 | // afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 44 | // afx_msg void OnMouseMove(UINT nFlags, CPoint point); 45 | afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 46 | }; 47 | -------------------------------------------------------------------------------- /KeyBoardRecord/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /KeyBoardRecord/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /KeyBoardRecord/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | 15 | 16 | -------------------------------------------------------------------------------- /KeyBoardRecord/res/KeyBoardRecord.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/KeyBoardRecord/res/KeyBoardRecord.ico -------------------------------------------------------------------------------- /KeyBoardRecord/res/KeyBoardRecord.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/KeyBoardRecord/res/KeyBoardRecord.rc2 -------------------------------------------------------------------------------- /KeyBoardRecord/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 KeyBoardRecord.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_KEYBOARDRECORD_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_EDIT1 1000 11 | #define IDC_BUTTON1 1001 12 | #define IDC_BUTTON2 1002 13 | #define IDC_BUTTON3 1003 14 | #define IDC_STATIC3 1006 15 | #define IDC_STATIC4 1007 16 | 17 | // Next default values for new objects 18 | // 19 | #ifdef APSTUDIO_INVOKED 20 | #ifndef APSTUDIO_READONLY_SYMBOLS 21 | #define _APS_NEXT_RESOURCE_VALUE 130 22 | #define _APS_NEXT_COMMAND_VALUE 32771 23 | #define _APS_NEXT_CONTROL_VALUE 1008 24 | #define _APS_NEXT_SYMED_VALUE 101 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /KeyBoardRecord/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 ZTI 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Lambda/Lambda.cpp: -------------------------------------------------------------------------------- 1 | // Lambda.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | //对于习惯了C#语言的人来说,这lambda确实舒服。个人感觉,C++里Lambda的语法比C#里的要复杂 一些, 4 | 5 | //感觉编程语言里一些好的特性,都会被互相学习和借鉴。 在新版本js和Java中,也可以看到Lambda的身影 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using std::deque; 13 | using std::string; 14 | 15 | class Person 16 | { 17 | private: 18 | string firstname; 19 | string lastname; 20 | public: 21 | Person(string firstname, string lastname); 22 | public: 23 | inline string GetFirstname() { return firstname; }; 24 | inline string GetLastname() { return lastname; }; 25 | }; 26 | 27 | int main() 28 | { 29 | auto a = [](double d) {return d * d * d; }; 30 | //在C#里是这样的 31 | //Func func = d => d * d * d; 32 | std::cout << a(10) << std::endl; 33 | 34 | deque coll{ 1,3,19,5,13,7,11,2,17 }; 35 | int x = 5; 36 | int y = 12; 37 | //跟C#里的断言(Predicate)是一样的 38 | auto pos = std::find_if(coll.cbegin(), coll.cend(), 39 | [=](int i) { return i > x && i < y; }); 40 | 41 | std::cout << "first elem > 5 & < 12 : " << *pos << std::endl; 42 | 43 | //对应以下的代码 44 | deque::iterator pos; 45 | for (pos = coll.begin(); pos != coll.end(); ++pos) 46 | { 47 | if (*pos > x && *pos < y) 48 | break; 49 | } 50 | 51 | //在C#里是这样的 52 | //var result = coll.Where(x = > i > x && i < y); 53 | 54 | //以lambda作为排序准则 55 | 56 | } -------------------------------------------------------------------------------- /Lambda/Lambda.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /Message/Message.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Message.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Message.h" 8 | #include "MessageDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CMessageApp 16 | 17 | BEGIN_MESSAGE_MAP(CMessageApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CMessageApp 构造 23 | 24 | CMessageApp::CMessageApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CMessageApp 对象 35 | 36 | CMessageApp theApp; 37 | 38 | 39 | // CMessageApp 初始化 40 | 41 | BOOL CMessageApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CMessageDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Message/Message.h: -------------------------------------------------------------------------------- 1 |  2 | // Message.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'pch.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CMessageApp: 15 | // 有关此类的实现,请参阅 Message.cpp 16 | // 17 | 18 | class CMessageApp : public CWinApp 19 | { 20 | public: 21 | CMessageApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CMessageApp theApp; 33 | -------------------------------------------------------------------------------- /Message/Message.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Message/Message.rc -------------------------------------------------------------------------------- /Message/Message.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /Message/MessageDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // MessageDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CMessageDlg 对话框 9 | class CMessageDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CMessageDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_MESSAGE_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | afx_msg void OnBnClickedButton2(); 37 | afx_msg void OnBnClickedButton3(); 38 | CEdit m_editText; 39 | }; 40 | -------------------------------------------------------------------------------- /Message/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Message.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_MESSAGE_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_EDIT1 1001 12 | #define IDC_BUTTON2 1002 13 | #define IDC_EDIT2 1003 14 | #define IDC_BUTTON3 1004 15 | 16 | // Next default values for new objects 17 | // 18 | #ifdef APSTUDIO_INVOKED 19 | #ifndef APSTUDIO_READONLY_SYMBOLS 20 | #define _APS_NEXT_RESOURCE_VALUE 130 21 | #define _APS_NEXT_COMMAND_VALUE 32771 22 | #define _APS_NEXT_CONTROL_VALUE 1005 23 | #define _APS_NEXT_SYMED_VALUE 101 24 | #endif 25 | #endif 26 | -------------------------------------------------------------------------------- /Message/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Message/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Message/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Message/res/Message.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Message/res/Message.ico -------------------------------------------------------------------------------- /Message/res/Message.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Message/res/Message.rc2 -------------------------------------------------------------------------------- /Message/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Mouse/Mouse.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Mouse.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Mouse.h" 8 | #include "MouseDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CMouseApp 16 | 17 | BEGIN_MESSAGE_MAP(CMouseApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CMouseApp 构造 23 | 24 | CMouseApp::CMouseApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CMouseApp 对象 35 | 36 | CMouseApp theApp; 37 | 38 | 39 | // CMouseApp 初始化 40 | 41 | BOOL CMouseApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CMouseDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Mouse/Mouse.h: -------------------------------------------------------------------------------- 1 |  2 | // Mouse.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'pch.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CMouseApp: 15 | // 有关此类的实现,请参阅 Mouse.cpp 16 | // 17 | 18 | class CMouseApp : public CWinApp 19 | { 20 | public: 21 | CMouseApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CMouseApp theApp; 33 | -------------------------------------------------------------------------------- /Mouse/Mouse.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Mouse/Mouse.rc -------------------------------------------------------------------------------- /Mouse/Mouse.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /Mouse/MouseDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // MouseDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CMouseDlg 对话框 9 | class CMouseDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CMouseDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_MOUSE_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | afx_msg void OnBnClickedButton2(); 37 | afx_msg void OnBnClickedButton3(); 38 | virtual BOOL PreTranslateMessage(MSG* pMsg); 39 | 40 | afx_msg void OnMouseMove(UINT nFlags, CPoint point); 41 | afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 42 | afx_msg void OnLButtonUp(UINT nFlags, CPoint point); 43 | 44 | public: 45 | BOOL capture; 46 | HWND m_hWndPrevious; 47 | HPEN hOldPen; 48 | HDC hdc; 49 | HBRUSH hOldBrush; 50 | HPEN hPen; 51 | afx_msg void OnBnClickedButton4(); 52 | afx_msg void OnBnClickedButton5(); 53 | }; 54 | -------------------------------------------------------------------------------- /Mouse/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Mouse.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_MOUSE_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | #define IDC_EDIT2 1003 13 | #define IDC_EDIT3 1004 14 | #define IDC_EDIT4 1005 15 | #define IDC_BUTTON3 1006 16 | #define IDC_BUTTON4 1007 17 | #define IDC_BUTTON5 1008 18 | 19 | // Next default values for new objects 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | #define _APS_NEXT_RESOURCE_VALUE 130 24 | #define _APS_NEXT_COMMAND_VALUE 32771 25 | #define _APS_NEXT_CONTROL_VALUE 1009 26 | #define _APS_NEXT_SYMED_VALUE 101 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /Mouse/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Mouse/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Mouse/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Mouse/res/Mouse.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Mouse/res/Mouse.ico -------------------------------------------------------------------------------- /Mouse/res/Mouse.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Mouse/res/Mouse.rc2 -------------------------------------------------------------------------------- /Mouse/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Mouse.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_MOUSE_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | #define IDC_EDIT2 1003 13 | #define IDC_EDIT3 1004 14 | #define IDC_EDIT4 1005 15 | #define IDC_BUTTON3 1006 16 | #define IDC_BUTTON4 1007 17 | #define IDC_BUTTON5 1008 18 | 19 | // Next default values for new objects 20 | // 21 | #ifdef APSTUDIO_INVOKED 22 | #ifndef APSTUDIO_READONLY_SYMBOLS 23 | #define _APS_NEXT_RESOURCE_VALUE 130 24 | #define _APS_NEXT_COMMAND_VALUE 32771 25 | #define _APS_NEXT_CONTROL_VALUE 1009 26 | #define _APS_NEXT_SYMED_VALUE 101 27 | #endif 28 | #endif 29 | -------------------------------------------------------------------------------- /Mouse/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Process/Process.cpp: -------------------------------------------------------------------------------- 1 | // Process.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using std::cout; 10 | using std::vector; 11 | using std::endl; 12 | using std::wcout; 13 | 14 | vector GetAllProcess(); 15 | 16 | int main() 17 | { 18 | auto processes = GetAllProcess(); 19 | 20 | auto b = processes.begin(); 21 | for (b = processes.begin(); b != processes.end(); ++b) 22 | { 23 | wcout << b->szExeFile << endl; 24 | cout << b->th32ProcessID << endl; 25 | 26 | //结束记事本进程 27 | if (wcscmp(b->szExeFile,L"notepad.exe") == 0) 28 | { 29 | auto hNotepad = OpenProcess(PROCESS_ALL_ACCESS, FALSE, b->th32ProcessID); 30 | TerminateProcess(hNotepad, 0); 31 | } 32 | 33 | cout << endl; 34 | } 35 | 36 | } 37 | 38 | vector GetAllProcess() 39 | { 40 | std::vector processes{}; 41 | //dwFlags 42 | //TH32CS_SNAPMODULE 枚举进程中的dll 43 | //TH32CS_SNAPPROCESS 枚举系统进程 44 | //TH32CS_SNAPTHREAD 枚举系统中的线程 45 | auto hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); 46 | 47 | if (hSnap == INVALID_HANDLE_VALUE) 48 | { 49 | return processes; 50 | } 51 | 52 | PROCESSENTRY32 pe32{}; 53 | pe32.dwSize = sizeof(PROCESSENTRY32); 54 | auto bRet = Process32First(hSnap, &pe32); 55 | 56 | while (bRet) 57 | { 58 | processes.push_back(pe32); 59 | bRet = Process32Next(hSnap, &pe32); 60 | } 61 | 62 | CloseHandle(hSnap); 63 | 64 | return processes; 65 | } 66 | 67 | -------------------------------------------------------------------------------- /Process/Process.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /ProcessMonitor/ProcessMonitor.h: -------------------------------------------------------------------------------- 1 |  2 | // ProcessMonitor.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CProcessMonitorApp: 15 | // 有关此类的实现,请参阅 ProcessMonitor.cpp 16 | // 17 | 18 | class CProcessMonitorApp : public CWinApp 19 | { 20 | public: 21 | CProcessMonitorApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CProcessMonitorApp theApp; 33 | -------------------------------------------------------------------------------- /ProcessMonitor/ProcessMonitor.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/ProcessMonitor/ProcessMonitor.rc -------------------------------------------------------------------------------- /ProcessMonitor/ProcessMonitorDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // ProcessMonitorDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CProcessMonitorDlg 对话框 9 | class CProcessMonitorDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CProcessMonitorDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_PROCESSMONITOR_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton2(); 36 | 37 | public: 38 | static STARTUPINFO sinfo; 39 | static PROCESS_INFORMATION pi; 40 | static DWORD WINAPI MonitorThreadProc(LPVOID lpThreadParameter); 41 | static DWORD WINAPI MonitorCMDThreadProc(LPVOID lpThreadParameter); 42 | afx_msg void OnBnClickedButton1(); 43 | }; 44 | -------------------------------------------------------------------------------- /ProcessMonitor/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /ProcessMonitor/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /ProcessMonitor/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /ProcessMonitor/res/ProcessMonitor.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/ProcessMonitor/res/ProcessMonitor.ico -------------------------------------------------------------------------------- /ProcessMonitor/res/ProcessMonitor.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/ProcessMonitor/res/ProcessMonitor.rc2 -------------------------------------------------------------------------------- /ProcessMonitor/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 ProcessMonitor.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_PROCESSMONITOR_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 129 18 | #define _APS_NEXT_COMMAND_VALUE 32771 19 | #define _APS_NEXT_CONTROL_VALUE 1002 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /ProcessMonitor/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | //如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Process_EnumProcesses/Process_EnumProcesses.cpp: -------------------------------------------------------------------------------- 1 | // Process_EnumProcesses.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | DWORD processesArray[1024], cbNeeded, processesCount; 12 | 13 | if (!EnumProcesses(processesArray, sizeof(processesArray), &cbNeeded)) 14 | { 15 | return 0; 16 | } 17 | 18 | processesCount = cbNeeded / sizeof(DWORD); 19 | 20 | 21 | for (int i = 0; i < processesCount; i++) 22 | { 23 | TCHAR szProcessName[MAX_PATH] = L""; 24 | 25 | HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 26 | FALSE, processesArray[i]); 27 | 28 | if (NULL != hProcess) 29 | { 30 | HMODULE hMod; 31 | 32 | if (EnumProcessModulesEx(hProcess, &hMod, sizeof(hMod), &cbNeeded, LIST_MODULES_ALL)) 33 | { 34 | GetModuleBaseName(hProcess, hMod, szProcessName, 35 | sizeof(szProcessName) / sizeof(TCHAR)); 36 | 37 | std::wcout << szProcessName << std::endl; 38 | 39 | CloseHandle(hProcess); 40 | } 41 | 42 | } 43 | } 44 | } -------------------------------------------------------------------------------- /Process_ZwQuerySystemInformation/Process_ZwQuerySystemInformation.cpp: -------------------------------------------------------------------------------- 1 | // Process_ZwQuerySystemInformation.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef long(__stdcall* funNtQuerySystemInformation)(UINT, PVOID, ULONG, PULONG); 10 | 11 | int main() 12 | { 13 | NTSTATUS status; 14 | PVOID buffer; 15 | PSYSTEM_PROCESS_INFORMATION pspi; 16 | 17 | //分配足够大的空间 18 | buffer = VirtualAlloc(NULL, 1024 * 1024, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); 19 | 20 | if (!buffer) 21 | { 22 | //分配内存失败 23 | //GetLastError 24 | return 0; 25 | } 26 | 27 | HMODULE hModule = LoadLibrary(L"ntdll.dll"); 28 | 29 | if (!hModule) 30 | { 31 | //加载dll失败 32 | //GetLastError 33 | return 0; 34 | } 35 | 36 | funNtQuerySystemInformation NtQuerySystemInformation = (funNtQuerySystemInformation)GetProcAddress(hModule, "NtQuerySystemInformation"); 37 | 38 | pspi = (PSYSTEM_PROCESS_INFORMATION)buffer; 39 | 40 | if (!NT_SUCCESS(status = NtQuerySystemInformation(SystemProcessInformation, pspi, 1024 * 1024, NULL))) 41 | { 42 | //查询进程列表失败 43 | VirtualFree(buffer, 0, MEM_RELEASE); 44 | return 0; 45 | } 46 | 47 | while (pspi->NextEntryOffset) // Loop over the list until we reach the last entry. 48 | { 49 | //在这里添加处理逻辑 50 | //...... 51 | TCHAR buf[128]{}; 52 | StringCchCopy(buf, pspi->ImageName.Length, pspi->ImageName.Buffer); 53 | std::wcout << buf << std::endl; 54 | 55 | //计算下一条目的地址 56 | pspi = (PSYSTEM_PROCESS_INFORMATION)((LPBYTE)pspi + pspi->NextEntryOffset); 57 | } 58 | 59 | //释放分配的空间 60 | VirtualFree(buffer, 0, MEM_RELEASE); 61 | 62 | return 0; 63 | } 64 | 65 | // 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单 66 | // 调试程序: F5 或调试 >“开始调试”菜单 67 | 68 | // 入门使用技巧: 69 | // 1. 使用解决方案资源管理器窗口添加/管理文件 70 | // 2. 使用团队资源管理器窗口连接到源代码管理 71 | // 3. 使用输出窗口查看生成输出和其他消息 72 | // 4. 使用错误列表窗口查看错误 73 | // 5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目 74 | // 6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件 75 | -------------------------------------------------------------------------------- /RemoteThreadDemo/RemoteThreadDemo.cpp: -------------------------------------------------------------------------------- 1 | // RemoteThreadDemo.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include "inject.h" 6 | 7 | 8 | 9 | int main() 10 | { 11 | CreateRemoteThreadInject(8448, LR"(E:\project\github\WindowsX\WindowsX\x64\Debug\net6.0-windows\WindowsXCoreShellHook.dll)"); 12 | } -------------------------------------------------------------------------------- /RemoteThreadDemo/inject.cpp: -------------------------------------------------------------------------------- 1 | #include "inject.h" 2 | 3 | BOOL EnablePrivileges(HANDLE hProcess,TCHAR* pszPrivilegesName) 4 | { 5 | HANDLE hToken = NULL; 6 | LUID luidValue = { 0 }; 7 | TOKEN_PRIVILEGES tokenPrivileges = { 0 }; 8 | BOOL bRet = FALSE; 9 | DWORD dwRet = 0; 10 | 11 | bRet = OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken); 12 | if (FALSE == bRet) 13 | { 14 | return FALSE; 15 | } 16 | 17 | bRet = LookupPrivilegeValue(NULL, pszPrivilegesName, &luidValue); 18 | if (FALSE == bRet) 19 | { 20 | return FALSE; 21 | } 22 | 23 | tokenPrivileges.PrivilegeCount = 1; 24 | tokenPrivileges.Privileges[0].Luid = luidValue; 25 | tokenPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 26 | 27 | bRet = AdjustTokenPrivileges(hToken, FALSE, &tokenPrivileges, 0, NULL, NULL); 28 | if (FALSE == bRet) 29 | { 30 | return FALSE; 31 | } 32 | else 33 | { 34 | dwRet = GetLastError(); 35 | 36 | if (ERROR_SUCCESS == dwRet) 37 | { 38 | return TRUE; 39 | } 40 | else if (ERROR_NOT_ALL_ASSIGNED == dwRet) 41 | { 42 | return FALSE; 43 | } 44 | } 45 | return FALSE; 46 | 47 | 48 | } 49 | 50 | BOOL CreateRemoteThreadInject(DWORD dwPid, LPCTSTR pszDllFileName) 51 | { 52 | HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid); 53 | 54 | if (NULL == hProcess) 55 | return FALSE; 56 | 57 | SIZE_T dwSize = (1 + lstrlen(pszDllFileName)) * sizeof(TCHAR); 58 | LPVOID lpDllAddr = VirtualAllocEx(hProcess, NULL, dwSize, MEM_COMMIT, PAGE_READWRITE); 59 | 60 | if (NULL == lpDllAddr) 61 | { 62 | CloseHandle(hProcess); 63 | return FALSE; 64 | } 65 | 66 | BOOL bRet = WriteProcessMemory(hProcess, lpDllAddr, pszDllFileName, dwSize, NULL); 67 | 68 | if (!bRet) 69 | { 70 | CloseHandle(hProcess); 71 | return FALSE; 72 | } 73 | 74 | LPVOID lpLoadLibraryFunc = LoadLibraryW; 75 | 76 | HANDLE hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lpLoadLibraryFunc, (LPVOID)lpDllAddr, 0, NULL); 77 | 78 | if (NULL == hRemoteThread) 79 | { 80 | CloseHandle(hProcess); 81 | return FALSE; 82 | } 83 | 84 | //WaitForSingleObject(hRemoteThread, INFINITE); 85 | 86 | CloseHandle(hProcess); 87 | CloseHandle(hRemoteThread); 88 | return TRUE; 89 | } 90 | -------------------------------------------------------------------------------- /RemoteThreadDemo/inject.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | BOOL EnablePrivileges(HANDLE hProcess, TCHAR* pszPrivilegesName); 5 | 6 | BOOL CreateRemoteThreadInject(DWORD dwPid, LPCTSTR pszDllFileName); -------------------------------------------------------------------------------- /RemoteThread_lib/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : 定义 DLL 应用程序的入口点。 2 | #include "framework.h" 3 | #include 4 | #include 5 | 6 | BOOL APIENTRY DllMain(HMODULE hModule, 7 | DWORD ul_reason_for_call, 8 | LPVOID lpReserved 9 | ) 10 | { 11 | switch (ul_reason_for_call) 12 | { 13 | case DLL_PROCESS_ATTACH: 14 | { 15 | //TCHAR szBuffer[MAX_PATH]{}; 16 | //GetModuleFileName(hModule, szBuffer, 260); 17 | MessageBox(NULL, L"Hello World", L"Inject Success", MB_OK); 18 | } 19 | break; 20 | case DLL_THREAD_ATTACH: 21 | case DLL_THREAD_DETACH: 22 | case DLL_PROCESS_DETACH: 23 | break; 24 | } 25 | return TRUE; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /RemoteThread_lib/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 8 | // Windows 头文件 9 | #include 10 | -------------------------------------------------------------------------------- /Screenshot/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Screenshot.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_SCREENSHOT_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 129 17 | #define _APS_NEXT_COMMAND_VALUE 32771 18 | #define _APS_NEXT_CONTROL_VALUE 1001 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /Screenshot/Screenshot.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Screenshot.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Screenshot.h" 8 | #include "ScreenshotDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CScreenshotApp 16 | 17 | BEGIN_MESSAGE_MAP(CScreenshotApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CScreenshotApp 构造 23 | 24 | CScreenshotApp::CScreenshotApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CScreenshotApp 对象 35 | 36 | CScreenshotApp theApp; 37 | 38 | 39 | // CScreenshotApp 初始化 40 | 41 | BOOL CScreenshotApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CScreenshotDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Screenshot/Screenshot.h: -------------------------------------------------------------------------------- 1 |  2 | // Screenshot.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CScreenshotApp: 15 | // 有关此类的实现,请参阅 Screenshot.cpp 16 | // 17 | 18 | class CScreenshotApp : public CWinApp 19 | { 20 | public: 21 | CScreenshotApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CScreenshotApp theApp; 33 | -------------------------------------------------------------------------------- /Screenshot/Screenshot.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Screenshot/Screenshot.rc -------------------------------------------------------------------------------- /Screenshot/Screenshot.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /Screenshot/ScreenshotDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // ScreenshotDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CScreenshotDlg 对话框 9 | class CScreenshotDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CScreenshotDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_SCREENSHOT_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | }; 37 | -------------------------------------------------------------------------------- /Screenshot/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Screenshot/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Screenshot/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Screenshot/res/Screenshot.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Screenshot/res/Screenshot.ico -------------------------------------------------------------------------------- /Screenshot/res/Screenshot.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Screenshot/res/Screenshot.rc2 -------------------------------------------------------------------------------- /Screenshot/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Screenshot.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_SCREENSHOT_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | 12 | // Next default values for new objects 13 | // 14 | #ifdef APSTUDIO_INVOKED 15 | #ifndef APSTUDIO_READONLY_SYMBOLS 16 | #define _APS_NEXT_RESOURCE_VALUE 129 17 | #define _APS_NEXT_COMMAND_VALUE 32771 18 | #define _APS_NEXT_CONTROL_VALUE 1001 19 | #define _APS_NEXT_SYMED_VALUE 101 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /Screenshot/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /Self-starting/Self-starting.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Self-starting.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Self-starting.h" 8 | #include "Self-startingDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CSelfstartingApp 16 | 17 | BEGIN_MESSAGE_MAP(CSelfstartingApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CSelfstartingApp 构造 23 | 24 | CSelfstartingApp::CSelfstartingApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CSelfstartingApp 对象 35 | 36 | CSelfstartingApp theApp; 37 | 38 | 39 | // CSelfstartingApp 初始化 40 | 41 | BOOL CSelfstartingApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CSelfstartingDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Self-starting/Self-starting.h: -------------------------------------------------------------------------------- 1 |  2 | // Self-starting.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CSelfstartingApp: 15 | // 有关此类的实现,请参阅 Self-starting.cpp 16 | // 17 | 18 | class CSelfstartingApp : public CWinApp 19 | { 20 | public: 21 | CSelfstartingApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CSelfstartingApp theApp; 33 | -------------------------------------------------------------------------------- /Self-starting/Self-starting.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /Self-starting/Self-startingDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // Self-startingDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CSelfstartingDlg 对话框 9 | class CSelfstartingDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CSelfstartingDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_SELFSTARTING_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | afx_msg void OnBnClickedButton2(); 37 | afx_msg void OnBnClickedButton3(); 38 | afx_msg void OnBnClickedButton4(); 39 | }; 40 | -------------------------------------------------------------------------------- /Self-starting/Selfstarting.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Self-starting/Selfstarting.rc -------------------------------------------------------------------------------- /Self-starting/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Self-starting/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Self-starting/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Self-starting/res/Self-starting.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Self-starting/res/Self-starting.ico -------------------------------------------------------------------------------- /Self-starting/res/Selfstarting.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Self-starting/res/Selfstarting.rc2 -------------------------------------------------------------------------------- /Self-starting/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Selfstarting.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_SELFSTARTING_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_BUTTON1 1000 11 | #define IDC_BUTTON2 1001 12 | #define IDC_BUTTON3 1002 13 | #define IDC_BUTTON4 1003 14 | 15 | // Next default values for new objects 16 | // 17 | #ifdef APSTUDIO_INVOKED 18 | #ifndef APSTUDIO_READONLY_SYMBOLS 19 | #define _APS_NEXT_RESOURCE_VALUE 130 20 | #define _APS_NEXT_COMMAND_VALUE 32771 21 | #define _APS_NEXT_CONTROL_VALUE 1004 22 | #define _APS_NEXT_SYMED_VALUE 101 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /Self-starting/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /SingleInstance/Resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 由 SingleInstance.rc 使用 4 | // 5 | #define IDR_MAINFRAME 128 6 | #define IDM_ABOUTBOX 0x0010 7 | #define IDD_ABOUTBOX 100 8 | #define IDS_ABOUTBOX 101 9 | #define IDD_SINGLEINSTANCE_DIALOG 102 10 | 11 | // 新对象的下一组默认值 12 | // 13 | #ifdef APSTUDIO_INVOKED 14 | #ifndef APSTUDIO_READONLY_SYMBOLS 15 | 16 | #define _APS_NEXT_RESOURCE_VALUE 129 17 | #define _APS_NEXT_CONTROL_VALUE 1000 18 | #define _APS_NEXT_SYMED_VALUE 101 19 | #define _APS_NEXT_COMMAND_VALUE 32771 20 | #endif 21 | #endif 22 | -------------------------------------------------------------------------------- /SingleInstance/SingleInstance.h: -------------------------------------------------------------------------------- 1 |  2 | // SingleInstance.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "include 'pch.h' before including this file for PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CSingleInstanceApp: 15 | // 有关此类的实现,请参阅 SingleInstance.cpp 16 | // 17 | 18 | class CSingleInstanceApp : public CWinApp 19 | { 20 | public: 21 | CSingleInstanceApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | 31 | public: 32 | BOOL IsSingleInstance(); 33 | }; 34 | 35 | extern CSingleInstanceApp theApp; 36 | -------------------------------------------------------------------------------- /SingleInstance/SingleInstance.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/SingleInstance/SingleInstance.rc -------------------------------------------------------------------------------- /SingleInstance/SingleInstance.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 49 | 50 | 资源文件 51 | 52 | 53 | 54 | 55 | 资源文件 56 | 57 | 58 | 59 | 60 | 资源文件 61 | 62 | 63 | -------------------------------------------------------------------------------- /SingleInstance/SingleInstanceDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // SingleInstanceDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CSingleInstanceDlg 对话框 9 | class CSingleInstanceDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CSingleInstanceDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_SINGLEINSTANCE_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | }; 35 | -------------------------------------------------------------------------------- /SingleInstance/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /SingleInstance/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /SingleInstance/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /SingleInstance/res/SingleInstance.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/SingleInstance/res/SingleInstance.ico -------------------------------------------------------------------------------- /SingleInstance/res/SingleInstance.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/SingleInstance/res/SingleInstance.rc2 -------------------------------------------------------------------------------- /SingleInstance/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /StringLiteral/StringLiteral.cpp: -------------------------------------------------------------------------------- 1 | // StringLiteral.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace std::string_literals; 9 | 10 | #define notepadR R"(C:\Windows\System32\notepad.exe)" 11 | #define notepad "C:\Windows\System32\notepad.exe" 12 | 13 | int main() 14 | { 15 | // Character literals 16 | auto c0 = 'A'; // char 17 | auto c1 = u8'A'; // char 18 | auto c2 = L'A'; // wchar_t 19 | auto c3 = u'A'; // char16_t 20 | auto c4 = U'A'; // char32_t 21 | 22 | // Multicharacter literals 23 | auto m0 = 'abcd'; // int, value 0x61626364 24 | 25 | // String literals 26 | auto s0 = "hello"; // const char* 27 | auto s1 = u8"hello"; // const char*, encoded as UTF-8 28 | auto s2 = L"hello"; // const wchar_t* 29 | auto s3 = u"hello"; // const char16_t*, encoded as UTF-16 30 | auto s4 = U"hello"; // const char32_t*, encoded as UTF-32 31 | 32 | // Raw string literals containing unescaped \ and " 33 | auto R0 = R"("Hello \ world")"; // const char* 34 | auto R1 = u8R"("Hello \ world")"; // const char*, encoded as UTF-8 35 | auto R2 = LR"("Hello \ world")"; // const wchar_t* 36 | auto R3 = uR"("Hello \ world")"; // const char16_t*, encoded as UTF-16 37 | auto R4 = UR"("Hello \ world")"; // const char32_t*, encoded as UTF-32 38 | 39 | // Combining string literals with standard s-suffix 40 | auto S0 = "hello"s; // std::string 41 | auto S1 = u8"hello"s; // std::string 42 | auto S2 = L"hello"s; // std::wstring 43 | auto S3 = u"hello"s; // std::u16string 44 | auto S4 = U"hello"s; // std::u32string 45 | 46 | // Combining raw string literals with standard s-suffix 47 | auto S5 = R"("Hello \ world")"s; // std::string from a raw const char* 48 | auto S6 = u8R"("Hello \ world")"s; // std::string from a raw const char*, encoded as UTF-8 49 | auto S7 = LR"("Hello \ world")"s; // std::wstring from a raw const wchar_t* 50 | auto S8 = uR"("Hello \ world")"s; // std::u16string from a raw const char16_t*, encoded as UTF-16 51 | auto S9 = UR"("Hello \ world")"s; // std::u32string from a raw const char32_t*, encoded as UTF-32 52 | 53 | 54 | //WinExec(notepad, SW_SHOW); can not open notepad 55 | WinExec(notepadR, SW_SHOW); 56 | } -------------------------------------------------------------------------------- /StringLiteral/StringLiteral.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /TaskbarHookLib/HBitmapEx.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include"framework.h" 4 | 5 | class HBitmapEx 6 | { 7 | public: 8 | HBitmapEx(LPCTSTR szPath); 9 | ~HBitmapEx(); 10 | std::wstring GetAbsoluteImagePath(LPCTSTR szPath); 11 | 12 | HBITMAP hBitmap; 13 | 14 | private: 15 | HBITMAP InternalLoadBitmapFromStream(IStream* pStream, bool bTopDown, bool bPremultiply); 16 | }; 17 | -------------------------------------------------------------------------------- /TaskbarHookLib/TaskbarHook.cpp: -------------------------------------------------------------------------------- 1 | #include"TaskbarHook.h" 2 | 3 | BOOL CreateTaskbarHook() 4 | { 5 | HWND hwndProgMan = FindWindowEx(NULL, NULL, L"Progman", NULL); 6 | 7 | DWORD process = 0; 8 | DWORD thread = GetWindowThreadProcessId(hwndProgMan, &process); 9 | HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, process); 10 | 11 | wchar_t path[MAX_PATH]; 12 | if (GetModuleFileNameEx(hProcess, NULL, path, _countof(path))) 13 | { 14 | if (_wcsicmp(PathFindFileName(path), L"explorer.exe") != 0) 15 | return FALSE; 16 | } 17 | CloseHandle(hProcess); 18 | 19 | thread = GetWindowThreadProcessId(g_TaskBar, NULL); 20 | g_hook = SetWindowsHookEx(WH_GETMESSAGE, GetMessageProc, g_hModule, thread); 21 | PostMessage(g_TaskBar, WM_NULL, 0, 0); // make sure there is one message in the queue 22 | 23 | return true; 24 | } 25 | 26 | 27 | BOOL CALLBACK FindTaskBarEnum(HWND hwnd, LPARAM lParam) 28 | { 29 | // look for top-level window with class "Shell_TrayWnd" and process ID=lParam 30 | DWORD process; 31 | GetWindowThreadProcessId(hwnd, &process); 32 | if (process != lParam) return TRUE; 33 | wchar_t name[256]; 34 | GetClassName(hwnd, name, _countof(name)); 35 | if (_wcsicmp(name, L"Shell_TrayWnd") != 0) return TRUE; 36 | g_TaskBar = hwnd; 37 | return FALSE; 38 | } 39 | 40 | HWND FindTaskBar(DWORD dwProcessId) 41 | { 42 | // find the taskbar 43 | EnumWindows(FindTaskBarEnum, dwProcessId); 44 | if (!g_TaskBar) 45 | g_TaskBar = FindWindowEx(GetDesktopWindow(), NULL, L"Shell_TrayWnd", NULL); 46 | return g_TaskBar; 47 | } 48 | 49 | LRESULT GetMessageProc(int code, WPARAM wParam, LPARAM lParam) 50 | { 51 | if (code == HC_ACTION && !g_TaskBar) 52 | InitStartMenuDLL(); 53 | return CallNextHookEx(NULL, code, wParam, lParam); 54 | } 55 | 56 | VOID InitStartMenuDLL() 57 | { 58 | if (bInitCalled) 59 | return; 60 | 61 | bInitCalled = TRUE; 62 | 63 | //IatHooks? 64 | 65 | HMODULE dwn = GetModuleHandle(L"dwmapi.dll"); 66 | } -------------------------------------------------------------------------------- /TaskbarHookLib/TaskbarHook.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "framework.h" 3 | 4 | HHOOK g_hook; 5 | HWND g_TaskBar; 6 | 7 | HMODULE g_hModule; 8 | static BOOL bInitCalled = FALSE; 9 | 10 | typedef VOID(WINAPI *tDwmpBeginTransitionRequest)(int param); 11 | typedef VOID(WINAPI *tDwmpTransitionWindowWithRects)(HWND, int, RECT*, RECT*, RECT*, RECT*, RECT*); 12 | typedef VOID(WINAPI* tDwmpEndTransitionRequest)(int param); 13 | 14 | tDwmpBeginTransitionRequest g_DwmBeginTransitionRequest; 15 | tDwmpTransitionWindowWithRects g_DwmTransitionWindowWithRects; 16 | tDwmpEndTransitionRequest g_DwmpEndTransitionRequest; 17 | 18 | BOOL CreateTaskbarHook(); 19 | LRESULT __stdcall GetMessageProc(int code, WPARAM wParam, LPARAM lParam); 20 | HWND FindTaskBar(DWORD dwProcessId); 21 | BOOL CALLBACK FindTaskBarEnum(HWND hwnd, LPARAM lParam); 22 | VOID InitStartMenuDLL(); 23 | -------------------------------------------------------------------------------- /TaskbarHookLib/dllmain.cpp: -------------------------------------------------------------------------------- 1 | // dllmain.cpp : 定义 DLL 应用程序的入口点。 2 | #include "framework.h" 3 | 4 | extern HMODULE g_hModule; 5 | static HANDLE g_DllInitThread; 6 | 7 | 8 | BOOL APIENTRY DllMain( HMODULE hModule, 9 | DWORD ul_reason_for_call, 10 | LPVOID lpReserved 11 | ) 12 | { 13 | switch (ul_reason_for_call) 14 | { 15 | case DLL_PROCESS_ATTACH: 16 | g_hModule = hModule; 17 | case DLL_THREAD_ATTACH: 18 | case DLL_THREAD_DETACH: 19 | case DLL_PROCESS_DETACH: 20 | break; 21 | } 22 | return TRUE; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /TaskbarHookLib/framework.h: -------------------------------------------------------------------------------- 1 | // header.h: 标准系统包含文件的包含文件, 2 | // 或特定于项目的包含文件 3 | // 4 | 5 | #pragma once 6 | 7 | #define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容 8 | // Windows 头文件 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #pragma comment(lib,"shlwapi.lib") 17 | 18 | -------------------------------------------------------------------------------- /Thread/ProcessState.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Thread/ProcessState.jpg -------------------------------------------------------------------------------- /Thread/Thread.cpp: -------------------------------------------------------------------------------- 1 |  2 | // Thread.cpp: 定义应用程序的类行为。 3 | // 4 | 5 | #include "pch.h" 6 | #include "framework.h" 7 | #include "Thread.h" 8 | #include "ThreadDlg.h" 9 | 10 | #ifdef _DEBUG 11 | #define new DEBUG_NEW 12 | #endif 13 | 14 | 15 | // CThreadApp 16 | 17 | BEGIN_MESSAGE_MAP(CThreadApp, CWinApp) 18 | ON_COMMAND(ID_HELP, &CWinApp::OnHelp) 19 | END_MESSAGE_MAP() 20 | 21 | 22 | // CThreadApp 构造 23 | 24 | CThreadApp::CThreadApp() 25 | { 26 | // 支持重新启动管理器 27 | m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; 28 | 29 | // TODO: 在此处添加构造代码, 30 | // 将所有重要的初始化放置在 InitInstance 中 31 | } 32 | 33 | 34 | // 唯一的 CThreadApp 对象 35 | 36 | CThreadApp theApp; 37 | 38 | 39 | // CThreadApp 初始化 40 | 41 | BOOL CThreadApp::InitInstance() 42 | { 43 | // 如果一个运行在 Windows XP 上的应用程序清单指定要 44 | // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, 45 | //则需要 InitCommonControlsEx()。 否则,将无法创建窗口。 46 | INITCOMMONCONTROLSEX InitCtrls; 47 | InitCtrls.dwSize = sizeof(InitCtrls); 48 | // 将它设置为包括所有要在应用程序中使用的 49 | // 公共控件类。 50 | InitCtrls.dwICC = ICC_WIN95_CLASSES; 51 | InitCommonControlsEx(&InitCtrls); 52 | 53 | CWinApp::InitInstance(); 54 | 55 | 56 | AfxEnableControlContainer(); 57 | 58 | // 创建 shell 管理器,以防对话框包含 59 | // 任何 shell 树视图控件或 shell 列表视图控件。 60 | CShellManager *pShellManager = new CShellManager; 61 | 62 | // 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题 63 | CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 64 | 65 | // 标准初始化 66 | // 如果未使用这些功能并希望减小 67 | // 最终可执行文件的大小,则应移除下列 68 | // 不需要的特定初始化例程 69 | // 更改用于存储设置的注册表项 70 | // TODO: 应适当修改该字符串, 71 | // 例如修改为公司或组织名 72 | SetRegistryKey(_T("应用程序向导生成的本地应用程序")); 73 | 74 | CThreadDlg dlg; 75 | m_pMainWnd = &dlg; 76 | INT_PTR nResponse = dlg.DoModal(); 77 | if (nResponse == IDOK) 78 | { 79 | // TODO: 在此放置处理何时用 80 | // “确定”来关闭对话框的代码 81 | } 82 | else if (nResponse == IDCANCEL) 83 | { 84 | // TODO: 在此放置处理何时用 85 | // “取消”来关闭对话框的代码 86 | } 87 | else if (nResponse == -1) 88 | { 89 | TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n"); 90 | TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n"); 91 | } 92 | 93 | // 删除上面创建的 shell 管理器。 94 | if (pShellManager != nullptr) 95 | { 96 | delete pShellManager; 97 | } 98 | 99 | #if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS) 100 | ControlBarCleanUp(); 101 | #endif 102 | 103 | // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, 104 | // 而不是启动应用程序的消息泵。 105 | return FALSE; 106 | } 107 | 108 | -------------------------------------------------------------------------------- /Thread/Thread.h: -------------------------------------------------------------------------------- 1 |  2 | // Thread.h: PROJECT_NAME 应用程序的主头文件 3 | // 4 | 5 | #pragma once 6 | 7 | #ifndef __AFXWIN_H__ 8 | #error "在包含此文件之前包含 'pch.h' 以生成 PCH" 9 | #endif 10 | 11 | #include "resource.h" // 主符号 12 | 13 | 14 | // CThreadApp: 15 | // 有关此类的实现,请参阅 Thread.cpp 16 | // 17 | 18 | class CThreadApp : public CWinApp 19 | { 20 | public: 21 | CThreadApp(); 22 | 23 | // 重写 24 | public: 25 | virtual BOOL InitInstance(); 26 | 27 | // 实现 28 | 29 | DECLARE_MESSAGE_MAP() 30 | }; 31 | 32 | extern CThreadApp theApp; 33 | -------------------------------------------------------------------------------- /Thread/Thread.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Thread/Thread.md -------------------------------------------------------------------------------- /Thread/Thread.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Thread/Thread.rc -------------------------------------------------------------------------------- /Thread/ThreadDlg.h: -------------------------------------------------------------------------------- 1 |  2 | // ThreadDlg.h: 头文件 3 | // 4 | 5 | #pragma once 6 | 7 | 8 | // CThreadDlg 对话框 9 | class CThreadDlg : public CDialogEx 10 | { 11 | // 构造 12 | public: 13 | CThreadDlg(CWnd* pParent = nullptr); // 标准构造函数 14 | 15 | // 对话框数据 16 | #ifdef AFX_DESIGN_TIME 17 | enum { IDD = IDD_THREAD_DIALOG }; 18 | #endif 19 | 20 | protected: 21 | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 22 | 23 | 24 | // 实现 25 | protected: 26 | HICON m_hIcon; 27 | 28 | // 生成的消息映射函数 29 | virtual BOOL OnInitDialog(); 30 | afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 31 | afx_msg void OnPaint(); 32 | afx_msg HCURSOR OnQueryDragIcon(); 33 | DECLARE_MESSAGE_MAP() 34 | public: 35 | afx_msg void OnBnClickedButton1(); 36 | }; 37 | -------------------------------------------------------------------------------- /Thread/framework.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef VC_EXTRALEAN 4 | #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 5 | #endif 6 | 7 | #include "targetver.h" 8 | 9 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 10 | 11 | // 关闭 MFC 的一些常见且经常可放心忽略的隐藏警告消息 12 | #define _AFX_ALL_WARNINGS 13 | 14 | #include // MFC 核心组件和标准组件 15 | #include // MFC 扩展 16 | 17 | 18 | #include // MFC 自动化类 19 | 20 | 21 | 22 | #ifndef _AFX_NO_OLE_SUPPORT 23 | #include // MFC 对 Internet Explorer 4 公共控件的支持 24 | #endif 25 | #ifndef _AFX_NO_AFXCMN_SUPPORT 26 | #include // MFC 对 Windows 公共控件的支持 27 | #endif // _AFX_NO_AFXCMN_SUPPORT 28 | 29 | #include // MFC 支持功能区和控制条 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | #ifdef _UNICODE 40 | #if defined _M_IX86 41 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") 42 | #elif defined _M_X64 43 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") 44 | #else 45 | #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") 46 | #endif 47 | #endif 48 | 49 | 50 | -------------------------------------------------------------------------------- /Thread/pch.cpp: -------------------------------------------------------------------------------- 1 | // pch.cpp: 与预编译标头对应的源文件 2 | 3 | #include "pch.h" 4 | 5 | // 当使用预编译的头时,需要使用此源文件,编译才能成功。 6 | -------------------------------------------------------------------------------- /Thread/pch.h: -------------------------------------------------------------------------------- 1 | // pch.h: 这是预编译标头文件。 2 | // 下方列出的文件仅编译一次,提高了将来生成的生成性能。 3 | // 这还将影响 IntelliSense 性能,包括代码完成和许多代码浏览功能。 4 | // 但是,如果此处列出的文件中的任何一个在生成之间有更新,它们全部都将被重新编译。 5 | // 请勿在此处添加要频繁更新的文件,这将使得性能优势无效。 6 | 7 | #ifndef PCH_H 8 | #define PCH_H 9 | 10 | // 添加要在此处预编译的标头 11 | #include "framework.h" 12 | 13 | #endif //PCH_H 14 | -------------------------------------------------------------------------------- /Thread/priority_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Thread/priority_table.png -------------------------------------------------------------------------------- /Thread/res/Thread.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Thread/res/Thread.ico -------------------------------------------------------------------------------- /Thread/res/Thread.rc2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zhaotianff/WindowsProgramming/f7dc9819fcd89503077cf245df97d76e57d02c8a/Thread/res/Thread.rc2 -------------------------------------------------------------------------------- /Thread/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ 生成的包含文件。 3 | // 供 Thread.rc 使用 4 | // 5 | #define IDM_ABOUTBOX 0x0010 6 | #define IDD_ABOUTBOX 100 7 | #define IDS_ABOUTBOX 101 8 | #define IDD_THREAD_DIALOG 102 9 | #define IDR_MAINFRAME 128 10 | #define IDC_LIST1 1000 11 | #define IDC_BUTTON1 1001 12 | 13 | // Next default values for new objects 14 | // 15 | #ifdef APSTUDIO_INVOKED 16 | #ifndef APSTUDIO_READONLY_SYMBOLS 17 | #define _APS_NEXT_RESOURCE_VALUE 130 18 | #define _APS_NEXT_COMMAND_VALUE 32771 19 | #define _APS_NEXT_CONTROL_VALUE 1002 20 | #define _APS_NEXT_SYMED_VALUE 101 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /Thread/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 包括 SDKDDKVer.h 将定义可用的最高版本的 Windows 平台。 4 | 5 | // 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 6 | // 将 _WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /UniformInitialization/UniformInitialization.cpp: -------------------------------------------------------------------------------- 1 | // UniformInitialization.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。 2 | // 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | // No constructor 11 | struct TempData 12 | { 13 | int StationId; 14 | time_t timeSet; 15 | double current; 16 | double maxTemp; 17 | double minTemp; 18 | }; 19 | 20 | // Has a constructor 21 | struct TempData2 22 | { 23 | TempData2(double minimum, double maximum, double cur, int id, time_t t) : 24 | stationId{ id }, timeSet{ t }, current{ cur }, maxTemp{ maximum }, minTemp{ minimum } {} 25 | int stationId; 26 | time_t timeSet; 27 | double current; 28 | double maxTemp; 29 | double minTemp; 30 | }; 31 | 32 | class P 33 | { 34 | public: 35 | P(); 36 | P(int, int); 37 | P(std::initializer_list); 38 | }; 39 | 40 | P::P() 41 | { 42 | } 43 | 44 | 45 | P::P(int, int) 46 | { 47 | 48 | } 49 | 50 | P::P(std::initializer_list) 51 | { 52 | 53 | } 54 | 55 | int main() 56 | { 57 | int values[]{ 1,2,3,4,5 }; 58 | 59 | std::vector v{ 1,2,3,4,5,6 }; 60 | std::vector strs{"Hello", "World"}; 61 | 62 | //i has undefined value 63 | int i; 64 | //j is initalized by 0 65 | int j{}; 66 | 67 | //p has undefined value 68 | int* p; 69 | //q has initialized by nullptr 70 | int* q{}; 71 | 72 | //narrowing is not allowed 73 | //error 74 | //int x{ 5.3 }; 75 | 76 | 77 | //P::P(int,int) 78 | P pp{ 1,2 }; 79 | 80 | //P::P(initializer_list) 81 | P qq{ 1,2,3,4 }; 82 | P rr = { 1,2,3,4 }; 83 | 84 | time_t time_to_set; 85 | 86 | // Member initialization (in order of declaration): 87 | TempData td{ 45978, time(&time_to_set), 28.9, 37.0, 16.7 }; 88 | 89 | // Default initialization = {0,0,0,0,0} 90 | TempData td_default{}; 91 | 92 | // Uninitialized = if used, emits warning C4700 uninitialized local variable 93 | TempData td_noInit; 94 | 95 | // Member declaration (in order of ctor parameters) 96 | TempData2 td2{ 16.7, 37.0, 28.9, 45978, time(&time_to_set) }; 97 | 98 | } 99 | 100 | -------------------------------------------------------------------------------- /UniformInitialization/UniformInitialization.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /WMI/QuerySink.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifndef QUERYSINK_H 4 | #define QUERYSIN_H 5 | 6 | #define _WIN32_DCOM 7 | #include 8 | #include 9 | 10 | #pragma comment(lib,"wbemuuid.lib") 11 | 12 | class QuerySink : public IWbemObjectSink 13 | { 14 | LONG m_lRef; 15 | bool bDone; 16 | 17 | CRITICAL_SECTION threadLock; 18 | 19 | public: 20 | QuerySink() { m_lRef = 0, bDone = false; InitializeCriticalSection(&threadLock); }; 21 | }; 22 | 23 | #endif // !QUERYSINK_H 24 | --------------------------------------------------------------------------------