* * *

Author Topic: Is there a control like TGraphicControl with Handle ?  (Read 631 times)

sainimu78

  • Full Member
  • ***
  • Posts: 100
Is there a control like TGraphicControl with Handle ?
« on: February 03, 2018, 06:19:06 am »
On windows the Handle is a HWND.

I create a gl render context using a third party library. It is ok with TWinControl.Handle, but TWinControl will erase my painted context because DoubleBuffered = False doesn't work when the globel var ThemeService with ThemeEnabled, here is the code lazarus\lcl\interfaces\win32\win32callback.inc, SendPaintMessage
Code: Pascal  [Select]
  1.   // check if double buffering is requested
  2.   useDoubleBuffer := (ControlDC = 0) and (lWinControl.DoubleBuffered or ThemeServices.ThemesEnabled);
  3.  

I can use TGraphicControl to paint completely by myself,  but it has no Handle.
« Last Edit: February 03, 2018, 06:25:28 am by sainimu78 »

Thaddy

  • Hero Member
  • *****
  • Posts: 5393
Re: Is there a control like TGraphicControl with Handle ?
« Reply #1 on: February 03, 2018, 09:13:34 am »
TOpenGLCanvas maybe?
High(Methusalem) - 1;

sainimu78

  • Full Member
  • ***
  • Posts: 100
Re: Is there a control like TGraphicControl with Handle ?
« Reply #2 on: February 03, 2018, 11:36:41 am »
TOpenGLCanvas maybe?

Not just support gl in my case.
I want a control of LCL that has Handle and can be painted completely by myself.

I know how TOpenGLCanvas works, maybe I can modify it to meet my reqirement, but I rather use LCL because LCL has an official team supporting.

I add a Boolean switch UseWinControlCustomPaint to TWinControl
Is this good ? Will I make a feature request with the patch to bugtracker?

in lazarus\lcl\interfaces\win32\win32callback.inc, SendPaintMessage,
Code: Pascal  [Select]
  1.   if(ControlDC = 0)and(lWinControl.UseWinControlCustomPaint = True)then
  2.   begin
  3.     DC := Windows.BeginPaint(Window, @PS);
  4.     PaintMsg.Msg := LM_PAINT;
  5.     PaintMsg.PaintStruct := @PS;
  6.     PaintMsg.DC := DC;
  7.     DeliverMessage(lWinControl, PaintMsg);
  8.     Windows.EndPaint(Window, @PS);
  9.     Exit;
  10.   end;
  11.  
« Last Edit: February 04, 2018, 07:46:31 am by sainimu78 »

Thaddy

  • Hero Member
  • *****
  • Posts: 5393
Re: Is there a control like TGraphicControl with Handle ?
« Reply #3 on: February 03, 2018, 11:43:31 am »
You really want to mix two completely different paint engines? (GDI and OGL) Then simply assign the OpenGLCanvas to the window where you need it. Under Windows that has a THandle/Hwnd.
High(Methusalem) - 1;

sainimu78

  • Full Member
  • ***
  • Posts: 100
Re: Is there a control like TGraphicControl with Handle ?
« Reply #4 on: February 03, 2018, 12:26:31 pm »
You really want to mix two completely different paint engines? (GDI and OGL) Then simply assign the OpenGLCanvas to the window where you need it. Under Windows that has a THandle/Hwnd.
You mean TOpenGLControl instead ?
Oh no, it desn't sound so easy, I think I should override so many functions of it.

So no such control in LCL, maybe I should commit the patch and see what they say.

Thaddy

  • Hero Member
  • *****
  • Posts: 5393
Re: Is there a control like TGraphicControl with Handle ?
« Reply #5 on: February 03, 2018, 12:45:41 pm »
I really do not see where you have to override anything? Really?! :o %) Of course not.
Show us some code?
BTW: SDL can also play accelerated in a window, may be that's an option for you.
« Last Edit: February 03, 2018, 12:53:54 pm by Thaddy »
High(Methusalem) - 1;

sainimu78

  • Full Member
  • ***
  • Posts: 100
Re: Is there a control like TGraphicControl with Handle ?
« Reply #6 on: February 03, 2018, 03:44:33 pm »
You'r right, there is nothing to be overridden, but it works not expectly, triggering 3 times OnResize on showing up. I should override SetBounds

I simply want to create native windows and native controls and do message loop, SDL is not enough.
« Last Edit: February 04, 2018, 07:40:02 am by sainimu78 »

jamie

  • Sr. Member
  • ****
  • Posts: 430
Re: Is there a control like TGraphicControl with Handle ?
« Reply #7 on: February 03, 2018, 05:39:39 pm »
Have you looked at the TCustomControl?

 You can create your own TWinControl and handle a lot of the messaging.

sainimu78

  • Full Member
  • ***
  • Posts: 100
Re: Is there a control like TGraphicControl with Handle ?
« Reply #8 on: February 04, 2018, 05:19:40 am »
Have you looked at the TCustomControl?

 You can create your own TWinControl and handle a lot of the messaging.

Year, it is almost the same as TWinControl in my case and it will erase my painted context too due to double buffering in SendPaintMessage

jamie

  • Sr. Member
  • ****
  • Posts: 430
Re: Is there a control like TGraphicControl with Handle ?
« Reply #9 on: February 04, 2018, 04:03:10 pm »
You need to override the paint handler, its that simple..

Return it as handled to the OS so it does not attempt any more processing..

As for the WM_ERASEBKKGRD you can handle that too, just add a message handler for it and
return it as handled, don't be calling any inherited methods..

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus