各位大神求指導!用MFC做一個界面,下位機每隔一秒通過串口傳資料到上位機,現在能接收到串口傳來的資料,要想根據這些資料實時的畫矩形,是如何呼叫onpaint函式啊,或者如何用這些資料去畫圖啊,現在我是在類中將串口資料傳到onpaint里,然后設定了個定時器,每隔一秒invalidate和updatewindow,但是不能再視窗顯示圖形啊 ,求各位大神指點指點,我是基于對話框的MFC程式
uj5u.com熱心網友回復:
假設接收的資料是一個矩形坐標點,分兩種情況:1、實時更新,UI上面只有一個矩形顯示不擦除上次的,那這種情況,只需要定一個成員/全域變數,串口接收上來的資料更改這個變數,再呼叫CDC繪,而不是用定時器!!
2、實時更析,UI上面顯示多個矩形,不擦除上次的,那就用vector或queue來存盤,串口接收的矩形坐標每次都push_back,定時器調CDC繪這個鏈表或佇列的資料即可
uj5u.com熱心網友回復:
上面打反了,第1種是只顯示一個,第2種是多個uj5u.com熱心網友回復:
我也是這么做的 我是在類中定義一個變數 然后在onpaint中畫矩形的時候也是用的同一個變數 但是資料變化時 還是沒辦法顯示圖形啊 能不能私聊解釋下 謝謝 QQ1361055847
uj5u.com熱心網友回復:
CWnd::OnEraseBkgndafx_msg BOOL OnEraseBkgnd( CDC* pDC );
Return Value
Nonzero if it erases the background; otherwise 0.
Parameters
pDC
Specifies the device-context object.
Remarks
The framework calls this member function when the CWnd object background needs erasing (for example, when resized). It is called to prepare an invalidated region for painting.
The default implementation erases the background using the window class background brush specified by the hbrBackground member of the window class structure.
If the hbrBackground member is NULL, your overridden version of OnEraseBkgnd should erase the background color. Your version should also align the origin of the intended brush with the CWnd coordinates by first callingUnrealizeObject for the brush, and then selecting the brush.
An overridden OnEraseBkgnd should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If it returns 0, the window will remain marked as needing to be erased. (Typically, this means that the fErase member of the PAINTSTRUCT structure will be TRUE.)
Windows assumes the background is computed with the MM_TEXT mapping mode. If the device context is using any other mapping mode, the area erased may not be within the visible part of the client area.
Note This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
CWnd Overview | Class Members | Hierarchy Chart
See Also WM_ICONERASEBKGND, CGdiObject::UnrealizeObject,WM_ERASEBKGND
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/73877.html
標籤:界面
上一篇:新人求救,完成埠發送資料的問題
