mirror of
https://github.com/WinampDesktop/winamp.git
synced 2024-11-28 18:50:48 +01:00
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#include <windows.h>
|
|
#include "link_control.h"
|
|
|
|
static HCURSOR link_hand_cursor;
|
|
static LRESULT link_handlecursor(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
LRESULT ret = CallWindowProcW((WNDPROC)GetPropW(hwndDlg, L"link_proc"), hwndDlg, uMsg, wParam, lParam);
|
|
// override the normal cursor behaviour so we have a hand to show it is a link
|
|
if(uMsg == WM_SETCURSOR)
|
|
{
|
|
if((HWND)wParam == hwndDlg)
|
|
{
|
|
if(!link_hand_cursor)
|
|
{
|
|
link_hand_cursor = LoadCursor(NULL, IDC_HAND);
|
|
}
|
|
SetCursor(link_hand_cursor);
|
|
return TRUE;
|
|
}
|
|
}
|
|
return ret;
|
|
}
|
|
|
|
void link_startsubclass(HWND hwndDlg, UINT id){
|
|
HWND ctrl = GetDlgItem(hwndDlg, id);
|
|
SetPropW(ctrl, L"link_proc",
|
|
(HANDLE)(LONG_PTR)SetWindowLongPtrW(ctrl, GWLP_WNDPROC, (LONG_PTR)link_handlecursor));
|
|
}
|
|
|
|
void link_handledraw(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
if (uMsg == WM_DRAWITEM)
|
|
{
|
|
DRAWITEMSTRUCT *di = (DRAWITEMSTRUCT *)lParam;
|
|
if (di->CtlType == ODT_BUTTON)
|
|
{
|
|
wchar_t wt[123] = {0};
|
|
int y;
|
|
RECT r;
|
|
HPEN hPen, hOldPen;
|
|
GetDlgItemTextW(hwndDlg, (INT)wParam, wt, 123);
|
|
|
|
// draw text
|
|
SetTextColor(di->hDC, (di->itemState & ODS_SELECTED) ? RGB(220, 0, 0) : RGB(0, 0, 220));
|
|
r = di->rcItem;
|
|
r.left += 2;
|
|
DrawTextW(di->hDC, wt, -1, &r, DT_VCENTER | DT_SINGLELINE);
|
|
|
|
memset(&r, 0, sizeof(r));
|
|
DrawTextW(di->hDC, wt, -1, &r, DT_SINGLELINE | DT_CALCRECT);
|
|
|
|
// draw underline
|
|
y = di->rcItem.bottom - ((di->rcItem.bottom - di->rcItem.top) - (r.bottom - r.top)) / 2 - 1;
|
|
hPen = CreatePen(PS_SOLID, 0, (di->itemState & ODS_SELECTED) ? RGB(220, 0, 0) : RGB(0, 0, 220));
|
|
hOldPen = (HPEN) SelectObject(di->hDC, hPen);
|
|
MoveToEx(di->hDC, di->rcItem.left + 2, y, NULL);
|
|
LineTo(di->hDC, di->rcItem.right + 2 - ((di->rcItem.right - di->rcItem.left) - (r.right - r.left)), y);
|
|
SelectObject(di->hDC, hOldPen);
|
|
DeleteObject(hPen);
|
|
|
|
}
|
|
}
|
|
}
|