Recent

Author Topic: [SOLVED]Control '' has no parent window  (Read 1575 times)

CM630

  • Hero Member
  • *****
  • Posts: 1527
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[SOLVED]Control '' has no parent window
« on: October 09, 2025, 03:06:18 pm »
I am trying to handle Windows events in a custom control.
When I place the control on a form I get Control '' has no parent window.
If I comment (remove) the next line the error is not shown, but of course, events are not handled:
FPrevWndProc:=Windows.WNDPROC(SetWindowLongPtr(Self.Handle,GWL_WNDPROC,PtrUInt(@WndCallback)));
I suppose that is the form on which the control is located, which should handle the event, but I have to link it somehow.
Replacing Self.Handle with Parent.Handle causes some other error.

The exception is generated by Application.CreateForm(TForm1, Form1);   which is in the .LPR file of the sample app.

Code: Pascal  [Select][+][-]
  1. unit ComboSample;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   Windows;
  10.  
  11. type
  12.   TComboSample = class(tcustomcombobox)
  13.   private
  14.     FPrevWndProc: Windows.WNDPROC;
  15.     function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
  16.   protected
  17.  
  18.   public
  19.     constructor Create (aOwner: TComponent); override;
  20.  
  21.   published
  22.  
  23.   end;
  24.  
  25. procedure Register;
  26.  
  27. implementation
  28.  
  29. {$ifdef windows}
  30. //Handles windows messages
  31. function TComboSample.WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam):LRESULT; stdcall;
  32. var
  33.   mMessage : TMessage;
  34. begin
  35.   {if (uMsg = WM_DEVICECHANGE) then
  36.   begin
  37.     result:=Windows.DefWindowProc(Ahwnd, uMsg, WParam, LParam);  //not sure about this one
  38.     mMessage.wParam:= wParam;
  39.     mMessage.lParam:= lParam;
  40.     mMessage.Result:= Result;
  41.     WMPnPDeviceChange(mMessage);
  42.     exit;
  43.   end;
  44.   result:=CallWindowProc(FPrevWndProc,Ahwnd, uMsg, WParam, LParam);}
  45. end;
  46. {$endif}
  47.  
  48. constructor TComboSample.Create (aOwner: TComponent);
  49. begin
  50.   inherited;
  51.   FPrevWndProc:=Windows.WNDPROC(SetWindowLongPtr(Self.Handle,GWL_WNDPROC,PtrUInt(@WndCallback)));
  52. end;
  53.  
  54.  
  55. procedure Register;
  56. begin
  57.   RegisterComponents('MySample',[TComboSample]);
  58. end;
  59.  
  60. end.
« Last Edit: October 10, 2025, 10:30:07 pm by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Control '' has no parent window
« Reply #1 on: October 09, 2025, 03:28:20 pm »
I don't think you can capture the handle during control creation, possibly during window creation.
But you don't need to; you can use 'inherited' to handle the original procedure without capturing it.

Code: Pascal  [Select][+][-]
  1. type
  2.   TMyCustomControl = class(tcustomcombobox)
  3.     protected
  4.       procedure CreateWnd; override;
  5.       function WndProc(var Message: TMessage): Integer; override;
  6.   end;
  7.  
  8. //Here you can do something
  9. procedure TMyCustomControl.CreateWnd;
  10. begin
  11.   inherited CreateWnd;
  12. end;
  13.  
  14. function TMyCustomControl.WndProc(var Message: TMessage): Integer;
  15. begin
  16.   case Message.Msg of
  17.     WM_LBUTTONDOWN: //for example
  18.       begin
  19.         ShowMessage('Mouse Button Down!');
  20.         Result := 0; // Messagge handled
  21.       end;
  22.     else
  23.       Result := inherited WndProc(Message); // call original function
  24.   end;
  25.  

CM630

  • Hero Member
  • *****
  • Posts: 1527
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Control '' has no parent window
« Reply #2 on: October 09, 2025, 03:44:35 pm »
I don't think you can capture the handle during control creation, possibly during window creation.

Indeed, I should have taken care about that.


But you don't need to; you can use 'inherited' to handle the original procedure without capturing it.
...

