标题:WIN32自绘按钮,求大神解答问题
只看楼主
tianci0756
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-2-20
 问题点数:0 回复次数:0 
WIN32自绘按钮,求大神解答问题
以下是我自己写的Button类,但是自绘效果是有了,点击按钮没反应,是不是主窗口没收到消息呢?怎么解决
//创建按钮
void cbutton::CreateButton(HWND hWnd, HINSTANCE hInstance, int hB_x, int hB_y, int hB_w, int hB_h, int ID)
{
    //创建按钮
    hButton = CreateWindow(
        L"button",      
        L" ",            
        WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_OWNERDRAW,
        hB_x,   
        hB_y,
        hB_w,
        hB_h,
        hWnd,
        (HMENU) ID,
        hInstance,
        NULL);

    w = hB_w;     
    h = hB_y;

    SetWindowLong(hButton, GWL_WNDPROC, (LONG)ButtonProc);
}
//(静态)按钮窗口过程处理函数
LRESULT cbutton::ButtonProc(HWND hbwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    cbutton *athis = (cbutton*)GetWindowLong(hbwnd, GWL_USERDATA);
    athis->hButton=hbwnd;
    switch (msg)
    {
        PAINTSTRUCT ps;
        HBITMAP hb;

    case WM_DESTROY:
   
        PostQuitMessage(0);
        break;

    case WM_PAINT:
        
        b_hdc = BeginPaint(hbwnd, &ps);      //开始绘图

        b_mdc = CreateCompatibleDC(b_hdc);   //兼容DC
        
        //加载图片
        hb = (HBITMAP)LoadImage(NULL, FileName, IMAGE_BITMAP,
            0, 0, LR_LOADFROMFILE);

        SelectObject(b_mdc, hb);
        
        //贴图
        BitBlt(b_hdc, 0, 0, w ,h, b_mdc, 0, 0, SRCCOPY);
        EndPaint(hbwnd, &ps);              //结束绘图
        
        w = 0;
        h = 0;
        DeleteObject(b_hdc);
        DeleteObject(b_mdc);
        memset(FileName, '\0', sizeof(FileName));

        break;
   
    }
    return DefWindowProc(hbwnd,msg,wParam,lParam);
}
搜索更多相关主题的帖子: 展览馆 俱乐部 西餐厅 中国 北京 
2017-02-20 15:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-474365-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056237 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved