Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid a crash if GdiPlus is not initialized #309

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

WeberAndre
Copy link

@WeberAndre WeberAndre commented Oct 19, 2023

  1. If GdiPlus is not initialized in GetIcon a GDI Plus exception is raised. If this happends inside a detour function this leads to a serious crash of the whole application.

  2. Fix DrawStyleParentBackgroundEx wrong portion of background used
    DrawStyleParentBackgroundEx used the coordinates of the parentwindow (LPoint) to copy from LBuffer device context, thats wrong to copy from the bitmap dc the source position must be 0, 0. For the WM_ERASEBKGND you must change the Origin of the bitmap devicecontext so that the right part of the background is painted into to bitmap.

(DrawStyleParentBackground may be removed later, because its complete wrong and doesn't paint anything to DC !)

  1. For Menus with OwnerDraw we don't get a ItemText, this is also the case for the history drop down of the FileOpen / FileSave dialog. This patch tries to delegate ownerdraw back to the owner windows of the menu - in case of the file dialogs it works.

  2. Detour_UxTheme_GetThemeColor: Reorganized code instead that every TMT_TEXTCOLOR is answered with clWindowText. First give a try to each case if this doesn't set the pColor to something different as clNone - stay at clWindowText. For VSCLASS_MENU we get ask for the TMT_TEXTCOLOR and for the TMT_FILLCOLOR of the same state.

Replaced calls to DrawStyleParentBackground with DrawStyleParentBackgroundEx after fixing it. -> this also fixes drawing issues with TButton in Designmode.

UxTheme_Button: Reverted the drawing on a temporary bitmap with a simple transparent color - because the fill and transparentcolor clBtnFace is also the color used of some style to draw the button surface .. which becomes in that case transparent and not visible.
If the button itself has rounded corners - these are drawn with semitransparency in the StyleService - so if a temporary bitmap is used it must be set to pf32bit with AlphaFormat instead of a transparent color.
After replacing not working DrawStyleParentBackGround with my modifed DrawStyleParentBackgroundEx it seems to work.

If GdiPlus is not initialized in GetIcon a GDI Plus exception is raised. If this happends inside a detour function this leads to a serious crash.
DrawStyleParentBackgroundEx used the coordinates of the parentwindow (LPoint) to copy from LBuffer device context, thats wrong to copy from the bitmap dc the source position must be 0, 0.  For the WM_ERASEBKGND you must change the Origin of the bitmap devicecontext so that the right part of the background is painted into to bitmap.

(DrawStyleParentBackground may be removed later, because its complete wrong and doesn't paint anything to DC !)
…ialog

For Menus with OwnerDraw we don't get a ItemText, this is also the case for the history drop down of the FileOpen / FileSave dialog. This patch tries to delegate ownerdraw back to the owner windows of the menu - in case of the file dialogs it works.
…r align popup

Detour_UxTheme_GetThemeColor: Reorganized code instead that every TMT_TEXTCOLOR is answered with clWindowText. First give a try to each case if this doesn't set the pColor to something different as clNone - stay at clWindowText. For VSCLASS_MENU we get ask for the TMT_TEXTCOLOR and for the TMT_FILLCOLOR of the same state.

Replaced calls to DrawStyleParentBackground with DrawStyleParentBackgroundEx after fixing it. -> this also fixes drawing issues with TButton in Designmode.

UxTheme_Button: Reverted the drawing on a temporary bitmap with a simple transparent color - because the fill and transparentcolor clBtnFace is also the color used of some style to draw the button surface .. which becomes in that case transparent and not visible.
If the button itself has rounded corners - these are drawn with semitransparency in the StyleService - so if a temporary bitmap is used it must be set to pf32bit with AlphaFormat instead of a transparent color.
After replacing not working DrawStyleParentBackGround with my modifed DrawStyleParentBackgroundEx it seems to work.
…ylesBrush

Resolving a problem using a GetSysColorBrush as hbrBackground in RegisterClass. The detour created HBRUSH will be destroyed by windows in UnregisterClass and leave a invalid HBRUSH in VCLStylesBrush dictionary.  So the next call to GetSysColorBrush will return a invalid HBRUSH.
(problem occured useing TWAIN driver written with QT Library)
This reverts commit 37875ab, reversing
changes made to 9a75a2e.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant