用了皮肤bug真多,staticbox 不能用,背景成了透明的,而且拖动大小后背景不会刷新。成了下面的效果

还好手头有源代码,只有慢慢看源码,找原因了。
bool wxStaticBox::Create(wxWindow *parent,
wxWindowID id,
const wxString& label,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
if ( !CreateControl(parent, id, pos, size, style, wxDefaultValidator, name) )
return false;
if ( !MSWCreateControl(wxT("BUTTON"), label, pos, size) )
return false;
// Always use LTR layout. Otherwise, the label would be mirrored.
SetLayoutDirection(wxLayout_LeftToRight);
#ifndef __WXWINCE__
if (!wxSystemOptions::IsFalse(wxT("msw.staticbox.optimized-paint")))
Connect(wxEVT_PAINT, wxPaintEventHandler(wxStaticBox::OnPaint));
#endif // !__WXWINCE__
return true;
}staticbox的创建函数,OnPaint是protected的,python代码好像没法调用
在OnPaint处打上断点,发现加载皮肤库没有进入,估计是SkinSharp内置的消息钩子处理了PAINT消息,导致
OnPaint事件无效。。。。。。。。。
// all the hacks below are not necessary for WinCE
#ifndef __WXWINCE__
WXLRESULT wxStaticBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
if ( nMsg == WM_NCHITTEST )
{
// This code breaks some other processing such as enter/leave tracking
// so it's off by default.
static int s_useHTClient = -1;
if (s_useHTClient == -1)
s_useHTClient = wxSystemOptions::GetOptionInt(wxT("msw.staticbox.htclient"));
if (s_useHTClient == 1)
{
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
ScreenToClient(&xPos, &yPos);
// Make sure you can drag by the top of the groupbox, but let
// other (enclosed) controls get mouse events also
if ( yPos < 10 )
return (long)HTCLIENT;
}
}
if ( nMsg == WM_PRINTCLIENT )
{
// we have to process WM_PRINTCLIENT ourselves as otherwise child
// windows' background (eg buttons in radio box) would never be drawn
// unless we have a parent with non default background
// so check first if we have one
if ( !HandlePrintClient((WXHDC)wParam) )
{
// no, we don't, erase the background ourselves
// (don't use our own) - see PaintBackground for explanation
wxBrush brush(GetParent()->GetBackgroundColour());
wxFillRect(GetHwnd(), (HDC)wParam, GetHbrushOf(brush));
}
return 0;
}
if ( nMsg == WM_UPDATEUISTATE )
{
// DefWindowProc() redraws just the static box text when it gets this
// message and it does it using the standard (blue in standard theme)
// colour and not our own label colour that we use in PaintForeground()
// resulting in the label mysteriously changing the colour when e.g.
// "Alt" is pressed anywhere in the window, see #12497.
//
// To avoid this we simply refresh the window forcing our own code
// redrawing the label in the correct colour to be called. This is
// inefficient but there doesn't seem to be anything else we can do.
//
// Notice that the problem is XP-specific and doesn't arise under later
// systems.
if ( m_hasFgCol && wxGetWinVersion() == wxWinVersion_XP )
Refresh();
}
//xugangjava add this
if (nMsg==WM_NCPAINT)
{
OnPaint(wxPaintEvent());
}
//xugangjava add this
return wxControl::MSWWindowProc(nMsg, wParam, lParam);
}staticbox下面还有这样一个函数,hook本地消息的,只有试一下看了,拦截WM_NCPAINT
调用OnPaint,Ok 编译替换[wxmsw294u_core_vc90.dll]文件
运行代码,一切正常,


本文详细记录了解决wxStaticBox在使用皮肤时出现的各种Bug的过程,包括背景透明及拖动后背景不刷新等问题,并提供了具体的修改代码及解决思路。
1239

被折叠的 条评论
为什么被折叠?



