The important thing is to invoke InitCommonControls in anywhere in the program
To create a tooltip in CreateWindowEx use tooltips_class32 as class name and WS_POPUP or TTS_NOPREFIX or TTS_BALLOON as window styles.
Then we have to set our window top of other windows so we use SetWindowPos to do it.
The main task here is to fill the members of TOOLINFO structure
TOOLINFO STRUCT cbSize DWORD ? uFlags DWORD ? hWnd DWORD ? uId DWORD ? rect RECT <> hInst DWORD ? lpszText DWORD ? lParam LPARAM ? TOOLINFO ENDS
cbSize- We'll be passing the size of TOOLINFO structure here.
uFlags- Flags used in our tooltip we use TTF_SUBCLASS or TTF_IDISHWND, we use or to add them together.
hWnd- handle of our main window.
uId- we'll be using the handle of the child controls.
rect- we use TTF_IDISHWND flag so we can ignore this member.
hInst- Instance of our program
lpszText- Text to be displayed in the tooltip contol
After filling the members of TOOLINFO we register the tooltip by TTM_ADDTOOL message
I've attached full source of the program. I used dialog box as main window to make this simple dialog procedure only explained here,
.if uMsg==WM_INITDIALOG invoke GetDlgItem,hWin,IDC_BUTTON1002 mov hwndbut1,eax invoke GetDlgItem,hWin,IDC_BUTTON1003 mov hwndbut2,eax invoke GetDlgItem,hWin,IDC_EDIT1004 mov hwndedit,eax ;create our tooltip invoke CreateWindowEx,WS_EX_TOPMOST,addr ttclass,NULL, WS_POPUP or TTS_NOPREFIX or TTS_BALLOON,0,0,0,0,hWin,NULL,hInstance,NULL mov htooltip,eax invoke SetWindowPos,htooltip,HWND_TOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE ;intialize members of ti struct mov ti.cbSize,sizeof TOOLINFO mov ti.uFlags,TTF_SUBCLASS or TTF_IDISHWND push hWin pop ti.hWnd push hInstance pop ti.hInst push hwndbut1 pop ti.uId mov ti.lpszText,OFFSET ttxt1 invoke SendMessage,htooltip,TTM_ADDTOOL,0,addr ti push hwndbut2 pop ti.uId mov ti.lpszText,OFFSET ttxt2 invoke SendMessage,htooltip,TTM_ADDTOOL,0,addr ti push hwndedit pop ti.uId mov ti.lpszText,OFFSET ttxt3 invoke SendMessage,htooltip,TTM_ADDTOOL,0,addr ti .elseif uMsg==WM_CLOSE invoke EndDialog,hWin,0 .else mov eax,FALSE ret .endif mov eax,TRUE ret Dlgproc endp
Explanation:
.if uMsg==WM_INITDIALOG invoke GetDlgItem,hWin,IDC_BUTTON1002 mov hwndbut1,eax invoke GetDlgItem,hWin,IDC_BUTTON1003 mov hwndbut2,eax invoke GetDlgItem,hWin,IDC_EDIT1004 mov hwndedit,eax
I have created two button controls and a edit control in a resource editor and get the handle to the button control using GetDlgItem API ,Dialog Boxes do not send WM_CREATE message instead it sends WM_INITDIALOG message, this is where all the initial setting of the dialog box done and all controls are created. This is a suitable place for creating the tooltip control, get the handles of child controls etc.
invoke CreateWindowEx,WS_EX_TOPMOST,addr ttclass,NULL, WS_POPUP or TTS_NOPREFIX or TTS_BALLOON,0,0,0,0,hWin,NULL,hInstance,NULL mov htooltip,eax invoke SetWindowPos,htooltip,HWND_TOPMOST,0,0,0,0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOACTIVATE
Using the CreateWindowEx code create a tooltip and set the window on top of all others using SetWindowPos. SWP_NOMOVE to retain the current position, SWP_NOSIZE to retain current size and SWP_NOACTIVATE to not to activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group.
mov ti.cbSize,sizeof TOOLINFO mov ti.uFlags,TTF_SUBCLASS or TTF_IDISHWND push hWin pop ti.hWnd push hInstance pop ti.hInst
Its time to fill the members of TOOLINFO structure. As discussed earlier move the size of the TOOLINFO structure to the cbSize member of structure using the "sizeof" macro in MASM
Set the flags,set the handle and also the handle of the instance.
push hwndbut1 pop ti.uId mov ti.lpszText,OFFSET ttxt1 invoke SendMessage,htooltip,TTM_ADDTOOL,0,addr ti
Push and pop is an alternative way to move data, since we cannot move memory to memory. Here we push the handle to the button to the top stack and pop the handle to the uId member of the ti structure. Move our text to be displayed on the tooltip to the member of ti structure. Now its time to register our tooltip by sending TTM_ADDTOOL message.
push hwndbut2 pop ti.uId mov ti.lpszText,OFFSET ttxt2 invoke SendMessage,htooltip,TTM_ADDTOOL,0,addr ti push hwndedit pop ti.uId mov ti.lpszText,OFFSET ttxt3 invoke SendMessage,htooltip,TTM_ADDTOOL,0,addr ti
Similarly register other controls by changing the uId member of ti structure ie. handle to the next child control for which tooltip to be registered and the text to be displayed in tooltip. And finally register using TTM_ADDTOOL message.
Attached File(s)
-
DIC 2.zip (9.55K)
Number of downloads: 801
This post has been edited by GunnerInc: 20 October 2012 - 08:36 AM
Reason for edit:: Fixed typos and grammer