Board index » delphi » Can't get BitBlt to work?

Can't get BitBlt to work?

I posted the following on borland.public.turbopascal, haven't got a response
yet, and thought I would try here.

I cannot do a simple thing from the ObjectWindows 7.0
Programmer's Guide and cannot figure out what is wrong.
I am using TDlgWindow.  In the Init method, I do the following:
HMyBit := LoadBitMap(HInstance, 'TestBMP')
In the SetupWindow method, I do the following:
  TheDC := GetDC(HWindow);
  MemDC := CreateCompatibleDC(TheDC);
  SelectObject(MemDC, HMyBit);
  B := BitBlt(TheDC, 20, 20, 50, 25, MemDC, 0, 0, SRCCOPY);
I check all return codes and I think everything is working.
No bitmap gets displayed.  I am sure the answer is obvious.
I just have never worked with any GDI at all.
Please help.
TIA,
   Mark Bennion
address:  mark.benn...@worldnet.att.net

 

Re:Can't get BitBlt to work?


Quote
Mark Bennion wrote in message <629noi$...@bgtnsc01.worldnet.att.net>...
>I posted the following on borland.public.turbopascal, haven't got a
response
>yet, and thought I would try here.

>I cannot do a simple thing from the ObjectWindows 7.0
>Programmer's Guide and cannot figure out what is wrong.
>I am using TDlgWindow.  In the Init method, I do the following:
>HMyBit := LoadBitMap(HInstance, 'TestBMP')
>In the SetupWindow method, I do the following:
>  TheDC := GetDC(HWindow);
>  MemDC := CreateCompatibleDC(TheDC);
>  SelectObject(MemDC, HMyBit);
>  B := BitBlt(TheDC, 20, 20, 50, 25, MemDC, 0, 0, SRCCOPY);
>I check all return codes and I think everything is working.
>No bitmap gets displayed.  I am sure the answer is obvious.
>I just have never worked with any GDI at all.
>Please help.
>TIA,
>   Mark Bennion
>address:  mark.benn...@worldnet.att.net

hhm, I just made a simple program based on that that draws to the screen
instead of a window

uses winprocs,wintypes;
{$R C:\temp.res}
var
  HMyBit : HBitmap;
  TheDC : HDC;
  MemDC : HDC;
  B : Boolean;
Begin
  HMyBit := LoadBitMap(HInstance, 'BITMAP_1');
  TheDC := GetDC(0);
  MemDC := CreateCompatibleDC(TheDC);
  SelectObject(MemDC, HMyBit);
  B := BitBlt(TheDC, 20, 20, 64, 64, MemDC, 0, 0, SRCCOPY);
end.

worked fine...
it was a 256 color bitmap, and my video mode is 256 colors...
let me try a 16 color bitmap on a 256 color screen... that worked too....
must be that its drawing to hwindow...
let me try drawing to a window.... worked drawing it to a winCRT window...
odd:

uses wincrt,winprocs,wintypes,Strings;
{$R C:\temp.res}
var
  HMyBit : HBitmap;
  TheDC : HDC;
  MemDC : HDC;
  B : Boolean;
Begin
  StrCopy(WindowTitle,'test');
  writeln('starting up wincrt');
  HMyBit := LoadBitMap(HInstance, 'BITMAP_1');
  TheDC := GetDC(findwindow(nil,'test'));
  MemDC := CreateCompatibleDC(TheDC);
  SelectObject(MemDC, HMyBit);
  repeat
  B := BitBlt(TheDC, random(400), random(300), 64, 64, MemDC, 0, 0,
SRCCOPY);
  until keypressed;
  donewincrt;
end.

well, maybe if you email me your code

Zyklon

Re:Can't get BitBlt to work?


In article <629noi$...@bgtnsc01.worldnet.att.net>, Mark Bennion
<mark.benn...@worldnet.att.net> writes

