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

can pass parameter afCmd a combination of filter flags, which will allow only certain type of messages to be<br />

sent to the application. The following table shows some examples:<br />

Parameter<br />

Meaning<br />

APPCLASS_STANDARD Registers the application as a standard DDE application.<br />

APPCMD_CLIENTONLY Registers the application as a DDE client, the server specific messages will not<br />

be sent to this application.<br />

APPCMD_FILTERINIT Prevent the application from receiving connection request messages before it has<br />

S<br />

registered the name service.<br />

♦ DDE uninitialization:<br />

BOOL ::DdeUninitialize(DWORD idInst);<br />

The only parameter of this function is the value obtained from function ::DdeInitialize(…).<br />

♦ DDE name service registration and unregistration:<br />

HDDEDATA ::DdeNameService(DWORD idInst, HSZ hsz1, HSZ hsz2, UINT afCmd);<br />

Again, idInst is the DDE instance ID which is obtained from function ::DdeInitialize(…). The<br />

second parameter is the handle of the name service string, which is a new type of variable. Actually, it is<br />

just a new type of handle that can be obtained by calling another function supported by DDEML.<br />

In DDE, data is exchanged through sending string handles among different applications. For example,<br />

if we have a string that is contained in a series of buffers, we cannot send the buffers’ starting address to<br />

another process and let the string be accessed there. To let the string be shared by other DDE applications,<br />

we need to create a string handle and let it be shared by other applications. With the handle, any application<br />

can access the contents contained in the buffers. In DDEML, following two functions can be used to create<br />

and free string handle:<br />

HSZ ::DdeCreateStringHandle(DWORD idInst, LPTSTR psz, int iCodePage);<br />

BOOL ::DdeFreeStringHandle(DWORD idInst, HSZ hsz);<br />

For the first function, we can pass the string pointer to parameter psz, and the function will return a<br />

string handle. When the string is no longer useful, we need to call function ::DdeFreeStringHandle(…) to<br />

free the string handle.<br />

When registering a service name, we must use a string handle rather than the service name itself.<br />

A service name is the identifier of the server that lets the client applications find the server when<br />

requesting a service. We can use any string as the service name so long as it is not identical to other DDE<br />

service names present in the system. When a client requests for services from the server, it must obtain a<br />

string handle for the service name and use it to communicate with the server.<br />

DDE Callback Function<br />

The DDE callback function is similar to the callback functions implemented for common dialog boxes<br />

and hooks, except that the situation is more complicated here. A DDE callback function has 8 parameters,<br />

which may have different meanings for different messages. The basic form of the callback function is as<br />

follows:<br />

HDDEDATA CALLBACK DdeCallback<br />

(<br />

UINT uType,<br />

UINT uFmt,<br />

HCONV hconv,<br />

HSZ hszTopic,<br />

HSZ hszAppName,<br />

HDDEDATA hdata,<br />

DWORD lData1,<br />

458

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

Saved successfully!

Ooh no, something went wrong!