hdc to Bitmap
-
Hello friends, I require to show the dc into the Picture Control as a bitmap. For that I am using the code like below, but only shows blank bitmap in the Picture control.
HDC DeskDC = GetDC(NULL);
HDC hdcStatic = GetDC(hWndStatic);
HBITMAP hb = CreateCompatibleBitmap(hdcStatic,200,200);
SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SendMessage(hWndStatic, STM_SETIMAGE , IMAGE_BITMAP,(LPARAM)hb);Please tell me if you know what is going wrong.
[ Screen Capture ][ Tool Tip ]
-
Hello friends, I require to show the dc into the Picture Control as a bitmap. For that I am using the code like below, but only shows blank bitmap in the Picture control.
HDC DeskDC = GetDC(NULL);
HDC hdcStatic = GetDC(hWndStatic);
HBITMAP hb = CreateCompatibleBitmap(hdcStatic,200,200);
SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SendMessage(hWndStatic, STM_SETIMAGE , IMAGE_BITMAP,(LPARAM)hb);Please tell me if you know what is going wrong.
[ Screen Capture ][ Tool Tip ]
What are you trying to do??? You want the bitmap to be a copy of a a 200x200 rect of the screen? That's fine. You should select the hb bitmap back out of the memory DC before you hand it off to the static (picture) control.HGDIOBJ hOldBM = SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcStatic, hOldBM);Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What are you trying to do??? You want the bitmap to be a copy of a a 200x200 rect of the screen? That's fine. You should select the hb bitmap back out of the memory DC before you hand it off to the static (picture) control.HGDIOBJ hOldBM = SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcStatic, hOldBM);Mark Salsbery Microsoft MVP - Visual C++ :java:
Thnk you vary much for you help. But still I am not able to perform the thing. I am doing something like this as you have told me to do. But getting NULL in hOLdBM. and So getting BLANK Image (black Image)
HDC DeskDC = GetDC(NULL);
HDC hdcStatic = GetDC(hWndStatic);
HBITMAP hb = CreateCompatibleBitmap(hdcStatic,200,200);
//Getting NULL(0x000000) in hOldBM. When I check The error Code it Show 0x00000005. Means "ACCESS DENIED"
HGDIOBJ hOldBM = SelectObject(hdcStatic,hb);
SelectObject(hdcStatic, hOldBM);SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcStatic, hOldBM);//Gettting noting in the Picture Control
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hOldBM);//Blank Image (Black Colored)
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);-- modified at 2:00 Friday 12th October, 2007
[ Screen Capture ][ Tool Tip ]
-
Thnk you vary much for you help. But still I am not able to perform the thing. I am doing something like this as you have told me to do. But getting NULL in hOLdBM. and So getting BLANK Image (black Image)
HDC DeskDC = GetDC(NULL);
HDC hdcStatic = GetDC(hWndStatic);
HBITMAP hb = CreateCompatibleBitmap(hdcStatic,200,200);
//Getting NULL(0x000000) in hOldBM. When I check The error Code it Show 0x00000005. Means "ACCESS DENIED"
HGDIOBJ hOldBM = SelectObject(hdcStatic,hb);
SelectObject(hdcStatic, hOldBM);SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcStatic, hOldBM);//Gettting noting in the Picture Control
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hOldBM);//Blank Image (Black Colored)
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);-- modified at 2:00 Friday 12th October, 2007
[ Screen Capture ][ Tool Tip ]
Try this
HDC DeskDC = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(0);
HBITMAP hb = CreateCompatibleBitmap(DeskDC,200,200); //<-- FixedHGDIOBJ hOldBM = SelectObject(hdcMem,hb);
BitBlt(hdcMem,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcMem, hOldBM);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
*edit* Fixed my bug
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Try this
HDC DeskDC = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(0);
HBITMAP hb = CreateCompatibleBitmap(DeskDC,200,200); //<-- FixedHGDIOBJ hOldBM = SelectObject(hdcMem,hb);
BitBlt(hdcMem,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcMem, hOldBM);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
*edit* Fixed my bug
Mark Salsbery Microsoft MVP - Visual C++ :java:
Hi Thnx a lot. It works. But it displays only monochrome bitmap. I.e. the image I m gettting in static control is Blak and white image.
[ Screen Capture ][ Tool Tip ]
-
What are you trying to do??? You want the bitmap to be a copy of a a 200x200 rect of the screen? That's fine. You should select the hb bitmap back out of the memory DC before you hand it off to the static (picture) control.HGDIOBJ hOldBM = SelectObject(hdcStatic,hb);
SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ;
BitBlt(hdcStatic,0,0,200,200,DeskDC,0,0,SRCCOPY);
SelectObject(hdcStatic, hOldBM);Mark Salsbery Microsoft MVP - Visual C++ :java:
Thnx a lot for you help I just made the little change and its working..................:) HDC DeskDC = GetDC(NULL); HDC hdcMem = CreateCompatibleDC(DeskDC); HBITMAP hb = CreateCompatibleBitmap(DeskDC,200,200); HGDIOBJ hOldBM = SelectObject(hdcMem,hb); BitBlt(hdcMem,0,0,200,200,DeskDC,0,0,SRCCOPY); SelectObject(hdcMem, hOldBM); SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ; SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
[ Screen Capture ][ Tool Tip ]
-
Hi Thnx a lot. It works. But it displays only monochrome bitmap. I.e. the image I m gettting in static control is Blak and white image.
[ Screen Capture ][ Tool Tip ]
I screwed up - see my modified post. Sorry about that :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Thnx a lot for you help I just made the little change and its working..................:) HDC DeskDC = GetDC(NULL); HDC hdcMem = CreateCompatibleDC(DeskDC); HBITMAP hb = CreateCompatibleBitmap(DeskDC,200,200); HGDIOBJ hOldBM = SelectObject(hdcMem,hb); BitBlt(hdcMem,0,0,200,200,DeskDC,0,0,SRCCOPY); SelectObject(hdcMem, hOldBM); SetWindowLong(hWndStatic,GWL_STYLE,(GetWindowLong(hWndStatic,GWL_STYLE) & ~SS_TYPEMASK) | SS_BITMAP) ; SendMessage(hWndStatic, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hb);
[ Screen Capture ][ Tool Tip ]
You found it....good :) Cheers!
Mark Salsbery Microsoft MVP - Visual C++ :java: