Recent

Author Topic: How to hide window buttons (Minimize, Maximize and Close) in a Windows app  (Read 1133 times)

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1396
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to hide window buttons (Minimize, Maximize and Close) in a Windows app
« Reply #15 on: December 11, 2022, 05:27:40 pm »
I really suggest to upgrade from GetWindowLong to GetWindowLongPtr and same for SetWindowLong to SetWindowLongPtr for a compatible to 32 and 64 bit always working solution.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

440bx

  • Hero Member
  • *****
  • Posts: 3399
Re: How to hide window buttons (Minimize, Maximize and Close) in a Windows app
« Reply #16 on: December 12, 2022, 08:36:07 am »
I really suggest to upgrade from GetWindowLong to GetWindowLongPtr and same for SetWindowLong to SetWindowLongPtr for a compatible to 32 and 64 bit always working solution.
Yes, that is a good suggestion.

An alternative is to define 32bit (Set/Get)(Window/Class)LongPtr functions to point to the non-Ptr names in 32bit (since there are no xxxPtr names in the 32bit dll) and show them as returning a ptrint (which will automatically expand or contract to the bitness of the code being compiled.) and do the opposite for the 64 bit definitions of the non-Ptr functions.

That way the xxxPtr functions exist in both 32bit and 64bit making them the right choice no matter the program bitness.  no need for $ifdef WIN64 to determine which API should be called since with that definition the xxxPtr functions exist in both bitnesses.





« Last Edit: December 12, 2022, 08:37:43 am by 440bx »
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 SP1 64bit.

Libra07

  • New Member
  • *
  • Posts: 17
Re: How to hide window buttons (Minimize, Maximize and Close) in a Windows app
« Reply #17 on: December 12, 2022, 11:31:55 am »
Thank you ASerge! This is exactly what I wanted! I wanted to prevent the user from accidentally or lazily closing the console without exiting normally. If the user wants, he can close it in the taskbar menu or through the program manager. Perfect just like that!

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1396
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to hide window buttons (Minimize, Maximize and Close) in a Windows app
« Reply #18 on: December 12, 2022, 11:32:30 am »
@440bx, you really just need to replace the non-Ptr with the Ptr variant, the rest the OS do for you. No need anything else.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

Libra07

  • New Member
  • *
  • Posts: 17
Re: How to hide window buttons (Minimize, Maximize and Close) in a Windows app
« Reply #19 on: December 12, 2022, 12:20:27 pm »
KodeZwerg and 440bx, thanks for your suggestions!
I replaced the commads:
 GetWindowLong ->  GetWindowLongPrt
 SetWindowLong ->  SetWindowLongPrt
It seems that everything works perfectly, the parameters were basically the same.

I see in the microsoft.com develiopment page there are a lot of variants
GetWindowLongPtrA function  /  GetWindowLongPtrW function
SetWindowLongPtrA function  /  SetWindowLongPtrW function

I think these 2 types are because of ANSI / Unicode.
But I can use the simple GetWindowLongPtr too. So I use now the simple GetWindowLongPtr / SetWindowLongPtr.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 1396
  • Fifty shades of code.
    • Delphi & FreePascal
Re: How to hide window buttons (Minimize, Maximize and Close) in a Windows app
« Reply #20 on: December 12, 2022, 12:37:48 pm »
KodeZwerg and 440bx, thanks for your suggestions!
I replaced the commads:
 GetWindowLong ->  GetWindowLongPrt
 SetWindowLong ->  SetWindowLongPrt
It seems that everything works perfectly, the parameters were basically the same.

I see in the microsoft.com develiopment page there are a lot of variants
GetWindowLongPtrA function  /  GetWindowLongPtrW function
SetWindowLongPtrA function  /  SetWindowLongPtrW function

I think these 2 types are because of ANSI / Unicode.
But I can use the simple GetWindowLongPtr too. So I use now the simple GetWindowLongPtr / SetWindowLongPtr.
You also need to change its receiver to LONG_PTR (important!) and than you are good to go  O:-)
You are welcome.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

 

TinyPortal © 2005-2018