Vladimir Ilic
OnDDECommand enables your application to act as a DDE execute server.
It passes in a null-terminated command string sent from another client
process to your application for it to execute.
The MFC will accept DDE initiate messages whose application = your
application name and topic = "system". Following that any command
strings received will be handled in OnDDECommand. The CWinApp
implementation handles a few standard commands such as the commands to
open or print a file that you can get from the shell if you have
registered your file types.
You can override this in your own application class. Your implementation is
free to accept command strings in any syntax you want to define and
publicize to your anticipated clients. Your handler must parse the
string, process the command or commands, and return the boolean to say
if handled. You will probably want to call the base class
implementation first to allow it to handle the standard commands.
If you want to do more with DDE your best bet is to use the Win32 DDE
Management Library (DDEML). MFC does not wrap this in C++ classes,
although several examples of doing this are on the MSDN and maybe other
public sources. You can also look in the Petzold book for an
explanation of DDE and DDEML.
>Hi to all,
>I am new in Visual C++ (and MFC too). I need sample how to use
>DDE with MFC. In on-line books I found CWinApp::OnDDECommand and
>DDEML but I didn't found any sample. Please send me code with sample
>for this function.
>
>Vladimir Ilic
look on your CD in the MSDev\Samples\Win32\DDEML directory
--
Guenter from Frankfurt/Germany
eMail: gtsc...@compuserve.com
>>Hi to all,
>>I am new in Visual C++ (and MFC too). I need sample how to use
>>DDE with MFC. In on-line books I found CWinApp::OnDDECommand and
>>DDEML but I didn't found any sample. Please send me code with sample
>>for this function.
>>
>>Vladimir Ilic
>
>look on your CD in the MSDev\Samples\Win32\DDEML directory
>--
>Guenter from Frankfurt/Germany
I did, but there is not sample with MFC and DDE. I know how to make
standard DDE program (like Clock in MSDev\Samples\Sdk\Win32...) but
now I want to make same thing using MFC. In previus message Andres N.
Weinstein wrote about OnDDECommand (to which one I'm interested) but
without any sample. My problem is:
1.- How to initialize DDE server in C++ program
2.- Who to manage DDE messages like in example at the end of article.
3.- How to uninitialize DDE in program
Vladimir Ilic
vi...@eunet.yu
Part of Program:
HDDEDATA CALLBACK DdeCallback(WORD usType,WORD usFmt,HCONV hConv,HSZ
hsz1, HSZ hsz2,HDDEDATA hData,DWORD lData1,DWORD lData2)
{
static HANDLE hToken;
static TOKEN_PRIVILEGES tp;
static LUID luid;
if (usType == XTYP_CONNECT) {
return((HDDEDATA)TRUE);
}
if (usType == XTYP_WILDCONNECT) {
HDDEDATA hData;
HSZPAIR FAR *phszp;
DWORD cb;
if ((!hsz1 || hsz1 == hszTopic) && (!hsz2 || hsz2 ==
hszService)) {
if ((hData = DdeCreateDataHandle(idInst, NULL,
2 * sizeof(HSZPAIR), 0L, 0, 0, 0))) {
phszp = (HSZPAIR FAR *)DdeAccessData(hData, &cb);
phszp[0].hszSvc = hszService;
phszp[0].hszTopic = hszTopic;
phszp[1].hszSvc = phszp[1].hszTopic = 0;
DdeUnaccessData(hData);
return(hData);
}
}
return(0);
}
if (usFmt == CF_TEXT) {
CHAR MyCommand[40];
if (usType == XTYP_ADVSTART || usType == XTYP_ADVSTOP) {
return((HDDEDATA)TRUE);
}
if (hsz1 == hszTopic && hsz2 == hszItem) {
if (usType == XTYP_REQUEST || usType == XTYP_ADVREQ) {
itoa(vreme, sz, 10);
return(DdeCreateDataHandle(idInst, (LPBYTE)sz,
strlen(sz) + 1, 0L,hszItem, CF_TEXT, 0));
}
if (usType == XTYP_POKE) { //Client send data to server
DdeGetData(hData, (LPBYTE)sz, 40L, 0L);
sscanf(sz, "%s", &MyCommand);
DdePostAdvise(idInst, hszTopic, hszItem);
return((HDDEDATA)DDE_FACK);
}
}
}
return(0);
UNREFERENCED_PARAMETER(lData1);
UNREFERENCED_PARAMETER(lData2);
UNREFERENCED_PARAMETER(hConv);
}
>I did, but there is not sample with MFC and DDE. I know how to make
>standard DDE program (like Clock in MSDev\Samples\Sdk\Win32...) but
>now I want to make same thing using MFC. In previus message Andres N.
>Weinstein wrote about OnDDECommand (to which one I'm interested) but
>without any sample. My problem is:
>1.- How to initialize DDE server in C++ program
>2.- Who to manage DDE messages like in example at the end of article.
>3.- How to uninitialize DDE in program
>
I have an MFC wrapper for DDE (tested for Win16, should work for Win32
also). The wrapper was based on the code from the sample once uploaded
to one of former Microsoft's CompuServe forums (original sample was
written by MS's Brian Scott). If you are interested, mail me at
va...@sn.no, and I will mail you the code.
Vagif Abilov
va...@sn.no
Object Factory
Oslo Norway
At the lowest level the "raw" DDE protocol works by building and
exchanging appropriate window messages. The DDEML library provides a
higher level functional interface for users of the protocol.
The built-in MFC support for OnDDECommand uses only the raw DDE messages.
It does *not* use DDEML and requires no special intitialization
or termination on your part. So if the *only* thing you wanted to do was
to process DDE EXECUTE strings, you can just override the OnDDECommand
method, and you're done.
But you probably want to do more, however, like send or receive data.
MFC provides no special support for any of these functions -- Microsoft
is pushing everyone to learn OLE instead. You can perfectly well use the
straight C DDEML API calls in an MFC program. Then you will not deal
with DDE messages directly but "transactions" dispatched to a callback
procedure you register when you initialize the DDEML.
So: Call DdeInitialize in your InitInstance; write a static member
function (or global function) to use as your DDE callback routine; save
the DDEML instance handle in your application object, and call
DdeUninitialize in your ExitInstance. Your callback routine needs to
do the work of processing the connection and data requests.
If you are doing a lot you will probably want to implement something
like a DDE manager as a global class for your application to use, one
which maintains a list of conversation objects, say. There is an example on
the MSDN library of C++ classes that wraps the DDEML, but I don't
know where else it's available. I also saw some free C++ classes for DDE
at:
http://web.ukonline.co.uk/Members/julian.smart/code.html