- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
i have a problem by adding some ToolTips to Controls.
I am using a function for creating a ToolTip and adding it to a control. The ToolTip seems to be created fine and adding it also seems to work.
But when i "mouse over" the control, then nothing happens. No ToolTip is popping up.
Can you tell me, what i have done wrong?
Here is the ToolTip creation:
[fortran]function CreateToolTip( toolID, hDlg, pszText, toolTipPtr) result (hwndTip) use ifwinty use ToolTip_TestGlobals use user32 use ifwbase IMPLICIT NONE !input variables integer toolID, hDlg character*(*) pszText TYPE (T_TTTOOLINFO), pointer :: toolTipPtr !internal variables integer :: hWndItem, hWndTip logical bRet ! Get item handle. hWndItem = GetDlgItem(hDlg, toolID) ! Create the tooltip. hWndTip = CreateWindowEx (WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, & ior(WS_POPUP,ior(TTS_ALWAYSTIP,TTS_NOPREFIX)), & CW_USEDEFAULT, CW_USEDEFAULT, & CW_USEDEFAULT, CW_USEDEFAULT, & hDlg, NULL, ghInstance, NULL) bret = SetWindowPos(hwndTip, HWND_TOPMOST, 0, 0, 0, 0, ior(SWP_NOMOVE,ior( SWP_NOSIZE , SWP_NOACTIVATE))) ! Associate the tooltip with the tool. toolTipPtr%cbSize = sizeof(toolTipPtr) toolTipPtr%hwnd = hDlg toolTipPtr%uFlags = ior(TTF_IDISHWND , TTF_SUBCLASS) toolTipPtr%uId = loc(hWndItem) toolTipPtr%lpszText = loc(pszText) bret = SendMessage(hWndTip, TTM_ADDTOOL, 0, loc(toolTipPtr)) bret = SendMessage(hWndTip, TTM_ACTIVATE, .TRUE., 0) end function [/fortran]
Best Regards
Oliver
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For starters, the toolTipPtr%hwnd needs to be set to the handle of the target for the tooltip, in your case that would be hWndItem, not hDlg. Here is a more concise setup utility function:
And an example of setup code (in this case for a window with handle ghClock):
The above example is for a callback tooltip which can be dynamically set in the proc of the targeted window or control; here is how that is done:
[bash]FUNCTION CreateToolTips (hParent) RESULT (hTT) IMPLICIT NONE INTEGER(HANDLE), INTENT(IN) :: hParent INTEGER(HANDLE) :: hTT INTEGER :: rval ! creates a ToolTips control as a child to hParent hTT = CreateWindowEx (0, TOOLTIPS_CLASS, ""c, & IOR(TTS_ALWAYSTIP,WS_POPUP), & CW_USEDEFAULT, CW_USEDEFAULT, & CW_USEDEFAULT, CW_USEDEFAULT, & hParent, NULL, ghInstance, NULL) rval = SetWindowPos (hTT, HWND_TOPMOST, 0,0,0,0, & IOR(SWP_NOACTIVATE,IOR(SWP_NOMOVE,SWP_NOSIZE))) rval = SendMessage (hTT, TTM_SETDELAYTIME, TTDT_INITIAL, MakeLong(INT2( 5),INT2(0))) rval = SendMessage (hTT, TTM_SETDELAYTIME, TTDT_AUTOPOP, MakeLong(INT2(3000),INT2(0))) rval = SendMessage (hTT, TTM_ACTIVATE, TRUE, 0) END FUNCTION CreateToolTips [/bash]
And an example of setup code (in this case for a window with handle ghClock):
[bash]TYPE(T_TTTOOLINFO) :: ti ! Tooltip control for clock window hTT_clock = CreateToolTips (ghClock) ti%cbSize = SIZEOF(ti) ti%hwnd = ghClock ! text callback TTN_ messages will be sent here ti%uId = ghClock rval = SendMessage (hTT_clock, TTM_DELTOOL, 0, LOC(ti)) ti%uFlags = IOR(TTF_IDISHWND, TTF_SUBCLASS) ti%hinst = NULL ti%lpszText = LPSTR_TEXTCALLBACKA rval = SendMessage (hTT_clock, TTM_ADDTOOL, 0, LOC(ti)) [/bash]
The above example is for a callback tooltip which can be dynamically set in the proc of the targeted window or control; here is how that is done:
[bash]! tooltip report CASE (WM_NOTIFY) SELECT CASE (di%hdr%code) CASE (TTN_GETDISPINFO) rval = SendMessage (hTT_clock, TTM_SETTITLE, info_icon, LOC(title)) rval = SendMessage (hTT_clock, TTM_SETMAXTIPWIDTH, 0, 300) WRITE (di%szText, '(" Total hours",F12.2,A, & "Session hours",F12.2,A)') & global_runhours, & crlf, & tdif_secs (ts_sessionstart, get_current_time(1))/sph, & CHAR(0) di%szText = ADJUSTL(di%szText) END SELECT ClockProc = 0 RETURN [/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Paul and thanks for your answer.
Well i changed the variable as you wrote, but it still not working.
What i recognized is, that i have to fire an event when i mouse over the control (edit control, a button, or else)...thought that i dont have to to that, because TTM_ADDTOOLdone this automatically.
Am i right?
In the case that i have to fire an event or catching this event manually...how to i create this event?
Look at the Example in Pseudocode to understand what i mean:
trueOrfalse = CreateEvent(dialogHandle, controlHandle,call this eventMethodName, eventCase like MOUSEHOVER)
Is it something like that?
I have to control all events of the dialog and catching the case of which event is fired right?
How do i add a delegate for the dialog eventhandler (Saw WndProc on much pages when i googlet) ?
.oO(Damn...i wish fortran GUI coding would be as easy as in .NET)
Best Regards
Oliver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In looking at your code, your T_TTTOOLINFO should not have the POINTER attribute, but rather be a true instance of that type. Tooltips are a complete micro-universe, and do not require any additional coding such as events or special mouse handling, that is all taken care of automatically. Suggest you try using my code, which is complete, internally consistent, and proven to work.
If your code does not include the proc function for the dialog containing the control(s) with tooltips (ie, you are using an abstraction layer such as Quickwin), then you will only be able to use static tooltips. Here is more sample code showing the setup of a static tooltip, where the tooltip message is contained in "versionstring":
If your code does not include the proc function for the dialog containing the control(s) with tooltips (ie, you are using an abstraction layer such as Quickwin), then you will only be able to use static tooltips. Here is more sample code showing the setup of a static tooltip, where the tooltip message is contained in "versionstring":
[bash]! tooltip info structure for program version report ti%cbSize = SIZEOF(ti) ti%hwnd = hwnd ti%uId = 1 rval = SendMessage (hTT_version, TTM_DELTOOL, 0, LOC(ti)) ! just in case ti%rect%left = 4 ti%rect%top = clientRect%top ! - logoHeight ti%rect%bottom = clientRect%bottom ! + logoHeight ti%rect%right = ti%Rect%left + logoWidth ti%hinst = NULL ! for callback tooltip !ti%uFlags = IOR(TTF_IDISHWND, TTF_SUBCLASS) !ti%lpszText = LPSTR_TEXTCALLBACKA ! for static tooltip ti%uFlags = TTF_SUBCLASS ti%lpszText = LOC(nullb) rval = SendMessage (hTT_version, TTM_ADDTOOL, 0, LOC(ti)) rval = SendMessage (hTT_version, TTM_SETTITLE, info_icon, LOC(versionstring)) rval = SendMessage (hTT_version, TTM_SETMAXTIPWIDTH, 0, 200) [/bash]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
First i want to thank you Paul, for your support.
Sadly i still not got the ToolTip working.
I copied your first CreateToolTips function and used it to create the ToolTip Window and activate it. As hParent i think i have to give the handle of the Item, where i want to pop up the ToolTip later then right?
So in my case i want to add a ToolTip to a Button for example. Tried Edit Control, ListView, and much more too, but they all not worked.
I used the function like this:
[fortran]hToolTip = CreateToolTips(GetDlgItem(gdlg%hwnd,IDM_APPLY))[/fortran]Then i set the ToolTip Attributes as you postet in your last posting.
Is the rectangle very important?...i commented it out because i think i dont need it.
Where i am not sure is the hwnd attribute. Do i have to use the handle of the Dialog there...or the handle of the Control? I dont know...the msdn explained it, that to use the handle of the dialog window.
Tried both and nothing worked
Look at the very cutted code:
[fortran]ti%cbSize = SIZEOF(ti) ti%hwnd = GetDlgItem(gdlg%hwnd,IDM_APPLY ) !gdlg%hwnd also not working ti%uId = 1 ti%hinst = NULL ti%uFlags = TTF_SUBCLASS ti%lpszText = LOC(tooltext) iret = SendMessage (hToolTip, TTM_ADDTOOL, 0, LOC(ti)) iret = SendMessage (hToolTip, TTM_SETTITLE, TTI_INFO, LOC(testStr)) [/fortran]ADDTOOL ans SETTITLE both return 1, which i understand as everything went fine, but still nothing happens if i mouse over the control :(
Maybe you can help me again :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Got it working now.
"hInstance = GetWindowLong(dlgMe%hWnd, GWL_HINSTANCE)" does the thing.
My instance handle seems always been wrong...with this method everything went fine :)
YEHAA! :)

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page