Quote
>I cannot do a simple thing from the ObjectWindows 7.0
>Programmer's Guide and cannot figure out what is wrong.
>I am using TDlgWindow.  In the Init method, I do the following:
>HMyBit := LoadBitMap(HInstance, 'TestBMP')
>In the SetupWindow method, I do the following:
>  TheDC := GetDC(HWindow);
>  MemDC := CreateCompatibleDC(TheDC);
>  SelectObject(MemDC, HMyBit);
>  B := BitBlt(TheDC, 20, 20, 50, 25, MemDC, 0, 0, SRCCOPY);
>I check all return codes and I think everything is working.
>No bitmap gets displayed.  I am sure the answer is obvious.
>I just have never worked with any GDI at all.
>Please help.
>TIA,
>   Mark Bennion
>address:  mark.benn...@worldnet.att.net

I am working with TPW 1.5 rather than TP7 so I might be off beam but
here's a bit of code grabbed from one of my progs which does work.  Note
the GetObject line.  I learned the little trick to put a bitmap picture
centre screen from Long's book (see below).  Indeed all of this little
snippet is a blatant copy of one of his sample progs.  You might find it
a very useful book to have by you.

  DestDC := GetDC (DestWnd); if DestDC = 0 then Exit;
  HMemDC := CreateCompatibleDC (DestDC);
  If Boolean (HMemDC) then
    begin
      If boolean (SrcBmp) then
        begin
          HOldBmp := SelectObject (HMemDC, SrcBmp);
          GetObject (SrcBmp, SizeOf (BmpBuf), @BmpBuf);  {*****}
          if Centre then
            begin
              R.left := GetDeviceCaps
                (DestDC,HORZRES) div 2 - BmpBuf.bmWidth div 2;
              R.top := GetDeviceCaps
                (DestDC,VERTRES) div 2 - BmpBuf.bmHeight div 2
            end;
          BitBlt (DestDC, R.left, R.top,
             BmpBuf.bmWidth, bmpBuf.bmHeight, HMemDC, 0, 0, SrcCopy);
          R.right := R.left + BmpBuf.bmWidth;
          R.bottom := R.top + BmpBuf.bmHeight;
          SelectObject (HMemDC, HOldBmp)
        end;
      DeleteDC (HMemDC)
    end;
  ReleaseDC (DestWnd, DestDC)

Hope this is some help.  Good luck with your prog - we all go through
these traumas!

Afterthought:  You say you are writing an Init method.  Though I don't
always understand the reasons why, I have found that there are some
things that don't work when included in a Constructor.  To dodge this
little trap, I often write two methods and call them in succession:

        Constructor Init;
        Procedure FirstAction;

However, I'm not sure whether that would be a feasible thing to do if
you are writing code for a dialog.

Reference: Brian Long: The Borland Pascal Problem Solver, published by
Addison-Wesley.  (Covers TP 6 & 7 and TPW 1 & 1.5)

--
E. J. Jewell

Re:Can't get BitBlt to work?


Quote
E. J. Jewell wrote:

> In article <629noi$...@bgtnsc01.worldnet.att.net>, Mark Bennion
> <mark.benn...@worldnet.att.net> writes

> >I cannot do a simple thing from the ObjectWindows 7.0
> >Programmer's Guide and cannot figure out what is wrong.
> >I am using TDlgWindow.  In the Init method, I do the following:
> >HMyBit := LoadBitMap(HInstance, 'TestBMP')
> >In the SetupWindow method, I do the following:
> >  TheDC := GetDC(HWindow);
> >  MemDC := CreateCompatibleDC(TheDC);
> >  SelectObject(MemDC, HMyBit);
> >  B := BitBlt(TheDC, 20, 20, 50, 25, MemDC, 0, 0, SRCCOPY);
> >I check all return codes and I think everything is working.
> >No bitmap gets displayed.  I am sure the answer is obvious.

Not to be annoying, but you _do_ bitblt the bitmap also in the
paint method of your window object?
If you want to have the bitmap on screen all the time (as a
background? marker?) you need to redraw it every time your
window receives a wm_paint message. But in that case, you don't
need to draw the bitmap in the setup method.

Hope this helps,

Remco
--
Remco Vietor                            Department of Chemistry
re...@chem.gla.ac.uk                       J. Black Building
                                        University of Glasgow
                                        Glasgow G12 8QQ
                                        U.K.

Other Threads