Recent

Author Topic: No displaying a bitmap using WinApi/GDI  (Read 690 times)

ADMGNS

  • New Member
  • *
  • Posts: 34
  • keep it simple and smart
No displaying a bitmap using WinApi/GDI
« on: August 14, 2024, 12:43:54 am »
Hello

I am traying to display a bitmap using WinApi/GDI, but no displaying.. C and Pascal source codes are identical (see attachments).. C one works, but pascal one doesn't..

What is the wrong thing?? Thanks

440bx

  • Hero Member
  • *****
  • Posts: 4486
Re: No displaying a bitmap using WinApi/GDI
« Reply #1 on: August 14, 2024, 02:29:42 am »
The C version declares some of the variables as "static" which means, the variables retain their value in subsequent calls to the window procedure.  In your Pascal code, the same variables are NOT static, just plain local variables, this causes them to lose their value.

Specifically, the value of the bitmap handle obtained in the WM_CREATE is lost when WM_CREATE ends, therefore the WM_PAINT is using some garbage that is occupying the bitmap handle when the WM_PAINT is processed.

Solution: ensure the variables declared as "static" in the C code are either global variables in your code or writable type constants (which is what "static" is in FPC.)

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

440bx

  • Hero Member
  • *****
  • Posts: 4486
Re: No displaying a bitmap using WinApi/GDI
« Reply #2 on: August 14, 2024, 02:36:52 am »
Also, if you're interested in programming directly to the Windows API, the following examples may be useful to you:

https://forum.lazarus.freepascal.org/index.php/topic,53791.0.html

Among others, there is an example that loads a bitmap and displays it in the window.

HTH.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ADMGNS

  • New Member
  • *
  • Posts: 34
  • keep it simple and smart
Re: No displaying a bitmap using WinApi/GDI
« Reply #3 on: August 14, 2024, 04:59:24 am »
thanks for your replies.. SOLVED.
« Last Edit: August 14, 2024, 05:03:58 am by ADMGNS »

 

TinyPortal © 2005-2018