|
|

楼主 |
发表于 2026-4-24 10:25:13
|
显示全部楼层
广东省惠州市
#include <windows.h>
#include "module_HH_W编辑框.h"
// 全局变量
HINSTANCE g_hInstance = NULL;
HWND g_hEditWindow = NULL;
HH_W编辑框* g_编辑框 = nullptr;
const wchar_t g_窗口类名[] = L"HH_W编辑框无边框窗口类";
// 窗口过程
LRESULT CALLBACK 窗口过程(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
{
switch (uMsg)
{
case WM_CREATE:
{
{
{
// 创建编辑框
g_编辑框 = new HH_W编辑框();
if (g_编辑框)
{
{
// 获取窗口客户区大小
RECT rc;
GetClientRect(hWnd, &rc);
// 创建编辑框,填满整个客户区
HRESULT hr = g_编辑框->_创建(hWnd, 0.0f, 0.0f,
{
{
{
{
{
{
static_cast<float>(rc.right),
static_cast<float>(rc.bottom));
}
}
}
}
}
}
if (SUCCEEDED(hr))
{
{
// 设置编辑框属性
g_编辑框->_设置多行(1);
//g_编辑框->_设置自动换行(1);
g_编辑框->_设置字体大小(16.0f);
g_编辑框->_设置字体名称(L"微软雅黑");
g_编辑框->_设置文本颜色(RGB(255, 255, 255));
g_编辑框->_设置背景颜色(RGB(40, 40, 40));
g_编辑框->_设置背景图(L"1.png", 2, 0.5f);
g_编辑框->_设置边框宽度(1); // 无边框
g_编辑框->_设置显示边框(1); // 不显示边框
// 设置示例文本
g_编辑框->_设置文本(L"这是一个无边框窗口中的编辑框\n可以输入多行文本\n\n试试点击和输入...");
}
}
}
}
}
}
break;
}
case WM_SIZE:
{
if (g_编辑框)
{
{
// 当窗口大小改变时,调整编辑框大小
}
RECT rc;
GetClientRect(hWnd, &rc);
g_编辑框->_设置位置(0.0f, 0.0f,
{
{
{
{
{
static_cast<float>(rc.right),
static_cast<float>(rc.bottom));
}
}
}
}
}
}
break;
}
case WM_PAINT:
{
{
{
//PAINTSTRUCT ps;
//HDC hdc = BeginPaint(hWnd, &ps);
// 绘制窗口背景
//RECT rc;
//GetClientRect(hWnd, &rc);
//HBRUSH hBrush = CreateSolidBrush(RGB(40, 40, 40));
//FillRect(hdc, &rc, hBrush);
//DeleteObject(hBrush);
// 绘制编辑框
if (g_编辑框)
{
{
g_编辑框->_绘制();
//g_编辑框->_绘制滚动条();
}
}
//EndPaint(hWnd, &ps);
}
}
break;
}
case WM_CHAR:
{
if (g_编辑框 && g_编辑框->_处理字符输入(wParam, lParam))
{
{
//InvalidateRect(hWnd, NULL, TRUE);
}
}
break;
}
case WM_KEYDOWN:
{
if (g_编辑框 && g_编辑框->_处理按键输入(wParam, lParam))
{
{
//InvalidateRect(hWnd, NULL, TRUE);
}
}
break;
}
case WM_LBUTTONDOWN:
{
{
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
if (g_编辑框)
{
{
g_编辑框->_处理鼠标左键按下(x, y, (wParam &MK_SHIFT) != 0);
}
}
// 允许拖动无边框窗口
//SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
}
}
break;
}
case WM_LBUTTONUP:
{
if (g_编辑框)
{
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
g_编辑框->_处理鼠标左键释放(x, y);
//InvalidateRect(hWnd, NULL, TRUE);
}
}
break;
}
case WM_MOUSEMOVE:
{
if (g_编辑框 && g_编辑框->_是否获得焦点())
{
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
g_编辑框->_处理鼠标移动(x, y);
}
}
break;
}
case WM_LBUTTONDBLCLK:
{
if (g_编辑框)
{
{
int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam);
g_编辑框->_处理鼠标双击(x, y);
}
}
break;
}
case WM_MOUSEWHEEL:
{
if (g_编辑框)
{
{
int 滚动量 = GET_WHEEL_DELTA_WPARAM(wParam);
int 标志 = GET_KEYSTATE_WPARAM(wParam);
g_编辑框->_处理鼠标滚轮(滚动量, 标志);
}
}
break;
}
case WM_TIMER:
{
if (wParam == 1 && g_编辑框)
{
{
//g_编辑框->_处理光标闪烁();
}
}
break;
}
case WM_SETFOCUS:
{
if (g_编辑框)
{
{
g_编辑框->_设置焦点(true);
}
}
break;
}
case WM_KILLFOCUS:
{
if (g_编辑框)
{
{
g_编辑框->_设置焦点(false);
}
}
break;
}
case WM_DESTROY:
{
if (g_编辑框)
{
{
delete g_编辑框;
g_编辑框 = nullptr;
}
}
PostQuitMessage(0);
break;
}
default:
{
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
}
return 0;
}
}
// 创建无边框窗口
HWND 创建无边框窗口(HINSTANCE hInstance, int 宽度, int 高度)
{
{
// 注册窗口类
WNDCLASS wc = {};
wc.lpfnWndProc = 窗口过程;
wc.style = CS_DBLCLKS; // ← 这个!允许窗口接收双击消息
wc.hInstance = hInstance;
wc.lpszClassName = g_窗口类名;
wc.hCursor = LoadCursor(NULL, IDC_IBEAM);
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
if (!RegisterClass(&wc))
{
{
MessageBox(NULL, L"窗口类注册失败!", L"错误", MB_ICONERROR);
return NULL;
}
}
// 创建无边框窗口
// 注意:使用 WS_POPUP 样式创建无边框窗口
// 添加 WS_THICKFRAME 以便可以调整大小
HWND hWnd = CreateWindow(
{
g_窗口类名,
L"无边框编辑框窗口",
WS_POPUP | WS_VISIBLE, // 无边框,不可调整大
//WS_POPUP | WS_VISIBLE | WS_THICKFRAME, // 无边框,可调整大小
CW_USEDEFAULT, CW_USEDEFAULT,
宽度, 高度,
NULL,
NULL,
hInstance,
NULL
}
);
return hWnd;
}
}
// 主函数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
{
g_hInstance = hInstance;
// 创建无边框窗口
g_hEditWindow = 创建无边框窗口(hInstance, 600, 400);
if (!g_hEditWindow)
{
{
MessageBox(NULL, L"窗口创建失败!", L"错误", MB_ICONERROR);
return 0;
}
}
// 显示窗口
ShowWindow(g_hEditWindow, nCmdShow);
UpdateWindow(g_hEditWindow);
// 创建光标闪烁定时器
SetTimer(g_hEditWindow, 1, 5000, NULL);
// 消息循环
MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0))
{
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
}//以上是例子 |
|