There is some visibility isse.
combosample.pas(18,14) Error: There is no method in an ancestor class to be overridden: "WndProc(var TMessage):LongInt;"

WNDPROC is located in base.inc, but adding Base in the uses section does not compile.

Also, the event that I need to handle is WM_DEVICECHANGE, should it be handleable from the control itself?
« Last Edit: October 09, 2025, 03:52:55 pm by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Control '' has no parent window
« Reply #3 on: October 09, 2025, 03:53:04 pm »
WNDPROC is located in base.inc, but adding Base in the uses section does not compile.
You are not supposed to add inc files to a uses clause. They are not units.
They are part of a unit or program.

Also, WndProc is a method, it needs to be part of a TComponent or TForm. It is not standalone.
Look at the example that LeP gave you.
« Last Edit: October 09, 2025, 03:59:14 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Control '' has no parent window
« Reply #4 on: October 09, 2025, 04:00:26 pm »
Also, the event that I need to handle is WM_DEVICECHANGE, should it be handleable from the control itself?

Yes: https://learn.microsoft.com/en-us/windows/win32/devio/wm-devicechange

Result TRUE to grant the request.

Result BROADCAST_QUERY_DENY to deny the request.


Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1566
    • Lebeau Software
Re: Control '' has no parent window
« Reply #5 on: October 09, 2025, 06:11:34 pm »
I am trying to handle Windows events in a custom control.
When I place the control on a form I get Control '' has no parent window.

That is because you are trying to access Self.Handle in your constructor before a Parent has been assigned. A child control cannot create its HWND without a parent window.

I suppose that is the form on which the control is located, which should handle the event, but I have to link it somehow.

That is not necessary.  Any HWND can be registered via RegisterDeviceNotification() to receive WM_DEVICECHANGE messages.

In any case, you don't need to subclass the control's HWND directly. UI controls already handle that for you. Simply override the inherited WndProc() method instead. And you can override the inherited CreateWnd() method to know when your control's HWND is ready for use.

Try this instead:

Code: Pascal  [Select][+][-]
  1. type
  2.   TComboSample = class(TCustomComboBox)
  3.   protected
  4.     {$ifdef windows}
  5.     FDevNotify: HDEVNOTIFY;
  6.     procedure CreateWnd; override;
  7.     procedure DestroyWnd; override;
  8.     procedure WndProc(var Message: TMessage); override;
  9.     {$endif}
  10.   end;
  11.  
  12. {$ifdef windows}
  13. procedure TComboSample.CreateWnd;
  14. begin
  15.   inherited;
  16.   FDevNotify := RegisterDeviceNotification(Self.Handle, ...);
  17. end;
  18.  
  19. procedure TComboSample.DestroyWnd;
  20. begin
  21.   if (FDevNotify <> 0) then
  22.   begin
  23.     UnregisterDeviceNotification(FDevNotify);
  24.     FDevNotify := 0;
  25.   end;
  26.   inherited;
  27. end;
  28.  
  29. procedure TComboSample.WndProc(var Message: TMessage);
  30. begin
  31.   inherited;
  32.   if (Message.Msg = WM_DEVICECHANGE) then
  33.     WMPnPDeviceChange(Message);
  34. end;
  35. {$endif}
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

CM630

  • Hero Member
  • *****
  • Posts: 1527
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Control '' has no parent window
« Reply #6 on: October 09, 2025, 09:04:39 pm »
...Try this instead...

So I added jwaWinUser in Uses.
Then I added
Code: Pascal  [Select][+][-]
  1. const
  2.   WM_DEVICECHANGE = $0219;
  3.   DBT_DEVNODES_CHANGED = $0007;  
Then I changed
Code: Pascal  [Select][+][-]
  1. procedure TComboSample.DestroyWnd;
  2. begin
  3.   if (FDevNotify <> 0) then
  4.   begin
  5.     UnregisterDeviceNotification(FDevNotify);
  6.     FDevNotify := 0;

to
Code: Pascal  [Select][+][-]
  1. procedure TComboSample.DestroyWnd;
  2. begin
  3.   if (FDevNotify <> nil) then
  4.   begin
  5.     UnregisterDeviceNotification(FDevNotify);
  6.     FDevNotify := nil;

