1 #include <stdio.h>
2 #include "Original.h"
3
CompWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)4 LRESULT APIENTRY CompWndProc(HWND hWnd,
5 UINT msg,
6 WPARAM wParam,
7 LPARAM lParam)
8 {
9 switch (msg)
10 {
11 case WM_PAINT:
12 PaintCompWindow( hWnd);
13 break;
14 case WM_SETCURSOR:
15 case WM_MOUSEMOVE:
16 case WM_LBUTTONUP:
17 case WM_RBUTTONUP:
18 DragUI(hWnd, NULL, msg, wParam, lParam, TRUE);
19 if ((msg == WM_SETCURSOR) &&
20 (HIWORD(lParam) != WM_LBUTTONDOWN) &&
21 (HIWORD(lParam) != WM_RBUTTONDOWN))
22 return DefWindowProc(hWnd, msg, wParam, lParam);
23 if ((msg == WM_LBUTTONUP) || (msg == WM_RBUTTONUP))
24 SetWindowLong(hWnd, FIGWL_MOUSE, 0L);
25 break;
26 default:
27 if (!MyIsIMEMessage(msg))
28 return DefWindowProc(hWnd, msg, wParam, lParam);
29 break;
30 }
31 return 0;
32 }
33
UICreateCompWindow(HWND hUIWnd)34 void UICreateCompWindow(HWND hUIWnd)
35 {
36 if (!IsWindow(uiComp.hWnd))
37 {
38 HDC hDC;
39 HFONT oldFont;
40 SIZE sz;
41 TCHAR szStr[100];
42
43 uiComp.hWnd =
44 CreateWindowEx(WS_EX_WINDOWEDGE, UICOMPCLASSNAME, NULL,
45 WS_DISABLED | WS_POPUP | WS_DLGFRAME,
46 0, 0, 1, 1, hUIWnd, NULL, hInst, NULL);
47 SetWindowLong(uiComp.hWnd, FIGWL_SVRWND, (DWORD)hUIWnd);
48
49 _stprintf(szStr, _T("AAAAAAAAAAAAA"));
50 hDC = GetDC(uiComp. hWnd);
51 oldFont = (HFONT)SelectObject(hDC, hUIFont);
52 GetTextExtentPoint(hDC, szStr, _tcslen(szStr), &sz);
53 SelectObject(hDC, oldFont);
54 ReleaseDC(uiComp.hWnd,hDC);
55
56 uiComp.sz.cx = sz.cx;
57 uiComp.sz.cy = sz.cy+4;
58 }
59 UIHideCompWindow();
60 return;
61 }
62
UIMoveCompWindow(HWND hUIWnd,int X,int Y,LPTSTR lpStr)63 void UIMoveCompWindow(HWND hUIWnd, int X, int Y, LPTSTR lpStr)
64 {
65 free(lpCompStr);
66 lpCompStr = _tcsdup(lpStr);
67 if(_tcslen(lpStr) <= 0)
68 {
69 UIHideCompWindow();
70 return;
71 }
72
73 if (!IsWindow(uiComp.hWnd))
74 UICreateCompWindow(hUIWnd);
75
76 if (IsWindow(uiComp.hWnd))
77 {
78 HDC hDC;
79 HFONT oldFont;
80 POINT pt;
81 RECT screenrc;
82 SIZE sz;
83
84 sz.cx = 0;
85 sz.cy = 0;
86 uiComp.pt.x = X;
87 uiComp.pt.y = Y;
88
89 if(lpCompStr)
90 {
91 hDC = GetDC(uiComp.hWnd);
92 oldFont = (HFONT)SelectObject(hDC, hUIFont);
93 GetTextExtentPoint(hDC, lpCompStr, _tcslen(lpCompStr), &sz);
94 SelectObject(hDC, oldFont);
95 ReleaseDC(uiComp.hWnd, hDC);
96 if(_tcslen(lpCompStr))
97 sz.cx += 2 * sz.cx / _tcslen(lpCompStr);
98 }
99 else
100 {
101 UIHideCompWindow();
102 return;
103 }
104
105 if(sz.cx < uiComp.sz.cx)
106 sz.cx = uiComp.sz.cx;
107
108 sz.cy = uiComp.sz.cy;
109 sz.cx += 4 * GetSystemMetrics(SM_CXEDGE);
110 sz.cy += 4 * GetSystemMetrics(SM_CYEDGE);
111
112 pt.x = uiComp.pt.x;
113 pt.y = uiComp.pt.y;
114
115 SystemParametersInfo(SPI_GETWORKAREA,
116 0,
117 &screenrc,
118 0);
119
120 if( (pt.x + sz.cx) > screenrc.right )
121 pt.x = screenrc.right - sz.cx;
122 if( (pt.y + sz.cy) > screenrc.bottom )
123 pt.y = screenrc.bottom - sz.cy;
124
125 MoveWindow(uiComp.hWnd,
126 pt.x,
127 pt.y,
128 sz.cx,
129 sz.cy,
130 TRUE);
131 ShowWindow(uiComp.hWnd, SW_SHOWNOACTIVATE);
132 InvalidateRect(uiComp.hWnd,NULL, FALSE);
133 }
134 }
135
PaintCompWindow(HWND hCompWnd)136 void PaintCompWindow(HWND hCompWnd)
137 {
138 PAINTSTRUCT ps;
139 HDC hDC;
140 HFONT oldFont;
141 RECT rc;
142 HBRUSH hBrush = (HBRUSH)NULL;
143 HBRUSH hOldBrush = (HBRUSH)NULL;
144 HPEN hPen = (HPEN)NULL;
145 HPEN hOldPen = (HPEN)NULL;
146
147 hDC = BeginPaint(hCompWnd,&ps);
148 oldFont = (HFONT)SelectObject(hDC, hUIFont);
149
150 GetClientRect(hCompWnd,&rc);
151
152 hBrush = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
153 hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
154 PatBlt(hDC,
155 rc.left,
156 rc.top ,
157 rc.right - GetSystemMetrics(SM_CXEDGE)/2,
158 rc.bottom - GetSystemMetrics(SM_CYEDGE)/2,
159 PATCOPY);
160 if(hBrush && hOldBrush)
161 SelectObject(hDC,hOldBrush);
162
163 hPen = (HPEN)GetStockObject(WHITE_PEN);
164 hOldPen = (HPEN)SelectObject(hDC,hPen);
165 MoveToEx(hDC,0,rc.bottom - GetSystemMetrics(SM_CXEDGE) / 2, NULL);
166 LineTo(hDC, rc.right - GetSystemMetrics(SM_CXEDGE) / 2,
167 rc.bottom - GetSystemMetrics(SM_CXEDGE) / 2);
168 LineTo(hDC, rc.right - GetSystemMetrics(SM_CXEDGE) / 2, 0);
169
170 hPen = CreatePen(PS_SOLID ,0,RGB(128,128,128));
171 SelectObject(hDC,hPen);
172 MoveToEx(hDC, rc.right - GetSystemMetrics(SM_CXEDGE) / 2, 0, NULL);
173 LineTo(hDC, 0, 0);
174 LineTo(hDC, 0, rc.bottom - GetSystemMetrics(SM_CYEDGE) / 2);
175
176 SelectObject(hDC,hOldPen);
177 DeleteObject(hPen);
178
179
180 if(lpCompStr)
181 {
182 SetBkMode(hDC, TRANSPARENT);
183 TextOut(hDC, 2, 2, lpCompStr, _tcslen(lpCompStr));
184 }
185
186 SelectObject(hDC, oldFont);
187 EndPaint(hCompWnd,&ps);
188 }
189
UIShowCompWindow()190 void UIShowCompWindow()
191 {
192 if (IsWindow(uiComp.hWnd))
193 ShowWindow(uiComp.hWnd, SW_SHOWNOACTIVATE);
194 }
195
UIHideCompWindow()196 void UIHideCompWindow()
197 {
198 if (IsWindow(uiComp.hWnd))
199 ShowWindow(uiComp.hWnd, SW_HIDE);
200 }
201