1 /*=============================================================================
\r
5 ===============================================================================
\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.
\r
8 / Redistribution and use in source and binary forms, with or without
\r
9 / modification, are permitted provided that the following conditions
\r
12 / 1. Redistributions of source code must retain the above copyright
\r
13 / notice, this list of conditions and the following disclaimer.
\r
14 / 2. Redistributions in binary form must reproduce the above copyright
\r
15 / notice, this list of conditions and the following disclaimer in the
\r
16 / documentation and/or other materials provided with the distribution.
\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
\r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
\r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
28 /============================================================================*/
\r
30 /* このソースは MFC Programmer's SourceBook (http://www.codeguru.com/)を参考にしました */
\r
33 #include <windows.h>
\r
37 #include <windowsx.h>
\r
38 #include <commctrl.h>
\r
41 #include "resource.h"
\r
44 /*===== プロトタイプ =====*/
\r
46 static void TipsShow(HWND hWnd, RECT rectTitle, LPCTSTR lpszTitleText, int xoffset, int xoffset2, int InRect);
\r
47 static int CellRectFromPoint(HWND hWnd, POINT point, RECT *cellrect, int *col);
\r
48 static LRESULT CALLBACK TitleTipWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
\r
50 /*===== ローカルなワーク =====*/
\r
52 static HWND hWndTips; /* tipsのウインドウハンドル */
\r
56 /*----- リストビューティップスのウインドウを作成 ------------------------------
\r
59 * HWND hWnd : 親ウインドウのハンドル
\r
60 * HINSTANCE hInst : インスタンスハンドル
\r
64 * FFFTP_SUCCESS/FFFTP_FAIL
\r
65 *----------------------------------------------------------------------------*/
\r
67 int InitListViewTips(HWND hWnd, HINSTANCE hInst)
\r
74 wClass.cbSize = sizeof(WNDCLASSEX);
\r
76 wClass.lpfnWndProc = TitleTipWndProc;
\r
77 wClass.cbClsExtra = 0;
\r
78 wClass.cbWndExtra = 0;
\r
79 wClass.hInstance = hInst;
\r
80 wClass.hIcon = NULL;
\r
81 wClass.hCursor = NULL;
\r
82 wClass.hbrBackground = (HBRUSH)CreateSolidBrush(GetSysColor(COLOR_INFOBK));
\r
83 wClass.lpszMenuName = NULL;
\r
84 wClass.lpszClassName = "XTitleTip";
\r
85 wClass.hIconSm = NULL;
\r
86 RegisterClassEx(&wClass);
\r
88 hWndTips = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
\r
90 WS_BORDER | WS_POPUP,
\r
92 hWnd, NULL, hInst, NULL);
\r
94 if(hWndTips != NULL)
\r
95 Ret = FFFTP_SUCCESS;
\r
101 /*----- リストビューティップスのウインドウを削除 ------------------------------
\r
108 *----------------------------------------------------------------------------*/
\r
110 void DeleteListViewTips(void)
\r
112 if(hWndTips != NULL)
\r
113 DestroyWindow(hWndTips);
\r
118 /*----- リストビューティップスのウインドウを消去 ------------------------------
\r
125 *----------------------------------------------------------------------------*/
\r
127 void EraseListViewTips(void)
\r
130 ShowWindow(hWndTips, SW_HIDE);
\r
135 /*----- リストビューティップスのウインドウハンドルを返す ----------------------
\r
142 *----------------------------------------------------------------------------*/
\r
144 HWND GetListViewTipsHwnd(void)
\r
150 /*----- リストビューティップスの表示チェック ----------------------------------
\r
153 * HWND hWnd : ListViewのウインドウハンドル
\r
154 * LPARAM lParam : WM_MOUSEMOVEのLPARAM値
\r
158 *----------------------------------------------------------------------------*/
\r
160 void CheckTipsDisplay(HWND hWnd, LPARAM lParam)
\r
163 static RECT cur_rect;
\r
172 Point.x = LOWORD(lParam);
\r
173 Point.y = HIWORD(lParam);
\r
176 row = CellRectFromPoint(hWnd, Point, &cellrect, &col);
\r
184 ListView_GetItemRect(hWnd, row, &rcLabel, LVIR_LABEL);
\r
185 offset = rcLabel.left - cellrect.left + offset / 2;
\r
190 ListView_GetItemText(hWnd, row, col, Buf, 256 );
\r
191 if(strlen(Buf) > 0)
\r
192 TipsShow(hWnd, cellrect, Buf, offset-1, offset2-1, InRect);
\r
198 if(PtInRect(&cur_rect, Point) == FALSE)
\r
200 EraseListViewTips();
\r
208 /*----- リストビューティップスを表示 ------------------------------------------
\r
211 * HWND hWnd : ListViewのウインドウのハンドル
\r
212 * RECT rectTitle : ListViewコントルールのアイテムの矩形
\r
213 * LPCTSTR lpszTitleText : 文字列
\r
214 * int xoffset : オフセット
\r
215 * int xoffset2 : オフセット2
\r
216 * int InRect : 表示するかどうか
\r
220 *----------------------------------------------------------------------------*/
\r
222 static void TipsShow(HWND hWnd, RECT rectTitle, LPCTSTR lpszTitleText, int xoffset, int xoffset2, int InRect)
\r
232 if(GetFocus() != NULL)
\r
234 RectClientToScreen(hWnd, &rectTitle);
\r
236 /* ListViewウインドウのフォントを得る */
\r
238 pFont = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);
\r
239 ReleaseDC(hWnd, dc);
\r
241 dc = GetDC(hWndTips);
\r
242 pFontDC = SelectObject(dc, pFont);
\r
244 SetTextColor(dc, GetSysColor(COLOR_INFOTEXT));
\r
245 SetBkMode(dc, TRANSPARENT);
\r
247 rectDisplay = rectTitle;
\r
248 GetTextExtentPoint32(dc, lpszTitleText, strlen(lpszTitleText), &size);
\r
249 rectDisplay.left += xoffset;
\r
250 rectDisplay.right = rectDisplay.left + size.cx + 2;
\r
252 if(rectDisplay.right > rectTitle.right-xoffset2)
\r
254 rectDisplay.right += 1;
\r
256 SetWindowPos(hWndTips, HWND_TOPMOST,
\r
257 rectDisplay.left, rectDisplay.top,
\r
258 rectDisplay.right - rectDisplay.left,
\r
259 rectDisplay.bottom - rectDisplay.top,
\r
260 SWP_SHOWWINDOW|SWP_NOACTIVATE );
\r
262 TextOut(dc, 0, 0, lpszTitleText, strlen(lpszTitleText));
\r
267 SelectObject(dc, pFontDC);
\r
268 ReleaseDC(hWndTips, dc);
\r
275 /*----- リストビューティップスを表示する位置を返す ----------------------------
\r
278 * HWND hWnd : ListViewのウインドウハンドル
\r
279 * POINT point : カーソルの位置
\r
280 * RECT *cellrect : アイテムの矩形を返すワーク
\r
281 * int *col : 桁番号を返すワーク
\r
286 *----------------------------------------------------------------------------*/
\r
288 static int CellRectFromPoint(HWND hWnd, POINT point, RECT *cellrect, int *col)
\r
300 if((GetWindowLong(hWnd, GWL_STYLE) & LVS_TYPEMASK) == LVS_REPORT )
\r
302 row = ListView_GetTopIndex(hWnd);
\r
303 bottom = row + ListView_GetCountPerPage(hWnd);
\r
304 if(bottom > ListView_GetItemCount(hWnd))
\r
305 bottom = ListView_GetItemCount(hWnd);
\r
307 nColumnCount = Header_GetItemCount(GetDlgItem(hWnd, 0));
\r
309 for(; row <= bottom; row++)
\r
311 ListView_GetItemRect(hWnd, row, &rect, LVIR_BOUNDS);
\r
312 if(PtInRect(&rect, point))
\r
314 for(colnum = 0; colnum < nColumnCount; colnum++)
\r
316 colwidth = ListView_GetColumnWidth(hWnd, colnum);
\r
317 if((point.x >= rect.left) &&
\r
318 (point.x < (rect.left + colwidth)))
\r
320 GetClientRect(hWnd, &rectClient);
\r
321 if(point.x <= rectClient.right)
\r
323 rect.right = rect.left + colwidth;
\r
324 if(rect.right > rectClient.right)
\r
325 rect.right = rectClient.right;
\r
332 rect.left += colwidth;
\r
342 /*----- リストビューティップスウインドウのコールバック ------------------------
\r
345 * HWND hWnd : ウインドウハンドル
\r
346 * UINT message : メッセージ番号
\r
347 * WPARAM wParam : メッセージの WPARAM 引数
\r
348 * LPARAM lParam : メッセージの LPARAM 引数
\r
352 *----------------------------------------------------------------------------*/
\r
354 static LRESULT CALLBACK TitleTipWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
\r
356 return(DefWindowProc(hWnd, message, wParam, lParam));
\r