📄 dde_stuf.cpp
字号:
User_Reading = true;
rData = *(int*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (unsigned int& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_uint)) return false;
User_Reading = true;
rData = *(unsigned int*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (long& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_long)) return false;
User_Reading = true;
rData = *(long*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (unsigned long& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_ulong)) return false;
User_Reading = true;
rData = *(unsigned long*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (float& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_float)) return false;
User_Reading = true;
rData = *(float*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (double& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_double)) return false;
User_Reading = true;
rData = *(double*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (long double& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_long_double)) return false;
User_Reading = true;
rData = *(long double*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (char& rData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_char)) return false;
User_Reading = true;
rData = *(char*)pTheData;
User_Reading = false;
return true;
}
bool C_DDE_Item::GetValue (char* pData)
{
if ((DDE_Writing == true) || (TheDataType != DDT_string)) return false;
User_Reading = true;
strcpy (pData, (char*)pTheData);
User_Reading = false;
return true;
}
//-------------------------------------------------------------------------------------
// Function: SendAdviseData
// This function runs within the DDE thread. It checks to see if this data item
// is advise linked and has been changed by a call to SetValue(). If so, the
// function sends a message to the DDEML indicating that this data has changed.
// Clients which are advise linked to this data will be advised of the change
// and they'll send advise-request messages asking for the new value.
bool C_DDE_Item::SendAdviseData (void)
{
// If this item isn't advise linked or hasn't changed, don't send it to anybody
if ((AdviseLinked == false) || (DataChanged == false)) return false;
#ifdef MT_DEBUG_MODE
TakeDebugNote ("Post advise notice, item \"%s\"\n", ItemName);
#endif
// OK, there's something to send, so send it and clear the data-changed flag
DdePostAdvise (idInstance, hszTopic, hszItem);
DataChanged = false;
return true;
}
//-------------------------------------------------------------------------------------
// Function: PokeChangedData
// Running within the DDE thread, this function checks to see if data has been
// changed by the user's thread. If so, it sends the changed data to a server.
bool C_DDE_Item::PokeChangedData (HCONV hConversation)
{
HDDEDATA DidItWork; // Whether the transaction worked right
char DataString[256]; // Buffer to hold data in string format
// If DDEML isn't ready or the data hasn't changed, don't do anything
if ((DataChanged == false) || (hConversation == NULL) || (idInstance == 0L))
return false;
// Create a data handle for the data, then send data to the server synchronously
// (synchronously until I figure out how asynchronous transfers work, anyway)
strcpy (DataString, DataToString ());
HDDEDATA hData = DdeCreateDataHandle (idInstance, (LPBYTE)DataString,
lstrlen (DataString), 0L, hszItem, CF_TEXT, 0);
DidItWork = DdeClientTransaction ((LPBYTE)hData, -1, hConversation, hszItem,
CF_TEXT, XTYP_POKE, DDE_SYNCH_TIMEOUT, NULL);
#ifdef MT_DEBUG_MODE
TakeDebugNote ("Poke data item \"%s\", value \"%s\"\n", ItemName, DataString);
#endif
// If the data was sent successfully, return true to indicate that it was
if (DidItWork)
{
DataChanged = false;
return true;
}
else
return false;
}
//-------------------------------------------------------------------------------------
// Function: StartAdviseLink
// This function initiates and advise link. When this data item has been advise
// linked, the server will tell the client when the data's value changes, and
// the client (which owns this item) can then update the item's value.
void C_DDE_Item::StartAdviseLink (HCONV aConversation)
{
// If no conversation is currently taking place, we can't link any items
if ((idInstance == 0L) || (aConversation == NULL) || (AdviseLinked == false))
return;
// If there is a conversation active, try starting an advise link
DdeClientTransaction (NULL, NULL, aConversation, GetStringHandle (), CF_TEXT,
XTYP_ADVSTART, DDE_SYNCH_TIMEOUT, NULL);
}
//-------------------------------------------------------------------------------------
// Function: EndAdviseLink
// This function terminates an advise link which was set up the the function
// StartAdviseLink().
void C_DDE_Item::EndAdviseLink (HCONV aConversation)
{
// If no conversation is currently taking place, we can't link any items
if ((idInstance == 0L) || (aConversation == NULL) || (AdviseLinked == false))
return;
// If there is a conversation active, try starting an advise link
DdeClientTransaction (NULL, NULL, aConversation, GetStringHandle (), CF_TEXT,
XTYP_ADVSTOP, DDE_SYNCH_TIMEOUT, NULL);
}
//=====================================================================================
// Class: C_DDE_Topic
// This class represents a topic to be served by the DDE server. Each topic has
// a name and a list of data items associated with it.
//=====================================================================================
//-------------------------------------------------------------------------------------
// Constructor: C_DDE_Topic
// This constructor creates a new topic to be added to its parent DDE server's
// topic list.
C_DDE_Topic::C_DDE_Topic (const char* aName) : CBasicList ()
{
Name = new char[strlen (aName) + 1]; // Allocate space for topic name
strcpy (Name, aName); // Save the topic name
idInstance = 0L; // No handle to DDEML instance yet
}
//-------------------------------------------------------------------------------------
// Destructor: ~C_DDE_Topic
// This destructor just frees memory used by the topic object.
C_DDE_Topic::~C_DDE_Topic (void)
{
delete [] Name;
// Go through the data item list, deleting every data item we find
C_DDE_Item* pTemp;
C_DDE_Item* pCurItem = (C_DDE_Item*) GetHead ();
while (pCurItem != NULL)
{
pTemp = pCurItem;
pCurItem = (C_DDE_Item*) GetNext ();
delete (pTemp);
}
}
//-------------------------------------------------------------------------------------
// Function: Register
// This function registers the topic with DDEML. It's made separate from the
// constructor because the constructor is called from the user's thread, while
// this function must be called from within the DDE thread. When this function
// is called to register the topic, it also calls the Register() methods of all
// the items included in this topic.
void C_DDE_Topic::Register (DWORD aInstance)
{
// Save instance handle, create DDE string handle for the name of this topic
idInstance = aInstance;
hszTopic = DdeCreateStringHandle (idInstance, Name, CP_DDESERV);
if (hszTopic == 0L) DDE_CheckForError (idInstance);
#ifdef MT_DEBUG_MODE
TakeDebugNote ("Registering topic \"%s\", handle %08X\n", Name,
(int)hszTopic);
#endif
// Go through the data item list, registering every item we find
C_DDE_Item* pCurItem = (C_DDE_Item*) GetHead ();
while (pCurItem != NULL)
{
pCurItem->Register (idInstance, hszTopic);
pCurItem = (C_DDE_Item*) GetNext ();
}
}
//-------------------------------------------------------------------------------------
// Function: AddItem
// This function creates a new DDE item and adds it to this topic's item list.
// It's overloaded like crazy so that items can be created to contain data of
// each of the many types supported by the DDE server.
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, int& rData)
{
// Create a new data item and put a pointer to it in the list
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, unsigned int& rData)
{
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, long& rData)
{
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, unsigned long& rData)
{
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, float& rData)
{
// Create a new data item and put a pointer to it in the list
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, double& rData)
{
// Create a new data item and put a pointer to it in the list
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, long double& rData)
{
// Create a new data item and put a pointer to it in the list
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, char& rData)
{
// Create a new data item and put a pointer to it in the list
C_DDE_Item* pNew = new C_DDE_Item (aName, rData);
CBasicList::Insert ((void*)pNew);
return pNew;
}
C_DDE_Item* C_DDE_Topic::AddItem (const char* aName, char* rData, int aSize)
{
// Create a new data item and put a pointer to it in the list
C_DDE_Item* pNew = new C_DDE_Item (aName, rData, aSize);
CBasicList::Insert ((void*)pNew);
return pNew;
}
//-------------------------------------------------------------------------------------
// Function: GetItemWithName
// This function returns a pointer to an item in this topic's item list whose
// name matches the given name. If no item matches, it returns NULL.
C_DDE_Item* C_DDE_Topic::GetItemWithName (const char* aName)
{
// Go through the data item list, until we find the one we want
C_DDE_Item* pCurItem = (C_DDE_Item*)GetHead ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -