Advanced MFC Programming
Advanced MFC Programming Advanced MFC Programming
Chapter 16. Context Sensitive Help ( m_dwInst, (LPBYTE)(LPCSTR)m_szPoke, m_szPoke.GetLength(), 0, hszPokeItem, CF_TEXT, 0 ); ::DdeClientTransaction ( (LPBYTE)hData, 0xFFFFFFFF, m_hConvClient, hszPokeItem, CF_TEXT, XTYP_POKE, TIMEOUT_ASYNC, NULL ); …… UnobtainHsz(hszPokeItem); Synchronous Transaction Asynchronous Transaction Initialize transaction Initialize transaction Yes Has the server responded? No Receive XTYP_XACT_COMPLETE message Yes Has timer timed out? No Go on Transaction finished Transaction finished Figure 15-6. Synchronous & asynchronous transactions The following code fragment shows how the transaction result is processed when the client receives an XTYP_XACT_COMPLETE message: …… case XTYP_XACT_COMPLETE: { HSZ hszPokeItem; hszPokeItem=ObtainHsz(TEXT("Poke")); if ( hConv == m_hConvClient && 478
Chapter 16. Context Sensitive Help …… } ) { hszTopic == m_hszTopicName && hszItem == hszPokeItem && wFormat == CF_TEXT if(hData != NULL) { Printf("Poke executed!\r\n"); } else Printf("Poke failed!\r\n"); } UnobtainHsz(hszPokeItem); There is no change on the server side. All types of transactions can be implemented by either synchronous or asynchronous mode. 15.7 Program Manager: A DDE Server By now, we have introduced some of the most useful DDE transactions. We can use these data transfer protocols to design and build applications that can share data and information. Besides this, we can also write client application to communicate with standard DDE servers contained in the system. Program Manager Under Windows, all types of applications are managed into groups. By clicking on Start | Programs command on the task bar, we will see many groups, such as “Accessories”, “Startup”. Within each group, there may exist some items that are linked directly to executable files, or there may exist some sub-groups. Sometimes we may want to modify this structure by adding a new item or deleting an existing item. Actually this structure is managed by Program Manager, which is a DDE server. We can interact with this server to create group, delete group, add items to the group, delete items from a group through initiating Execute transactions. The client sample from the previous section is modified so that it can be used to communicate only to Program Manager. Here, the service name of the Program Manager is “Progman”. As we can see, the DDE initialization for this client is exactly the same as we did before. The five commands we will ask the server to execute are: creating group; bringing up an existing group; deleting a group; creating an item; deleting an item. All the DDE commands must start and end with square braces (‘[’ and ‘]’). The following table lists the formats of five commands: Function Command format Create a group "[CreateGroup(group name)]" Pop up a group "[ShowGroup(group name, 1)]" Delete a group "[DeleteGroup(group name)]" Create an item "[AddItem(File name, item name)]" Delete an item "[DeleteItem(Item name)]" A combo box for storing the command types is added to sample’s dialog box. Besides this, the dialog box also contains an edit box and a button labeled “Command”. The edit box will be used to let the user input parameters for the command. For example, if we want to create a group with name “Test”, we can select “Create group” from the combo box and input “Test” into the edit box then click “Command” button. The application will initiate an execute transaction to the Program Manager and send “[CreateGroup(Test)]” command to it. We can use this program to create groups and add items to a group. We can also delete unwanted groups or remove items from a group. 479
- 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 and 480: Chapter 16. Context Sensitive Help
- Page 481 and 482: 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: 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 />
……<br />
}<br />
)<br />
{<br />
hszTopic == m_hszTopicName &&<br />
hszItem == hszPokeItem &&<br />
wFormat == CF_TEXT<br />
if(hData != NULL)<br />
{<br />
Printf("Poke executed!\r\n");<br />
}<br />
else Printf("Poke failed!\r\n");<br />
}<br />
UnobtainHsz(hszPokeItem);<br />
There is no change on the server side.<br />
All types of transactions can be implemented by either synchronous or asynchronous mode.<br />
15.7 Program Manager: A DDE Server<br />
By now, we have introduced some of the most useful DDE transactions. We can use these data transfer<br />
protocols to design and build applications that can share data and information. Besides this, we can also<br />
write client application to communicate with standard DDE servers contained in the system.<br />
Program Manager<br />
Under Windows, all types of applications are managed into groups. By clicking on Start | Programs<br />
command on the task bar, we will see many groups, such as “Accessories”, “Startup”. Within each group,<br />
there may exist some items that are linked directly to executable files, or there may exist some sub-groups.<br />
Sometimes we may want to modify this structure by adding a new item or deleting an existing item.<br />
Actually this structure is managed by Program Manager, which is a DDE server. We can interact with<br />
this server to create group, delete group, add items to the group, delete items from a group through<br />
initiating Execute transactions.<br />
The client sample from the previous section is modified so that it can be used to communicate only to<br />
Program Manager. Here, the service name of the Program Manager is “Progman”. As we can see, the<br />
DDE initialization for this client is exactly the same as we did before.<br />
The five commands we will ask the server to execute are: creating group; bringing up an existing<br />
group; deleting a group; creating an item; deleting an item. All the DDE commands must start and end with<br />
square braces (‘[’ and ‘]’). The following table lists the formats of five commands:<br />
Function<br />
Command format<br />
Create a group "[CreateGroup(group name)]"<br />
Pop up a group "[ShowGroup(group name, 1)]"<br />
Delete a group "[DeleteGroup(group name)]"<br />
Create an item "[AddItem(File name, item name)]"<br />
Delete an item "[DeleteItem(Item name)]"<br />
A combo box for storing the command types is added to sample’s dialog box. Besides this, the dialog<br />
box also contains an edit box and a button labeled “Command”. The edit box will be used to let the user<br />
input parameters for the command. For example, if we want to create a group with name “Test”, we can<br />
select “Create group” from the combo box and input “Test” into the edit box then click “Command” button.<br />
The application will initiate an execute transaction to the Program Manager and send<br />
“[CreateGroup(Test)]” command to it.<br />
We can use this program to create groups and add items to a group. We can also delete unwanted<br />
groups or remove items from a group.<br />
479