// hide_global_cursor.cpp: 定义应用程序的类行为。
//
#include "pch.h"
#include "framework.h"
#include "hide_global_cursor.h"
#include "hide_global_cursorDlg.h"
#define OCR_NORMAL 32512
#define OCR_IBEAM 32513
#define OCR_WAIT 32514
#define OCR_CROSS 32515
#define OCR_UP 32516
#define OCR_SIZE 32640 /* OBSOLETE: use OCR_SIZEALL */
#define OCR_ICON 32641 /* OBSOLETE: use OCR_NORMAL */
#define OCR_SIZENWSE 32642
#define OCR_SIZENESW 32643
#define OCR_SIZEWE 32644
#define OCR_SIZENS 32645
#define OCR_SIZEALL 32646
#define OCR_ICOCUR 32647 /* OBSOLETE: use OIC_WINLOGO */
#define OCR_NO 32648
#define OCR_APPSTARTING 32650
#define OCR_HAND 32649
#define OCR_HELP 32651 /* only defined in wine */
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#include <string>
#include <vector>
#include <olectl.h>
#pragma comment(lib, "oleaut32.lib")
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
// ChideglobalcursorApp
BEGIN_MESSAGE_MAP(ChideglobalcursorApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
// ChideglobalcursorApp 构造
ChideglobalcursorApp::ChideglobalcursorApp()
{
// 支持重新启动管理器
m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART;
// TODO: 在此处添加构造代码,
// 将所有重要的初始化放置在 InitInstance 中
}
// 唯一的 ChideglobalcursorApp 对象
ChideglobalcursorApp theApp;
void replacecursor(HCURSOR hCursor)
{
SetSystemCursor(CopyCursor(hCursor), OCR_APPSTARTING);
SetSystemCursor(CopyCursor(hCursor), OCR_NORMAL);
SetSystemCursor(CopyCursor(hCursor), OCR_CROSS);
SetSystemCursor(CopyCursor(hCursor), OCR_HAND);
SetSystemCursor(CopyCursor(hCursor), OCR_HELP);
SetSystemCursor(CopyCursor(hCursor), OCR_IBEAM);
SetSystemCursor(CopyCursor(hCursor), OCR_NO);
SetSystemCursor(CopyCursor(hCursor), OCR_SIZEALL);
SetSystemCursor(CopyCursor(hCursor), OCR_SIZENESW);
SetSystemCursor(CopyCursor(hCursor), OCR_SIZENS);
SetSystemCursor(CopyCursor(hCursor), OCR_SIZENWSE);
SetSystemCursor(CopyCursor(hCursor), OCR_SIZEWE);
SetSystemCursor(CopyCursor(hCursor), OCR_UP);
SetSystemCursor(CopyCursor(hCursor), OCR_WAIT);
SetSystemCursor(CopyCursor(hCursor), OCR_ICOCUR);
SetSystemCursor(CopyCursor(hCursor), OCR_SIZE);
SetSystemCursor(CopyCursor(hCursor), OCR_ICON);
}
// ChideglobalcursorApp 初始化
HICON HICONFromCBitmap(CBitmap& bitmap)
{
BITMAP bmp;
bitmap.GetBitmap(&bmp);
HBITMAP hbmMask = ::CreateCompatibleBitmap(::GetDC(NULL),
bmp.bmWidth, bmp.bmHeight);
ICONINFO ii = { 0 };
ii.fIcon = TRUE;
ii.hbmColor = bitmap;
ii.hbmMask = hbmMask;
HICON hIcon = ::CreateIconIndirect(&ii);//一旦不再需要,注意用DestroyIcon函数释放占用的内存及资源
::DeleteObject(hbmMask);
return hIcon;
}
HRESULT SaveIcon(HICON hIcon, const wchar_t* path) {
// Create the IPicture intrface
PICTDESC desc = { sizeof(PICTDESC) };
desc.picType = PICTYPE_ICON;
desc.icon.hicon = hIcon;
IPicture* pPicture = 0;
HRESULT hr = OleCreatePictureIndirect(&desc, IID_IPicture, FALSE, (void**)&pPicture);
if (FAILED(hr)) return hr;
// Create a stream and save the image
IStream* pStream = 0;
CreateStreamOnHGlobal(0, TRUE, &pStream);
LONG cbSize = 0;
hr = pPicture->SaveAsFile(pStream, TRUE, &cbSize);
// Write the stream content to the file
HGLOBAL hBuf = 0;
GetHGlobalFromStream(pStream, &hBuf);
void* buffer = GlobalLock(hBuf);
if (!FAILED(hr)) {
HANDLE hFile = CreateFile(path, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
if (!hFile) hr = HRESULT_FROM_WIN32(GetLastError());
else {
DWORD written = 0;
WriteFile(hFile, buffer, cbSize, &written, 0);
CloseHandle(hFile);
}
}
HCURSOR hic;
hic = LoadCursorFromFile(L"test.cur");
//hic = (HICON)::LoadImage(AfxGetInstanceHandle(), TEXT("test.ico"), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);
replacecursor(hic);
// Cleanup
pStream->Release();
pPicture->Release();
GlobalUnlock(buffer);
return hr;
}
BOOL ChideglobalcursorApp::InitInstance()
{
// 如果一个运行在 Windows XP 上的应用程序清单指定要
// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
//则需要 InitCommonControlsEx()。 否则,将无法创建窗口。
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// 将它设置为包括所有要在应用程序中使用的
// 公共控件类。
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinApp::InitInstance();
AfxEnableControlContainer();
// 创建 shell 管理器,以防对话框包含
// 任何 shell 树视图控件或 shell 列表视图控件。
CShellManager *pShellManager = new CShellManager;
// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));
// 标准初始化
// 如果未使用这些功能并希望减小
// 最终可执行文件的大小,则应移除下列
// 不需要的特定初始化例程
// 更改用于存储设置的注册表项
// TODO: 应适当修改该字符串,
// 例如修改为公司或组织名
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
while (0)
{
CURSORINFO hCur;
ZeroMemory(&hCur, sizeof(hCur));
hCur.cbSize = sizeof(hCur);
GetCursorInfo(&hCur);
SaveIcon(hCur.hCursor, L"test.cur");
}
int shift = 0,last_shift=0;
bool is_hide = false;
while (true)
{
if (GetAsyncKeyState(VK_LSHIFT) & GetAsyncKeyState(VK_RSHIFT) & 0X8000)shift = 1;
else shift = 0;
if (last_shift==0&&shift==1)
{
is_hide = !is_hide;
if (is_hide)
{
HCURSOR hCursor = ::LoadCursor(theApp.m_hInstance, MAKEINTRESOURCE(IDC_CURSOR1));
replacecursor(hCursor);
}
else
{
SystemParametersInfo(SPI_SETCURSORS, 0, NULL, 0);
}
}
else
Sleep(20);
last_shift = shift;
}
ChideglobalcursorDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: 在此放置处理何时用
// “确定”来关闭对话框的代码
}
else if (nResponse == IDCANCEL)
{
// TODO: 在此放置处理何时用
// “取消”来关闭对话框的代码
}
else if (nResponse == -1)
{
TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
}
// 删除上面创建的 shell 管理器。
if (pShellManager != nullptr)
{
delete pShellManager;
}
#if !defined(_AFXDLL) && !defined(_AFX_NO_MFC_CONTROLS_IN_DIALOGS)
ControlBarCleanUp();
#endif
// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
// 而不是启动应用程序的消息泵。
return FALSE;
}
没有合适的资源?快使用搜索试试~ 我知道了~
windows全局隐藏鼠标
共23个文件
h:6个
cpp:3个
exe:2个
需积分: 0 46 下载量 140 浏览量
2023-02-08
14:12:34
上传
评论
收藏 6.76MB ZIP 举报
温馨提示
windows全局隐藏鼠标
资源推荐
资源详情
资源评论
收起资源包目录
hide_global_cursor.zip (23个子文件)
hide_global_cursor.sln 1KB
x64
Release
hide_global_cursor.pdb 8.57MB
hide_global_cursor.exe 89KB
Debug
hide_global_cursor.pdb 20.09MB
hide_global_cursor.exe 265KB
hide_global_cursor
hide_global_cursorDlg.h 799B
hide_global_cursor.cpp 7KB
hide_global_cursor.h 542B
resource.h 737B
framework.h 2KB
hide_global_cursor.vcxproj.user 242B
res
hideglobalcursor.rc2 688B
cursor1.cur 326B
hide_global_cursor.ico 66KB
hide_global_cursor.vcxproj 10KB
pch.h 544B
x64
Release
hide_global_cursorDlg.cpp 6KB
hideglobalcursor.aps 107KB
pch.cpp 158B
test.cur 766B
hide_global_cursor.vcxproj.filters 2KB
hideglobalcursor.rc 11KB
targetver.h 295B
共 23 条
- 1
资源评论
lol66suifeng
- 粉丝: 4
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功