Home > Software engineering >  Be urgent!!!! Turn to the great god of parameter passing in the MFC drawing!
Be urgent!!!! Turn to the great god of parameter passing in the MFC drawing!

Time:10-01

Double r1.
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; KSafearray_inp. GetElement (& amp; K, rxdata + k);//receive the data transformation and on the type BYTE array rxdata 111111
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:

reference zhao4zhong1 reply: 3/f
I mean "to define r1 as global variables is that ok?" Did you actually try don't know the answer,


Tried, seemingly no,,, but in theory should be ah

CodePudding user response:

Qq_36634306
reference 4 floor response:
you should customize a message, the message of the response function is you the content of the onpaint, the encapsulation of data to a message that you have received a serial port, serial port for each data received to send a message,

MFC small white, and you can say specific?

CodePudding user response:

Onpaint () only when execution in the dialog box, you serial certainly haven't received the data,

In another way, the message may be difficult to explain,

New you define a function, mypaint (int r1);
You write this function, the drawing part

Each received value, and the value to, call mypaint ();

CodePudding user response:

refer to 7th floor qq_36634306 response:
onpaint () only when execution in the dialog box, you serial certainly haven't received the data,

In another way, the message may be difficult to explain,

New you define a function, mypaint (int r1);
You write this function, the drawing part

Each received value, and the value to, call mypaint ();


Sounds complicated, well, I try thank you but there's no easier way ah,, just want to draw a diagram,

CodePudding user response:

MFC with message is safe,

CodePudding user response:

Defined as a member variable of the dialog box, and then two can access to the member function, you can modify, read

CodePudding user response:

R1=atof (STR. Mid (0, 6)); After
Redrawn Invalidate ()

CodePudding user response:

CodePudding user response:

refer to the second floor m0_37585568 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,


Since is a curve, you should have a series of points, so the data received at least should be a array rather than a single point; After receiving data refresh inform main window
Drawing, it should be made according to the window size and proportions of the actual data to do a mapping or conversion

CodePudding user response:

reference 13 floor zgl7903 reply:
Quote: refer to the second floor m0_37585568 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,


Since is a curve, you should have a series of points, so the data received at least should be a array rather than a single point; After receiving data refresh inform main window
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related