utiltydll.cpp
来自「此为本书的配套光盘.本书不但由浅入深地讲解了软件保护技术」· C++ 代码 · 共 115 行
CPP
115 行
// UtiltyDll.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "UtiltyDll.h"
UTILTYDLL_API HWND hDll=0;
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szWindowClass[] = "UtilityDll"; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY DllMain( HINSTANCE hInstance,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
{
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance))
{
return FALSE;
}
}
break;
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
{
if( NULL != hDll )
{
DestroyWindow(hDll);
hDll = NULL;
}
}
break;
}
return TRUE;
}
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = 0;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = 0;
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = "";
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = 0;
return RegisterClassEx(&wcex);
}
BOOL InitInstance(HINSTANCE hInstance)
{
hInst = hInstance; // Store instance handle in our global variable
hDll = CreateWindow(szWindowClass, "", 0,//WS_OVERLAPPEDWINDOW,
0, 0, 0, 0, NULL, NULL, hInstance, NULL);
if (!hDll)
{
return FALSE;
}
ShowWindow(hDll, SW_HIDE);
UpdateWindow(hDll);
return TRUE;
}
//内部功能函数前置声明;
void InternalShowMsgBox(WPARAM wParam, LPARAM);
//窗口过程处理函数,它进行窗口默认处理和功能消息的分发;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_SHOWMSGBOX://识别功能消息,调用内部功能函数
InternalShowMsgBox(wParam,lParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
//内部功能函数实现
void InternalShowMsgBox(WPARAM wParam, LPARAM /* not use */)
{
sShowMsgBoxParam * pParam = (sShowMsgBoxParam*)wParam;
::MessageBox(NULL,pParam->sText,pParam->sTitle,pParam->nStyle);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?