home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / w / wpjv1n1.zip / PMDDE.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  4KB  |  119 lines

  1. /*  PMDDE.C
  2.     Pete Davis
  3.     Windows Programmer's Journal
  4.     Volume 1 Number 1
  5.     Copyright 1992
  6.  
  7.     This is the Program Manager DDE Window procedure.
  8.  
  9. */
  10.  
  11. #include <windows.h>
  12. #include "install.h"   /* Not included with WPJV1N1 */
  13.  
  14.  
  15. long FAR PASCAL DDEWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
  16. {
  17.    LPSTR           Command, TStr;      /* Used for building user commands */
  18.    HANDLE          MemStuff;           /* Same as above                   */
  19.    static BOOL     FirstAck;           /* Is the WM_DDE_ACK for the INIT? */
  20.    ATOM            Topic, Application; /* Our PROGMAN Topic and App. atoms*/
  21.    static HWND     hProgman;           /* Handle for Program Manager.     */
  22.  
  23.    switch(message)
  24.    {
  25.  
  26.         case WM_CREATE:
  27.                 /* make sure that first Ack grabs hProgman */
  28.                 FirstAck    = TRUE;                   
  29.  
  30.                 /* Setup Application and Topic atoms */
  31.                 Application = GlobalAddAtom("PROGMAN");
  32.                 Topic       = GlobalAddAtom("PROGMAN");
  33.  
  34.                 /* Initiate the DDE conversation */
  35.                 SendMessage(-1,WM_DDE_INITIATE, hWnd, MAKELONG(Application, Topic));
  36.  
  37.                 /* Don't need our atoms anymore */
  38.                 GlobalDeleteAtom(Application);
  39.                 GlobalDeleteAtom(Topic);
  40.                 break;
  41.  
  42.  
  43.         case WM_DDE_ACK:
  44.                 if(FirstAck)    /* Gotta get hProgman */
  45.                 {
  46.                         /* We only handle the DDE_ACK this way once. */
  47.                         FirstAck=FALSE
  48.  
  49.                         /* Get rid of Program Manager's atoms. These are
  50.                            set by Program Manager as to it's topic and
  51.                            application. We already know what they are. */
  52.                         GlobalDeleteAtom(LOWORD(lParam));
  53.                         GlobalDeleteAtom(HIWORD(lParam));
  54.  
  55.                         /* Get the handle for Program Manager */
  56.                         hProgman = wParam;
  57.                 }
  58.                 else
  59.                 {
  60.                         /* Kill anything it's trying to return */
  61.                         if (HIWORD(lParam))
  62.                                 GlobalFree(HIWORD(lParam));
  63.  
  64.                 }
  65.                 break;
  66.  
  67.         case WM_CREATE_PMGRP:
  68.                 /* Just assume 80 chars as max for our string. */
  69.                 /* Allocate the block                          */
  70.                 MemStuff =GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, 80);
  71.  
  72.                 /* Lock it so we can use it */
  73.                 Command = GlobalLock(MemStuff);
  74.                 
  75.                 /* Set up our Program Manager Command */
  76.                 lstrcpy(Command, "[CREATEGROUP(");
  77.  
  78.                 /* Get the users program group name */
  79.                 TStr = GlobalLock(wParam);
  80.  
  81.                 /* Finish building Command */
  82.                 lstrcat(Command, TStr);
  83.                 lstrcat(Command, ")]");
  84.  
  85.                 /* Unlock it so we can pass it off to Program Manager */
  86.                 GlobalUnlock(MemStuff);
  87.  
  88.                 /* Have Program Manager execute the command */
  89.                 PostMessage(hProgman, WM_DDE_EXECUTE, hWnd, MAKELONG(0,MemStuff));
  90.  
  91.                 /* Bang, we're done here */
  92.                 break;
  93.  
  94.  
  95.         case WM_ADD_ITEM:
  96.                 /* Comments are the same as last message */
  97.                 MemStuff =GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, 80);
  98.                 Command = GlobalLock(MemStuff);
  99.                 lstrcpy(Command, "[ADDITEM(");
  100.                 TStr = GlobalLock(wParam);
  101.                 lstrcat(Command, TStr);
  102.                 lstrcat(Command, ")]");
  103.                 GlobalUnlock(MemStuff);
  104.                 PostMessage(hProgman, WM_DDE_EXECUTE, hWnd, MAKELONG(0,MemStuff));
  105.                 break;
  106.  
  107.  
  108.         /* And to end the DDE session */
  109.         case WM_END_DDE:
  110.                 PostMessage(hProgMan, WM_DDE_TERMINATE, hWnd, 0L);
  111.                 break;
  112.  
  113.         default:
  114.                 return DefWindowProc(hWnd, message, wParam, lParam);
  115.         }
  116.         return(0L);
  117. }
  118.  
  119.