11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 16. Context Sensitive Help<br />

}<br />

XTYP_ADVSTOP,<br />

5000,<br />

NULL<br />

);<br />

if(hData != FALSE)<br />

{<br />

m_btnAdvise.SetWindowText("Advise");<br />

m_bAdvise=FALSE;<br />

}<br />

}<br />

UnobtainHsz(hszTextItem);<br />

On the server side, after receiving this message, it simply turns off CMainFrame::m_bAdvise flag. After<br />

this, if the user updates variable CMainFrame::m_szText, function ::DdePostAdvise(…) will not be called.<br />

15.5 Transactions: Poke and Execute<br />

Sample 15.5\DDE\Server and 15.5\DDE\Client are based on sample 15.4\DDE\Server and<br />

15.4\DDE\Client respectively.<br />

The poke transaction is the opposite of request transaction: the client can use this transaction to send<br />

data to the server. The transaction is relatively simple: the client initiates the transaction by sending a<br />

message along with the data handle to the server. After the server receives the message, it can obtain the<br />

data from the data handle.<br />

Like require and advise transactions, poke transaction also needs a topic name and an item name. In<br />

the samples contained in 15.5\DDE\, a new item “Poke” is supported by both the server and the client.<br />

Also, a new edit box and a new button labeled “Poke” are added to the client dialog box (see Figure 15-5).<br />

The user can input any string into the edit box, and use poke transaction to send it to the server.<br />

Poke Transaction: Client Side<br />

Figure 15-5. New controls are added for “poke” and “execute”<br />

transactions<br />

The procedure of preparing data and calling function ::DdeClientTransaction(…) is very similar to<br />

that of request transaction. The difference between two types of transactions is that here it is the client that<br />

needs to prepare the data handle. In sample 15.5\DDE\Client, the user can input any string into the edit box<br />

and send it to the server.<br />

By now when sending data between two DDE applications, we always use data handle. An alternate<br />

way of sending data is to use a pointer that contains the address to the data buffers. (The samples contained<br />

in 15.5\DDE use data handle. We will see an example using pointer to transfer data in a later section).<br />

When the client calls function ::DdeClientTransaction(…), the first parameter can be set to either a string<br />

handle or a string pointer. If it is string handle, the second parameter must be 0xFFFFFFFF. If the first<br />

parameter is a string pointer, the second parameter must specify the length of the buffers.<br />

474

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!