实际上,我的目标是为复选框功能设置工具提示,但它似乎不起作用。 :/
复选框在资源文件中使用每种格式的BS_AUTOSTATE格式进行管理。虽然我想初始化这些复选框的工具提示,并且某位朋友建议使用以下方法,
text = dialog_message(IDC_FILE);
SetWindowText(GetDlgItem(m_hWnd, IDC_FILE), text));
并且不幸的是,它没有用。任何人都有任何其他想法来实现工具提示没有任何其他依赖。
答案 0 :(得分:0)
来自@ andlab 的链接:如何为控件或矩形区域创建工具提示:
Using Tooltip Controls
工具提示需要通用控件版本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 failed\nWrong project manifest!");
MessageBox(0, TEXT("TTM_ADDTOOL failed\nWrong 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;
}