Click here to Skip to main content
15,867,885 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
on windows 10 64 i want to draw a bitmap in a window, but i do not see something of the bitmap, but the rest works.
(in which library+dll is the wm_paint-constant?)

Pascal
program Bmp2;

{$APPTYPE GUI}

uses System.SysUtils,windows;

Var winc:WNDCLASSEx;
    wname,wcl:PChar;
    wnddc:hdc;
    windbp,hwind:hwnd;
    PStrc:TPAINTSTRUCT;
    FH:THandle;
    FBuf,Bmpf:Pointer;
    fch:Pchar;
    fba,fbb:longint;
    F:File of byte;
    BmpH:HBitmap;
    Bmp:tagBitmap;
    BmpDC1:Hdc;
    bmpdc2:hdc;
    bmpdc3:hdc;
    BDC1,DC1:HDC;

  Function wndproc(hwndow:HWND;msga,msgword:word;msglong:longint):LResult;stdcall;
  Begin
    case msga of
      wm_paint:begin
{method 1:}
  BmpH:=CreateBitmapIndirect(bmp);
  bmpdc1:=getdc(bmph);
  selectobject(bmpdc2,Bmpdc1);
  BmpDC3:=CreateCompatibleDC(Bmpdc2);
  BitBlT(wnddc,30,10,700,500,BmpDC3,0,0,SRCCOPY);
{method 2:}
  BDC1:=CreateCompatibleDC(wnddc);
  selectobject(BDC1,BmpH);
  GetObject(BmpH,Sizeof(bmp),Addr(Bmp));
  BitBlT(wnddc,30,10,700,500,BDC1,0,0,SRCCOPY);
  DeleteDC(BDC1);
{method 3:}
  DC1:=CreateCompatibleDC(windbp);
  GetObject(BmpH,Sizeof(bmp),Addr(Bmp));
  BitBlT(windbp,30,10,700,500,DC1,0,0,SRCCOPY);
      end;
    end;
    wndproc:=DefWindowProc(hwndow,msga,msgword,msglong);
  End;

Begin
  winc.cbSize:=sizeof(winc);
  winc.style:=CS_HREDRAW Or CS_VREDRAW;
  winc.lpfnWndProc:=Addr(wndproc);
  winc.cbclsExtra:=0;
  winc.cbWndExtra:=0;
  winc.hInstance:=0;;
  winc.hIcon:=LoadIcon(0, IDI_APPLICATION);
  winc.hCursor:=0;
  winc.hbrBackground:=(14 + 1);
  winc.lpszMenuName:=NiL;
  winc.lpszClassName:='Window'#0;
  winc.hIconSm:=LoadIcon(winc.hInstance, IDI_APPLICATION);
  RegisterClassEx(winc);
  wcl:='Program'#0;
  wname:='Window'#0;
  hwind:=CreateWindow(wname,wcl,WS_OVERLAPPED+WS_SIZEBOX,300,100,750,
          600,0,0,0,NiL);
  ShowWindow(hwind,sw_show);
  UpdateWindow(hwind);
  wndDC:=GetDC(hwind);
  PStrc.hdc:=wndDC;
  PStrc.ferase:=false;
  PStrc.rcpaint.left:=0;
  PStrc.rcpaint.top:=0;
  PStrc.rcpaint.right:=700;
  PStrc.rcpaint.bottom:=500;
  windBP:=BeginPaint(hwind,PStrc);

  Bmpf:=GetMemory(1000000*2);
  AsSign(F,'C:\Paints.bmp');
  FH:=FileOpen('C:\Paints.bmp',fmOpenReadWrite);
  FileRead(FH,Bmpf^,735829);
  fch:=bmpf;
  fch:=fch+10;
  move(fch^,fba,4);
  move(bmpf,fbb,4);
  fba:=fba+fbb;
  move(fba,fbuf,4);

  bmp.bmtype:=0;
  bmp.bmwidth:=700;
  bmp.bmheight:=500;
  bmp.bmWidthBytes:=2*3*bmp.bmwidth;
  bmp.bmplanes:=1;
  bmp.bmbitspixel:=24;
  bmp.bmBits:=FBuf;
end.


What I have tried:

run all the versions which are by microsoft and other programming sites.
Posted
Updated 24-Mar-23 6:14am
v2
Comments
Richard MacCutchan 24-Mar-23 3:58am    
Your drawing code needs to be inside a WM_PAINT handler. Although you have the code to blit the image to the Window's DC you are doing it in the wrong place.
[no name] 28-Mar-23 8:24am    
i have improved my question
[no name] 29-Mar-23 13:44pm    
i mean and it does not work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900