I am newbie in c++ win32 Programming and I am using visual studio 2013 on Windows 7 X64 SP1.
I have used this code in link below to create tooltip for a button in DialogBox and successfully it worked.
but when I want to change the background color or foreground color , it does not work and it shows the default colors.
SendMessage(hwndTip, TTM_SETTIPBKCOLOR, 0xFF326FD8, 0);
//SendMessage(hwndTip, TTM_SETTIPBKCOLOR, (WPARAM)CreateSolidBrush(RGB(255,255, 255), 0);
SendMessage(hwndTip, TTM_SETTIPTEXTCOLOR, (WPARAM)CreateSolidBrush(RGB(255,255, 255)), 0);
Because in this link :
http://msdn.microsoft.com/en-us/library/windows/desktop/bb760411%28v=vs.85%29.aspx
the MSDN said that "When visual styles are enabled, this message has no effect." so I changed the
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON |TTS_USEVISUALSTYLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
hInst, NULL);
to :
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
hInst, NULL);
but without any success.
also I have used :
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' "\
"name='Microsoft.Windows.Common-Controls' "\
"version='6.0.0.0' "\
"processorArchitecture='*' "\
"publicKeyToken='6595b64144ccf1df' "\
"language='*'\"")
in my code so I removed it to see if tooltip coloring works but the tooltip did not appeared at all !
what is the problem ?
Thanks.
Update 1 :
Here is my full source code , hope to solve the problem :
Main.cpp :
#include <Windows.h>
#include <stdlib.h>
#include <tchar.h>
#include <memory>
#include <malloc.h>
#include "resource.h"
#include <CommCtrl.h>
#include <Uxtheme.h>
HINSTANCE hInst;
BOOL InitInstance(HINSTANCE, int);
INT_PTR CALLBACK MainWin(HWND, UINT, WPARAM, LPARAM);
#pragma comment(linker, \
"\"/manifestdependency:type='Win32' "\
"name='Microsoft.Windows.Common-Controls' "\
"version='6.0.0.0' "\
"processorArchitecture='*' "\
"publicKeyToken='6595b64144ccf1df' "\
"language='*'\"")
#pragma comment(lib, "ComCtl32.lib")
#pragma comment(lib,"UxTheme.lib")
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,_In_opt_ HINSTANCE hPrevInstance,_In_ LPTSTR lpCmdLine,_In_ int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
MSG msg;
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
while (GetMessage(&msg, NULL, 0, 0)>0)
{
if (!IsDialogMessage(msg.hwnd,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int)msg.wParam;
}
HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, PTSTR pszText)
{
if (!toolID || !hDlg || !pszText)
{
return NULL;
}
HWND hwndTool = GetDlgItem(hDlg, toolID);
if (!hwndTool)
{
return NULL;
}
HWND hwndTip = CreateWindowEx(NULL, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON |TTS_USEVISUALSTYLE,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
hDlg, NULL,
hInst, NULL);
if (!hwndTip)
{
return NULL;
}
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = sizeof(toolInfo);
toolInfo.hwnd = hDlg;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hwndTool;
toolInfo.lpszText = pszText;
if (!SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo))
{
DestroyWindow(hwndTip);
return NULL;
}
SendMessage(hwndTip, TTM_SETTIPBKCOLOR, 0xFF326FD8, 0);
return hwndTip;
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hWnd = CreateDialogParam(hInstance, MAKEINTRESOURCE(IDD_MainDlg), NULL, MainWin, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
SetWindowTheme(hWnd, L"", L"");
return TRUE;
}
INT_PTR CALLBACK MainWin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
{
CreateToolTip(IDC_TestBtn, hDlg, hInst, L"TESTTOOLTIP");
return (INT_PTR)TRUE;
}
break;
case WM_CLOSE:
DestroyWindow(hDlg);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDC_TestBtn)
{
MessageBox(NULL, L"TEST", L"TEST", MB_OK);
return (INT_PTR)TRUE;
}
}
return (INT_PTR)FALSE;
}
resource.h :
#define IDD_MainDlg 103
#define IDC_TestBtn 104
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
resource script for resource.rc :
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_MainDlg, DIALOG
BEGIN
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MainDlg DIALOGEX 0, 0, 149, 75
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "testbtn",IDC_TestBtn,41,12,57,49
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////