Advanced MFC Programming
Advanced MFC Programming Advanced MFC Programming
Chapter 16. Context Sensitive Help conversation must be terminated. Either the server or the client can terminate the conversion. This can be implemented by calling function ::DdeDisconnect(…) using the conversion handle. This function can be called either from the server or from the client side. Once the message is sent, the other side will be notified of the disconnection by receiving an XTYP_DISCONNECT message. In the sample, once the connection is set up, it can be terminated from the client side by pressing “Disconnect” button or from the server side through executing DDE | Disconnect command. This is implemented as follows: The server side: void CMainFrame::OnDdeDisconnect() { if(m_hConvServer != 0) { ::DdeDisconnect(m_hConvServer); m_hConvServer=0; Printf("Disconnected by the server.\r\n"); } } The client side: …… void CDDECliDlg::OnButtonConnect() { if(m_hConvClient == 0) { } } else { ::DdeDisconnect(m_hConvClient); m_hConvClient=0; UnobtainHsz(m_hszTopicName); m_hszTopicName=0; m_btnConnect.SetWindowText("Connect"); Printf("Disconnected by the client!\r\n"); } The following shows how message XTYP_DISCONNECT is handled in both sides: The client side: …… …… case XTYP_DISCONNECT: { m_hConvClient=0; UnobtainHsz(m_hszTopicName); m_hszTopicName=0; ((CDDECliDlg *)(AfxGetApp()->m_pMainWnd))->m_btnConnect.SetWindowText("Connect"); Printf("Disconnected by the server.\r\n"); return (HDDEDATA)NULL; } The server side: …… case XTYP_DISCONNECT: { if(m_hConvServer == hConv) { m_hConvServer=0; Printf("Disconnected by the client.\r\n"); } return (HDDEDATA)FALSE; 464
Chapter 16. Context Sensitive Help …… } Test We can test this version of DDE client and server by starting both applications, then inputting “Topic” into the edit box contained in the client dialog box, and clicking “Connect” button (see Figure 15-1). After this, we will see that the server will output some information indicating if the connection is successful. Then, we can terminate the conversation either from the client or from the server side. We can also try to use an incorrect topic name while making the connection, this will cause the connection to be unsuccessful. To prevent the application from exiting without terminating the conversation, both client and server need to check if the conversation is still undergoing while exiting. If necessary, function ::DdeDisconnect(…) will be called before the applications exit. Figure 15-2 explains the procedure of DDE connection and disconnection. Input the topic name and click Connect button Figure 15-1. Initiate connection from the client side 15.3 Transaction: Data Request Samples 15.3\DDE\Server and 15.3\DDE\Client are based on samples 15.2\DDE\Server and 15.2\DDE\Client respectively. There are several types of transactions, one of which is XTYPE_REQUEST, it can be used by the client to request the server to send up-to-date value of an item to it. We know that there are two names that are used to set up a connection: the service name and the topic name. The service name is used to locate the server and the topic name is used to specify a general topic. Under any topic there may exist several items, each item also needs an item name. When the client wants to request a transaction from the server, it needs to specify the item name. For example, if a server provides a service that sends different type of data to the client(s), there may be different topics such as “Image”, “Text” (indicating different type of data). Under each topic, there may exist different items such as “Image A”, “Image B”, “Text 1”, “Text 2”. Data Request Transaction: Client Side The client should call function ::DdeClientTransaction(…) to initiate a transaction: HDDEDATA DdeClientTransaction ( LPBYTE pData, DWORD cbData, HCONV hConv, HSZ hszItem, UINT wFmt, UINT wType, DWORD dwTimeout, LPDWORD pdwResult 465
- Page 429 and 430: Chapter 13. Adding Special Features
- Page 431 and 432: Chapter 13. Adding Special Features
- Page 433 and 434: Chapter 13. Adding Special Features
- Page 435 and 436: Chapter 13. Adding Special Features
- Page 437 and 438: Chapter 13. Adding Special Features
- Page 439 and 440: Chapter 13. Adding Special Features
- Page 441 and 442: Chapter 13. Adding Special Features
- Page 443 and 444: Chapter 13. Adding Special Features
- Page 445 and 446: Chapter 14. Views ID_EDIT_PASTE pas
- Page 447 and 448: Chapter 14. Views Another feature o
- Page 449 and 450: Chapter 14. Views szFind=newName; s
- Page 451 and 452: Chapter 14. Views ON_COMMAND(ID_BUT
- Page 453 and 454: Chapter 14. Views IDB_BITMAP_CLOSEF
- Page 455 and 456: Chapter 14. Views Because we do not
- Page 457 and 458: Chapter 14. Views For the root dire
- Page 459 and 460: Chapter 14. Views The columns are a
- Page 461 and 462: Chapter 14. Views } ff.Close(); Des
- Page 463 and 464: Chapter 14. Views …… …… if(
- Page 465 and 466: Chapter 14. Views void CDirView::Ad
- Page 467 and 468: Chapter 14. Views Actually, in the
- Page 469 and 470: Chapter 14. Views } if(szName1.GetL
- Page 471 and 472: Chapter 14. Views Mouse Cursor Coor
- Page 473 and 474: Chapter 16. Context Sensitive Help
- Page 475 and 476: Chapter 16. Context Sensitive Help
- Page 477 and 478: Chapter 16. Context Sensitive Help
- Page 479: Chapter 16. Context Sensitive Help
- Page 483 and 484: Chapter 16. Context Sensitive Help
- Page 485 and 486: Chapter 16. Context Sensitive Help
- Page 487 and 488: Chapter 16. Context Sensitive Help
- Page 489 and 490: Chapter 16. Context Sensitive Help
- Page 491 and 492: Chapter 16. Context Sensitive Help
- Page 493 and 494: Chapter 16. Context Sensitive Help
- Page 495 and 496: Chapter 16. Context Sensitive Help
- Page 497 and 498: Chapter 16. Context Sensitive Help
- Page 499 and 500: Chapter 16. Context Sensitive Help
- Page 501 and 502: Chapter 16. Context Sensitive Help
- Page 503 and 504: Chapter 16. Context Sensitive Help
- Page 505 and 506: Chapter 16. Context Sensitive Help
- Page 507 and 508: Appendix A. Virtual-key Codes Appen
- Page 509 and 510: Appendix A. Virtual-key Codes Funct
- Page 511 and 512: Appendix B. Ternary Raster Operatio
- Page 513 and 514: Appendix B. Ternary Raster Operatio
- Page 515 and 516: Appendix B. Ternary Raster Operatio
- Page 517 and 518: Index Index #if, 416 #pragma, 416 .
- Page 519 and 520: Index CDC::SetPixel, 321 CDC::SetRO
- Page 521 and 522: Index CRectTracker, 345 CRectTracke
- Page 523 and 524: Index CWnd::SetMenu, 55 CWnd::SetTi
- Page 525 and 526: Index HBRUSH, 201 HCURSOR, 262 HDAT
- Page 527 and 528: Index Background palette, 224 Chang
- Page 529 and 530: Index Default tool bar, 1 Enable or
Chapter 16. Context Sensitive Help<br />
conversation must be terminated. Either the server or the client can terminate the conversion. This can be<br />
implemented by calling function ::DdeDisconnect(…) using the conversion handle. This function can be<br />
called either from the server or from the client side. Once the message is sent, the other side will be notified<br />
of the disconnection by receiving an XTYP_DISCONNECT message.<br />
In the sample, once the connection is set up, it can be terminated from the client side by pressing<br />
“Disconnect” button or from the server side through executing DDE | Disconnect command. This is<br />
implemented as follows:<br />
The server side:<br />
void CMainFrame::OnDdeDisconnect()<br />
{<br />
if(m_hConvServer != 0)<br />
{<br />
::DdeDisconnect(m_hConvServer);<br />
m_hConvServer=0;<br />
Printf("Disconnected by the server.\r\n");<br />
}<br />
}<br />
The client side:<br />
……<br />
void CDDECliDlg::OnButtonConnect()<br />
{<br />
if(m_hConvClient == 0)<br />
{<br />
}<br />
}<br />
else<br />
{<br />
::DdeDisconnect(m_hConvClient);<br />
m_hConvClient=0;<br />
UnobtainHsz(m_hszTopicName);<br />
m_hszTopicName=0;<br />
m_btnConnect.SetWindowText("Connect");<br />
Printf("Disconnected by the client!\r\n");<br />
}<br />
The following shows how message XTYP_DISCONNECT is handled in both sides:<br />
The client side:<br />
……<br />
……<br />
case XTYP_DISCONNECT:<br />
{<br />
m_hConvClient=0;<br />
UnobtainHsz(m_hszTopicName);<br />
m_hszTopicName=0;<br />
((CDDECliDlg *)(AfxGetApp()->m_pMainWnd))->m_btnConnect.SetWindowText("Connect");<br />
Printf("Disconnected by the server.\r\n");<br />
return (HDDEDATA)NULL;<br />
}<br />
The server side:<br />
……<br />
case XTYP_DISCONNECT:<br />
{<br />
if(m_hConvServer == hConv)<br />
{<br />
m_hConvServer=0;<br />
Printf("Disconnected by the client.\r\n");<br />
}<br />
return (HDDEDATA)FALSE;<br />
464