Home   Index   About
Ultimate Pack


Custom Search
Initiating a Data Link with the Paste Link Command

Applications that support hot or warm data links typically support a registered clipboard format named Link. When associated with the application's Copy and Paste Link commands, this clipboard format enables the user to establish DDE conversations between applications simply by copying a data item in the server application and pasting it into the client application.

A server application supports the Link clipboard format by placing in the clipboard a string containing the application, topic, and item names when the user chooses the Copy command from the Edit menu. Following is the standard Link format:

application\0topic\0item\0\0

A single null character separates the names, and two null characters terminate the entire string.

Both the client and server applications must register the Link clipboard format, as shown:

cfLink = RegisterClipboardFormat("Link");

A client application supports the Link clipboard format by means of a Paste Link command on its Edit menu. When the user chooses this command, the client application parses the application, topic, and item names from the Link-format clipboard data. Using these names, the client application initiates a conversation for the application and topic, if such a conversation does not already exist. The client application then sends a WM_DDE_ADVISE message to the server application, specifying the item name contained in the Link-format clipboard data.

Following is an example of a client application's response when the user chooses the Paste Link command.

  • oid DoPasteLink(hwndClientDDE)

HWND hwndClientDDE;

{

HANDLE hData;

LPSTR lpData;

HWND hwndServerDDE;

CHAR szApplication[APP_MAX_SIZE + 1];

CHAR szTopic[TOPIC_MAX_SIZE + 1];

CHAR szItem[ITEM_MAX_SIZE + 1];

int nBufLen;

if (OpenClipboard(hwndClientDDE)) {

if (!(hData = GetClipboardData(cfLink)) ||

!(lpData = GlobalLock(hData))) {

CloseClipboard();

return;

}

/* Parse the clipboard data. */

if ((nBufLen = lstrlen(lpData)) >= APP_MAX_SIZE) {

CloseClipboard();

GlobalUnlock(hData);

return;

}

lstrcpy(szApplication, lpData);

lpData += (nBufLen + 1); /* skips over null */

if ((nBufLen = lstrlen(lpData)) >= TOPIC_MAX_SIZE) {

CloseClipboard();

GlobalUnlock(hData);

return;

}

lstrcpy(szTopic, lpData);

lpData += (nBufLen + 1); /* skips over null */

if ((nBufLen = lstrlen(lpData)) >= ITEM_MAX_SIZE) {

CloseClipboard();

GlobalUnlock(hData);

return;

}

lstrcpy(szItem, lpData);

GlobalUnlock(hData);

CloseClipboard();

if (hwndServerDDE =

FindServerGivenAppTopic(szApplication, szTopic)) {

/* App/topic conversation is already started. */

if (DoesAdviseAlreadyExist(hwndServerDDE, szItem))

MessageBox(hwndMain,

"Advisory already established",

"Client", MB_ICONEXCLAMATION | MB_OK);

else

SendAdvise(hwndClientDDE, hwndServerDDE, szItem);

}

else {

/* Client must initiate a new conversation first. */

SendInitiate(szApplication, szTopic);

if (hwndServerDDE =

FindServerGivenAppTopic(szApplication,

szTopic))

SendAdvise(hwndClientDDE, hwndServerDDE, szItem);

}

}

return;

}

In this example, the client application opens the clipboard and determines whether it contains data in the Link format (that is, cfLink) it had previously registered. If not, or if it cannot lock the data in the clipboard, the client returns.

After the client application retrieves a pointer to the clipboard data, it parses the data to extract the application, topic, and item names.

The client application determines whether a conversation on the topic already exists between it and the server application. If a conversation does exist, the client checks whether a link already exists for the data item. If such a link exists, the client displays a message box to the user; otherwise, it calls its own SendAdvise function to send a WM_DDE_ADVISE message to the server for the item.

If a conversation on the topic does not already exist between the client and the server, the client first calls its own SendInitiate function to broadcast the WM_DDE_INITIATE message to request a conversation and, second, calls its own FindServerGivenAppTopic function to establish the conversation with the window that responds on behalf of the server application. After the conversation has begun, the client application calls SendAdvise to request the link.


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun