用于复选框的c++工具提示函数
C++ Tooltip function for checkbox
实际上,我的目的是为复选框函数设置一个工具提示,尽管它似乎不起作用。:/
复选框在资源文件中使用格式BS_AUTOSTATE对每个复选框进行管理。虽然我想为这些复选框初始化一个工具提示,一个朋友建议使用下面的方法,
text = dialog_message(IDC_FILE);
SetWindowText(GetDlgItem(m_hWnd, IDC_FILE), text));
不幸的是,它不起作用。任何人都有其他的想法来实现没有任何其他依赖的工具提示。
From @andlab的链接:如何为控件或矩形区域创建工具提示:
使用工具提示控件
工具提示需要4.70或更高版本的通用控件。确保项目清单设置正确。
可以使用下面的CreateToolTip
函数:
CreateToolTip(hWnd, hWndDialogItem, L"TESTING");
对话框示例:
#include "windows.h"
#include "resource.h"
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib")
void CreateToolTip(
HWND hWndParent, /*HWND handle for the parent window, for example dialog box*/
HWND hControlItem, /*HWND handle for the control item, for example checkbox*/
PTSTR pszText /*text for the tool-tip*/)
{
if (!hControlItem || !hWndParent || !pszText)
return;
// Create the tooltip. g_hInst is the global instance handle.
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP /* | TTS_BALLOON*/,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hWndParent, NULL, GetModuleHandle(0), NULL);
if (!hwndTip)
return;
// Associate the tooltip with the tool.
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hWndParent;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hControlItem;
toolInfo.lpszText = pszText;
if (!SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo))
{
//OutputDebugString(L"TTM_ADDTOOL failednWrong project manifest!");
MessageBox(0, TEXT("TTM_ADDTOOL failednWrong project manifest!"), 0, 0);
}
}
BOOL CALLBACK DialogProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_INITDIALOG:
{
HWND hDlgItem = GetDlgItem(hDlg, IDOK);
if (hDlgItem)
{
CreateToolTip(hDlg, hDlgItem, L"TESTING");
}
else
{
MessageBox(0, TEXT("Cannot find dialog item with IDOK identifier"), 0, 0);
}
break;
}
case WM_COMMAND:
switch (wp)
{
case IDOK:
EndDialog(hDlg, wp);
break;
case IDCANCEL:
EndDialog(hDlg, wp);
break;
}
}
return FALSE;
}
int APIENTRY wWinMain(HINSTANCE hinst, HINSTANCE, LPTSTR, int nCmdShow)
{
DialogBox(hinst, MAKEINTRESOURCE(IDD_DIALOG1), 0, DialogProc);
return 0;
}
相关文章:
- 如何在动态创建的CMFCToolbar的工具提示中添加描述?
- 添加带有 QSyntaxHighlight 和 QTextCharFormat 的工具提示
- CScrollView 中的跟踪工具提示?
- 当鼠标悬停在 MFC C++ 中列表控件的列标题上时,可视显示工具提示
- 在 MFC C++中悬停列表控件的列标题的可视化显示工具提示
- 无法隐藏工具提示
- 更新模型/视图方案中 QXXXView (QTableView, QTreeView,..) 元素的显示工具提示
- 将工具提示添加到 ComboBoxEx 失败
- 如何在 c++/cli 中增加工具提示的大小
- QT 4.7-在OS X 10.12下,工具提示和Qcombobox弹出窗口空白
- QLineEdit:如果鼠标悬停,则显示超长文本作为工具提示
- Visual studio调试工具提示-隐藏变量
- C++Listview工具提示
- 使用分析工具的函数调用图选项时出现日食 CDT 错误
- 鼠标悬停在TableView上时显示工具提示
- 如何在Qt的子小部件中忽略父小部件的工具提示?
- 如何在QToolbar上禁用工具提示
- 如何显示动态工具提示
- 如何在C++Builder中长时间显示工具提示
- 用于复选框的c++工具提示函数