在cmybutton中的drawitem和其他能画的地方都试了肯定没在背景上的pdc画

解决方案 »

  1.   

    他不能作异型窗口再说了,现在不只是做这个按钮的问题,问题是为什么pDC会把东西画到窗口以外高人救我
      

  2.   

    呵呵,奇怪.还需要更多信息做判断:
    你的异形按钮如何得到的? SetWindowRgn?
    你用于绘画的屏幕设备句柄如何得到的? 通过 DRAWITEMSTRUCT?
      

  3.   

    使用DrawTextEx, 设置lprc参数即可。DrawTextEx
    The DrawTextEx function draws formatted text in the specified rectangle.int DrawTextEx(
      HDC hdc,                     // handle to DC
      LPTSTR lpchText,             // text to draw
      int cchText,                 // length of text to draw
      LPRECT lprc,                 // rectangle coordinates
      UINT dwDTFormat,             // formatting options
      LPDRAWTEXTPARAMS lpDTParams  // more formatting options
    );
      

  4.   

    楼上没有明白我的意思,我并不是在乎字符串,而是异型窗口再说了,现在不只是做这个按钮的问题,问题是为什么pDC会把东西画到窗口以外
      

  5.   

    BOOL CALLBACK OwnDrawProc(HWND hDlg, UINT message, WPARAM wParam, 
                              LPARAM lParam) 

        HDC hdcMem; 
        LPDRAWITEMSTRUCT lpdis; 
     
        switch (message) 
        { 
            case WM_INITDIALOG: 
     
                // hinst, hbm1 and hbm2 are defined globally. 
                hbm1 = LoadBitmap((HANDLE) hinst, "OwnBit1"); 
                hbm2 = LoadBitmap((HANDLE) hinst, "OwnBit2"); 
                return TRUE; 
     
            case WM_DRAWITEM: 
                lpdis = (LPDRAWITEMSTRUCT) lParam; 
                hdcMem = CreateCompatibleDC(lpdis->hDC); 
     
                if (lpdis->itemState & ODS_SELECTED)  // if selected 
                    SelectObject(hdcMem, hbm2); 
                else 
                    SelectObject(hdcMem, hbm1); 
     
                // Destination 
                StretchBlt( 
                    lpdis->hDC,         // destination DC 
                    lpdis->rcItem.left, // x upper left 
                    lpdis->rcItem.top,  // y upper left 
     
                    // The next two lines specify the width and 
                    // height. 
                    lpdis->rcItem.right - lpdis->rcItem.left, 
                    lpdis->rcItem.bottom - lpdis->rcItem.top, 
                    hdcMem,    // source device context 
                    0, 0,      // x and y upper left 
                    32,        // source bitmap width 
                    32,        // source bitmap height 
                    SRCCOPY);  // raster operation 
     
                DeleteDC(hdcMem); 
                return TRUE; 
     
            case WM_COMMAND: 
                if (wParam == IDOK 
                    || wParam == IDCANCEL) 
                { 
                    EndDialog(hDlg, TRUE); 
                    return TRUE; 
                } 
                if (HIWORD(wParam) == BN_CLICKED) 
                { 
                    switch (LOWORD(wParam)) 
                    { 
                        case IDC_OWNERDRAW: 
     
                            // application-defined processing 
     
                            break; 
                    } 
                } 
                break; 
     
            case WM_DESTROY: 
                DeleteObject(hbm1);  // delete bitmaps 
                DeleteObject(hbm2); 
     
                break; 
     
        } 
        return FALSE; 
            UNREFERENCED_PARAMETER(lParam); 

      

  6.   

    需要通过LPDRAWITEMSTRUCT中的rcItem来做限制。
      

  7.   

    需要通过LPDRAWITEMSTRUCT中的rcItem来做限制。