11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 16. Context Sensitive Help<br />

)<br />

{<br />

}<br />

DWORD lData2<br />

switch(wType)<br />

{<br />

case XTYP_REGISTER:<br />

case XTYP_UNREGISTER:<br />

case XTYP_ADVSTART:<br />

case XTYP_ADVDATA:<br />

case XTYP_ADVREQ:<br />

case XTYP_ADVSTOP:<br />

case XTYP_XACT_COMPLETE:<br />

case XTYP_CONNECT:<br />

case XTYP_DISCONNECT:<br />

case XTYP_CONNECT_CONFIRM:<br />

{<br />

return (HDDEDATA)NULL;<br />

}<br />

default:<br />

{<br />

return (HDDEDATA)NULL;<br />

}<br />

}<br />

The most important parameter here is uType, which indicates what kind of message has been sent to<br />

this application. There are many types of DDE messages. In the callback function, we can return NULL if<br />

we do not want to process the message. Standard DDE messages will be explained in the following<br />

sections.<br />

Server<br />

Sample 15.1\DDE\Server is a standard SDI application generated by Application Wizard. The view of<br />

this application is based on class CEditView, so that it can be used to display current server states. The<br />

sample is a very basic DDE server, which implements DDE registration and name service registration but<br />

actually provides no service. In the sample, the service name is “Server”. All the DDE functions are<br />

implemented in the frame window. In the sample, function CMainFrame::InitializeDDE() is called to<br />

initialize DDE. This function is called after the client view is created:<br />

void CDDESrvView::OnInitialUpdate()<br />

{<br />

CEditView::OnInitialUpdate();<br />

((CMainFrame *)(AfxGetApp()->m_pMainWnd))->InitializeDDE();<br />

}<br />

Function CMainFrame::InitializeDDE() simply calls ::DdeInitialize(…) with appropriate<br />

parameters, if the function returns DMLERR_NO_ERROR, it further proceeds to register the name service:<br />

void CMainFrame::InitializeDDE()<br />

{<br />

UINT uDdeInit;<br />

CString szRlt;<br />

uDdeInit=::DdeInitialize<br />

(<br />

&m_dwInst,<br />

(PFNCALLBACK)DdeCallback,<br />

APPCMD_FILTERINITS,<br />

0L<br />

);<br />

switch(uDdeInit)<br />

{<br />

case DMLERR_NO_ERROR:<br />

{<br />

Hszize();<br />

459

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

Saved successfully!

Ooh no, something went wrong!