发新话题
打印

自己的HLINK控件源代码如下,HAND-CURSOR总是超出一小段?

自己的HLINK控件源代码如下,HAND-CURSOR总是超出一小段?

class HLink  
{
        class _autoinitializer
        {
        public:
                _autoinitializer();
                ~_autoinitializer();
        protected:
                HMODULE hModule;
        };
        friend class _autoinitializer;
public:
        HLink();
        virtual ~HLink();
        void create(int id, HWND parent);
public:
        char m_url [256];
        HWND m_hwnd;
        HFONT m_font;
        static _autoinitializer __autoinitializer;
        static HCURSOR cursor;
        static int WndProc(HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam);
};

//===========================================================


HLink::_autoinitializer::_autoinitializer() : hModule(NULL)
{
        WNDCLASS hc;

        hc.style = 0;
        hc.lpfnWndProc = (WNDPROC)HLink::WndProc;
        hc.cbClsExtra = 0;
        hc.cbWndExtra = sizeof(HLink*);
        hc.hInstance = NULL;
        hc.hIcon = NULL;
        hc.hCursor = NULL;
        hc.hbrBackground = NULL;
        hc.lpszMenuName = NULL;
        hc.lpszClassName = WNDCLASSNAME;
        RegisterClass(&hc);

        HLink::cursor = :oadCursor(NULL, MAKEINTRESOURCE(32649));
        if (HLink::cursor == NULL)
        {
                TCHAR dir[MAX_PATH];
                GetWindowsDirectory(dir ,MAX_PATH);
                strcat(dir,"\\winhlp32.exe");
                hModule = LoadLibrary(dir);               
                if (hModule)
                        HLink::cursor = :oadCursor(hModule, MAKEINTRESOURCE(106));
        }
}

HLink::_autoinitializer::~_autoinitializer()
{
        if (hModule != NULL)
                FreeLibrary(hModule);
}

HLink::_autoinitializer HLink::__autoinitializer;
HCURSOR HLink::cursor = NULL;

HLink::HLink()
{
}

HLink::~HLink()
{}


void HLink::create(int id, HWND parent)
{
        HWND old = ::GetDlgItem(parent, id);

        RECT rc;
        POINT pos;

        GetWindowText(old, m_url, sizeof(m_url));
        GetWindowRect(old, &rc);

        pos.x = rc.left;
        pos.y = rc.top;
        ScreenToClient(parent, &pos);
        rc.left = pos.x;
        rc.top = pos.y;

        pos.x = rc.right;
        pos.y = rc.bottom;
        ScreenToClient(parent, &pos);
        rc.right = pos.x;
        rc.bottom = pos.y;

        m_font = (HFONT)SendMessage(old, WM_GETFONT, 0, 0);

        m_hwnd = ::CreateWindow(WNDCLASSNAME, m_url, WS_CHILD | WS_VISIBLE,
                rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
                parent, NULL, NULL, NULL);
        SetWindowLong(m_hwnd, GWL_USERDATA, (LONG)this);

        DestroyWindow(old);
}

int HLink::WndProc(HWND hwnd, WORD wMsg, WPARAM wParam, LPARAM lParam)
{
        HLink *hl = (HLink*) GetWindowLong(hwnd, GWL_USERDATA);
        HDC hdc;
        PAINTSTRUCT ps;
        RECT rect;
        SIZE size;
        POINT pt;

        switch (wMsg)  
        {
        case WM_LBUTTONDOWN:
                ShellExecute(NULL, "open", hl->m_url, NULL, NULL, SW_SHOWNORMAL);
                break;

        case WM_PAINT:
                hdc = ::BeginPaint(hwnd, &ps);
                GetClientRect(hwnd, &rect);
                SelectObject(hdc, hl->m_font);
                SetTextColor(hdc, RGB(0,0,255));
                SetBkMode(hdc, TRANSPARENT);
                DrawText(hdc, hl->m_url, strlen(hl->m_url), &rect, 0);
                EndPaint(hwnd, &ps);
                break;

        case WM_SETCURSOR:
                hdc = GetDC(hwnd);
                GetTextExtentPoint32(hdc, hl->m_url, strlen(hl->m_url), &size);
                ReleaseDC(hwnd, hdc);
                GetWindowRect(hwnd, &rect);
                rect.right = rect.left + size.cx;
                rect.bottom = rect.top + size.cy;
                GetCursorPos(&pt);
                if (PtInRect(&rect, pt))
                        SetCursor(HLink::cursor);
                break;

        default:
                DefWindowProc(hwnd, wMsg, wParam, lParam);
        }

        return TRUE;
}

TOP

就是说HAND在字符串外面一小部分仍然显示,不正好对应,
感觉是字体的一些问题造成的
不直到各位有什么好的建议

TOP

超级简单易用的音视频转换组件 支持RMVB解码 FFmpeg for Delphi / VB http://www.CCAVC.com

TOP

VC++早就还给老师的路过....
金品时尚购物商城http://www.GoldenShopping.cn

TOP

用delphi
你才是国家队的,你全家都是国家队的

TOP

已解决。
最后写了个窗口类。

TOP


哈哈,现在wsg的理解能力越来越高,大家笑笑,他就能领会了。所以以后大家笑笑就行了。
单如暴雨哗哗下
刀似长江滚滚来
横批:韩信点兵

TOP

引用:
原帖由 wandou 于 2008-5-6 16:55 发表

哈哈,现在wsg的理解能力越来越高,大家笑笑,他就能领会了。所以以后大家笑笑就行了。
超级简单易用的音视频转换组件 支持RMVB解码 FFmpeg for Delphi / VB http://www.CCAVC.com

TOP

发新话题