Recent

Author Topic: How to get the HWND under Lazarus  (Read 15033 times)

lu7hz

  • Newbie
  • Posts: 2
How to get the HWND under Lazarus
« on: August 01, 2013, 04:04:00 am »
Hi,

I do need to port an applications passing to a Windows dll (bass dll) the applications handle thru TApplication.handle property which seems not to exists in Lazarus.

Not really concerned by portability issues as the dll is Win32 anyway.

Any hint?

Thanks in advance, Pedro.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: How to get the HWND under Lazarus
« Reply #1 on: August 01, 2013, 04:16:44 am »
hello,
are you using DYNAMIC_BASS.PAS   here
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: How to get the HWND under Lazarus
« Reply #2 on: August 01, 2013, 06:19:58 am »
You can use TForm.handle.

Also you should only use official header from http://www.un4seen.com/
It is crossplatform and both Delphi and Lazarus compatible.
« Last Edit: August 01, 2013, 06:22:05 am by User137 »

DtC17

  • New Member
  • *
  • Posts: 13
Re: How to get the HWND under Lazarus
« Reply #3 on: August 02, 2013, 07:15:06 pm »
Define exactly what you mean with "application handle" ? Application.MainFormHandle exists -- it may suit your purpose.

Windows has a lot of handles (form handles, process handles etc) and most of the time you'll be needing the Handle of your mainform (given above), which is the first one created.

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: How to get the HWND under Lazarus
« Reply #4 on: August 02, 2013, 08:01:20 pm »
TApplication.handle property which seems not to exists in Lazarus.
There is patch attached. http://bugs.freepascal.org/view.php?id=24052

Use that, if form handle doesn't work or exist.

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: How to get the HWND under Lazarus
« Reply #5 on: August 02, 2013, 08:49:29 pm »
Well, i'm not sure what intention of Application.Handle is. If it's like we suspected from original post, that he uses BASS library, it specifically wants window handle. I've used form handle with BASS for long time without issues. I haven't gotten to test what it means by pointer instead of HWND on Linux though... if form handle is compatible with that?
https://code.google.com/p/nxpascal/source/browse/trunk/src/Bass.pas#734

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: How to get the HWND under Lazarus
« Reply #6 on: August 02, 2013, 09:12:46 pm »
As already discussed into the related bug report ( http://bugs.freepascal.org/view.php?id=24052 ), Application.Handle was originatively in Delphi the handle of an hidden window 'owning' all the other -visible- user windows.

In a Windows environment only, of course (i.e. Delphi).

Currently, it seems that even within Delphi this property is -about to be - deprecated.

Concretely, Application.MainForm.Handle should do the trick in -almost- all the cases, if:

-you are in a windows environment,

-your main form has been created (i.e. don't use it inside the oncreate method of your main form -usually Form1-, for instance).

dorry

  • New Member
  • *
  • Posts: 12
Re: How to get the HWND under Lazarus
« Reply #7 on: October 10, 2013, 04:23:59 am »
form:
http://bugs.freepascal.org/view.php?id=24052

uses interfacebase;

try below code .
...................
  WidgetSet.AppHandle

.............
for example
ShowWindow(WidgetSet.AppHandle, SW_HIDE); 
it will be hided on taskbar.

WidgetSet.AppHandle equal Application.handle?
« Last Edit: October 10, 2013, 04:37:38 am by dorry »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to get the HWND under Lazarus
« Reply #8 on: October 10, 2013, 11:39:49 am »
Quote
WidgetSet.AppHandle equal Application.handle?
Seems not. WidgetSet.AppHandle is the native handle understood by the underlying widgetset, Application.Handle is the handle known by LCL.

Timewarp

  • Full Member
  • ***
  • Posts: 144
Re: How to get the HWND under Lazarus
« Reply #9 on: October 10, 2013, 02:22:36 pm »
Application.MainForm.Handle should do the trick in -almost- all the cases
Only one working correctly is WidgetSet.AppHandle, just test example given (in Windows)

ChrisF

  • Hero Member
  • *****
  • Posts: 542
Re: How to get the HWND under Lazarus
« Reply #10 on: October 10, 2013, 05:28:16 pm »
That's not completely true. You' re focusing upon only one behavior: showing/hiding the application into the Windows taskbar.

But there are a lot of other possible utilizations for such a handle. And for most of them, the handle of the main form is quite sufficient.

BTW, even the case you're talking of is OK with : Application.MainFormOnTaskbar := true (unless you want to hide the application in the taskbar only, while still showing the form(s) on the desktop).

Which is the now by-default value for Delphi applications (see http://docwiki.embarcadero.com/Libraries/XE5/en/Vcl.Forms.TApplication.MainFormOnTaskBar ).
« Last Edit: October 11, 2013, 12:14:28 am by ChrisF »

 

TinyPortal © 2005-2018