Recent

Author Topic: Controls inside the form disappear in execution.  (Read 8296 times)

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Controls inside the form disappear in execution.
« Reply #45 on: January 28, 2023, 07:45:04 pm »
Thank you, jamie, it works. But when there are many child controls, redrawing is noticeable...

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Controls inside the form disappear in execution.
« Reply #46 on: January 28, 2023, 08:59:08 pm »
Always or just switching the complete form out of scope?



The only true wisdom is knowing you know nothing

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Controls inside the form disappear in execution.
« Reply #47 on: January 28, 2023, 09:14:04 pm »
Switching the complete form out of scope.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Controls inside the form disappear in execution.
« Reply #48 on: January 28, 2023, 09:23:40 pm »
Ok, I don't think there much about that can done about that, unless someone wants to narrow is down to only take place with a Groupbox but I think that would be stupid.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Controls inside the form disappear in execution.
« Reply #49 on: January 28, 2023, 11:19:59 pm »
Ok, I have added a message to the GroupBox message handler.
In file "Win32WSStdCtrls"
Code: Pascal  [Select][+][-]
  1. function GroupBoxWindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
  2.     LParam: Windows.LParam): LResult; stdcall;
  3. var
  4.   Info: PWin32WindowInfo;
  5.   DC: HDC;
  6.   Flags: Cardinal;
  7.   ARect: TRect;
  8.   WideBuffer: WideString;
  9.   GroupBox: TCustomGroupBox;
  10. begin
  11.   // move groupbox specific code here
  12.   case Msg of
  13.     WM_NCHITTEST:
  14.       begin
  15.         Result := HTCLIENT;
  16.         Exit;
  17.       end;
  18.     WM_ENABLE:
  19.       begin
  20.         Result := WindowProc(Window, Msg, WParam, LParam);
  21.         // if it is groupbox and themed app then invalidate it on enable change
  22.         // to redraw graphic controls on it (issue 0007877)
  23.         if ThemeServices.ThemesAvailable then
  24.           InvalidateRect(Window, nil, True);
  25.          Exit;
  26.       end;
  27.     WM_KILLFOCUS: InvalidateRect(Window,Nil,false);//Jp;
  28.     WM_PAINT:                                  
  29.  

There seems to be a Focus issue with the group box, personnaly, I didn't know a group box received focus.?
 Please try that where "Jp" is marked in comments, just insert that message handler.

EDIT:
 I just noticed that also, there is a problem with WM_SETFOCUS.
 basically the same thing happens if the Groupbox was in focus and then you restore it from another form. So I think the WM_ SETFOCUS will also be required in this addition.
« Last Edit: January 28, 2023, 11:24:57 pm by jamie »
The only true wisdom is knowing you know nothing

balazsszekely

  • Guest
Re: Controls inside the form disappear in execution.
« Reply #50 on: January 29, 2023, 06:32:14 pm »
@jamie
Your changes definitely helps. I also see flickering, but it's much better then controls disappearing.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Controls inside the form disappear in execution.
« Reply #51 on: January 29, 2023, 06:52:22 pm »
Well, until someone can explain why the groupbox is allowed to receive focus which delphi apparently doesn't do, I guess I can finalize my changes to the local copies and call it a day.

 Btw, it is the groupbox getting focus which is causing the issue.

 Maybe base LCL should not allow this because in the end, you cannot capture the keystrokes from any Wincontrol that may have focus within the groupbox.


The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: Controls inside the form disappear in execution.
« Reply #52 on: January 29, 2023, 07:34:42 pm »
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.

« Last Edit: January 29, 2023, 07:47:16 pm by jamie »
The only true wisdom is knowing you know nothing

balazsszekely

  • Guest
Re: Controls inside the form disappear in execution.
« Reply #53 on: January 30, 2023, 07:45:54 am »
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.
Apparently that solves the issue, I don't see any side effects either. However modifying LCL is always tricky, needs thorough testing before it can be applied in main.

@all
Please test @jamie's changes.

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Controls inside the form disappear in execution.
« Reply #54 on: January 30, 2023, 08:22:51 am »
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.
Apparently that solves the issue, I don't see any side effects either. However modifying LCL is always tricky, needs thorough testing before it can be applied in main.

@all
Please test @jamie's changes.

I would gladly test... but using what? The original test.zip for post #1 I assume. Is there a patch or diff with the changes that need to be applied to perform the testing?
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Controls inside the form disappear in execution.
« Reply #55 on: January 30, 2023, 08:36:20 am »
It seems if though if I simply block those messages from being processed it works fine?

