Results 1 to 4 of 4

Thread: Putting a bitmap on a dialog

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Posts
    64
    HOw can i do this? this is what i tryed:

    extern void LoadBack(HWND hBack)
    {
    HANDLE bDC;
    HANDLE hBit;
    HANDLE BitDC;
    bDC=GetDC(hBack);
    hBit=LoadResource(hInst,600);
    BitDC=GetDC(hBit);
    BitBlt(bDC,(long)30,(long)30,(long)50,(long)50,BitDC,(long)0,(long)0,SRCCOPY); //(int)"&HCC0020");




    }

    in C, and i pass the dialog's handle to this function, the resource #600 is a bitmap i wanna use for the dialog. how can i load a bitmap from a resource and Bitblt it onto the dialog?

  2. #2
    New Member
    Join Date
    Jul 2000
    Posts
    3
    This should work. The code was designed for a CView, but it should be compatible. You will have to specify a string resource ID though instead of a number.

    extern void LoadBack(HWND hBack)
    {
    CDC* cdc=NULL;
    HDC hDC=NULL;
    CBitmap* bmp=NULL;
    HBITMAP hbmp=NULL;

    hbmp=(HBITMAP)LoadImage(NULL,"BMP_ID",IMAGE_BITMAP,100,100, NULL);
    bmp=bmp->FromHandle(hbmp);
    cdc=cdc->FromHandle(hDC);
    cdc->CreateCompatibleDC(pDC);
    CBitmap* oldbmp=(CBitmap*)hDC.SelectObject(bmp);

    pDC->BitBlt(0,0,100,100,cdc,0,0,SRCCOPY);

    cdc->SelectObject(oldbmp);
    delete cdc;
    }
    Wulf
    "When in doubt, change something"

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Posts
    64
    Thanks, but it is incompatable, first it says undeclared identifier for 'CDC' and there is like 50 other errors, i'm trying to do this with the LCC 32bit C compiler and api, I can't get it to work Also, in VC++, when making a bitmap in the resource, it only allows number values for the resource. So how would i do this. I'm stuck

  4. #4
    New Member
    Join Date
    Jul 2000
    Posts
    3
    As usual, I forgot about couple things I'm more confidant about this code though.

    extern void LoadBack(HWND hBack)
    {
    CDC* cdc=NULL,pDC=new CDC;
    HDC hDC=NULL;
    CBitmap* bmp=new CBitmap;

    if(!bmp->LoadBitmap(BMP_ID))
    return;

    hDC=GetDC(hBack);
    cdc=cdc->FromHandle(hDC);
    cdc->CreateCompatibleDC(pDC);
    CBitmap* oldbmp=(CBitmap*)cdc->SelectObject(bmp);

    pDC->BitBlt(0,0 ,100 ,100 ,cdc,0,0,SRCCOPY);

    ReleaseDC(hBack,hDC);
    cdc->SelectObject(oldbmp);
    delete cdc;
    }

    If one of your errors was similar to
    "error C2065: 'CDC' : undeclared identifier"
    then use this. Note: you will have to supply an application instance. AfxGetInstanceHandle() can be used, but if you have access to the Afx... commands you should be able to declare CDC, CBitmap, etc. The other source is a HINSTANCE passed to WinMain()

    extern void LoadBack(HWND hBack)
    {
    HDC hDC=NULL;
    HBITMAP bmp=NULL;
    LPCSTR strBmpID;

    strBmpID=MAKEINTRESOURCE(BMP_ID);
    bmp=LoadBitmap(programInstance,strBmpID)
    if(bmp==(HBITMAP)NULL)
    return;

    hDC=GetDC(hBack);

    BitBlt(hDC,0,0 ,100 ,100 ,cdc,0,0,SRCCOPY);

    ReleaseDC(hBack,hDC);
    }
    Wulf
    "When in doubt, change something"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width