【发布时间】:2017-12-14 14:18:14
【问题描述】:
我有一个 C++ 项目,我在其中使用 Winapi 开发一个带有按钮的窗口,并且我想在按钮悬停时更改按钮的文本。例如,悬停时将“点击我”更改为“现在点击我!”。我试过搜索,但我没有找到任何好的方法来做到这一点。
我注意到当用户悬停时,收到WM_NOTIFY 消息,但我不知道如何确保它已被鼠标悬停调用。我发现我可以使用TrackMouseEvent 来检测悬停,但它仅限于一段时间,我希望每次用户悬停按钮时执行一个动作。
这是我创建按钮的方法:
HWND Button = CreateWindow("BUTTON", "Click me",
WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_NOTIFY,
20, 240, 120, 20,
hwnd, (HMENU)101, NULL, NULL);
这是我的窗口程序:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_NOTIFY:
{
//??? Here is where I get a message everytime I hover the button, But I don't know any proper way to see if it has been executed by the button.
}
case WM_CREATE: //On Window Create
{
//...
}
case WM_COMMAND: //Command execution
{
//...
break;
}
case WM_DESTROY: //Form Destroyed
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
【问题讨论】:
标签: c++ winapi button hover mouse