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 />

“Time” item<br />

Figure 15-3. “Time” item under “Topic” topic<br />

The following function shows how the client initiates the transaction after the user clicks “Request”<br />

button, and how the client updates the time displayed in the edit box if the transaction is successful:<br />

void CDDECliDlg::OnButtonRequest()<br />

{<br />

HSZ hszTimeItem;<br />

HDDEDATA hData;<br />

LPBYTE lpByte;<br />

}<br />

hszTimeItem=ObtainHsz(TEXT("Time"));<br />

hData=::DdeClientTransaction<br />

(<br />

NULL,<br />

0,<br />

m_hConvClient,<br />

hszTimeItem,<br />

CF_TEXT,<br />

XTYP_REQUEST,<br />

5000,<br />

NULL<br />

);<br />

if(hData != NULL)<br />

{<br />

lpByte=::DdeAccessData(hData, NULL);<br />

m_szTimeItem=lpByte;<br />

::DdeUnaccessData(hData);<br />

::DdeFreeDataHandle(hData);<br />

UpdateData(FALSE);<br />

}<br />

UnobtainHsz(hszTimeItem);<br />

The following code fragment shows how the server responds to message XTYPE_REQUEST, prepares data<br />

and sends it to the client:<br />

……<br />

case XTYP_REQUEST:<br />

{<br />

if<br />

(<br />

!::DdeCmpStringHandles(hszTopic, m_hszTopicName) &&<br />

!::DdeCmpStringHandles(hszItemName, m_hszTimeItem) &&<br />

wFormat == CF_TEXT<br />

)<br />

{<br />

CTime time;<br />

CString szTime;<br />

HDDEDATA hData;<br />

time=CTime::GetCurrentTime();<br />

szTime=time.Format("%H:%M:%S");<br />

469

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

Saved successfully!

Ooh no, something went wrong!