gsdx:windows: Add tooltip support

Tooltips will be usable for all Gsdx dialogs if required.
This commit is contained in:
Jonathan Li 2015-08-22 18:32:55 +01:00
parent 6f6a7b92e4
commit 48bba4d581
4 changed files with 91 additions and 3 deletions

View File

@ -770,7 +770,7 @@ EXPORT_C GSconfigure()
if(!GSUtil::CheckSSE()) return;
#ifdef _WINDOWS
GSDialog::InitCommonControls();
if(GSSettingsDlg().DoModal() == IDOK)
{
if(s_gs != NULL && s_gs->m_wnd->IsManaged())

View File

@ -20,6 +20,8 @@
*/
#include "StdAfx.h"
#include <Shlwapi.h>
#include <CommCtrl.h>
#include "GSdx.h"
#include "GSDialog.h"
#include "GSVector.h"
@ -64,9 +66,48 @@ INT_PTR CALLBACK GSDialog::DialogProc(HWND hWnd, UINT message, WPARAM wParam, LP
dlg = (GSDialog*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (message == WM_NOTIFY)
{
if (((LPNMHDR)lParam)->code == TTN_GETDISPINFO)
{
LPNMTTDISPINFO pInfo = (LPNMTTDISPINFO)lParam;
UINT id = GetWindowLongPtr((HWND)pInfo->hdr.idFrom, GWL_ID);
// lpszText is used only if hinst is NULL. Seems to be NULL already,
// but it can't hurt to explicitly set it.
pInfo->hinst = NULL;
pInfo->lpszText = (LPTSTR)dialog_message(id);
SendMessage(pInfo->hdr.hwndFrom, TTM_SETMAXTIPWIDTH, 0, 500);
return true;
}
}
return dlg != NULL ? dlg->OnMessage(message, wParam, lParam) : FALSE;
}
// Tooltips will only show if the TOOLINFO cbSize <= the struct size. If it's
// smaller some functionality might be disabled. So let's try and use the
// correct size.
UINT GSDialog::GetTooltipStructSize()
{
DLLGETVERSIONPROC dllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(GetModuleHandle("ComCtl32.dll"), "DllGetVersion");
if (dllGetVersion) {
DLLVERSIONINFO2 dllversion = { 0 };
dllversion.info1.cbSize = sizeof(DLLVERSIONINFO2);
if (dllGetVersion((DLLVERSIONINFO*)&dllversion) == S_OK) {
// Minor, then major version.
DWORD version = MAKELONG(dllversion.info1.dwMinorVersion, dllversion.info1.dwMajorVersion);
DWORD tooltip_v3 = MAKELONG(0, 6);
if (version >= tooltip_v3)
return TTTOOLINFOA_V3_SIZE;
}
}
// Should be fine for XP and onwards, comctl versions >= 4.7 should at least
// be this size.
return TTTOOLINFOA_V2_SIZE;
}
bool GSDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
return message == WM_COMMAND ? OnCommand((HWND)lParam, LOWORD(wParam), HIWORD(wParam)) : false;
@ -226,3 +267,45 @@ void GSDialog::ComboBoxFixDroppedWidth(UINT id)
}
}
}
void GSDialog::AddTooltip(UINT id)
{
static UINT tooltipStructSize = GetTooltipStructSize();
bool hasTooltip;
dialog_message(id, &hasTooltip);
if (!hasTooltip)
return;
HWND hWnd = GetDlgItem(m_hWnd, id);
if (hWnd == NULL)
return;
// TTS_NOPREFIX allows tabs and '&' to be used.
HWND hwndTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
TTS_ALWAYSTIP | TTS_NOPREFIX,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
m_hWnd, NULL, theApp.GetModuleHandle(), NULL);
if (hwndTip == NULL)
return;
TOOLINFO toolInfo = { 0 };
toolInfo.cbSize = tooltipStructSize;
toolInfo.hwnd = m_hWnd;
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
toolInfo.uId = (UINT_PTR)hWnd;
// Can't directly add the tooltip string - it doesn't work for long messages
toolInfo.lpszText = LPSTR_TEXTCALLBACK;
SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
// 32.767s is the max show time.
SendMessage(hwndTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 32767);
}
void GSDialog::InitCommonControls()
{
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icex);
}

View File

@ -28,6 +28,7 @@ class GSDialog
int m_id;
static INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
static UINT GetTooltipStructSize();
protected:
HWND m_hWnd;
@ -54,4 +55,8 @@ public:
int ComboBoxAppend(UINT id, const char* str, LPARAM data = 0, bool select = false);
bool ComboBoxGetSelData(UINT id, INT_PTR& data);
void ComboBoxFixDroppedWidth(UINT id);
void AddTooltip(UINT id);
static void InitCommonControls();
};

View File

@ -8,7 +8,7 @@
<ItemDefinitionGroup>
<ClCompile>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>_WINDOWS;_WIN32_WINNT=0x500;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINDOWS;_WIN32_WINNT=0x501;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<FloatingPointModel>Fast</FloatingPointModel>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<WarningLevel>Level4</WarningLevel>
@ -18,7 +18,7 @@
<MultiProcessorCompilation>true</MultiProcessorCompilation>
</ClCompile>
<Link>
<AdditionalDependencies>d3d11.lib;d3dx11.lib;d3d10_1.lib;d3dx10.lib;d3d9.lib;d3dx9.lib;dxgi.lib;dxguid.lib;winmm.lib;strmiids.lib;xinput.lib;opengl32.lib;opencl.lib;comsuppw.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>d3d11.lib;d3dx11.lib;d3d10_1.lib;d3dx10.lib;d3d9.lib;d3dx9.lib;dxgi.lib;dxguid.lib;winmm.lib;strmiids.lib;xinput.lib;opengl32.lib;opencl.lib;comsuppw.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<DelayLoadDLLs>d3d9.dll;d3dx9_43.dll;d3d11.dll;d3dx11_43.dll;dxgi.dll;opengl32.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem>