-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_CTRL_HLINK.cpp
More file actions
168 lines (131 loc) · 3.93 KB
/
C_CTRL_HLINK.cpp
File metadata and controls
168 lines (131 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <windows.h>
#include "C_WIN.h"
#include "C_CTRL_HLINK.h"
static HFONT g_hFont = NULL;
LRESULT CALLBACK WndProcHLink(HWND hwnd , UINT msg , WPARAM wp , LPARAM lp) {
PHLINK_WINDATA pWinData = (PHLINK_WINDATA)GetWindowLong( hwnd, GWL_USERDATA );
if(!pWinData){
pWinData = (PHLINK_WINDATA)::GlobalAlloc(GMEM_FIXED,sizeof(HLINK_WINDATA));
SetWindowLong( hwnd, GWL_USERDATA ,(LONG)pWinData);
pWinData->hTarget = NULL;
}
switch (msg) {
case WM_DESTROY:
{
::GlobalFree(pWinData);
}
break;
case WM_HLINKALING_LEFT:
if(pWinData)pWinData->fRightAlign = FALSE;
break;
case WM_HLINKALING_RIGHT:
if(pWinData)pWinData->fRightAlign = TRUE;
SetWindowLong( hwnd, GWL_USERDATA ,(LONG)pWinData);
break;
case WM_HLINKALING_TARGET:
{
pWinData->hTarget = (HWND)wp;
pWinData->iIDItem = (int)lp;
}
break;
case WM_PAINT:
{
char* strText;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
int iTextLength;
char* pPoint;
iTextLength = GetWindowTextLength(hwnd) + 2;
strText = (char*)GlobalAlloc(GMEM_FIXED,iTextLength);
GetWindowText(hwnd , strText , iTextLength);
pPoint = strText;
while(*pPoint){
if(*pPoint=='\t'){*pPoint='\0';break;}
pPoint++;
}
GetClientRect(hwnd , &rect);
hdc = BeginPaint(hwnd , &ps);
SelectObject(hdc,g_hFont);
SetBkMode(hdc,TRANSPARENT);
SetTextColor(hdc,RGB(0x00,0x00,0xff));
DrawText(hdc , strText , -1 , &rect ,(pWinData->fRightAlign ? DT_RIGHT : DT_LEFT) | DT_CALCRECT);
/*
RECT rtwin;
::GetWindowRect(hwnd,&rtwin);
int sw = (rtwin.right-rtwin.left) - (rect.right-rect.left); //k‚ß‚ç‚ê‚é—Ê
int sy = (rtwin.bottom-rtwin.top) - (rect.bottom-rect.top);
POINT pt;
pt.x = rtwin.left;pt.y = rtwin.top;
::ScreenToClient(::GetParent(hwnd),&pt);
*/
if(pWinData->fRightAlign == DT_LEFT){
::SetWindowPos(hwnd,NULL,0,0,
rect.right,rect.bottom,SWP_NOZORDER|SWP_NOMOVE);
}
GetClientRect(hwnd , &rect);
int iHeight = DrawText(hdc , strText , -1 , &rect ,pWinData->fRightAlign ? DT_RIGHT : DT_LEFT);
// RECT rt;
// GetWindowRect(hwnd,&rt);
// SetWindowPos(hwnd,NULL,0,0,rect.right-rect.left,
// iHeight,SWP_NOZORDER);
EndPaint(hwnd , &ps);
GlobalFree((HGLOBAL)strText);
}
break;
case WM_LBUTTONUP:
{
if(pWinData->hTarget){
::SendMessage(pWinData->hTarget,WM_HLINKALING_TARGET,(WPARAM)hwnd,(LPARAM)pWinData->iIDItem);
}else{
char* strText;
int iTextLength;
iTextLength = GetWindowTextLength(hwnd) + 2;
strText = (char*)GlobalAlloc(GMEM_FIXED,iTextLength);
GetWindowText(hwnd , strText , iTextLength);
char *pPoint = strText;
while(*pPoint){
if(*pPoint=='\t'){pPoint++;break;}
pPoint++;
}
ShellExecute(NULL,"open" ,pPoint,NULL,NULL,SW_SHOWNORMAL );
GlobalFree((HGLOBAL)strText);
}
}
break;
}
return DefWindowProc(hwnd , msg , wp , lp);
}
C_CTRL_HYPERLINK::C_CTRL_HYPERLINK()
{
}
C_CTRL_HYPERLINK::~C_CTRL_HYPERLINK()
{
}
BOOL C_CTRL_HYPERLINK::RegisterClass(HINSTANCE hInstance,LPCSTR lpClassName)
{
WNDCLASS winc;
winc.style = CS_HREDRAW | CS_VREDRAW;
winc.lpfnWndProc = WndProcHLink;
winc.cbClsExtra = 0;
winc.cbWndExtra = sizeof(HLINK_WINDATA);
winc.hInstance = hInstance;
winc.hIcon = NULL;
winc.hCursor = LoadCursor(NULL , MAKEINTRESOURCE(32649));
winc.hbrBackground = NULL;//(HBRUSH)GetStockObject(WHITE_BRUSH);
winc.lpszMenuName = NULL;
winc.lpszClassName = TEXT(lpClassName);
if (!::RegisterClass(&winc)) return -1;
return TRUE;
}
void
C_CTRL_HYPERLINK::SetFont(HFONT hFont){
if(hFont){
LOGFONT logfont;
GetObject(hFont,sizeof(logfont),&logfont);
logfont.lfUnderline = TRUE;
g_hFont=CreateFontIndirect(&logfont);
}else{
g_hFont = NULL;
}
}