1 /*=============================================================================
\r
3 *
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\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 /*
\82±
\82Ì
\83\
\81[
\83X
\82Í MFC Programmer's SourceBook (http://www.codeguru.com/)
\82ð
\8eQ
\8dl
\82É
\82µ
\82Ü
\82µ
\82½ */
\r
33 #include <windows.h>
\r
37 #include <windowsx.h>
\r
38 #include <commctrl.h>
\r
41 #include "resource.h"
\r
44 /*=====
\83v
\83\8d\83g
\83^
\83C
\83v =====*/
\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 /*=====
\83\8d\81[
\83J
\83\8b\82È
\83\8f\81[
\83N =====*/
\r
52 static HWND hWndTips; /* tips
\82Ì
\83E
\83C
\83\93\83h
\83E
\83n
\83\93\83h
\83\8b */
\r
56 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82Ì
\83E
\83C
\83\93\83h
\83E
\82ð
\8dì
\90¬ ------------------------------
\r
59 * HWND hWnd :
\90e
\83E
\83C
\83\93\83h
\83E
\82Ì
\83n
\83\93\83h
\83\8b\r
60 * HINSTANCE hInst :
\83C
\83\93\83X
\83^
\83\93\83X
\83n
\83\93\83h
\83\8b\r
63 * int
\83X
\83e
\81[
\83^
\83X
\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
101 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82Ì
\83E
\83C
\83\93\83h
\83E
\82ð
\8dí
\8f\9c ------------------------------
\r
108 *----------------------------------------------------------------------------*/
\r
110 void DeleteListViewTips(void)
\r
112 if(hWndTips != NULL)
\r
113 DestroyWindow(hWndTips);
\r
118 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82Ì
\83E
\83C
\83\93\83h
\83E
\82ð
\8fÁ
\8b\8e ------------------------------
\r
125 *----------------------------------------------------------------------------*/
\r
127 void EraseListViewTips(void)
\r
130 ShowWindow(hWndTips, SW_HIDE);
\r
135 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82Ì
\83E
\83C
\83\93\83h
\83E
\83n
\83\93\83h
\83\8b\82ð
\95Ô
\82· ----------------------
\r
141 * HWND
\83E
\83C
\83\93\83h
\83E
\83n
\83\93\83h
\83\8b\r
142 *----------------------------------------------------------------------------*/
\r
144 HWND GetListViewTipsHwnd(void)
\r
150 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82Ì
\95\
\8e¦
\83`
\83F
\83b
\83N ----------------------------------
\r
153 * HWND hWnd : ListView
\82Ì
\83E
\83C
\83\93\83h
\83E
\83n
\83\93\83h
\83\8b\r
154 * LPARAM lParam : WM_MOUSEMOVE
\82ÌLPARAM
\92l
\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 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82ð
\95\
\8e¦ ------------------------------------------
\r
211 * HWND hWnd : ListView
\82Ì
\83E
\83C
\83\93\83h
\83E
\82Ì
\83n
\83\93\83h
\83\8b\r
212 * RECT rectTitle : ListView
\83R
\83\93\83g
\83\8b\81[
\83\8b\82Ì
\83A
\83C
\83e
\83\80\82Ì
\8bé
\8c`
\r
213 * LPCTSTR lpszTitleText :
\95¶
\8e\9a\97ñ
\r
214 * int xoffset :
\83I
\83t
\83Z
\83b
\83g
\r
215 * int xoffset2 :
\83I
\83t
\83Z
\83b
\83g
\82Q
\r
216 * int InRect :
\95\
\8e¦
\82·
\82é
\82©
\82Ç
\82¤
\82©
\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
\83E
\83C
\83\93\83h
\83E
\82Ì
\83t
\83H
\83\93\83g
\82ð
\93¾
\82é */
\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 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\82ð
\95\
\8e¦
\82·
\82é
\88Ê
\92u
\82ð
\95Ô
\82· ----------------------------
\r
278 * HWND hWnd : ListView
\82Ì
\83E
\83C
\83\93\83h
\83E
\83n
\83\93\83h
\83\8b\r
279 * POINT point :
\83J
\81[
\83\
\83\8b\82Ì
\88Ê
\92u
\r
280 * RECT *cellrect :
\83A
\83C
\83e
\83\80\82Ì
\8bé
\8c`
\82ð
\95Ô
\82·
\83\8f\81[
\83N
\r
281 * int *col :
\8c\85\94Ô
\8d\86\82ð
\95Ô
\82·
\83\8f\81[
\83N
\r
284 * int
\8ds
\94Ô
\8d\86\r
285 * -1=
\8aY
\93\96\82È
\82µ
\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 /*-----
\83\8a\83X
\83g
\83r
\83\85\81[
\83e
\83B
\83b
\83v
\83X
\83E
\83C
\83\93\83h
\83E
\82Ì
\83R
\81[
\83\8b\83o
\83b
\83N ------------------------
\r
345 * HWND hWnd :
\83E
\83C
\83\93\83h
\83E
\83n
\83\93\83h
\83\8b\r
346 * UINT message :
\83\81\83b
\83Z
\81[
\83W
\94Ô
\8d\86\r
347 * WPARAM wParam :
\83\81\83b
\83Z
\81[
\83W
\82Ì WPARAM
\88ø
\90\94\r
348 * LPARAM lParam :
\83\81\83b
\83Z
\81[
\83W
\82Ì LPARAM
\88ø
\90\94\r
351 *
\83\81\83b
\83Z
\81[
\83W
\82É
\91Î
\89\9e\82·
\82é
\96ß
\82è
\92l
\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