c - How do I get TTM_POPUP to not fade out instantly and then come back? -
i've decided th easiest way handle tooltips in table control handle initial delay myself, create tooltip dynamically, , destroy when it's not needed anymore. problem when use ttm_popup show tooltip, fades out instantly , comes again time later. i'd rather have fade in , stay there once.
my hypothesis tooltip handling tooltip delay itself, , fading existing tip out , in. i'm not sure that. should set delay time 0 , expect work (without worrying ttm_popup @ all)? or there better way? or wrong?
the program below demonstrates what's going on. hover mouse on window , should see it.
tested on windows xp , windows 7. strictly common controls 6.
edit okay, tried adding ttm_setdelaytime set initial time 0 (not reflected in program below). didn't work. if keep ttm_popup afterward, fades out faster usual (which proves hypothesis, maybe). if remove ttm_popup, doesn't show until move mouse anyway. there else can tooltip pop up?
thanks!
// 5 april 2015 // based on wintooltipsubclasstest.c 31 march-2 april 2015 #define unicode #define _unicode #define strict #define strict_typed_itemids #define cinterface // windows version right; right windows xp #define winver 0x0501 #define _win32_winnt 0x0501 #define _win32_windows 0x0501 /* according microsoft's winperf.h */ #define _win32_ie 0x0600 /* according microsoft's sdkddkver.h */ #define ntddi_version 0x05010000 /* according microsoft's sdkddkver.h */ #include <windows.h> #include <commctrl.h> #include <windowsx.h> #include <stdio.h> #include <stdlib.h> void die(char *why) { fprintf(stderr, "error %s: %i32u\n", why, getlasterror()); abort(); } hwnd tooltip = null; hinstance hinstance; void maketooltip(hwnd hwnd) { toolinfow ti; tooltip = createwindowexw(ws_ex_toolwindow, tooltips_classw, l"", ws_popup | tts_noprefix, 0, 0, 0, 0, hwnd, null, hinstance, null); if (tooltip == null) die("creating tooltip"); zeromemory(&ti, sizeof (toolinfow)); ti.cbsize = tttoolinfow_v2_size; ti.uflags = ttf_idishwnd | ttf_subclass | ttf_transparent; ti.hwnd = hwnd; ti.uid = (uint_ptr) hwnd; ti.hinst = hinstance; ti.lpsztext = l"this tooltip! wow!"; if (sendmessagew(tooltip, ttm_addtool, 0, (lparam) (&ti)) == false) die("setting tooltip"); } lparam last = 0; lresult callback wndproc(hwnd hwnd, uint umsg, wparam wparam, lparam lparam) { switch (umsg) { case wm_close: postquitmessage(0); break; case wm_mousemove: // cheap way of testing hovers if (lparam != last) settimer(hwnd, 1, getdoubleclicktime(), null); last = lparam; break; case wm_timer: if (wparam != 1) break; killtimer(hwnd, 1); maketooltip(hwnd); sendmessage(tooltip, ttm_popup, 0, 0); return 0; } return defwindowproc(hwnd, umsg, wparam, lparam); } void initcommoncontrols(bool); int main(int argc, char *argv[]) { bool comctl5; wndclassw wc; hwnd mainwin; msg msg; hinstance = getmodulehandle(null); comctl5 = false; if (argc > 1) comctl5 = strcmp(argv[1], "comctl5") == 0; initcommoncontrols(comctl5); zeromemory(&wc, sizeof (wndclassw)); wc.lpszclassname = l"mainwin"; wc.lpfnwndproc = wndproc; wc.hicon = loadiconw(null, idi_application); wc.hcursor = loadcursorw(null, idc_arrow); wc.hbrbackground = (hbrush) (color_btnface + 1); wc.hinstance = getmodulehandle(null); if (registerclassw(&wc) == 0) die("registering main window class"); mainwin = createwindowexw(0, l"mainwin", l"main window", ws_overlappedwindow, cw_usedefault, cw_usedefault, cw_usedefault, cw_usedefault, null, null, getmodulehandle(null), null); if (mainwin == null) die("creating main window"); showwindow(mainwin, sw_showdefault); updatewindow(mainwin); while (getmessage(&msg, null, 0, 0) > 0) { translatemessage(&msg); dispatchmessage(&msg); } return 0; } // msdn doesn't list constant includes tooltips says , few others #define wantediccclasses (icc_bar_classes) static ulong_ptr comctlmanifestcookie; static hmodule comctl32; // note 8-bit character string we're writing; see encoding clause static const char manifest[] = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestversion=\"1.0\">\n<assemblyidentity\n version=\"1.0.0.0\"\n processorarchitecture=\"*\"\n name=\"companyname.productname.yourapplication\"\n type=\"win32\"\n/>\n<description>your application description here.</description>\n<dependency>\n <dependentassembly>\n <assemblyidentity\n type=\"win32\"\n name=\"microsoft.windows.common-controls\"\n version=\"6.0.0.0\"\n processorarchitecture=\"*\"\n publickeytoken=\"6595b64144ccf1df\"\n language=\"*\"\n />\n </dependentassembly>\n</dependency>\n</assembly>\n"; void initcommoncontrols(bool comctl5) { wchar temppath[max_path + 1]; wchar filename[max_path + 1]; handle file; dword nexpected, ngot; actctx actctx; handle ac; initcommoncontrolsex icc; farproc f; // listed winapi in both microsoft's , mingw's headers, not on msdn reason bool (*winapi ficc)(const lpinitcommoncontrolsex); if (!comctl5) { if (gettemppathw(max_path + 1, temppath) == 0) die("getting temporary path writing manifest file"); if (gettempfilenamew(temppath, l"manifest", 0, filename) == 0) die("getting temporary filename writing manifest file"); file = createfilew(filename, generic_write, 0, // don't share while writing null, create_always, file_attribute_normal, null); if (file == null) die("creating manifest file"); nexpected = (sizeof manifest / sizeof manifest[0]) - 1; // - 1 omit terminating null character) if (writefile(file, manifest, nexpected, &ngot, null) == 0) die("writing manifest file"); if (ngot != nexpected) die("short write manifest file"); if (closehandle(file) == 0) die("closing manifest file (this error here because not doing prevent windows being able use manifest file in activation context)"); zeromemory(&actctx, sizeof (actctx)); actctx.cbsize = sizeof (actctx); actctx.dwflags = actctx_flag_set_process_default; actctx.lpsource = filename; ac = createactctx(&actctx); if (ac == invalid_handle_value) die("creating activation context synthesized manifest file"); if (activateactctx(ac, &comctlmanifestcookie) == false) die("activating activation context synthesized manifest file"); } zeromemory(&icc, sizeof (initcommoncontrolsex)); icc.dwsize = sizeof (initcommoncontrolsex); icc.dwicc = wantediccclasses; comctl32 = loadlibraryw(l"comctl32.dll"); if (comctl32 == null) die("loading comctl32.dll"); f = getprocaddress(comctl32, "initcommoncontrolsex"); if (f == null) die("loading initcommoncontrolsex()"); ficc = (bool (*winapi)(const lpinitcommoncontrolsex)) f; if ((*ficc)(&icc) == false) die("initializing common controls (comctl32.dll)"); }
Comments
Post a Comment