BOOL Ctest1Dlg: : OnMscomm1 ()
{
The VARIANT variant_inp;//the variant variables used to store the received data
COleSafeArray safearray_inp;//safeassay variables
LONG len, k;//long integer variables
BYTE rxdata [2048].//set the BYTE array
Cstrings strtemp;//define string
//cstrings data;
The switch (m_Comm1 get_CommEvent ())
{
//case 1://comEvSend send data
//break;
Case 2://comEvReceive read
//MessageBox (_T (" read data event "), _T (" TRACE "), MB_OK);
Variant_inp=m_Comm1. Get_Input ();//read buffer
Safearray_inp=variant_inp;//the VARIANT type variables into ColeSafeArray type
Len=safearray_inp. GetOneDimSize ();//to get effective data length
STR="\ 0";//to accept data
For (k=0; K
BYTE bt=* (char *) (rxdata + k);//character type 111111
Strtemp. The Format (" % c ", bt);//the character into strtemp store temporary variables, a string string type (% c single characters into cstrings)
STR +=strtemp;
}
r1=atof (STR. Mid (0, 6));
break;
}
The UpdateData (FALSE);
}
Void Ctest1Dlg: : OnPaint ()
{
If (IsIconic ())
{
CPaintDC dc (this);//device context for painting
The SendMessage (WM_ICONERASEBKGND, reinterpret_cast & lt; WPARAM> (dc) GetSafeHdc ()), 0);
//Center icon in the client rectangle
Int cxIcon=GetSystemMetrics (SM_CXICON);
Int cyIcon=GetSystemMetrics (SM_CYICON);
CRect the rect.
GetClientRect (& amp; The rect);
Int x=(the rect. Width () - cxIcon + 1)/2;
Int y=(the rect. Height () - cyIcon + 1)/2;
//Draw the icon
Dc. DrawIcon (x, y, m_hIcon);
}
The else
{
CDialogEx: : OnPaint ();
//CDialog: : UpdateWindow ();
//ShowImage (TheImage, IDC_picture);
}
The CDC * pDC=m_picture. GetWindowDC ();
The CWnd * pWnd=GetDlgItem (IDC_picture);
PWnd - & gt; Invalidate ().
PWnd - & gt; UpdateWindow ();
PDC - & gt; MoveTo (30, 10);
PDC - & gt; The LineTo (30, 600);
PDC - & gt; The LineTo (800, 600);
PDC - & gt; MoveTo (200, 300);
//pDC - & gt; LineTo (0800);
Double x, y;
x=r1 * 100 + 500;
Y=r1 * 100 + 800;
//pDC - & gt; MoveTo (x, y);
PDC - & gt; The LineTo (x, y);
The ReleaseDC (pDC);
}
Want to ask, how does ability let the Onpaint function below the r1 change with r1 in the function above? I define the r1 into global variables is that ok? That is how the function calls the above function in the r1? Pray god to solve!
CodePudding user response:
Don't superstitious books, examination questions, teachers, reply;CPU to superstitions, compiler, debugger, run results,
And please combine "the blind man touched the sun" and "boat out to sea must carry only a compass," try to understand,
Any theory, authority, according to legend, the truth, and the standard, explain, imagination, knowledge... Is not in my eyes!
CodePudding user response:
In general is above the function is a serial port communication, receiving MCU send to come over to the coordinates of the data, I want to make the following drawing functions according to the coordinates of the data in the above function to draw a curve,CodePudding user response:
I mean "to define r1 as global variables is that ok?" Try what you actually don't know the answer?CodePudding user response:
You should have a custom message, the message response function is you the content of the onpaint, encapsulate the data that you have received a serial port to the message, a serial port each received a data to send a message,CodePudding user response: