我正在使用Visual Studios Win32为ARINC 629总线开发控制应用程序。它适用于事件驱动的操作,例如鼠标点击,但我需要它在我通过ARINC 629总线接收数据时实时更新。
我已经了解到Win32不是最需要不断更新的图形环境,但我的应用程序运行得相当好,除了一些闪烁。
似乎大多数关于如何减少闪烁的建议都不会在连续调用函数时解决。
双缓冲似乎没什么帮助。
在这种情况下,如果我只能重绘矩形而不是整个客户区,我可以减少或消除闪烁。
以下是代码段:
void twirling_baton_left_channel(HDC hdc, HWND hWnd, unsigned int left_chan_data_receive)
{
LPRECT lpRect;
RECT rect_chan_one;
lpRect = &rect_chan_one;
lpRect->left = 0;
lpRect->top = 0;
lpRect->right = 0x01ba;
lpRect->bottom = 0x01c6;
static unsigned int wait_to_redraw_left_chan = 0;
status_baton_one.left = 0xb2;
status_baton_one.top = 0x28;
status_baton_one.right = 0x11c;
status_baton_one.bottom = 0x4b;
/* draw the running indicator */
if(wait_to_redraw_left_chan > 5)
{
RedrawWindow(hWnd, lpRect, NULL, RDW_INVALIDATE); //RedrawWindow((HWND)hdc, NULL, NULL, RDW_ERASE);
wait_to_redraw_left_chan = 0;
}
wait_to_redraw_left_chan++;
//SelectObject(ps.hdc, GetStockObject(DC_BRUSH));
if(left_chan_data_txrx)
{
SetDCBrushColor(hdc, RGB(0, 255, 0)); // green
Rectangle(hdc, status_baton_one.left, status_baton_one.top, status_baton_one.left+30, status_baton_one.top+20);
}
else
{
SetDCBrushColor(hdc, RGB(128,128,128)); //grey
Rectangle(hdc, status_baton_one.left, status_baton_one.top, status_baton_one.left+30, status_baton_one.top+20);
}
}
我正在尝试使用RedrawWindow()命令仅重绘“矩形”函数定义的框,但它会导致整个客户区重绘,这会导致闪烁,因为它是连续调用的。 / p>