uligerhardt 18 Posted November 20, 2020 Hello! I want to show a MessageBox from inside a TL21_.OnViewerButtonClicked event handler and need the window handle of the preview form for that. Any idea how to get there? Share this post Link to post
FPiette 385 Posted November 20, 2020 23 minutes ago, uligerhardt said: TL21_ What is it? Share this post Link to post
Remy Lebeau 1436 Posted November 20, 2020 I don't know what kind of control "TL21_" is supposed to refer to, but if it does not expose access to its HWND, one option would be to use a thread-local WH_CBT hook via the Win32 SetWindowsHookEx() function to receive notifications of every HWND that is created by the thread. For instance, set the hook just before displaying the preview Form, and then release the hook after the Form is ready/closed. Then you will know every HWND that the preview creates. Share this post Link to post
Guest Posted November 22, 2020 (edited) On 11/20/2020 at 12:04 PM, uligerhardt said: Hello! I want to show a MessageBox from inside a TL21_.OnViewerButtonClicked event handler and need the window handle of the preview form for that. Any idea how to get there? The List & Label report generator extends your application with extensive and convenient print, export and preview functions. You remain independent of programming languages and database formats. You retain control over data transfer and create the interface. did see this: https://www.combit.com/ https://forum.combit.net/t/programmatically-close-the-preview-window/2018 if possible, post your code for help us! Edited November 22, 2020 by Guest Share this post Link to post
uligerhardt 18 Posted November 23, 2020 (edited) On 11/20/2020 at 4:27 PM, FPiette said: What is it? Sorry, forgot to mention it in the message body. It's the List&Label report component. Edited November 23, 2020 by uligerhardt Share this post Link to post
uligerhardt 18 Posted November 23, 2020 Here is the relevant code, a bit condensed: type TPrintLLReportEventHandler = class public procedure OnViewerButtonClicked(Sender: TObject; Button: TViewerButton; var PerformDefaultAction: Boolean); end; { TPrintLLReportEventHandler } procedure TPrintLLReportEventHandler.OnViewerButtonClicked(Sender: TObject; Button: TViewerButton; var PerformDefaultAction: Boolean); begin if Button = vbExit then begin MessageBox(AWnd, .....); // <= I'd like to get the preview form's window handle here for AWnd end; end; var evh: TPrintLLReportEventHandler; evh := TPrintLLReportEventHandler.Create; try MyLLReportInstance.OnViewerButtonClicked := evh.OnViewerButtonClicked; // Show preview here (using LL_PRINT_PREVIEW) finally evh.Free; end; Share this post Link to post
Remy Lebeau 1436 Posted November 23, 2020 Did you try the WH_CBT hook, like I suggested? For example: uses ..., Windows; type TPrintLLReportEventHandler = class private FHook: HHOOK; public constructor Create; destructor Destroy; override; procedure OnViewerButtonClicked(Sender: TObject; Button: TViewerButton; var PerformDefaultAction: Boolean); end; { TPrintLLReportEventHandler } var gPrintReportWnd: HWND = 0; function CBTProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin if nCode = HCBT_ACTIVATE then begin if gPrintReportWnd = 0 then gPrintReportWnd := HWND(wParam); end; Result := CallNextHookEx(0, nCode, wParam, lParam); end; constructor TPrintLLReportEventHandler.Create; begin inherited; gPrintReportWnd := 0; FHook := SetWindowsHookEx(WH_CBT, @CBTProc, HInstance, GetCurrentThreadId); end; destructor TPrintLLReportEventHandler.Destroy; begin if FHook <> 0 then UnhookWindowsHookEx(FHook); gPrintReportWnd := 0; inherited; end; procedure TPrintLLReportEventHandler.OnViewerButtonClicked(Sender: TObject; Button: TViewerButton; var PerformDefaultAction: Boolean); begin if Button = vbExit then begin MessageBox(gPrintReportWnd, ...); end; end; var evh: TPrintLLReportEventHandler; begin evh := TPrintLLReportEventHandler.Create; try MyLLReportInstance.OnViewerButtonClicked := evh.OnViewerButtonClicked; // Show preview here (using LL_PRINT_PREVIEW) finally evh.Free; end; end; Share this post Link to post
uligerhardt 18 Posted November 24, 2020 13 hours ago, Remy Lebeau said: Did you try the WH_CBT hook, like I suggested? For example: uses ..., Windows; type TPrintLLReportEventHandler = class private FHook: HHOOK; public constructor Create; destructor Destroy; override; procedure OnViewerButtonClicked(Sender: TObject; Button: TViewerButton; var PerformDefaultAction: Boolean); end; { TPrintLLReportEventHandler } var gPrintReportWnd: HWND = 0; function CBTProc(nCode: Integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin if nCode = HCBT_ACTIVATE then begin if gPrintReportWnd = 0 then gPrintReportWnd := HWND(wParam); end; Result := CallNextHookEx(0, nCode, wParam, lParam); end; constructor TPrintLLReportEventHandler.Create; begin inherited; gPrintReportWnd := 0; FHook := SetWindowsHookEx(WH_CBT, @CBTProc, HInstance, GetCurrentThreadId); end; destructor TPrintLLReportEventHandler.Destroy; begin if FHook <> 0 then UnhookWindowsHookEx(FHook); gPrintReportWnd := 0; inherited; end; procedure TPrintLLReportEventHandler.OnViewerButtonClicked(Sender: TObject; Button: TViewerButton; var PerformDefaultAction: Boolean); begin if Button = vbExit then begin MessageBox(gPrintReportWnd, ...); end; end; var evh: TPrintLLReportEventHandler; begin evh := TPrintLLReportEventHandler.Create; try MyLLReportInstance.OnViewerButtonClicked := evh.OnViewerButtonClicked; // Show preview here (using LL_PRINT_PREVIEW) finally evh.Free; end; end; I tried it just now, and it works AFAICT - I used GetWindowText(gPrintReportWnd, ...) to verify. Thanks a lot. Share this post Link to post