home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PMHINTS1.ZIP / HINTS.C < prev    next >
Text File  |  1991-05-03  |  11KB  |  331 lines

  1. #define  INCL_WIN
  2.  
  3. #include <os2.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include "hints.h"
  7.  
  8.  
  9. PFNWP   OldFrameProc;
  10.  
  11. MRESULT EXPENTRY MainWndProc  (HWND, USHORT, MPARAM, MPARAM);
  12. MRESULT EXPENTRY ChildWndProc (HWND, USHORT, MPARAM, MPARAM);
  13. MRESULT EXPENTRY NewFrame     (HWND, USHORT, MPARAM, MPARAM);
  14.  
  15. /****************************************************************************/
  16.  
  17. VOID    cdecl main (void)
  18. {
  19.   HAB     hab;
  20.   HMQ     hmq;
  21.  
  22.   static  HWND   hwndEntry,
  23.                  hwndClient,
  24.                  hwndChild,
  25.                  hwndFrame,
  26.                  hwndChildFrame;
  27.  
  28.   QMSG    qmsg;
  29.  
  30.   ULONG   flFrameFlags,
  31.           flCFrameFlags,
  32.           DataLength;
  33.  
  34.   CHAR    Title[80],
  35.           CTitle[80];
  36.  
  37.   SWCNTRL PgmEntry;
  38.  
  39.   SWP     swp;
  40.  
  41. /****************************************************************************/
  42.  
  43.   hab = WinInitialize(0);
  44.   hmq = WinCreateMsgQueue(hab, 0);
  45.  
  46.   WinRegisterClass(hab,
  47.                    "Hints",
  48.                    MainWndProc,
  49.                    CS_SIZEREDRAW,
  50.                    0);
  51.  
  52.   WinRegisterClass(hab,
  53.                    "Hints2",
  54.                    ChildWndProc,
  55.                    CS_SIZEREDRAW,
  56.                    0);
  57.  
  58.   WinLoadString( hab, NULL, ID_TITLE, sizeof(Title), Title );
  59.   WinLoadString( hab, NULL, ID_CTITLE, sizeof(CTitle), CTitle );
  60.  
  61.   flCFrameFlags  = FCF_TITLEBAR   | FCF_SYSMENU | FCF_NOBYTEALIGN |
  62.                    FCF_SIZEBORDER | FCF_MINMAX;
  63.  
  64.   flFrameFlags  = FCF_TITLEBAR   | FCF_SYSMENU    | FCF_MENU       |
  65.                   FCF_SIZEBORDER | FCF_MINMAX     | FCF_ACCELTABLE |
  66.                   FCF_NOBYTEALIGN;
  67.  
  68.   hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  69.                                  0L,
  70.                                  &flFrameFlags,
  71.                                  "Hints",
  72.                                  (PSZ)Title,
  73.                                  0L,
  74.                                  NULL,
  75.                                  ID_MAINWND,
  76.                                  &hwndClient);
  77.  
  78.   OldFrameProc = WinSubclassWindow(hwndFrame, (PFNWP)NewFrame);
  79.  
  80.   DataLength = sizeof(swp);
  81.   if (!PrfQueryProfileData(HINI_USERPROFILE, "Hints", "Size",
  82.                            &swp, &DataLength))
  83.   {
  84.     swp.x  = 100;
  85.     swp.y  = 100;
  86.     swp.cx = 200;
  87.     swp.cy = 200;
  88.     /*-------------------------------------------------------------*/
  89.     /* For full screen -                                           */
  90.     /*                                                             */
  91.     /*  swp.cx = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);      */
  92.     /*  swp.cy = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);      */
  93.     /*-------------------------------------------------------------*/
  94.   }
  95.   WinSetWindowPos(hwndFrame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
  96.                   SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  97.  
  98.   hwndChildFrame = WinCreateStdWindow(HWND_DESKTOP,
  99.                                       0L,
  100.                                       &flCFrameFlags,
  101.                                       "Hints2",
  102.                                       (PSZ)CTitle,
  103.                                       0L,
  104.                                       NULL,
  105.                                       0,
  106.                                       &hwndChild);
  107.  
  108.   WinSetOwner(hwndChildFrame, hwndFrame);
  109.  
  110.   WinSetWindowPos(hwndChildFrame, HWND_TOP, 350, 100, 200, 200,
  111.                   SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ACTIVATE);
  112.  
  113.   PgmEntry.hwnd          = hwndFrame;
  114.   PgmEntry.hwndIcon      = NULL;
  115.   PgmEntry.hprog         = NULL;
  116.   PgmEntry.idProcess     = NULL;
  117.   PgmEntry.idSession     = NULL;
  118.   PgmEntry.uchVisibility = SWL_VISIBLE;
  119.   PgmEntry.fbJump        = SWL_JUMPABLE;
  120.  
  121.   strcpy(PgmEntry.szSwtitle, Title);
  122.  
  123.   hwndEntry = WinAddSwitchEntry(&PgmEntry);
  124.  
  125.   WinStartTimer( hab, hwndClient, 1, 500 );
  126.  
  127.   WinSendMsg(hwndFrame, WM_SETICON,
  128.              WinQuerySysPointer(HWND_DESKTOP, SPTR_APPICON, FALSE), NULL);
  129.   WinSendMsg(hwndChildFrame, WM_SETICON,
  130.              WinQuerySysPointer(HWND_DESKTOP, SPTR_APPICON, FALSE), NULL);
  131.  
  132.   while(WinGetMsg(hab, &qmsg, NULL, 0, 0))
  133.     WinDispatchMsg(hab, &qmsg);
  134.  
  135.   WinStopTimer( hab, hwndClient, 1);
  136.   WinDestroyWindow(hwndFrame);
  137.   WinRemoveSwitchEntry(hwndEntry);
  138.   WinDestroyMsgQueue(hmq);
  139.   WinTerminate(hab);
  140. }
  141.  
  142. /****************************************************************************/
  143.  
  144. MRESULT EXPENTRY MainWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  145. {
  146.   RECTL  rc;
  147.   SWP    swp;
  148.   HPS    hps;
  149.   HWND   hwndActiveWin,
  150.          hwndFrame;
  151.   PID    pid;
  152.   TID    tid;
  153.   CHAR   szText[20],
  154.          szPid[6];
  155.  
  156.   switch (msg)
  157.     {
  158.       case WM_PAINT:
  159.         hwndActiveWin = WinQueryActiveWindow(HWND_DESKTOP, FALSE);
  160.         WinQueryWindowProcess(hwndActiveWin, &pid, &tid);
  161.         strcpy(szText, "Process ID = ");
  162.         strcat(szText, itoa(pid, szPid, 10));
  163.  
  164.         WinQueryWindowRect(hwnd, &rc);
  165.  
  166.         /*------------------------------------------------------------------*/
  167.         /* WinMapWindowPoints(hwnd, WinQueryWindow(hwnd, QW_PARENT, FALSE), */
  168.         /*                    (PPOINTL)&rc, 2);                             */
  169.         /*------------------------------------------------------------------*/
  170.  
  171.         hps = WinBeginPaint(hwnd, NULL, &rc);
  172.         WinDrawText (hps, strlen(szText), szText, &rc, SYSCLR_WINDOWTEXT,
  173.                       SYSCLR_WINDOW, DT_LEFT | DT_ERASERECT);
  174.         WinEndPaint(hps);
  175.         break;
  176.  
  177.       case WM_TIMER:
  178.         hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
  179.         WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER);
  180.         WinInvalidateRect(hwnd, NULL, TRUE);  /* Cause PID to be displayed */
  181.         break;
  182.  
  183.       case WM_BUTTON1DOWN:
  184.         hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
  185.         WinSetWindowText(hwndFrame, "Hints - Size and Position Fixed");
  186.         WinEnableWindow (WinWindowFromID (hwndFrame, FID_TITLEBAR), FALSE);
  187.         WinEnableWindow (WinWindowFromID (hwndFrame, FID_MINMAX), FALSE);
  188.  
  189.         WinSetWindowBits(hwndFrame, QWL_STYLE,
  190.                          (~FS_SIZEBORDER | FS_DLGBORDER),
  191.                          ( FS_SIZEBORDER | FS_DLGBORDER));
  192.  
  193.         /*-----------------------------------------------------------------*/
  194.         /* WinSetWindowULong(hwndFrame, QWL_STYLE,                         */
  195.         /*                   (WinQueryWindowULong(hwndFrame, QWL_STYLE) &  */
  196.         /*                    ~FS_SIZEBORDER | FS_DLGBORDER));             */
  197.         /*-----------------------------------------------------------------*/
  198.  
  199.         WinInvalidateRect(hwndFrame, NULL, TRUE);
  200.         break;
  201.  
  202.       case WM_BUTTON2DOWN:
  203.         hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
  204.         WinSetWindowText(hwndFrame, "Hints");
  205.         WinEnableWindow (WinWindowFromID (hwndFrame, FID_TITLEBAR), TRUE);
  206.         WinEnableWindow (WinWindowFromID (hwndFrame, FID_MINMAX), TRUE);
  207.  
  208.         WinSetWindowBits(hwndFrame, QWL_STYLE,
  209.                          (FS_SIZEBORDER | ~FS_DLGBORDER),
  210.                          (FS_SIZEBORDER |  FS_DLGBORDER));
  211.  
  212.         /*-----------------------------------------------------------------*/
  213.         /* WinSetWindowULong(hwndFrame, QWL_STYLE,                         */
  214.         /*                   (WinQueryWindowULong(hwndFrame, QWL_STYLE) &  */
  215.         /*                    ~FS_DLGBORDER | FS_SIZEBORDER));             */
  216.         /*-----------------------------------------------------------------*/
  217.  
  218.         WinInvalidateRect(hwndFrame, NULL, TRUE);
  219.         break;
  220.  
  221.       case WM_MINMAXFRAME:
  222.         hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
  223.         if (((PSWP)mp1)->fs & SWP_MINIMIZE)
  224.         {
  225.           DosBeep(100, 100);
  226.         }
  227.         else
  228.           if (((PSWP)mp1)->fs & SWP_MAXIMIZE)
  229.           {
  230.             DosBeep(1000, 100);
  231.           }
  232.           else
  233.             if (((PSWP)mp1)->fs & SWP_RESTORE)
  234.             {
  235.               DosBeep(500, 100);
  236.             }
  237.  
  238.         WinSetWindowUShort(hwndFrame, QWS_XRESTORE, 100);
  239.         WinSetWindowUShort(hwndFrame, QWS_YRESTORE, 100);
  240.         WinSetWindowUShort(hwndFrame, QWS_CXRESTORE, 200);
  241.         WinSetWindowUShort(hwndFrame, QWS_CYRESTORE, 200);
  242.         break;
  243.  
  244.       case WM_SAVEAPPLICATION:
  245.         WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT, FALSE), &swp);
  246.         PrfWriteProfileData(HINI_USERPROFILE, "Hints", "Size",
  247.                             &swp, (ULONG)sizeof(swp));
  248.         return NULL;
  249.  
  250.       case WM_COMMAND:
  251.         switch (SHORT1FROMMP(mp1))
  252.           {
  253.             case MI_MIN:
  254.               hwndFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
  255.               WinSetWindowPos(hwndFrame, NULL, 0, 0, 0, 0, SWP_MINIMIZE);
  256.               break;
  257.  
  258.             case MI_EXIT:
  259.               WinPostMsg(hwnd, WM_QUIT, 0L, 0L);
  260.               break;
  261.           }
  262.  
  263.       case WM_ERASEBACKGROUND:
  264.         return (MRESULT)TRUE;
  265.     }
  266.   return WinDefWindowProc(hwnd, msg, mp1, mp2);
  267. }
  268.  
  269. /****************************************************************************/
  270.  
  271. MRESULT EXPENTRY NewFrame(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  272. {
  273.   PTRACKINFO  ptrack;
  274.  
  275.   switch(msg)
  276.   {
  277.     case WM_QUERYTRACKINFO:
  278.       /*----------------------------------------------------------*/
  279.       /* Invoke the default frame window procedure first in order */
  280.       /* to update the tracking rectangle to the new position.    */
  281.       /*----------------------------------------------------------*/
  282.       OldFrameProc(hwnd, msg, mp1, mp2);
  283.  
  284.       ptrack = (PTRACKINFO)mp2;
  285.       ptrack->ptlMinTrackSize.x = 25;
  286.       ptrack->ptlMinTrackSize.y = 25;
  287.  
  288.       return((MRESULT)TRUE);
  289.       break;
  290.  
  291.     default:
  292.       return(OldFrameProc(hwnd, msg, mp1, mp2));
  293.       break;
  294.   }
  295.   return((MRESULT)NULL);
  296. }
  297.  
  298. /****************************************************************************/
  299.  
  300. MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  301. {
  302.   RECTL  rc;
  303.   HPS    hps;
  304.   CHAR   szText[22];
  305.   HWND   hwndChildFrame;
  306.  
  307.  
  308.   switch(msg)
  309.     {
  310.       case WM_PAINT:
  311.         strcpy(szText, "I am a child of Hints");
  312.         WinQueryWindowRect(hwnd, &rc);
  313.         hps = WinBeginPaint(hwnd, NULL, &rc);
  314.         WinDrawText (hps, strlen(szText), szText, &rc, SYSCLR_WINDOWTEXT,
  315.                       SYSCLR_WINDOW, DT_LEFT | DT_ERASERECT);
  316.         WinEndPaint(hps);
  317.         break;
  318.  
  319.       case WM_ERASEBACKGROUND:
  320.         return (MRESULT)TRUE;
  321.  
  322.       case WM_CLOSE:
  323.         hwndChildFrame = WinQueryWindow(hwnd, QW_PARENT, FALSE);
  324.         WinDestroyWindow(hwndChildFrame);
  325.         break;
  326.     }
  327.   return WinDefWindowProc(hwnd, msg, mp1, mp2);
  328. }
  329.  
  330.  
  331.