CtrlCore: In win32, HTHEME handles now are released sometimes (should fix issue with invalid ones after running 3D game)

This commit is contained in:
Mirek Fidler 2022-10-20 23:27:56 +02:00
parent f484b64c19
commit f99915f112
2 changed files with 31 additions and 2 deletions

View file

@ -8,6 +8,8 @@
namespace Upp {
void XpClear(); // Clear cached windows theme handles
#define LLOG(x) // DLOG(x)
dword Ctrl::KEYtoK(dword chr) {
@ -528,7 +530,7 @@ LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
if(owner && (owner->IsForeground() || IsForeground()) && !owner->SetWantFocus())
IterateFocusForward(owner, owner);
}
if(IsWindowUnicode(hwnd)) // TRC 04/10/17: ActiveX unicode patch
if(IsWindowUnicode(hwnd))
DefWindowProcW(hwnd, message, wParam, lParam);
else
DefWindowProc(hwnd, message, wParam, lParam);
@ -590,6 +592,8 @@ LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
case WM_ACTIVATE:
LLOG("WM_ACTIVATE " << Name() << ", wParam = " << (int)wParam << ", focusCtrlWnd = " << UPP::Name(focusCtrlWnd) << ", raw = " << (void *)::GetFocus());
ignorekeyup = true;
case 0x031A: // WM_THEMECHANGED
XpClear();
break;
case WM_SETFOCUS:
LLOG("WM_SETFOCUS " << Name() << ", focusCtrlWnd = " << UPP::Name(focusCtrlWnd) << ", raw = " << (void *)::GetFocus());

View file

@ -1,5 +1,7 @@
#include "CtrlLib.h"
// #define STATIC_IMAGES // avoids calling theming API while app is running - probably wrong path
#ifdef GUI_WIN
#define LLOG(x) // RLOG(x)
@ -63,7 +65,11 @@ static VectorMap<XpElement, int> xp_opaque;
void XpClear()
{
memset(xp_widget_handle, 0, sizeof(xp_widget_handle));
for(int i = 0; i < XP_COUNT; i++)
if(xp_widget_handle[i]) {
XpTheme().CloseThemeData(xp_widget_handle[i]);
xp_widget_handle[i] = NULL;
}
xp_margin.Clear();
xp_opaque.Clear();
}
@ -210,6 +216,7 @@ struct Win32ImageMaker : ImageMaker {
}
};
#ifndef STATIC_IMAGES
Value XpLookFn(Draw& w, const Rect& rect, const Value& v, int op, Color)
{
if(IsTypeRaw<XpElement>(v)) {
@ -271,6 +278,7 @@ Value XpLookFn(Draw& w, const Rect& rect, const Value& v, int op, Color)
}
return Null;
}
#endif
struct chCtrlsImg {
int id;
@ -297,7 +305,22 @@ void Win32Look(Value *ch, int count, int widget, int part, int state = 1, bool c
e.part = part;
e.state = state + i;
e.contentm = contentm;
#ifdef STATIC_IMAGES
Image m = XpImage(widget, part, state + i);
int hotspot;
if(contentm) {
Rect r(0, 0, 100, 100);
Rect cr;
HANDLE htheme = XpWidget(widget);
XpTheme().GetThemeBackgroundContentRect(htheme, NULL, e.part, e.state, r, cr);
hotspot = cr.left;
}
else
hotspot = XpMargin(e);
ch[i] = WithHotSpot(m, hotspot, hotspot);
#else
ch[i] = RawToValue(e);
#endif
}
}
@ -441,7 +464,9 @@ void ChHostSkin()
}
else SColorDisabled_Write(Color(0x80, 0x80, 0x80));
#ifndef STATIC_IMAGES
ChLookFn(XpLookFn);
#endif
if(XpWidget(XP_BUTTON)) {
GUI_GlobalStyle_Write(GUISTYLE_XP);