The client application includes the following files:
The following sample shows the client application code:
===============DDEC.C =============== #define INCL_WIN #define INCL_DOS #include <os2.h> #include <stdio.h> #include "ddec.h" #pragma linkage (main,optlink) INT main(VOID); void ShowMessage(PSZ); /***********************************************************************/ /* Main() - program entry point. */ /***********************************************************************/ MRESULT EXPENTRY LocalWndProc(HWND, ULONG, MPARAM, MPARAM); HAB hab; HWND hFrameWnd, hListWnd, hServerWnd; PFNWP SysWndProc; INT main (VOID) { HMQ hmq; FRAMECDATA fcd; QMSG qmsg; if (!(hab = WinInitialize(0))) return FALSE; if (!(hmq = WinCreateMsgQueue(hab, 0))) return FALSE; /***********************************************************************/ /* Setup the frame control data for the frame window. */ /***********************************************************************/ fcd.cb = sizeof(FRAMECDATA); fcd.flCreateFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_MENU | FCF_SIZEBORDER | FCF_SHELLPOSITION | FCF_MINMAX | FCF_TASKLIST; fcd.hmodResources = NULLHANDLE; /***********************************************************************/ /* Set our resource key (so PM can find menus, icons, etc). */ /***********************************************************************/ fcd.idResources = DDEC; /***********************************************************************/ /* Create the frame - it will hold the container control. */ /***********************************************************************/ hFrameWnd = WinCreateWindow(HWND_DESKTOP, WC_FRAME, "DDE Client", 0, 0, 0, 0, 0, NULLHANDLE, HWND_TOP, DDEC, &fcd, NULL); /***********************************************************************/ /* Verify that the frame was created; otherwise, stop. */ /***********************************************************************/ if (!hFrameWnd) return FALSE; /***********************************************************************/ /* Set an icon for the frame window. */ /***********************************************************************/ WinSendMsg(hFrameWnd, WM_SETICON, (MPARAM)WinQuerySysPointer(HWND_DESKTOP, SPTR_FOLDER, FALSE), NULL); /***********************************************************************/ /* Create a list window child. */ /***********************************************************************/ hListWnd = WinCreateWindow(hFrameWnd, WC_LISTBOX, NULL, LS_HORZSCROLL, 0, 0, 0, 0, hFrameWnd, HWND_BOTTOM, FID_CLIENT, NULL, NULL); /***********************************************************************/ /* We must intercept the frame window's messages */ /* (to capture any input from the container control). */ /* We save the return value (the current WndProc), */ /* so we can pass it all the other messages the frame gets. */ /***********************************************************************/ SysWndProc = WinSubclassWindow(hFrameWnd, (PFNWP)LocalWndProc); WinShowWindow(hFrameWnd, TRUE); /***********************************************************************/ /* Standard PM message loop - get it, dispatch i.t */ /***********************************************************************/ while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0)) { WinDispatchMsg(hab, &qmsg); } /***********************************************************************/ /* Clean up on the way out. */ /***********************************************************************/ WinDestroyMsgQueue(hmq); WinTerminate(hab); return TRUE; } /***********************************************************************/ /* LocalWndProc() - window procedure for the frame window. */ /* Called by PM whenever a message is sent to the frame. */ /***********************************************************************/ MRESULT EXPENTRY LocalWndProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2) { PSZ szData; /* DDE strings */ PSZ szApp = "DDEdemo", szTopic = "System"; PSZ szInApp, szInTopic; /* System-defined DDE structures */ CONVCONTEXT context; PDDEINIT pDDEinit; PDDESTRUCT pDDEdata; /* Server process and thread IDs */ PID pid; TID tid; /* Pointer to memory we'll allocate */ ULONG mem; switch(msg) { /* All answers to the WinDDEInitate call arrive here */ case WM_DDE_INITIATEACK: pDDEinit = (PDDEINIT)mp2; szInApp = pDDEinit->pszAppName; szInTopic = pDDEinit->pszTopic; ShowMessage("server answered..."); hServerWnd = (HWND)mp1; break; /* All answers to DDE requests arrive here */ case WM_DDE_DATA: ShowMessage("data in"); pDDEdata = (PDDESTRUCT)mp2; DosGetSharedMem(pDDEdata, PAG_READ | PAG_WRITE); szData = (BYTE *)(pDDEdata+(pDDEdata->offabData)); ShowMessage(szData); break; /* Menu item processing */ case WM_COMMAND: switch (SHORT1FROMMP(mp1)) { /* User starts DDE conversation */ case IDM_POLL: WinPostMsg(hListWnd, LM_DELETEALL, 0, 0); ShowMessage("Polling..."); context.cb = sizeof(CONVCONTEXT); context.fsContext = 0; WinDdeInitiate(hwnd, szApp, szTopic, &context); ShowMessage("Polling complete."); break; /* User requests data from the server */ case IDM_DATA: /* Get some sharable memory */ DosAllocSharedMem((PVOID)&mem, NULL, sizeof(DDESTRUCT)+21, PAG_COMMIT | PAG_READ | PAG_WRITE | OBJ_GIVEABLE); /* Get the server's ID and give it access */ /* to the shared memory */ WinQueryWindowProcess(hServerWnd, &pid, &tid); DosGiveSharedMem(&mem, pid, PAG_READ | PAG_WRITE); /* Setup DDE data structures */ /* (11 byte name length, 10 plus NULL, */ /* 10 byte data length) */ pDDEdata = (PDDESTRUCT)mem; pDDEdata->cbData = 10; /* Data length */ pDDEdata->fsStatus = 0; /* Status */ pDDEdata->usFormat = DDEFMT_TEXT; /* Text format */ /* Go past end of structure for the name */ pDDEdata->offszItemName = sizeof(DDESTRUCT); /* Go past end of data structure */ /* (plus past the name) for the data */ pDDEdata->offabData = sizeof(DDESTRUCT)+11; strcpy((BYTE *)(pDDEdata+(pDDEdata->offszItemName)), "STATUS"); /* Post our request to the server program */ WinDdePostMsg(hServerWnd, hwnd, WM_DDE_REQUEST, pDDEdata, DDEPM_RETRY); break; /* User terminates the conversation */ case IDM_CLOSE: WinDdePostMsg(hServerWnd, hwnd, WM_DDE_TERMINATE, NULL, DDEPM_RETRY); break; /* User closes the window */ case IDM_EXIT: WinPostMsg(hwnd, WM_CLOSE, 0, 0); break; } break; /* Send the message to the usual WC_FRAME WndProc */ default: return (*SysWndProc)(hwnd, msg, mp1, mp2); break; } return FALSE; } /***********************************************************************/ /* ShowMessage(). */ /***********************************************************************/ void ShowMessage(PSZ szText) { WinPostMsg(hListWnd, LM_INSERTITEM, MPFROMSHORT(LIT_END), szText); } =============== DDEC.RC =============== #include <os2.h> #include "ddec.h" MENU DDEC BEGIN SUBMENU "Commands", IDM_MENU BEGIN MENUITEM "Initiate", IDM_POLL MENUITEM "Data", IDM_DATA MENUITEM "Close", IDM_CLOSE MENUITEM "Exit", IDM_EXIT END END =============== DDEC.H =============== #define DDEC 100 #define IDM_MENU 101 #define IDM_POLL 102 #define IDM_INITIATE 103 #define IDM_DATA 104 #define IDM_CLOSE 105 #define IDM_EXIT 106 =============== DDEC.DEF =============== NAME DDEC WINDOWAPI DESCRIPTION 'PM DDE Client Sample' CODE MOVEABLE DATA MOVEABLE MULTIPLE STACKSIZE 24576 HEAPSIZE 10240 PROTMODE =============== DDEC.LNK =============== ddec.obj ddec.exe ddec.map ddec.def =============== DDEC.MAK =============== CC = icc /c /Ge /Gd- /Se /Re /ss /Gm+ LINK = link386 HEADERS = ddec.h #------------------------------------------------------------------- # A list of all of the object files. #------------------------------------------------------------------- ALL_OBJ1 = ddec.obj all: ddec.exe ddec.res: ddec.rc ddec.h ddec.obj: ddec.c $(HEADERS) ddec.exe: $(ALL_OBJ1) ddec.def ddec.lnk ddec.res $(LINK) @ddec.lnk rc -p -x ddec.res ddec.exe