I also noticed the TAB operation seems to be funky, but it does not matter either way you alter the code, tabbing seems to be another abnormally.

So doing this instead of InvalidateRect...

 WM_KILLFOCUS,WM_SETFOCUS: Exit;

DO that in the same area instead and try that, it appears everything is working!?

I have not found any side effects doing this so this I will finalize instead. It seems to work.
Only difference - if WindowProc is called and what result it returns.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

balazsszekely

  • Guest
Re: Controls inside the form disappear in execution.
« Reply #56 on: January 30, 2023, 10:02:17 am »
@dsiders

Quote
I would gladly test... but using what? The original test.zip for post #1 I assume. Is there a patch or diff with the changes that need to be applied to perform the testing?
1. Download, extract then run attached project
2. Click ten times or so inside the TGroupBox, without clicking another control
3. Click a few times the taskbar(the empty part of the taskbar)
4. Click the TGroupBox again
Repeat 2 -> 4 until you see the issue. As mentioned before, there are other ways to reproduce the bug, but I found the above method the easiest.

Once you see the issue:
1. Open: $(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
2. Go to function GroupBoxWindowProc
3. Add the following lines, just before WM_PAINT:
Code: Pascal  [Select][+][-]
  1.  WM_KILLFOCUS, WM_SETFOCUS:
  2.     Exit;
  3.  
4. Rebuild IDE

The issue should be gone, hopefully without side effects.

Mr.Madguy

  • Hero Member
  • *****
  • Posts: 844
Re: Controls inside the form disappear in execution.
« Reply #57 on: January 30, 2023, 10:32:41 am »
The issue should be gone, hopefully without side effects.
Where can I find contents of GroupBox's WindowProc? I guess, DefWindowProc should be called for these messages. It is possible, that WindowProc overrides this behavior. Even if it just returns wrong result. Remember, that in most cases 0 result means processing message by application.
Is it healthy for project not to have regular stable releases?
Just for fun: Code::Blocks, GCC 13 and DOS - is it possible?

tetrastes

  • Sr. Member
  • ****
  • Posts: 473
Re: Controls inside the form disappear in execution.
« Reply #58 on: January 30, 2023, 10:54:14 am »
1. Open: $(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp
2. Go to function GroupBoxWindowProc
3. Add the following lines, just before WM_PAINT:
Code: Pascal  [Select][+][-]
  1.  WM_KILLFOCUS, WM_SETFOCUS:
  2.     Exit;
  3.  
4. Rebuild IDE

The issue should be gone, hopefully without side effects.

I am not sure in that also, as Mr.Madguy. GroupBoxWindowProc must return something. What does it return in this case?
Maybe do something like this:
Code: Pascal  [Select][+][-]
  1.     WM_NCHITTEST:
  2.       begin
  3.         Result := HTCLIENT;
  4.         Exit;
  5.       end;
  6.  
?

balazsszekely

  • Guest
Re: Controls inside the form disappear in execution.
« Reply #59 on: January 30, 2023, 11:22:14 am »
@Mr.Madguy
Quote
Where can I find contents of GroupBox's WindowProc?
$(LazarusDir)\lcl\interfaces\win32\Win32WSStdCtrls.pp


@Mr.Madguy,
Quote
I guess, DefWindowProc should be called for these messages. It is possible, that WindowProc overrides this behavior. Even if it just returns wrong result. Remember, that in most cases 0 result means processing message by application.
@tetrastes
Quote
I am not sure in that also, as Mr.Madguy. GroupBoxWindowProc must return something. What does it return in this case?

If I add CallDefaultWindowProc the issue is back:
Code: Pascal  [Select][+][-]
  1.   WM_KILLFOCUS, WM_SETFOCUS:
  2.     begin
  3.       CallDefaultWindowProc(Window, Msg, WParam, LParam);
  4.       Exit;
  5.     end;    
         
The idea is that TGroupBox should not receive message WM_SETFOCUS, WM_KILLFOCUS. I see similar solution in D. sources too, no DefWindowProc is called after WM_KILLFOCUS, just Exit;
This also works:
Code: Pascal  [Select][+][-]
  1.   WM_KILLFOCUS, WM_SETFOCUS:
  2.     begin
  3.        Result := 0;
  4.        Exit;
  5.     end;    


 

TinyPortal © 2005-2018