So
Code: Pascal  [Select][+][-]
  1. procedure TComboSample.CreateWnd;
  2. begin
  3.   inherited;
  4.   FDevNotify := RegisterDeviceNotification(Self.Handle, @Hello,WM_DEVICECHANGE);
  5. end;  
does not run, again Control '' has no parent window on inherited;.

I removed inherited;, but I get stack overflow.


Here is what I got:
Code: Pascal  [Select][+][-]
  1. unit CustomComboBox;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   Windows, jwaWinUser, messages;
  10.  
  11. type
  12.   TComboSample = class(tCustomComboBox)
  13.   private
  14.     fPnP_DevNodeChange : boolean;
  15.     fPnP_Removal : boolean;
  16.     fTestProperty: boolean;
  17.   protected
  18.     {$ifdef windows}
  19.     FDevNotify: HDEVNOTIFY;
  20.     procedure CreateWnd; override;
  21.     procedure DestroyWnd; override;
  22.     procedure WndProc(var Message: TMessage); override;
  23.     procedure WMPnPDeviceChange(var Message: TMessage);
  24.     {$endif}
  25.   public
  26.     constructor Create (aOwner: TComponent); override;
  27.   published
  28.     property TestProperty: boolean read fTestProperty write fTestProperty ;
  29.  
  30.   end;
  31.  
  32. const
  33.   WM_DEVICECHANGE = $0219;
  34.   DBT_DEVNODES_CHANGED = $0007;
  35.  
  36. procedure Register;
  37.  
  38. implementation
  39.  
  40.  
  41. procedure Hello;
  42. begin
  43.   ShowMessage ('hello');
  44. end;
  45.  
  46. {$ifdef windows}
  47. procedure TComboSample.CreateWnd;
  48. begin
  49. //  inherited;
  50.   FDevNotify := RegisterDeviceNotification(Self.Handle, @Hello,WM_DEVICECHANGE);
  51. end;
  52.  
  53. procedure TComboSample.DestroyWnd;
  54. begin
  55.   if (FDevNotify <> nil) then
  56.   begin
  57.     UnregisterDeviceNotification(FDevNotify);
  58.     FDevNotify := nil;
  59.   end;
  60.   inherited;
  61. end;
  62.  
  63. procedure TComboSample.WMPnPDeviceChange(var Message: TMessage);
  64. begin
  65.   if (Message.WParam = DBT_DEVNODES_CHANGED) then
  66.   begin
  67.     fPnP_DevNodeChange := true;
  68.     fPnP_Removal := false;
  69.   end;
  70. end;
  71.  
  72. procedure TComboSample.WndProc(var Message: TMessage);
  73. begin
  74.   inherited;
  75.   if (Message.Msg = WM_DEVICECHANGE) then
  76.     WMPnPDeviceChange(Message);
  77. end;
  78. {$endif}
  79.  
  80. constructor TComboSample.Create (aOwner: TComponent);
  81. begin
  82.   inherited;
  83.   {if HasParent then }CreateWnd;
  84.   ShowMessage ('Created');
  85. end;
  86.  
  87. procedure Register;
  88. begin
  89.   RegisterComponents('Additional',[TComboSample]);
  90. end;
  91.  
  92. end.


