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

按钮绘制不同步 #382

Open
nmgwddj opened this issue Feb 12, 2022 Discussed in #381 · 1 comment
Open

按钮绘制不同步 #382

nmgwddj opened this issue Feb 12, 2022 Discussed in #381 · 1 comment
Labels
bug Something isn't working

Comments

@nmgwddj
Copy link
Collaborator

nmgwddj commented Feb 12, 2022

Discussed in #381

Originally posted by huangzhengyi February 10, 2022
设置按钮的normal(红)、hot(绿) 2种状态颜色

<Button name="btn_test" width="200" height="200" normalcolor="#ffff0000" hotcolor="#ff00ff00"/>

加入按钮点击处理函数

m_pButton->AttachClick([this](ui::EventArgs* args) {
	SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); 
	return true;
});

会出现,当我们点击按钮窗口最小化了,但是我们重新点击任务栏的窗口显示窗口,发现按钮还是绿色,只有鼠标放在窗口或者按钮上才会重绘这个窗口

void Window::Invalidate(const UiRect& rcItem)
{
::InvalidateRect(m_hWnd, &rcItem, FALSE);
// Invalidating a layered window will not trigger a WM_PAINT message,
// thus we have to post WM_PAINT by ourselves.
if (m_bIsLayeredWindow) {
	::PostMessage(m_hWnd, WM_PAINT, (LPARAM)&rcItem, (WPARAM)FALSE);
}
}

void Window::Paint()
{
if (::IsIconic(m_hWnd) || !m_pRoot) {
	PAINTSTRUCT ps = { 0 };
	::BeginPaint(m_hWnd, &ps);
	::EndPaint(m_hWnd, &ps);
	return;
}
....

发现,是通过post发送的paint消息,怀疑是当我点击按钮之后,窗口隐藏了之后才收到paint导致的

@nmgwddj nmgwddj added the bug Something isn't working label Feb 12, 2022
@huangzhengyi
Copy link

((Button*)msg->pSender)->SetState(kControlStateNormal);
ui::UiRect _rcWnd;
::SendMessage(m_hWnd, WM_PAINT, (LPARAM)&_rcWnd, (WPARAM)FALSE);
ShowWindow(false);

在按钮隐藏前,先刷新一遍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants