На главную

On-line справка по Win32 API

Написать письмо
БЕСПЛАТНАЯ ежедневная online лотерея! Выигрывай каждый день БЕСПЛАТНО!
Список всех статей A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X-Y-Z | Скачать Вниз

Initiating a Conversation



To initiate a DDE conversation, the client sends a WM_DDE_INITIATE message. Usually, the client broadcasts this message by calling SendMessage, with -1 as the first parameter. If the application already has the window handle of the server application, it can send the message directly to that window. The client prepares atoms for the application name and topic name by calling GlobalAddAtom. The client can request conversations with any potential server application and for any potential topic by supplying NULL (wildcard) atoms for the application and topic.

The following example illustrates how the client initiates a conversation, where both the application and topic are specified.

/* Global variable */

static BOOL fInInitiate = FALSE;
char *szApplication;
char *szTopic;
atomApplication = *szApplication == 0 ?
NULL : GlobalAddAtom((LPSTR) szApplication);
atomTopic = *szTopic == 0 ?
NULL : GlobalAddAtom((LPSTR) szTopic);

fInInitiate = TRUE;
SendMessage((HWND) -1, /* broadcasts message */
WM_DDE_INITIATE, /* initiates conversation */
(WPARAM) hwndClientDDE, /* handle of client DDE window */

MAKELONG(atomApplication, /* application-name atom */
atomTopic)); /* topic-name atom */
fInInitiate = FALSE;
if (atomApplication != NULL)
GlobalDeleteAtom(atomApplication);
if (atomTopic != NULL)
GlobalDeleteAtom(atomTopic);


Note that if your application uses NULL atoms, you need not use the GlobalAddAtom and GlobalDeleteAtom functions. In this example, the client application creates two global atoms containing the name of the server and the name of the topic, respectively.
The client application sends a WM_DDE_INITIATE message with these two atoms in the lParam parameter of the message. In the call to the SendMessage function, the special window handle -1 directs Windows to send this message to all other active applications. SendMessage does not return to the client application until all applications that receive the message have, in turn, returned control to Windows. This means that all WM_DDE_ACK messages sent in reply by the server applications are guaranteed to have been processed by the client by the time the SendMessage call has returned.

After SendMessage returns, the client application deletes the global atoms.
Server applications respond according to the logic illustrated in the following diagram.

To acknowledge one or more topics, the server must create atoms for each conversation (requiring duplicate application-name atoms if there are multiple topics) and send a WM_DDE_ACK message for each conversation, as illustrated in the following example.

if ((atomApplication = GlobalAddAtom("Server")) != 0) {
if ((atomTopic = GlobalAddAtom(szTopic)) != 0) {
SendMessage(hwndClientDDE,
WM_DDE_ACK,
(WPARAM) hwndServerDDE,
MAKELONG(atomApplication, atomTopic));
GlobalDeleteAtom(atomApplication);
}

GlobalDeleteAtom(atomTopic);
}

if ((atomApplication == 0) || (atomTopic == 0)) {

.
. /* error handling */
.

}


When a server responds with a WM_DDE_ACK message, the client application should save the handle of the server window. The client receiving the handle as the wParam parameter of the WM_DDE_ACK message then sends all subsequent DDE messages to the server window this handle identifies.
If your client application uses a NULL atom for the application name or topic name, expect the application to receive acknowledgments from more than one server application. Multiple acknowledgements can also come from multiple instances of a DDE server, even if your client application does not use NULL atoms. A server should always use a unique window for each conversation. The window procedure in the client application can use the handle of the server window (provided as the lParam parameter of WM_DDE_INITIATE) to track multiple conversations. This allows a single client window to process several conversations without needing to terminate and reconnect with a new client window for each conversation.


Пригласи друзей и счет твоего мобильника всегда будет положительным!
Предыдущая статья
 
Сайт Народ.Ру Интернет
Следующая статья
Пригласи друзей и счет твоего мобильника всегда будет положительным!

Вводящий Разговор



Чтобы вводить разговор DDE, клиент посылает сообщение WM_DDE_INITIATE. Обычно, клиент транслирует это сообщение вызывая SendMessage, с -1 как первый параметр. Если приложение уже имеет ручку окна приложения сервера, оно может послать сообщение непосредственно в это окно. Клиент подготавливает атомы к прикладному имени и имя темы вызывая GlobalAddAtom. Клиент может запросить беседу с любым потенциальным приложением сервера и для любой потенциальной темы поставляя НЕДЕЙСТВИТЕЛЬНЫЕ атомы (шаблон) для приложения и темы.

Следующий пример иллюстрирует как клиент вводит разговор, где как приложение так и тема определены.

/* Глобальная переменная */

статическая BOOL fInInitiate = ЛОЖЬ;
символ *szApplication;
символ *szTopic;
atomApplication = *szApplication == 0?
НЕДЕЙСТВИТЕЛЬНЫЙ : GlobalAddAtom((LPSTR) szApplication);
atomTopic = *szTopic == 0?
НЕДЕЙСТВИТЕЛЬНЫЙ : GlobalAddAtom((LPSTR) szTopic);

fInInitiate = ИСТИНА;
SendMessage((HWND) -1, /* ТРАНСЛИРОВАТЬ сообщение */ WM_DDE_INITIATE, /* разговор initiates */ (WPARAM) hwndClientDDE, /* оперировать окна клиента DDE */

MAKELONG(atomApplication, /* ПРИКЛАДНОЕ имя атома */ atomTopic)); /* тема-имя атома */ fInInitiate = ЛОЖЬ;
если (atomApplication != НЕДЕЙСТВИТЕЛЬНЫЙ) GlobalDeleteAtom(atomApplication);
если (atomTopic != НЕДЕЙСТВИТЕЛЬНЫЙ) GlobalDeleteAtom(atomTopic);


Отметьтесь, что если ваше приложение использует НЕДЕЙСТВИТЕЛЬНЫЕ атомы, Вы не должны использовать GlobalAddAtom и функции GlobalDeleteAtom. В этом примере, приложение клиента создает два глобальных атомов, содержащих имя сервера и имя темы, соответственно.
Приложение клиента посылает сообщение WM_DDE_INITIATE с этими двумя атомами в параметре lParam сообщения. На вызове в функцию SendMessage, специальная ручка окна -1 направлять Windows, чтобы посылать это сообщение во все другие активные приложения. SendMessage НЕ возвращается в приложение клиента до всех приложений, которые получают сообщение, в свою очередь, возвращал управление на Windows. Это означает, что все сообщения WM_DDE_ACK посланные в ответ приложениями сервера гарантированы обработанное клиентом когда вызов SendMessage возвращался.

После возврат SendMessage, приложение клиента удаляет глобальные атомы.
Приложения Сервера отвечают в зависимости от того логика иллюстрировалась на следующей диаграмме.

Для того, чтобы признавать одна или более тем, сервер должен создать атомы для каждого разговора (двойные атомы требовать прикладного имени если есть многочисленные темы) и посылать сообщение WM_DDE_ACK для каждого разговора, как проиллюстрировано в следующем примере.

если ((atomApplication = GlobalAddAtom("Server")) != 0) { если ((atomTopic = GlobalAddAtom(szTopic)) != 0) { SendMessage(hwndClientDDE, WM_DDE_ACK, (WPARAM) hwndServerDDE, MAKELONG(atomApplication, atomTopic));
GlobalDeleteAtom(atomApplication);
}

GlobalDeleteAtom(atomTopic);
}

если ((atomApplication == 0) || (atomTopic == 0)) {

.
. /* обработка ошибки */
.

}


Когда сервер указывает сообщение WM_DDE_ACK, приложение клиента должно сохранять ручку окна сервера. Клиент, получающий ручку как параметр wParam сообщения WM_DDE_ACK затем посылает всем последующим сообщениям DDE в окно сервера эту ручку идентифицируется.
Если ваше приложение клиента использует НЕДЕЙСТВИТЕЛЬНОМУ атому для прикладного имени или имени темы, ожидайте, что приложение получит признания из более, чем одного приложения сервера. Многочисленные подтверждения могут также исходить из многочисленных примеров сервера DDE, даже если бы ваше приложение клиента не использует НЕДЕЙСТВИТЕЛЬНЫЕ атомы. Сервер должен всегда использовать уникальное окно для каждого разговора. Процедура окна в приложении клиента может использовать ручку окна сервера (предусмотренное как параметр lParam WM_DDE_INITIATE), чтобы прослеживать многочисленную беседу. Это позволяет единственное окно клиента, чтобы обрабатывать несколько беседы без необходимости завершать и пересоединяться с новым окном клиента для каждого разговора.


Вверх Version 1.3, Oct 26 2010 © 2007, 2010, mrhx Вверх
 mrhx software  Русский перевод OpenGL  Русский перевод Win32 API
 
Используются технологии uCoz