Still, why the HEX the control is created before its parent  >:(


compile.
You are not supposed to add inc files to a uses clause. They are not units.
They are part of a unit or program.
...
Still override; does not compile.
« Last Edit: October 09, 2025, 09:07:16 pm by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

jamie

  • Hero Member
  • *****
  • Posts: 7317
Re: Control '' has no parent window
« Reply #7 on: October 09, 2025, 11:21:15 pm »
Hmm
Although I never thought of registering the window but try this in any case.
Try this.
The only true wisdom is knowing you know nothing

CM630

  • Hero Member
  • *****
  • Posts: 1527
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Control '' has no parent window
« Reply #8 on: October 10, 2025, 08:02:14 am »
Thanks, your sample app mostly works (for example, on connecting/disconnecting my camera, all I get is Msg.wParam = 7, not a problem, anyway), at least it detects when a device is attached/detached with some small modification.
But still, I could not make it work in a component.
I added msghook.pas to the package.
But when I did:

Code: Pascal  [Select][+][-]
  1. constructor TComboSample.Create (aOwner: TComponent);
  2. begin
  3.   inherited;
  4.   {You have a choice, Single inputs or array input }
  5.   AddMsg(Self, WM_DeviceChange);
  6.   AddMsg(Self,WM_SIZING);
  7.   AddMsg(Self, WM_MOVING);
  8.   { or Just this one line that defaults to afmNone for Exit action}
  9.   AddMsgs(Self,[WM_DEVICECHANGE,WM_SIZING,WM_MOVING]);
  10.   {Messages won't duplicate}
  11. end;    
I got Error: Incompatible type for arg no. 1: Got "TComboSample", expected "TCustomForm"

The definition is Function AddMsg(Aform:TCustomForm; AMSg:UINT;AReturnType:TAfmDefaultAction=afmNone):Boolean;, but I have no form (yet).
Changing Aform:TCustomForm; to Aform:TComponent; did not help, it resulted in
Function AddMsg(Aform: in all cases of Aform.Handle.
« Last Edit: October 10, 2025, 08:05:21 am by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

Thaddy

  • Hero Member
  • *****
  • Posts: 18363
  • Here stood a man who saw the Elbe and jumped it.
Re: Control '' has no parent window
« Reply #9 on: October 10, 2025, 08:21:09 am »
Please, go back to the first answer by LeP, try to understand that and only THEN complain again....
You've already got the answer.
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

CM630

  • Hero Member
  • *****
  • Posts: 1527
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Control '' has no parent window
« Reply #10 on: October 10, 2025, 08:50:36 am »
Going back to the first post by @LeP:
1.     function WndProc(var Message: TMessage): Integer; override;
Override does not compile, possibly because the routine to be overridden is a procedure, not a function.
2. After removing the override; from the code:
Result := inherited WndProc(Message); // call original function does not compile.
Quote
Error: Invalid assignment, procedures return no value
Possibly because trying to assign a procedure to an integer.


Edit: There is some progress, this handles mouse clicks, but it does not react on connecting/ disconnecting devices:

Code: Pascal  [Select][+][-]
  1. unit ComboSample;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Windows, Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.    Lcl, msghook;
  10.  
  11. type
  12.   TComboSample = class(tcustomcombobox)
  13.   protected
  14.     procedure CreateWnd; override;
  15.     procedure WndProc(var Message: TMessage); override;
  16.   public
  17.     constructor Create (aOwner: TComponent); override;
  18.   published
  19.  
  20.   end;
  21.  
  22. procedure Register;
  23.  
  24. implementation
  25.  
  26. constructor TComboSample.Create (aOwner: TComponent);
  27. begin
  28.   inherited;
  29.   //CreateWnd;
  30. end;
  31.  
  32. procedure TComboSample.CreateWnd;
  33. begin
  34.   inherited CreateWnd;
  35. end;
  36.  
  37. procedure TComboSample.WndProc(var Message: TMessage);
  38. begin
  39.   writeln (IntToStr(Message.Msg));
  40.   case Message.Msg of
  41.     WM_LBUTTONDOWN: begin ShowMessage('Mouse Button Down!'); parent.Caption := 'WM_LBUTTONDOWN'; end;
  42.     WM_DEVICECHANGE : ShowMessage('WM_DEVICECHANGE');
  43.   else
  44.       inherited WndProc(Message); // call original function
  45.   end;
  46. end;    
  47.  
  48. procedure Register;
  49. begin
  50.   RegisterComponents('MySample',[TComboSample]);
  51. end;
  52.  
  53. end.
  54.  
« Last Edit: October 10, 2025, 10:11:37 am by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Control '' has no parent window
« Reply #11 on: October 10, 2025, 09:42:52 am »
Going back to the first post by @LeP:
1.     function WndProc(var Message: TMessage): Integer; override;
Override does not compile, possibly because the routine to be overridden is a procedure, not a function.
2. After removing the override; from the code:
Result := inherited WndProc(Message); // call original function does not compile.
Quote
Error: Invalid assignment, procedures return no value
Possibly because trying to assign a procedure to an integer.
Yes, the firms of that method is different, it's a procedure not a function.

I think that this should be the good version:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMyCustomControl = class(tcustomcombobox)
  3.     protected
  4.       procedure CreateWnd; override;
  5.       procedure WndProc(var Message: TMessage); override;
  6.   end;
  7.  
  8. //Here you can do something
  9. procedure TMyCustomControl.CreateWnd;
  10. begin
  11.   inherited CreateWnd;
  12. end;
  13.  
  14. //EDIT: pairing with definition
  15.  
  16. procedure TMyCustomControl.WndProc(var Message: TMessage);
  17. begin
  18.   case Message.Msg of
  19.     WM_DEVICECHANGE: //for example
  20.       begin
  21.         writeln('DEVICE Change message: ', Message.wparam);
  22.         Message.Result := 0; // Messagge handled.
  23.       end;
  24.     else
  25.       inherited WndProc(Message); // call original function
  26.   end;
  27. end;

It's not necessary to regsiter the notify. But if you want to do you don't have to act like you do, those are the step (forget the previous):

I have not tested them, only catch and adapt form very old code.
Code: Pascal  [Select][+][-]
  1. type
  2. TMyCustomControl = class(tcustomcombobox)
  3.     private
  4.        procedure InitResources_1;
  5.        procedure InitResources_2;
  6.     protected
  7.       procedure CreateWnd; override;
  8.       procedure WndProcNew(var Message: TMessage);
  9.    public
  10.      destructor; Destroy; override;
  11.   end;
  12.  
  13. const
  14.  DBT_DEVTYP_DEVICEINTERFACE = $5;
  15.  DEVICE_NOTIFY_WINDOW_HANDLE = $0;
  16.  DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = $4;
  17.  //THIS IS A GUI FOR USB
  18.  GUID_DEVINTERFACE_USB_DEVICE: TGUID = '{A5DCBF10-6530-11D2-901F-00C04FB951ED}';
  19.  
  20. type
  21.   DEV_BROADCAST_HDR_DEVICE_TYPE = Cardinal;
  22.   DEV_BROADCAST_HDR = record
  23.     dbch_size: Cardinal;
  24.     dbch_devicetype: DEV_BROADCAST_HDR_DEVICE_TYPE;
  25.     dbch_reserved: Cardinal;
  26.   end;
  27.  
  28. type
  29.   DEV_BROADCAST_DEVICEINTERFACE_W = record
  30.     dbcc_size: Cardinal;
  31.     dbcc_devicetype: Cardinal;
  32.     dbcc_reserved: Cardinal;
  33.     dbcc_classguid: TGuid;
  34.     dbcc_name: array[0..0] of AnsiChar;
  35.   end;
  36.  
  37. var _dev: Dev_Broadcast_DeviceInterface_W;
  38.  
  39. var DevBlockRem: DEV_BROADCAST_HDR;
  40.     FDevNotify: HDEVNOTIFY;
  41.     NewHandle: HWND;
  42.  
  43.  
  44. procedure TMyCustomControl.CreateWnd;
  45. begin
  46.   inherited CreateWnd;
  47.   //These two calls are equivalent like the have constructed here
  48.   //USE ONLY ONE OF THEM !!!
  49.   //Call this if you want define some type of resources, see documentation
  50.   InitResources_1;
  51.   //Call this if you want define Hardware resources
  52.   //InitResources_2;
  53. end;
  54.  
  55. procedure TMyCustomControl.InitResources_1;
  56. begin
  57.   NewHandle:=AllocateHwnd(WndProcNew);
  58.   ZeroMemory(@_dev, sizeOf(Dev_Broadcast_DeviceInterface_W));
  59.   with _dev do
  60.     begin
  61.       dbcc_size:=sizeOf(Dev_Broadcast_DeviceInterface_W);
  62.       dbcc_devicetype:= DBT_DEVTYP_DEVICEINTERFACE;
  63.       dbcc_reserved:=0;
  64.       dbcc_classguid:= GUID_DEVINTERFACE_USB_DEVICE;
  65.       dbcc_name:=chr(0);
  66.     end;
  67.   //Use "DEVICE_NOTIFY_ALL_INTERFACE_CLASSES" if you want catch all messages from all classes (ignore dbcc_classguid)
  68.   FDevNotify:=RegisterDeviceNotification(NewHandle, @_dev, DEVICE_NOTIFY_WINDOW_HANDLE or DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
  69.   Win32Check(FDevNotify <> nil);
  70. end;
  71.  
  72. procedure TMyCustomControl.InitResources_2;
  73. begin
  74.   NewHandle := AllocateHWnd(WndProcNew);
  75.   ZeroMemory(@DevBlockRem, sizeOf(DevBlockRem));
  76.   DevBlockRem.dbch_size := sizeof(DEV_BROADCAST_HDR)+sizeof(DEV_BROADCAST_DEVICEINTERFACE_W);
  77.   DevBlockRem.dbch_devicetype := DBT_DEVTYP_DEVICEINTERFACE;
  78.   DevBlockRem.dbch_reserved := 0;
  79.   FDevNotify := nil;
  80.   FDevNotify :=  RegisterDeviceNotification(NewHandle, @DevBlockRem, DEVICE_NOTIFY_WINDOW_HANDLE or DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
  81.   Win32Check(FDevNotify <> nil);
  82. end;
  83.  
  84. destructor TMyCustomControl.Destroy;
  85. begin
  86.   if FDevNotify <> nil then
  87.     UnregisterDeviceNotification(FDevNotify);
  88.  
  89.   inherited;
  90. end;
  91.  
  92. procedure TMyCustomControl.WndProcNew(var Message: TMessage);
  93. begin
  94.   case Message.Msg of
  95.     WM_DEVICECHANGE: //for example
  96.       begin
  97.         writeln(Message.WParam);
  98.         //Message.Result := 0; // Messagge handled
  99.       end;
  100.   end;
  101. end;
  102.  
« Last Edit: October 10, 2025, 02:33:04 pm by LeP »

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Control '' has no parent window
« Reply #12 on: October 10, 2025, 09:50:39 am »
Please, go back to the first answer by LeP, try to understand that and only THEN complain again....
You've already got the answer.

Sorry @Thaddy but I was wrong with WndProc, It's been a long time since I used this mode to "capture" Windows messages (probably back in the Windows XP days).

CM630

  • Hero Member
  • *****
  • Posts: 1527
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Control '' has no parent window
« Reply #13 on: October 10, 2025, 10:10:45 am »
Thanks, I suppose you have not seen the edit of my previous post.
I think the first snippet from your post will not compile, one definition of WndProc is a procedure, but still, the other one is a function.

If you take a look at my previous post:

Code: Pascal  [Select][+][-]
  1. ...
  2. procedure TComboSample.WndProc(var Message: TMessage);
  3. begin
  4.   writeln (IntToStr(Message.Msg));
  5.   case Message.Msg of
  6.     WM_LBUTTONDOWN: begin ShowMessage('Mouse Button Down!'); parent.Caption := 'WM_LBUTTONDOWN'; end;
  7.     WM_DEVICECHANGE : ShowMessage('WM_DEVICECHANGE');
  8.   else
  9.       inherited WndProc(Message); // call original function
  10.   end;
  11. end;  
  12. ...  
There is output from  writeln (IntToStr(Message.Msg)); only when I am doing something with the control (mouse, keyboard...)
Nothing happens when I unplug and replug devices in the PC.


I have not looked at the second snippet in your last post, yet.

EDIT:
I tried it,  NewHandle:=AllocateHwnd(WndProcNew);   does not compile (Error: Wrong number of parameters specified for call to "WndProcNew").
« Last Edit: October 10, 2025, 12:39:44 pm by CM630 »
Лазар 4,2 32 bit (sometimes 64 bit); FPC3,2,2

LeP

  • Jr. Member
  • **
  • Posts: 57
Re: Control '' has no parent window
« Reply #14 on: October 10, 2025, 02:44:54 pm »
@CM630, in the first example the implementation was wrong of course should be pair with declaration ... I modified it.

This time I tried it, with Lazarus and Delphi, and while in Delphi the messages are present, in Lazaru not.
I tried also with FORM1 (instead of MyCustom...).

Now I will try with the second sample.


 

TinyPortal © 2005-2018