home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PRIMAR.ZIP / DUMMY.C next >
Text File  |  1991-10-25  |  17KB  |  372 lines

  1. /*----------------------------------------------------------------------------*/
  2. /*--                                                                       ---*/
  3. /*--     Creation function and window procedure for Object DUMMY         ---*/
  4. /*--                                                                       ---*/
  5. /*----------------------------------------------------------------------------*/
  6.  
  7. /***********************************/
  8. /* C and PM definitions            */
  9. /***********************************/
  10. #define INCL_DOSMODULEMGR
  11. #define INCL_WINDDE
  12. #define INCL_WINFRAMEMGR
  13. #define INCL_WINHELP
  14. #define INCL_WININPUT
  15. #define INCL_WINSTDDRAG
  16. #include <os2.h>
  17.  
  18. #include <stdlib.h>
  19. #include <string.h>
  20. /*-----------------------------*/
  21. /* Interfaces to other objects */
  22. /*-----------------------------*/
  23. #include <seidlg2.h>
  24.  
  25. /*----------------------*/
  26. /* External header file */
  27. /*----------------------*/
  28. #include <dummy.h>
  29.  
  30. /*----------------------*/
  31. /* Internal header file */
  32. /*----------------------*/
  33. #include "dummyi.h"
  34.  
  35. /*-----------------------*/
  36. /* Prototype definitions */
  37. /*-----------------------*/
  38.  
  39. MRESULT EXPENTRY DlgWinProc( HWND hwnd, USHORT message,
  40.                              MPARAM mp1, MPARAM mp2 );
  41.  
  42. MRESULT EXPENTRY DlgProc   ( HWND hwnd, USHORT message,
  43.                              MPARAM mp1, MPARAM mp2 );
  44.  
  45. /*============================================================================*/
  46. /*=========================     CreateDummy     ============================*/
  47. /*============================================================================*/
  48. /*                                                                            */
  49. /*   PROCEDURE:        CreateDummy   (HWND, PVOID)                          */
  50. /*                                                                            */
  51. /*   INPUT PARAMETER:  (HWND) Window handle of the OWNER window               */
  52. /*                     (PVOID) Pointer to parameter structure                 */
  53. /*                                                                            */
  54. /*   RETURN VALUE:     Window handle of the frame of the dialog window        */
  55. /*                                                                            */
  56. /*   DESCRIPTION:      This is the creation function for an object DUMMY    */
  57. /*                                                                            */
  58. /*   STARTED BY:       who knows !!!                                          */
  59. /*                                                                            */
  60. /*----------------------------------------------------------------------------*/
  61. HWND EXPENTRY CreateDummy ( HWND hwnd, PVOID pParamDummy) {
  62.  
  63.   USHORT  usrc;
  64.   HMODULE hModule;
  65.   HWND    hwndFrame;
  66.  
  67.   usrc = DosGetModHandle (DLL_NAME, &hModule);
  68.  
  69.  
  70.   hwndFrame = SeiCreateDialogWindow (HWND_DESKTOP,      /* Parent      */
  71.                                      hwnd,              /* Owner       */
  72.                                      WS_VISIBLE,        /* Frame style */
  73.                                      NULL,              /* FCF         */
  74.                                      DlgWinProc,        /* WinProc     */
  75.                                      NULL,              /* Title       */
  76.                                      hModule,           /* Resource    */
  77.                                      DLG_MAIN,          /* ResourceID  */
  78.                                      pParamDummy);
  79.  
  80.   return (hwndFrame);
  81.   }
  82.  
  83.  
  84. /*============================================================================*/
  85. /*=========================     CreateSmallDummy     =======================*/
  86. /*============================================================================*/
  87. /*                                                                            */
  88. /*   PROCEDURE:        CreateSmallDummy (HWND, PVOID))                      */
  89. /*                                                                            */
  90. /*   INPUT PARAMETER:  (HWND) Window handle of the OWNER window               */
  91. /*                     (PVOID) Pointer to parameter structure                 */
  92. /*                                                                            */
  93. /*   RETURN VALUE:     Window handle of the frame of the dialog window        */
  94. /*                                                                            */
  95. /*   DESCRIPTION:      This is the creation function for an object DUMMY    */
  96. /*                                                                            */
  97. /*   STARTED BY:       who knows !!!                                          */
  98. /*                                                                            */
  99. /*----------------------------------------------------------------------------*/
  100. HWND EXPENTRY CreateSmallDummy ( HWND hwnd, PVOID pParamDummy)
  101.  {
  102.  
  103.   USHORT  usrc;
  104.   HMODULE hModule;
  105.   HWND    hwndFrame;
  106.  
  107.   usrc = DosGetModHandle (DLL_NAME, &hModule);
  108.  
  109.  
  110.   hwndFrame = SeiCreateDialogWindow (HWND_DESKTOP,      /* Parent       */
  111.                                      hwnd,              /* Owner        */
  112.                                      NULL,              /* Frame style  */
  113.                                      NULL,              /* FCF          */
  114.                                      DlgWinProc,        /* WinProc      */
  115.                                      NULL,              /* Title        */
  116.                                      hModule,           /* Resource     */
  117.                                      DLG_MAIN,          /* ResourceID   */
  118.                                      pParamDummy);
  119.  
  120.   WinSetWindowPos (hwndFrame, HWND_TOP, 20, 20, 200, 200,
  121.                    SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
  122.  
  123.   return (hwndFrame);
  124.   }
  125.  
  126.  
  127. /*============================================================================*/
  128. /*============================   DlgWinProc    ===============================*/
  129. /*============================================================================*/
  130. /*                                                                            */
  131. /*   PROCEDURE:   DlgWinProc(HWND, USHORT, ULONG, ULONG)                      */
  132. /*                                                                            */
  133. /*   DESCRIPTION: Message handling procedure for ID_DIALOG                    */
  134. /*                                                                            */
  135. /*   STARTED BY:  main                                                        */
  136. /*                                                                            */
  137. /*----------------------------------------------------------------------------*/
  138. MRESULT EXPENTRY DlgWinProc( HWND hwnd, USHORT message,
  139.                              MPARAM mp1, MPARAM mp2 )  {
  140.  
  141.   switch (message) {
  142.  
  143.     case WM_INITDLG: {
  144.          WinSetDlgItemText (hwnd, EF_NAME, PVOIDFROMMP (mp2));
  145.          } break;
  146.  
  147.     case WM_CONTROL: {
  148.          /*-----------------------------------------------------*/
  149.          /* This peace of code makes sure, that the window with */
  150.          /* the keyboard focus is always visible.               */
  151.          /* This code is optional!                              */
  152.          /*-----------------------------------------------------*/
  153.          if (SeiIsSetFocusNotification (hwnd,
  154.                                         SHORT1FROMMP (mp1),
  155.                                         SHORT2FROMMP (mp1))) {
  156.              SeiMoveToTop (hwnd,                         /* Window handle   */
  157.                            SHORT1FROMMP (mp1),           /* Control ID      */
  158.                            FALSE);                       /* Only is outside */
  159.  
  160.              SeiMoveToLeft (hwnd,                        /* Window handle   */
  161.                             SHORT1FROMMP (mp1),          /* Control ID      */
  162.                             FALSE);                      /* Only is outside */
  163.          }
  164.          } break;
  165.  
  166.     case WM_ACTIVATE: {
  167.          SeiChangeHelpTable (SeiQueryDialogFrame (hwnd),
  168.                              DLL_NAME, DUMMY_HELPTABLE, HELP_LIB,
  169.                              SHORT1FROMMP (mp1));
  170.          } break;
  171.  
  172.     case WM_CLOSE: {
  173.          WinDestroyWindow (hwnd);
  174.          } break;
  175.  
  176.     case WM_COMMAND: {
  177.          switch (SHORT1FROMMP (mp1))
  178.            {
  179.            case MN_FILEOPEN:
  180.                 CreateSmallDummy (WinQueryWindow (SeiQueryDialogFrame (hwnd),
  181.                                                   QW_OWNER, TRUE),
  182.                                   "Little John Doe");
  183.  
  184.                 break;
  185.  
  186.            case MN_FILEEXIT:
  187.                 /*--------------------*/
  188.                 /* Destroy the window */
  189.                 /*--------------------*/
  190.                 WinDestroyWindow (hwnd);
  191.                 break;
  192.  
  193.            case MN_FILENEW: {
  194.                 HMODULE     hmod;
  195.  
  196.                 /*---------------------*/
  197.                 /* Open a modal dialog */
  198.                 /*---------------------*/
  199.                 DosGetModHandle (DLL_NAME, &hmod);
  200.                 WinDlgBox (HWND_DESKTOP, hwnd,
  201.                            DlgProc, hmod, DLG_DIALOG, NULL);
  202.                 } break;
  203.  
  204.            default:
  205.                 DosBeep (500,100);
  206.                 break;
  207.            } /* end WM_COMMAND switch */
  208.  
  209.            } return (0); /* !!! Very, very, very IMPORTANT !!!!!             */
  210.                          /* Never use break at the end of WM_COMMAND !!!!!!  */
  211.  
  212.     /*********************************************************************/
  213.     /**********************  DRAG DROP SUPPORT ***************************/
  214.     /*********************************************************************/
  215.     case WM_BUTTON2DOWN: {
  216.          HPOINTER    hPtr;
  217.          PSZ         pszSendableDatatypes[1];
  218.          /*---------------------------------------------------------------*/
  219.          /* Build list of data types sendable through direct manipulation */
  220.          /*---------------------------------------------------------------*/
  221.          pszSendableDatatypes[0] = DDECUSTOMERTYPE;
  222.  
  223.          /*-----------------------------------------*/
  224.          /* Determine the shape of the drag pointer */
  225.          /*-----------------------------------------*/
  226.          hPtr = WinSendMsg (SeiQueryDialogFrame(hwnd), WM_QUERYICON,
  227.                             NULL, NULL);
  228.          SeiInitDrag (hwnd, pszSendableDatatypes, 1, hPtr);
  229.          return ((MRESULT)FALSE);
  230.          }
  231.  
  232.     case DM_DRAGOVER: {
  233.          SHORT sGoodDragitemIndex;
  234.          PSZ         pszReceivableDatatypes[1];
  235.  
  236.          /*-----------------------------------------------------------------*/
  237.          /* Build list of data types receivable through direct manipulation */
  238.          /*----------------------------------------------------------------*/
  239.          pszReceivableDatatypes[0] = DDECUSTOMERTYPE;
  240.          if (SeiDragOver ((PDRAGINFO) mp1, pszReceivableDatatypes, 1,
  241.                           &sGoodDragitemIndex )) {
  242.              /*-----------------*/
  243.              /* Data type is OK */
  244.              /*-----------------*/
  245.              DrgFreeDraginfo((PDRAGINFO)mp1);
  246.              return (MRFROM2SHORT (DOR_DROP, DO_COPY));
  247.          } else {
  248.              /*---------------------*/
  249.              /* Data type is not OK */
  250.              /*---------------------*/
  251.              DrgFreeDraginfo((PDRAGINFO)mp1);
  252.              return (MRFROM2SHORT (DOR_NEVERDROP, DO_COPY));
  253.          }
  254.          } break;
  255.  
  256.     case DM_DROP: {
  257.          /*-------------------------------------------*/
  258.          /* Request data with format 0                */
  259.          /* This method creates the DM_RENDER message */
  260.          /*-------------------------------------------*/
  261.          return ((MRESULT)SeiDrop (hwnd, (PDRAGINFO) mp1, 0));
  262.          }
  263.  
  264.     case DM_RENDER: {
  265.          /*--------------------------*/
  266.          /* Render customer DDE data */
  267.          /*--------------------------*/
  268.          DDECUSTOMER   ddeCust;
  269.          ddeCust.cb = (ULONG)sizeof (DDECUSTOMER);
  270.          WinQueryDlgItemText (hwnd, EF_NAME, sizeof (ddeCust.pszCustomer),
  271.                               ddeCust.pszCustomer);
  272.          WinQueryDlgItemText (hwnd, EF_CITY, sizeof (ddeCust.pszCity),
  273.                               ddeCust.pszCity);
  274.          WinQueryDlgItemText (hwnd, EF_STREET, sizeof (ddeCust.pszStreet),
  275.                               ddeCust.pszStreet);
  276.          WinQueryDlgItemText (hwnd, EF_ZIP, sizeof (ddeCust.pszZip),
  277.                               ddeCust.pszZip);
  278.          return ((MRESULT)SeiRender (hwnd, (PDRAGTRANSFER)mp1, (ULONG)sizeof(DDECUSTOMER),
  279.                                      &ddeCust));
  280.          }
  281.  
  282.     case WM_DDE_DATA: {
  283.          /*-----------------------------------------------------*/
  284.          /* This message is received by the TARGET container    */
  285.          /* Parameter 2 contains a pointer to the DDESTRUCT     */
  286.          /*-----------------------------------------------------*/
  287.          ULONG          cb;
  288.          CHAR           pszDDEType[40];
  289.          DDECUSTOMER    ddeCust;
  290.          /*----------------------------------*/
  291.          /* Determine the received data type */
  292.          /*----------------------------------*/
  293.          SeiQueryDDEDataInfo ((PDDESTRUCT) mp2, &cb, pszDDEType,
  294.                               (ULONG) sizeof(pszDDEType));
  295.  
  296.          /*-----------*/
  297.          /* Read data */
  298.          /*-----------*/
  299.          SeiGetDDEData ((PDDESTRUCT)mp2, (PVOID)&ddeCust, cb);
  300.  
  301.          /*---------------------*/
  302.          /* Update entry fields */
  303.          /*---------------------*/
  304.          WinSetDlgItemText (hwnd, EF_NAME,
  305.                               ddeCust.pszCustomer);
  306.          WinSetDlgItemText (hwnd, EF_CITY,
  307.                               ddeCust.pszCity);
  308.          WinSetDlgItemText (hwnd, EF_STREET,
  309.                               ddeCust.pszStreet);
  310.          WinSetDlgItemText (hwnd, EF_ZIP,
  311.                               ddeCust.pszZip);
  312.  
  313.          /*-------------------------*/
  314.          /* Change the window title */
  315.          /*-------------------------*/
  316.          WinSetWindowText (SeiQueryDialogFrame (hwnd),
  317.                            ddeCust.pszCustomer);
  318.  
  319.          /*-------------------------------------------------------*/
  320.          /* Be polite, and don't forget to acknowledge the        */
  321.          /* reception of the data !!!!!!!!!!!!!!!!!!!!!!          */
  322.          /*-------------------------------------------------------*/
  323.          SeiDDEAck (hwnd, (PDDESTRUCT) mp2, (HWND) mp1,
  324.                     (USHORT) TRUE);
  325.          } break;
  326.  
  327.     case WM_DDE_ACK: {
  328.          /*------------------------------------------------*/
  329.          /* Data transfer was OK. Let's free DDE structure */
  330.          /*------------------------------------------------*/
  331.          DosFreeSeg (SELECTOROF(mp2));
  332.          } break;
  333.     default:
  334.          break;
  335.     } /* end switch */
  336.   /*-------------------------------------------------------------------*/
  337.   /* Don't call WinDefDlgProc BUT SeiDefDlgProc !!!!!!!!               */
  338.   /*-------------------------------------------------------------------*/
  339.   return((MRESULT)SeiDefDlgProc(hwnd,message,mp1,mp2));
  340.  
  341. }/* end of DlgWinProc */
  342.  
  343. /*============================================================================*/
  344. /*============================   DlgProc       ===============================*/
  345. /*============================================================================*/
  346. /*                                                                            */
  347. /*   PROCEDURE:   DlgProc(HWND, USHORT, ULONG, ULONG)                         */
  348. /*                                                                            */
  349. /*   DESCRIPTION:                                                             */
  350. /*                                                                            */
  351. /*   STARTED BY:                                                              */
  352. /*                                                                            */
  353. /*----------------------------------------------------------------------------*/
  354. MRESULT EXPENTRY DlgProc( HWND hwnd, USHORT message,
  355.                           MPARAM mp1, MPARAM mp2 )  {
  356.  
  357.   switch (message) {
  358.  
  359.  
  360.     case WM_ACTIVATE: {
  361.          SeiChangeHelpTable (hwnd,
  362.                              DLL_NAME, DUMMY_HELPTABLE, HELP_LIB,
  363.                              SHORT1FROMMP (mp1));
  364.          } break;
  365.  
  366.     default:
  367.          break;
  368.     } /* end switch */
  369.   return((MRESULT)WinDefDlgProc(hwnd,message,mp1,mp2));
  370.  
  371. }/* end of DlgProc */
  372.