⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dde_stuf.hpp

📁 a program that generates a pulse-width modulated (PWM)signal.
💻 HPP
📖 第 1 页 / 共 2 页
字号:
//*************************************************************************************
//  DDE_Stuf.hpp
//      This file contains the class definition for DDE handler objects.  These objects
//      encapsulate a DDE communication interface which allows C++ programs to talk
//      to each other or to applications such as Excel.
//
//  Classes
//      C_DDE_Item   - An item of data maintained by one of a server's topics
//      C_DDE_Topic  - A topic which is to be serviced by a DDE server
//      C_DDE_Server - A DDE server which services a bunch of topics and items
//      C_DDE_Client - A DDE client object with topics and items and such
//
//  Revisions
//       8-16-97  JRR  Original file
//       9-12-97  JRR  Merged client and server files into one big mess
//*************************************************************************************

#ifdef __WIN32__                            //  Only compile this for Win95/NT apps.
#ifndef BASE_OBJ_HPP                        //  Someone must #include the header for
    #include <base_obj.hpp>                 //  base objects before this file
#endif
#ifndef DDE_STUFF                           //  This section protects the header from
    #define DDE_STUFF                       //  being included twice in a source file

//  Define a code-page variable so that someone could change the code page if needed
#define CP_DDESERV  CP_WINANSI

//  Define a text style to be used for drawing text in the DDE server's GUI window
#define DT_DDESTYLE  \
        (DT_LEFT | DT_EXTERNALLEADING | DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX)

//  How many milliseconds can a DDE transaction take before it's considered too slow
const int DDE_SYNCH_TIMEOUT = 1000;

//  This enumeration defines the types of data which can be kept by the DDE server
enum DDE_Data_Type {DDT_int, DDT_uint, DDT_long, DDT_ulong, DDT_float, DDT_double,
                    DDT_long_double, DDT_char, DDT_string};

//  Prototypes for the nonmember functions
HWND Create_DDE_Window (const char*);       //  Function creates a GUI window for DDE
void DDE_CheckForError (DWORD);             //  Function checks for any DDE errors
const char* DDE_ErrorString (UINT);         //  Function converts error codes to text


//=====================================================================================
//  Class:  C_DDE_Item
//      This class represents one item of data to be maintained by the DDE server.
//      Each item has an item name, a type, and a value.  The data is still held by
//      the program module which created it; this object holds a pointer to the data
//      and can change the data's value in response to a POKE message from DDE or
//      send the data to DDE in response to a REQUEST message (through C_DDE_Server).
//=====================================================================================

class C_DDE_Item
    {
    private:
        void Construct (const char*);       //  Common bits for all constructors

        char* ItemName;                     //  String holds the DDE name of the item
        void* pTheData;                     //  Pointer to the data item
        DDE_Data_Type TheDataType;          //  What kind of data is this, anyway?
        DWORD idInstance;                   //  Instance handle for DDE system
        HSZ hszItem;                        //  String handle assigned by DDEML
        HSZ hszTopic;                       //  Handle for topic owning this item
        bool AdviseLinked;                  //  Is an advise link set up for this item
        bool DataChanged;                   //  Has data been changed by SetValue()
        bool DDE_Reading;                   //  Flags indicate when DDE is reading
        bool DDE_Writing;                   //  or writing data
        bool User_Reading;                  //  GetValue() is reading the data
        bool User_Writing;                  //  SetValue() is writing the data

    public:
        C_DDE_Item (const char*, int&);             //  There is one constructor
        C_DDE_Item (const char*, unsigned int&);    //  for each type of data to
        C_DDE_Item (const char*, long&);            //  be used.  This way the
        C_DDE_Item (const char*, unsigned long&);   //  user code doesn't have to
        C_DDE_Item (const char*, float&);           //  specify the data type; the
        C_DDE_Item (const char*, double&);          //  compiler will figure it
        C_DDE_Item (const char*, long double&);     //  out and call the correct
        C_DDE_Item (const char*, char&);            //  constructor which then
        C_DDE_Item (const char*, char*, int);       //  saves the data type

        ~C_DDE_Item (void);                 //  The one destructor frees up memory
        void Register (DWORD, HSZ);         //  Function registers strings with DDEML

        bool SetValue (int);                //  These functions all copy the value
        bool SetValue (unsigned int);       //  given in their argument into the
        bool SetValue (long);               //  data buffer.  The copy is performed in
        bool SetValue (unsigned long);      //  a thread-protected fashion using a
        bool SetValue (float);              //  bunch of flags to prevent conflicts
        bool SetValue (double);             //  between the DDE thread and the calling
        bool SetValue (long double);        //  thread.  If the setting was blocked
        bool SetValue (char);               //  because DDE is writing the data, the
        bool SetValue (const char*);        //  return value is false

        bool GetValue (int&);               //  These functions all copy the value
        bool GetValue (unsigned int&);      //  given in their argument into the
        bool GetValue (long&);              //  data buffer for this item.  The copy
        bool GetValue (unsigned long&);     //  must be performed in a thread-safe
        bool GetValue (float&);             //  fashion because the DDE communication
        bool GetValue (double&);            //  is taking place in a different thread
        bool GetValue (long double&);       //  from the user code which is calling
        bool GetValue (char&);              //  these functions.  If the reading was
        bool GetValue (char*);              //  blocked, the function returns false

        void StringToData (const char*);    //  Convert a string into data item format
        const char* DataToString (void);    //  and convert data to a string
        const char* GetName (void)          //  Function returns the name of this
            { return ItemName; }            //  data item
        HSZ GetStringHandle (void)          //  This function returns a handle to the
            { return hszItem; }             //  DDE string with the data item's name
        void AdviseLink (void)              //  Function tells the item it will be
            { AdviseLinked = true; }        //  advise-linked to a server or client
        void AdviseUnlink (void)            //  Function which tells this item it
            { AdviseLinked = false; }       //  should cut off its advise link
        const bool IsAdviseLinked (void)    //  Function tells the caller if the item
            { return (AdviseLinked); }      //  is currently advise linked to a client
        bool SendAdviseData (void);         //  Send advise-linked data to DDE clients
        void StartAdviseLink (HCONV);       //  Set up an advise link to a server
        void EndAdviseLink (HCONV);         //  Break the aforementioned advise link
        bool PokeChangedData (HCONV);       //  Send client's data to a DDE server
    };


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

class C_DDE_Topic : public CBasicList
    {
    private:
        char* Name;                         //  String holds the name of this topic    
        HSZ hszTopic;                       //  Handle to string with topic name
        DWORD idInstance;                   //  Instance handle for DDE system

    public:
        //  Constructor gets topic name and DDEML instance handle
        C_DDE_Topic (const char*);
        ~C_DDE_Topic (void);

        void Register (DWORD);              //  Register topic & its items with DDEML

        //  Functions to add a new data item to this topic's list
        C_DDE_Item* AddItem (const char*, int&);
        C_DDE_Item* AddItem (const char*, unsigned int&);
        C_DDE_Item* AddItem (const char*, long&);
        C_DDE_Item* AddItem (const char*, unsigned long&);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -