资源简介
使用C++实现的屏幕水印效果。实现中考虑了多显示屏幕的问题,代码简单易懂,通过完整的封装可实现快速移植。
代码片段和文件信息
#include “StdAfx.h“
#include “MScreenInfoCtrl.h“
#include
#include
#include
#include
#define PI 3.1415927
int m_monitorNum = 0;
bool m_Flag = false;
CMScreenInfoCtrl::CMScreenInfoCtrl(void)
{
GdiplusStartupInput gdiplusStartupInput;
m_nTop = 0;
m_nLeft = 0;
m_nBottom = 0;
m_nRight = 0;
m_nWidth = 0;
m_nHeight = 0;
m_gdiplusToken = 0;
m_wsColor = L“red“;
m_FontName = L“新宋体“;
m_wstrText = L“屏幕水印显示“;
m_FontName = L“宋体“;
m_fontsize = 80;
// Initialize GDI+.
GdiplusStartup(&m_gdiplusToken &gdiplusStartupInput NULL);
}
CMScreenInfoCtrl::~CMScreenInfoCtrl(void)
{
GdiplusShutdown(m_gdiplusToken);
}
ATOM CMScreenInfoCtrl::RegisterWindowClass()
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW|CS_NOCLOSE;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = m_s_hInstance;
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = STR_CLASSNAME;
wcex.hIconSm = NULL;
return RegisterClassEx(&wcex);
}
WORD CMScreenInfoCtrl::CreateSCWindow()
{
RegisterWindowClass();
m_Blend.BlendOp = 0;
m_Blend.BlendFlags = 0;
m_Blend.AlphaFormat = 1;
m_Blend.SourceConstantAlpha = 60;
m_format.SetAlignment(StringAlignmentNear);
//刷新屏幕位置坐标和尺寸
RefreshSCWinSize();
m_hWnd = ::CreateWindowEx((WS_EX_TOOLWINDOW|
WS_EX_TRANSPARENT|WS_EX_TOPMOST)&~WS_EX_APPWINDOW
STR_CLASSNAME L““
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP
m_nLeft m_nTop m_nWidth m_nHeight NULL NULL m_s_hInstance NULL);
::SetProp(m_hWnd STR_CLASSPOINTER this);
::PostMessage(m_hWnd WM_PAINT 0 0);
return 0;
}
LRESULT CALLBACK CMScreenInfoCtrl::WndProc( HWND hWnd UINT message WPARAM wParam LPARAM lParam)
{
HANDLE h = ::GetProp(hWnd STR_CLASSPOINTER);
CMScreenInfoCtrl * p = (CMScreenInfoCtrl*)h;
if (NULL == h)
{
return ::DefWindowProc(hWnd message wParam lParam);
}
return p->OnWndProc(message wParam lParam);
}
LRESULT CMScreenInfoCtrl::OnWndProc( UINT message WPARAM wParam LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
BringWindowToTop(m_hWnd);
switch(message)
{
//屏幕水印 响应屏幕显示变化事件,包括 分辨率变化、增加/减少屏幕
case WM_DISPLAYCHANGE:
RefreshSCWinSize(); //刷新水印位置和大小
//不使用 break,继续执行 Paint 处理
case WM_PAINT:
hdc = ::BeginPaint(m_hWnd &ps);
OnPaint(hdc);
EndPaint(m_hWnd &ps);
BringWindowToTop(m_hWnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return D
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 9069 2018-09-06 17:10 ScreenWaterMark\MScreenInfoCtrl.cpp
文件 1044 2018-08-31 15:13 ScreenWaterMark\MScreenInfoCtrl.h
文件 4166 2018-08-31 14:26 ScreenWaterMark\ReadMe.txt
....... 67777 2007-11-28 16:21 ScreenWaterMark\res\ScreenWaterMark.ico
文件 406 2018-08-31 14:26 ScreenWaterMark\res\ScreenWaterMark.rc2
文件 549 2018-08-31 14:29 ScreenWaterMark\resource.h
文件 104592 2018-08-31 14:46 ScreenWaterMark\ScreenWaterMark.aps
文件 2207 2018-08-31 14:26 ScreenWaterMark\ScreenWaterMark.cpp
文件 562 2018-08-31 14:26 ScreenWaterMark\ScreenWaterMark.h
文件 4922 2018-08-31 14:46 ScreenWaterMark\ScreenWaterMark.rc
文件 5720 2018-08-31 14:32 ScreenWaterMark\ScreenWaterMark.vcproj
文件 1421 2018-09-06 17:14 ScreenWaterMark\ScreenWaterMark.vcproj.BY-LIAOJUMIN.Administrator.user
文件 2822 2018-09-06 17:00 ScreenWaterMark\ScreenWaterMarkDlg.cpp
文件 677 2018-09-06 16:29 ScreenWaterMark\ScreenWaterMarkDlg.h
文件 217 2018-08-31 14:26 ScreenWaterMark\stdafx.cpp
文件 2029 2018-08-31 14:26 ScreenWaterMark\stdafx.h
文件 1432 2018-08-31 14:26 ScreenWaterMark\targetver.h
目录 0 2018-08-31 14:26 ScreenWaterMark\res
目录 0 2018-09-06 17:14 ScreenWaterMark
----------- --------- ---------- ----- ----
209612 19
评论
共有 条评论