如何加入位图,并能够对它进行拖动,而且,需要在相应鼠标事件后,自动加入位图,如左键点击之后

解决方案 »

  1.   

    这不难吧。我这儿有一个CDib类,要不要。要,给我来个信息吧。
      

  2.   

    要,我的e_mail是[email protected]。有用一定给分。谢谢!!
      

  3.   

    应该不会很难吧!在相应的鼠标响应函数里GetDC来加载位图,不行么?试试看?
      

  4.   

    我用SDK写过,MFC也是类似的方式。载入的是1024*768图
    LRESULT CALLBACK  WinProc(HWND  hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    static HBITMAP  hBit;
    PAINTSTRUCT     ps;
    HDC    hdc;
    static POINT  oldPt,newPt,OriginPt;
    static BOOL   flag=FALSE;
    HDC    memdc;
        HINSTANCE       hInstance;
    static int      cxClient,cyClient;
    int    cx,cy;
        static int mincx,mincy;
    switch(msg)
    {
    case WM_CREATE:
    hInstance=((LPCREATESTRUCT)lParam)->hInstance;
            hBit=LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BACK));
    return 0;
    case WM_SIZE:
    cxClient=LOWORD(lParam);
    cyClient=HIWORD(lParam);
            OriginPt.x=OriginPt.y=0;
            mincx=cxClient-1024;
    mincy=cyClient-768;
    return 0;
        case WM_LBUTTONDOWN:
    newPt.x=LOWORD(lParam);
    newPt.y=HIWORD(lParam);
    oldPt=newPt;
    flag=TRUE;
    return 0;
    case WM_LBUTTONUP:
    flag=FALSE;
    return 0;
    case WM_MOUSEMOVE:
    if(flag)
    {
    newPt.x=LOWORD(lParam);
    newPt.y=HIWORD(lParam);
    if(newPt.x !=oldPt.x || newPt.y != oldPt.y )
    {
    hdc=GetDC(hwnd);
    cx=newPt.x-oldPt.x;
    cy=newPt.y-oldPt.y;
    OriginPt.x +=cx;
    OriginPt.y +=cy;
    if(OriginPt.x<=mincx)
    {
    cx=0;
    OriginPt.x=mincx;
    }
    if(OriginPt.x >=0)
    {
    cx=0;
    OriginPt.x=0;
    } if(OriginPt.y<=mincy)
    {
    cy=0;
    OriginPt.y=mincy;
    }
    if(OriginPt.y >=0 )
    {
    cy=0;
    OriginPt.y=0;
    }
    ScrollDC(hdc,cx,cy,NULL,NULL,NULL,NULL);
    InvalidateRect(hwnd,NULL,FALSE);
    ReleaseDC(hwnd,hdc);
    oldPt=newPt;
    }
    }
    return 0; case WM_PAINT:
    hdc=BeginPaint(hwnd,&ps);
            if(hBit)
    {
    memdc=CreateCompatibleDC(hdc);
    SelectObject(memdc,hBit);
                BitBlt(hdc,0,0,1024,768,memdc,-OriginPt.x,-OriginPt.y,SRCCOPY);
    DeleteDC(memdc);
    }
    EndPaint(hwnd,&ps);
    return 0;
    case WM_DESTROY:
    DeleteObject(hBit);
    PostQuitMessage(0);
    return 0;
    }
    return DefWindowProc(hwnd,msg,wParam,lParam);
    }