Здравствуйте, CEMb, Вы писали:
CEM>Здравствуйте, Сергей Мухин, Вы писали:
СМ>>SysLink Controls
CEM>MSDN:
CEM>Minimum operating systems: Windows XP
Для старья:
#define INTERNET_HREF_BUTTON_CLASS TEXT ("MCQ::INET::HREF")
// Стили окна
#define HBS_LEFT 0x0000
#define HBS_RIGHT 0x0001
#define HBS_CENTER 0x0002
#define HBS_MANUAL_SURF 0x0004
#define HBS_SHOW_NORMAL 0x0000
#define HBS_SHOW_MAXIMIZED 0x0008
#define HBS_ACTION_OPEN 0x0000
#define HBS_ACTION_PRINT 0x0010
#define HBS_ACTION_PROPERTIES 0x0020
#define WM_HREF_GOTO (WM_USER + 26)
VOID WINAPI RegisterInternetClasses (HINSTANCE hInstance);
VOID WINAPI UnregisterInternetClasses (HINSTANCE hInstance);
#define InternetHref_Go(hWnd) (SNDMSG (hWnd, WM_HREF_GOTO, 0, 0))
#define InternetHref_SetURL(hWnd,lpszURL) (SNDMSG (hWnd, WM_SET_TEXT, 0, (LPARAM) (LPCTSTR) lpszURL))
#define InternetHref_GetURLLength ((DWORD) SNDMSG (hWnd, WM_GETTEXTLENGTH, 0, 0))
#define InternetHref_GetURL(hWnd,lpszBuffer,dwSize) ((DWORD) SNDMSG (hWnd, WM_GETTEXT, (WPARAM) (DWORD) dwSize, (LPARAM) (LPTSTR) lpszBuffer))
/*****************************************************************************/
#define GWL_HREF_STATE 0
#define GWL_HREF_FONT 4
#define HBS_UNDERLINED 0x00000001
/*****************************************************************************/
static LRESULT WINAPI href_OnCreate (HWND hWnd, LPCREATESTRUCT lpCreate)
{
SetWindowLong (hWnd, GWL_HREF_STATE, 0);
return TRUE;
} // href_OnCreate
static VOID WINAPI href_OnPaint (HWND hWnd)
{
PAINTSTRUCT ps;
BeginPaint (hWnd, &ps);
INT iTextLength = GetWindowTextLength (hWnd);
LPTSTR lpszHref = new TCHAR [iTextLength + 1];
GetWindowText (hWnd, lpszHref, iTextLength + 1);
HBRUSH hBrush = (HBRUSH) SendMessage (GetParent (hWnd), WM_CTLCOLORSTATIC, (WPARAM) ps. hdc, (LPARAM) hWnd);
if (!hBrush)
hBrush = CreateSolidBrush (GetSysColor (COLOR_3DFACE));
SetBkMode (ps. hdc, TRANSPARENT);
SetTextColor (ps. hdc, RGB (0x00, 0x00, 0xFF));
FillRect (ps. hdc, &ps. rcPaint, hBrush);
DeleteObject (hBrush);
RECT rcClient;
GetClientRect (hWnd, &rcClient);
HFONT hFont = (HFONT) GetWindowLong (hWnd, GWL_HREF_FONT);
LOGFONT lf;
ZeroMemory (&lf, sizeof (lf));
GetObject (hFont, sizeof (lf), &lf);
if (GetWindowLong (hWnd, GWL_HREF_STATE) & HBS_UNDERLINED)
lf. lfUnderline = 1;
else
lf. lfUnderline = 0;
hFont = CreateFontIndirect (&lf);
hFont = (HFONT) SelectObject (ps. hdc, hFont);
DWORD dwStyle = GetWindowLong (hWnd, GWL_STYLE);
DWORD dwDT = DT_SINGLELINE | DT_VCENTER;
if (dwStyle & HBS_CENTER)
dwDT |= DT_CENTER;
else
if (dwStyle & HBS_RIGHT)
dwDT |= DT_RIGHT;
else
dwDT |= DT_LEFT;
InflateRect (&rcClient, -1, -1);
DrawText (ps. hdc, lpszHref, iTextLength, &rcClient, dwDT);
hFont = (HFONT) SelectObject (ps. hdc, hFont);
DeleteObject (hFont);
delete [] lpszHref;
EndPaint (hWnd, &ps);
} // href_OnPaint
static LRESULT WINAPI href_OnGetDlgCode (HWND hWnd, LPMSG lpMsg)
{
return DLGC_BUTTON;
} // href_OnGetDlgCode
static VOID WINAPI href_OnKillFocus (HWND hWnd, HWND hReceiver)
{
SetWindowLong (hWnd, GWL_HREF_STATE, GetWindowLong (hWnd, GWL_HREF_STATE) & ~HBS_UNDERLINED);
InvalidateRect (hWnd, NULL, FALSE);
} // href_OnKillFocus
static VOID WINAPI href_OnGetFocus (HWND hWnd, HWND hLooser)
{
SetWindowLong (hWnd, GWL_HREF_STATE, GetWindowLong (hWnd, GWL_HREF_STATE) | HBS_UNDERLINED);
InvalidateRect (hWnd, NULL, FALSE);
} // href_OnGetFocus
static VOID WINAPI href_OnSetFont (HWND hWnd, HFONT hFont, BOOL bRedraw)
{
SetWindowLong (hWnd, GWL_HREF_FONT, (LONG) hFont);
if (bRedraw)
InvalidateRect (hWnd, NULL, FALSE);
} // href_OnSetFont
static LRESULT WINAPI href_OnGetFont (HWND hWnd)
{
return (LRESULT) GetWindowLong (hWnd, GWL_HREF_FONT);
} // href_OnSetFont
static VOID href_OnMouseMove (HWND hWnd, INT iX, INT iY)
{
POINT pt = { iX, iY };
RECT rcClient;
GetClientRect (hWnd, &rcClient);
if (!PtInRect (&rcClient, pt))
{
ReleaseCapture ();
if (GetFocus () != hWnd)
href_OnKillFocus (hWnd, NULL);
}
else
{
if ((GetWindowLong (hWnd, GWL_HREF_STATE) & HBS_UNDERLINED) != HBS_UNDERLINED)
{
SetCapture (hWnd);
href_OnGetFocus (hWnd, NULL);
}
}
} // href_OnMouseMove
static VOID href_OnLButtonDown (HWND hWnd, INT iX, INT iY)
{
POINT pt = { iX, iY };
RECT rcClient;
GetClientRect (hWnd, &rcClient);
if (PtInRect (&rcClient, pt))
{
if (GetFocus () != hWnd)
SetFocus (hWnd);
}
} // href_OnLButtonDown
static VOID href_OnLButtonUp (HWND hWnd, INT iX, INT iY)
{
POINT pt = { iX, iY };
RECT rcClient;
GetClientRect (hWnd, &rcClient);
if (PtInRect (&rcClient, pt))
{
if (GetWindowLong (hWnd, GWL_STYLE) & HBS_MANUAL_SURF)
SendMessage (GetParent (hWnd), WM_COMMAND, MAKEWPARAM ((WORD) GetMenu (hWnd), 0), (LPARAM) hWnd);
else
SendMessage (hWnd, WM_HREF_GOTO, 0, 0);
}
} // href_OnLButtonUp
static VOID WINAPI href_OnGoto (HWND hWnd)
{
INT iTextLength = GetWindowTextLength (hWnd);
LPTSTR lpszHref = new TCHAR [iTextLength + 1];
GetWindowText (hWnd, lpszHref, iTextLength + 1);
DWORD dwStyle = GetWindowLong (hWnd, GWL_STYLE);
LPCTSTR lpszAction = TEXT ("open");
DWORD dwShow = SW_SHOWNORMAL;
if ((dwStyle & HBS_ACTION_PRINT) == HBS_ACTION_PRINT)
lpszAction = TEXT ("print");
if ((dwStyle & HBS_ACTION_PROPERTIES) == HBS_ACTION_PROPERTIES)
lpszAction = TEXT ("properties");
if ((dwStyle & HBS_SHOW_MAXIMIZED) == HBS_SHOW_MAXIMIZED)
dwShow = SW_SHOWMAXIMIZED;
ShellExecute (hWnd, lpszAction, lpszHref, TEXT (""), TEXT (""), dwShow);
delete lpszHref;
} // href_OnGoto
static VOID href_OnKeyUp (HWND hWnd, DWORD dwKey)
{
switch (dwKey)
{
case VK_SPACE: SendMessage (hWnd, WM_HREF_GOTO, 0, 0); break;
}
} // href_OnKeyUp
LRESULT WINAPI wpInternetHref (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE: return href_OnCreate (hWnd, (LPCREATESTRUCT) lParam); break;
case WM_PAINT: href_OnPaint (hWnd); break;
case WM_SETFOCUS: href_OnGetFocus (hWnd, (HWND) wParam); break;
case WM_KILLFOCUS: href_OnKillFocus (hWnd, (HWND) wParam); break;
case WM_SETFONT: href_OnSetFont (hWnd, (HFONT) wParam, (BOOL) lParam); break;
case WM_GETFONT: return href_OnGetFont (hWnd); break;
case WM_MOUSEMOVE: href_OnMouseMove (hWnd, GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); break;
case WM_LBUTTONDOWN: href_OnLButtonDown (hWnd, GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); break;
case WM_LBUTTONUP: href_OnLButtonUp (hWnd, GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam)); break;
case WM_KEYUP: href_OnKeyUp (hWnd, wParam); break;
case WM_GETDLGCODE: return href_OnGetDlgCode (hWnd, (MSG*) lParam); break;
case WM_HREF_GOTO: href_OnGoto (hWnd); break;
}
LRESULT lResult = DefWindowProc (hWnd, uMsg, wParam, lParam);
return lResult;
} // wpInternetHref
/*****************************************************************************/
ATOM g_aInternetHrefButton = NULL;
VOID WINAPI RegisterInternetClasses (HINSTANCE hInstance)
{
WNDCLASSEX wcx;
ZeroMemory (&wcx, sizeof (wcx));
wcx. cbSize = sizeof (wcx);
wcx. style = CS_GLOBALCLASS | CS_PARENTDC | CS_DBLCLKS;
wcx. lpfnWndProc = wpInternetHref;
wcx. cbClsExtra = 0;
wcx. cbWndExtra = 8;
wcx. hInstance = hInstance;
wcx. hIcon = NULL;
wcx. hCursor = LoadCursor (GetModuleHandle (TEXT ("XCTL")), MAKEINTRESOURCE (IDC_HREF));
wcx. hbrBackground = (HBRUSH) GetStockObject (NULL_BRUSH);
wcx. lpszMenuName = NULL;
wcx. lpszClassName = INTERNET_HREF_BUTTON_CLASS;
wcx. hIconSm = NULL;
g_aInternetHrefButton = RegisterClassEx (&wcx);
} // RegisterInternetClasses
VOID WINAPI UnregisterInternetClasses (HINSTANCE hInstance)
{
UnregisterClass (INTERNET_HREF_BUTTON_CLASS, hInstance);
} // RegisterInternetClasses
Выдирал с мясом. Могут быть нестыковочки, но контрол рабочий...
Т.е. я смотрю — это довольно сложно сделать?
А может по проще как то это можно сделать?
Создать в ресурсах, на диалоге контрол
CONTROL "<a>SysLink1</a>", IDC_SYSLINK, "SysLink", WS_TABSTOP, 12,22,41,12
А потом в обработке сообщений от элементов управления какой ни будь обработчик?
Здравствуйте, Смирнов Алексей, Вы писали:
СА>Т.е. я смотрю — это довольно сложно сделать?
СА>А может по проще как то это можно сделать?
СА>Создать в ресурсах, на диалоге контрол
СА>СА>CONTROL "<a>SysLink1</a>", IDC_SYSLINK, "SysLink", WS_TABSTOP, 12,22,41,12
СА>
СА>А потом в обработке сообщений от элементов управления какой ни будь обработчик?
Есть. NM_CLICK и NM_RETURN.