CodePudding user response:
PostThreadMessage ?CodePudding user response:
Shared memory or PostThreadMessage view, if you use the former, must pay attention to the synchronizationCodePudding user response:
typedef struct MoveCmd//coordinate command structurebut using PostThreadMessageA function should do only message processing function, that how to transfer the data to the worker thread to perform functions,
{
Float position_x;
Float position_y;
Int execute_cmd [512].
} MoveCmd;
MoveCmd * MoveCmd;
: : PostThreadMessageA (m_pThread - & gt; M_nThreadID WM_CMD_MSG, 0, 0);
LRESULT CMFC_TCP_IPDlg: : TransCommand (WPARAM WPARAM, LPARAM LPARAM)//message response function
{
}
UINT ThreadFunction (LPVOID pParam);
{
}
Master can say the detailed point
CodePudding user response:
I want to work through the button to update data in a threadCodePudding user response:
Global variables, static variables Shared memory pipeline...
CodePudding user response:
Do before download progress display with the global variables, it can realize, but the feeling with a global variable is not very good
CodePudding user response:
Multiple Threads in the User Interface of http://msdn.microsoft.com/zh-cn/library/ms810439.aspxCodePudding user response:
SetEvent + WaitForSingleObject?CodePudding user response:
Unsigned int CMFC_TCP_IPDlg: : Server_Thread (LPVOID pParam){
PParam CMFC_TCP_IPDlg * pDlg=(CMFC_TCP_IPDlg *);//forced into CMFC_TCP_IPDlg type thread pointer to a pointer
MSG MSG.
//tagRun=0;
//will send buffer and receive buffer reset
Memset (sendBuf, 0, sizeof (sendBuf));
Memset (recvBuf, 0, sizeof (recvBuf));
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Struct MoveCmd * cmdData=https://bbs.csdn.net/topics/new (MoveCmd);//thread to deal with data
Memset (cmdData, 0, sizeof (cmdData));
While (: : PeekMessageA (& amp; MSG, NULL, 0, 0, PM_REMOVE))
{
The switch (MSG) message)
{
Case WM_QUIT://exit from the thread
break;
ExitThread (10);
Case WM_CMD_MSG:
//AfxMessageBox (" receives the message success ");
CmdData=https://bbs.csdn.net/topics/(MoveCmd *) MSG. WParam.
break;
Default:
break;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * load socket character * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
WORD wVersion;//store the socket version
WVersion=MAKEWORD (1, 1);//save the WinSock library version number, not the type of the c + + standard, is the type in Microsoft SDK, the meaning of the WORD for WORD, 2 byte unsigned integer (16), said the range 0 to 65535.
WSADATA WSADATA;//to store Windows sockets initialization information
WSAStartup (wVersion, & amp; WsaData);//load socket word stock, successfully returns 0
If (LOBYTE (wsaData wVersion)!=1 | | HIBYTE (wsaData wVersion)!=1).//judgment wsaData wVersion low byte and high byte are to 1, if the version is not corresponding to call WSACleanup function terminates use of Socket
{
WSACleanup ();
}
//-- -- -- -- -- -- -- create listens for socket -- -- -- -- -- -- -- -- -- -- -//
If ((sockSrv=socket (AF_INET SOCK_STREAM, 0))==INVALID_SOCKET)//to create communication endpoints: sockSrv return socket descriptor
{
: : SetWindowText (: : GetDlgItem (pDlg - & gt; M_hWnd, IDC_EDIT2), "failed to create the listening socket");
}
The else
{
: : SetWindowText (: : GetDlgItem (pDlg - & gt; M_hWnd, IDC_EDIT2), "create a listening socket success");//get the window handle
}
//-- -- -- -- -- -- -- -- bind socket -- -- -- -- -- -- -- -- -- -//
SOCKADDR_IN addrSrv;//the server address typedef struct variable sockaddr_in sockaddr_in
Memset (& amp; AddrSrv, 0, sizeof (addrSrv));//to empty structure
AddrSrv. Sin_addr. S_un. S_addr=htonl (INADDR_ANY);////the IP address assigned to INADDR_ANY, allow the socket to any assigned to the IP address of the local machine to send or receive data, multiple IP when there are multiple network CARDS, use INADDR_ANY can simplify programming
//addrSrv sin_addr. S_un. S_addr=inet_addr (serverIP);//binding local IP
AddrSrv. Sin_family=AF_INET;//set the family cluster
AddrSrv. Sin_port=htons (Port_num);//bind port
//addrSrv sin_zero [8]=0;
/* bound sockfd descriptor specifies the local address to bind () when a socket with a socket () has been created, there is a name space (address), but it has not been named, bind () to the socket address (including local host address and local port address) linked with socket created shop name, the name to a socket, to specify the local related, */
If (SOCKET_ERROR==bind (sockSrv, (SOCKADDR *) & amp; AddrSrv, sizeof (SOCKADDR)))
{
: : SetWindowText (: : GetDlgItem (pDlg - & gt; M_hWnd, IDC_EDIT2), "binding error");
}
The else
{
//: : SetWindowText (: : GetDlgItem (pDlg - & gt; M_hWnd, IDC_EDIT2), "binding success");
PDlg - & gt; SetDlgItemText (IDC_EDIT2, "binding success");
}
//-- -- -- -- -- -- -- the socket set to monitor mode, ready to receive the client request -- -- -- -- -- -- --//
Listen (sockSrv, 2);//parameter (socket descriptor, backlog here is 2 (the maximum length of waiting for the connection queue))
//used to receive the client's address information
SOCKADDR_IN addrClient;//typedef sockaddr_in addrClient
Memset (& amp; AddrClient, 0, sizeof (addrClient));//to empty structure
Int iaddrSize=sizeof (SOCKADDR);//to accept a third function, before the call must be assigned an initial value for it, namely the SOCKADDR_IN
//the while (1)
//{
SockConn=accept (sockSrv, (struct sockaddr *) & amp; AddrClient, & amp; IaddrSize);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull