home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / videotlk.zip / SAMPLES / EX5 / EX5.ZIP / EX5.C next >
Text File  |  1999-06-15  |  31KB  |  836 lines

  1.  
  2. /*------------------------------------------------------------------*
  3.  *                                                                  *
  4.  *  Video Toolkit For OS/2 Version 2.0                              *
  5.  *  Example PM Application No. 5.                                   *
  6.  *  Date : 13/07/95.                                                *
  7.  *  Copyright (c) Abbotsbury Software Ltd., United Kingdom. 1995-99 *
  8.  *                                                                  *
  9.  *  Filename : ex5.c                                                *
  10.  *                                                                  *
  11.  *------------------------------------------------------------------*/
  12.  
  13. #define     INCL_PM
  14. #define     INCL_OS2MM
  15. #define     INCL_DOS
  16. #define     INCL_SW
  17.  
  18. #include    <os2.h>
  19. #include    <os2me.h>
  20. #include    <stdlib.h>
  21. #include    <stdio.h>
  22. #include    <string.h>
  23. #include    <vcadd.h>
  24. #include    <vcai.h>
  25. #include    "ex5.h"
  26. #include    "ex5cap.h"
  27. #include    "helpfunc.h"
  28. #include    "pmtv2rem.h"
  29. #include    "region.h"
  30.  
  31. extern  BOOL    RemOpen;
  32. extern  MRESULT EXPENTRY TuneDlgProc (HWND hwnd, ULONG msg,
  33.                                       MPARAM mp1, MPARAM mp2);
  34.  
  35. DRIVERHANDLE    DevHandle;
  36. USHORT  DevInstance;
  37. CHAR    DevType[20];
  38. HAB     Hab;
  39. HWND    HwndFrame, HwndClient;
  40. BOOL    CaptureOpen, ConvertASM;
  41. LONG    Width, Height, X, Y;
  42. LONG    NumColours;
  43. LONG    Colours[256];
  44. LONG    ColourKey;
  45.  
  46. static  HWND    HwndRemote, HwndMenu;
  47. static  HWND    HwndNotebook, HwndNBFrame, HwndCapture;
  48. static  USHORT  Connector;
  49. static  CHAR    txt[256];
  50. static  VCADEVINFO  DevInfo;
  51. static  BOOL    NotebookOpen;
  52. static  PSZ     InsertName = "InsertPage";
  53. static  PFN     InsertAddr;
  54. static  HMODULE HmodInsert;
  55. static  PSZ     RemoteName = "RemoteDlgProc";
  56. static  PFN     RemoteAddr;
  57. static  HMODULE HmodRemote;
  58.  
  59. #define VCADEV_SETPRIVATECLIPLIST 0x48f33329
  60. typedef struct {
  61.    unsigned short left, top, width, height;
  62. } ClipRect;
  63.  
  64. typedef struct _VCASETPRIVATECLIPLIST {
  65.    ULONG     ulLength;             /* length of the structure             */
  66.    ULONG     ulFlags;              /* Reserved and set to Zero            */
  67.    ULONG     ulNum_Rects;          /* Number of rectanlges in array below */
  68.    RECTL     VisRect[256];         /* Array of n Visible Retangle         */
  69. } VCASETPRIVATECLIPLIST;
  70. typedef VCASETPRIVATECLIPLIST FAR* PVCASETPRIVATECLIPLIST;
  71.  
  72. int     main (int argc, char **argv);
  73. void    err_msg (UCHAR *mess);
  74. void    msg_box (UCHAR *txt, UCHAR *title, ULONG options);
  75. LONG    get_colour (HPS hps);
  76. MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2,
  77.                                       PCHAR  pchAlias,
  78.                                       LONG   lOffSet );
  79. // MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  80. MRESULT EXPENTRY NotebookDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  81. MRESULT EXPENTRY QuitDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  82. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  83.  
  84. static  void    init_colour (void);
  85. static  void    map_pallete (HPS hps);
  86. static  void    size_notebook (void);
  87. static  BOOL    init_window (void);
  88. static  void    check_menu_item (short item_id, short state);
  89. static  void    enable_menu_item (short item_id, short state);
  90.  
  91. int main (int argc, char **argv)
  92. {
  93.     HMQ     hmq;
  94.     QMSG    qmsg;
  95.     CHAR    mod_txt[256];
  96.     PSZ     pmmbase, env = "MMBASE";
  97.     LONG    len;
  98.     APIRET  rc;
  99.  
  100.         if (argc < 3)
  101.             DosExit (EXIT_PROCESS, 1);
  102.  
  103.         Hab = WinInitialize (0);
  104.         if (!Hab)
  105.             DosExit (EXIT_PROCESS, 1);
  106.  
  107.         hmq = WinCreateMsgQueue (Hab, 0);
  108.         if (!hmq)
  109.             DosExit (EXIT_PROCESS, 1);
  110.  
  111.         strcpy (DevType, argv[1]);
  112.         DevInstance = (USHORT)atoi (argv[2]);
  113.         DevHandle = VcaiDeviceOpen (DevType, DevInstance);
  114.         if (DevHandle < 0)
  115.         {
  116.             sprintf (txt, "Cannot Open Device %u !", atoi(argv[2]));
  117.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  118.             DosExit (EXIT_PROCESS, 1);
  119.         }
  120.         Connector = (USHORT)atoi (argv[2]);
  121.  
  122.         rc = DosScanEnv (env, &pmmbase);
  123.         if (rc != 0)
  124.             DosExit (EXIT_PROCESS, 1);
  125.         len = strlen (pmmbase);
  126.         if (pmmbase[len-1] == ';')
  127.             pmmbase[len-1] = '\0';
  128.         sprintf (mod_txt, "%s\\DLL\\%5.5sNB.DLL", pmmbase, argv[1]);
  129.         rc = DosLoadModule (txt, sizeof (txt), mod_txt, &HmodInsert);
  130.         if (rc != 0)
  131.         {
  132.             sprintf (txt, "DosLoadModule <%s> - %ld", mod_txt, rc);
  133.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  134.             DosExit (EXIT_PROCESS, 1);
  135.         }
  136.         rc = DosQueryProcAddr (HmodInsert, 0L, InsertName, &InsertAddr);
  137.         if (rc != 0)
  138.         {
  139.             sprintf (txt, "DosQueryProcAddr (InsertPage) - %ld", rc);
  140.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  141.             DosExit (EXIT_PROCESS, 1);
  142.         }
  143.         sprintf (mod_txt, "%s\\DLL\\PMTV2REM.DLL", pmmbase);
  144.         rc = DosLoadModule (txt, sizeof (txt), mod_txt, &HmodRemote);
  145.         if (rc != 0)
  146.         {
  147.             sprintf (txt, "DosLoadModule (PMTV2REM.DLL) - %ld", rc);
  148.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  149.             DosExit (EXIT_PROCESS, 1);
  150.         }
  151.         rc = DosQueryProcAddr (HmodRemote, 0L, RemoteName, &RemoteAddr);
  152.         if (rc != 0)
  153.         {
  154.             sprintf (txt, "DosQueryProcAddr (RemoteDlgProc) - %ld", rc);
  155.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  156.             DosExit (EXIT_PROCESS, 1);
  157.         }
  158.  
  159.         if (!init_window ())
  160.             DosExit (EXIT_PROCESS, 1);
  161.  
  162.         while (WinGetMsg (Hab, &qmsg, NULLHANDLE, 0, 0))
  163.             WinDispatchMsg (Hab, &qmsg);
  164.  
  165.         DestroyHelpInstance ();
  166.         WinDestroyWindow (HwndFrame);
  167.         WinDestroyMsgQueue (hmq);
  168.         WinTerminate (Hab);
  169.         DosExit (EXIT_PROCESS, 0);
  170. }
  171.  
  172. void err_msg (UCHAR *mess)
  173. {
  174.     CHAR    txt[256];
  175.     ERRORID err;
  176.  
  177.         err = WinGetLastError (Hab);
  178.         sprintf (txt, "%s - %lx", mess,  err & 0xffff);
  179.         msg_box (txt, "Error", MB_OK | MB_ERROR);
  180. }
  181.  
  182. void msg_box (UCHAR *txt, UCHAR *title, ULONG options)
  183. {
  184.         WinMessageBox (HWND_DESKTOP,
  185.                        HWND_DESKTOP,
  186.                        txt,
  187.                        title,
  188.                        IDD_MSG,
  189.                        options);
  190. }
  191.  
  192.                         // The colour value for the Video Colour Key
  193.                         // is a physical palette value.
  194.                         // For systems with 256 or less colours in the
  195.                         // palette, you MUST map the physical palette
  196.                         // to PM logical palette first.
  197.                         // If there are more than 256 colours this
  198.                         // step should be ignored.
  199. LONG get_colour (HPS hps)
  200. {
  201.     LONG index;
  202.  
  203.         map_pallete (hps);
  204.  
  205.         index = VcaiColourkeyGet();
  206.         if (index > (ULONG)NumColours)
  207.         {
  208.             index = COLOUR_KEY_DEFAULT;
  209.             VcaiColourkeySet (index);
  210.         }
  211.         return (LONG)index;
  212. }
  213.  
  214. MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2,
  215.                                       PCHAR  pchAlias,
  216.                                       LONG   lOffSet )
  217. {
  218.     static  HPOINTER    hptr_rem;
  219.     static  BOOL        minimize, dbl;
  220.     HPS     hps;
  221.     RECTL   rcl;
  222.     LONG    bx, by, cy;
  223.     VCADEVAUDIO ad;
  224.     MOUSEPOS mousepos;
  225.     PSWP    pswp;
  226.  
  227.         switch (msg)
  228.         {
  229.             case WM_CREATE :
  230.                 RemOpen = NotebookOpen = CaptureOpen = FALSE;
  231.                 minimize = dbl = FALSE;
  232. //                VcaiOverlay (TRUE);
  233.                 VcaiOverlay (FALSE);
  234.                 VcaiFreeze (FALSE);
  235.                 HwndMenu = WinLoadMenu (hwnd, NULLHANDLE, IDR_MAIN);
  236.                 hptr_rem = WinLoadPointer (HWND_DESKTOP, NULLHANDLE,
  237.                                            PTR_REMOTE);
  238.                 init_colour ();
  239.                 ConvertASM = TRUE;
  240.                 check_menu_item (IDM_CAPTURE_ASM, CHECK);
  241.                 break;
  242.             case WM_PAINT :
  243.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  244.                 WinQueryWindowRect (hwnd, &rcl);
  245.                 ColourKey = get_colour (hps);
  246.                 if ((ULONG)NumColours <= 256)
  247.                     WinFillRect (hps, &rcl, Colours[ColourKey]);
  248.                 else
  249.                     WinFillRect (hps, &rcl, ColourKey);
  250.                 WinEndPaint (hps);
  251.  
  252.                 VcaiOverlay (TRUE);
  253.                 VcaiVideoRectValidate (0, 0, 0, 0, (USHORT) X, (USHORT) Y,
  254.                                        (USHORT) Width, (USHORT) Height);
  255.                 break;
  256.             case MSG_SIZE_TV :
  257.             case WM_SIZE :
  258.             case WM_MOVE :
  259.             case WM_WINDOWPOSCHANGED :
  260.                 if (minimize)
  261.                     break;
  262.                 if (!WinQueryWindowRect (hwnd, &rcl))
  263.                     return 0;
  264.  
  265.                 VcaiVideoRectValidate (0, 0, 0, 0, 0, 0, 0, 0);
  266.                 VcaiOverlay (FALSE);
  267.  
  268.                 WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2);
  269.                 bx = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER);
  270.                 by = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER);
  271.                 cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  272.                 X      = rcl.xLeft + bx;
  273.                 Y      = cy - rcl.yTop - by;
  274.                 Width  = rcl.xRight - rcl.xLeft;
  275.                 Height = rcl.yTop - rcl.yBottom;
  276.  
  277. //                VcaiVideoRectValidate (0, 0, 0, 0, 0, 0, 0, 0);
  278. //                VcaiOverlay (FALSE);
  279.  
  280.                 VcaiOverlay (TRUE);
  281.                 VcaiVideoRectValidate (0, 0, 0, 0, (USHORT) X, (USHORT) Y,
  282.                                        (USHORT) Width, (USHORT) Height);
  283.  
  284.                 if (RemOpen)
  285.                     WinSetActiveWindow (HWND_DESKTOP, HwndRemote);
  286.                 break;
  287.             case WM_MINMAXFRAME :
  288.                 pswp = (PSWP) PVOIDFROMMP (mp1);
  289.                 if (!(pswp->fl & SWP_MINIMIZE))
  290.                 {
  291.                     minimize = FALSE;
  292.                     break;
  293.                 }
  294.                 minimize = TRUE;
  295.                 VcaiVideoRectValidate (0, 0, 0, 0, 0, 0, 0, 0);
  296.                 break;
  297.             case WM_BUTTON1DOWN :
  298.                 if ((WinGetKeyState (HWND_DESKTOP, VK_BUTTON2) & 0x8000))
  299.                     dbl = TRUE;
  300.                 else
  301.                     dbl = FALSE;
  302.                 return 0;
  303.             case WM_BUTTON2DOWN :
  304.                 if ((WinGetKeyState (HWND_DESKTOP, VK_BUTTON1) & 0x8000))
  305.                     dbl = TRUE;
  306.                 else
  307.                     dbl = FALSE;
  308.                 return 0;
  309.             case WM_BUTTON1UP :
  310.                 if (dbl)
  311.                 {
  312.                     dbl = FALSE;
  313.                     if (CaptureOpen)
  314.                     {
  315.                         WinSendMsg (HwndCapture, MSG_CAPTURE, NULL, NULL);
  316.                         return 0;
  317.                     }
  318.                     HwndCapture = WinLoadDlg (HWND_DESKTOP,
  319.                                               HWND_OBJECT,
  320.                                               (PFNWP)CaptureDlgProc,
  321.                                               (HMODULE)NULLHANDLE,
  322.                                               IDD_CAPTURE,
  323.                                               NULL);
  324.                 }
  325.                 return 0;
  326.             case WM_BUTTON1CLICK :
  327.                 if (RemOpen)
  328.                     return 0;
  329.                 WinQueryWindowRect (hwnd, & rcl);
  330.                 WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2);
  331.                 mousepos.mp_x = MOUSEMSG (&msg)->x + rcl.xLeft;
  332.                 mousepos.mp_y = MOUSEMSG (&msg)->y + rcl.yBottom;
  333.                 init_audio ();
  334.                 init_video ();
  335.                 HwndRemote = WinLoadDlg (HWND_DESKTOP,
  336.                                          HWND_DESKTOP,
  337.                                          (PFNWP) RemoteAddr,
  338.                                          HmodRemote,
  339.                                          IDD_REM,
  340.                                          (PVOID) &mousepos);
  341.                 return 0;
  342.             case WM_BUTTON2CLICK :
  343.                 WinPopupMenu (hwnd, hwnd, HwndMenu,
  344.                               MOUSEMSG (&msg)->x, MOUSEMSG (&msg)->y, 0L,
  345.                               PU_HCONSTRAIN | PU_VCONSTRAIN |
  346.                               PU_NONE | PU_MOUSEBUTTON1 |
  347.                               PU_KEYBOARD);
  348.                 return 0;
  349.             case WM_MOUSEMOVE :
  350.                 WinSetPointer (HWND_DESKTOP, hptr_rem);
  351.                 return MRFROMSHORT (1);
  352.  
  353.             case WM_CLOSE :
  354.                 VcaiDeviceClose (DevHandle);
  355.                 break;
  356.  
  357.             case WM_COMMAND :
  358.                 switch (SHORT1FROMMP (mp1))
  359.                 {
  360.                     case IDM_FILE_QUIT :
  361.                         WinDlgBox (HWND_DESKTOP,
  362.                                    HwndFrame,
  363.                                    (PFNWP) QuitDlgProc,
  364.                                    (HMODULE) NULLHANDLE,
  365.                                    IDD_QUIT,
  366.                                    NULL);
  367.                         WinInvalidateRegion (HwndFrame, NULLHANDLE, FALSE);
  368.                         break;
  369.                     case IDM_CAPTURE_C :
  370.                         if ((ULONG)NumColours != 256)
  371.                         {
  372.                             sprintf (txt, "Conversion using C code will only work\n");
  373.                             strcat (txt, "in resolutions with 256 colours !");
  374.                             msg_box (txt, "Information",
  375.                                      MB_OK | MB_INFORMATION);
  376.                             ConvertASM = TRUE;
  377.                             return 0;
  378.                         }
  379.                         ConvertASM = FALSE;
  380.                         check_menu_item (SHORT1FROMMP (mp1), CHECK);
  381.                         check_menu_item (IDM_CAPTURE_ASM, UNCHECK);
  382.                         break;
  383.                     case IDM_CAPTURE_ASM :
  384.                         ConvertASM = TRUE;
  385.                         check_menu_item (SHORT1FROMMP (mp1), CHECK);
  386.                         check_menu_item (IDM_CAPTURE_C, UNCHECK);
  387.                         break;
  388.                     case IDM_CAPTURE_CAPTURE :
  389.                         if (CaptureOpen)
  390.                         {
  391.                             WinSendMsg (HwndCapture, MSG_CAPTURE, NULL, NULL);
  392.                             return 0;
  393.                         }
  394.                         HwndCapture = WinLoadDlg (HWND_DESKTOP,
  395.                                                   HWND_OBJECT,
  396.                                                   (PFNWP)CaptureDlgProc,
  397.                                                   (HMODULE)NULLHANDLE,
  398.                                                   IDD_CAPTURE,
  399.                                                   NULL);
  400.                         break;
  401.                     case IDM_TUNE :
  402.                         WinDlgBox  (HWND_DESKTOP,
  403.                                     HWND_DESKTOP,
  404.                                     (PFNWP) TuneDlgProc,
  405.                                     (HMODULE) NULLHANDLE,
  406.                                     IDD_TUNE,
  407.                                     NULL);
  408.                         break;
  409.                     case IDM_TV_SETUP :
  410.                         if (NotebookOpen)
  411.                                 return 0;
  412.                         HwndNBFrame = WinLoadSecondaryWindow
  413.                                                (HWND_DESKTOP,
  414.                                                 HWND_DESKTOP,
  415.                                                 (PFNWP) NotebookDlgProc,
  416.                                                 (HMODULE) NULLHANDLE,
  417.                                                 IDD_NOTE,
  418.                                                 NULL);
  419.                         break;
  420.                     case IDM_HELPCONTENTS :
  421.                         HelpContents ();
  422.                         break;
  423.                     case IDM_HELPINDEX :
  424.                         HelpIndex ();
  425.                         break;
  426.                     case IDM_KEYSHELP :
  427.                         HelpKeys ();
  428.                         break;
  429.                     case IDM_GENERALHELP :
  430.                         HelpHelpForHelp ();
  431.                         break;
  432.                     case IDM_HELPPRODUCTINFO :
  433.                         HelpAbout ();
  434.                         break;
  435.                     default :
  436.                         break;
  437.                 }
  438.                 break;
  439.             case HM_QUERY_KEYS_HELP :
  440.                 return ((MRESULT)PANEL_KEYSHELP);
  441.             case MSG_UPDATE_WINDOW :
  442.                 WinQueryWindowRect (hwnd, &rcl);
  443.                 WinInvalidateRect (hwnd, &rcl, TRUE);
  444.                 WinPostMsg (hwnd, MSG_SIZE_TV, NULL, NULL);
  445.  
  446.         case WM_VRNDISABLED:
  447.            return 0;                 /* hide this message from MMPM */
  448.  
  449.         case WM_VRNENABLED:
  450.            /*
  451.             * DJL 09/06/97 - Debug
  452.             */
  453. //         if (mp1)
  454.            {                /* yes, visible region has changed */
  455.  
  456.  
  457.               HRGN visRegion=0;
  458.               ULONG retCode;
  459.               HPS winPS;
  460.               RECTL r[256];
  461.               RGNRECT rectControl={0, 256, 0, RECTDIR_LFRT_BOTTOP};
  462.               VCASETCLIPLIST vClip;
  463.               int l;
  464.               USHORT mciDevId;
  465.  
  466. //      DosBeep(200, 200);
  467. //      DosBeep(200, 100);
  468. //      DosBeep(200, 200);
  469.  
  470.               /* first get visible regions */
  471.               winPS=WinGetPS(hwnd);
  472.               visRegion=GpiCreateRegion(winPS, 0, NULL);
  473.               retCode=WinQueryVisibleRegion(hwnd, visRegion);
  474.               /* enumerate them, store all rectangles in 'r' */
  475.               GpiQueryRegionRects(winPS, visRegion, NULL, &rectControl, r);
  476.  
  477.               /* now build the cliplist for the device driver */
  478.               for (l=0; l<rectControl.crcReturned; l++) {
  479.                   vClip.VisRect[l].X_Left=r[l].xLeft;
  480.                   vClip.VisRect[l].X_Width=r[l].xRight-r[l].xLeft;
  481.                   vClip.VisRect[l].Y_Top=r[l].yTop;
  482.                   vClip.VisRect[l].Y_Height=r[l].yTop-r[l].yBottom;
  483.  
  484.                   /*
  485.                    * Handle the frame offset used by WarpTv
  486.                    */
  487. /*
  488.                   vClip.VisRect[l].left   -= lOffSet;
  489.                   vClip.VisRect[l].top    -= lOffSet;
  490.                   vClip.VisRect[l].width  += ( lOffSet * 2 );
  491.                   vClip.VisRect[l].height += ( lOffSet * 2 );
  492. */
  493.               }
  494. //            vClip.ulNum_Rects=1;
  495. //            vClip.ulFlags=0x4243;
  496. //            vClip.ulLength=0x1234;
  497.               vClip.ulNum_Rects=rectControl.crcReturned;
  498.               vClip.ulFlags=0;
  499.               vClip.ulLength=sizeof vClip;
  500.  
  501. #undef MCI
  502. #ifdef MCI
  503.               mciDevId=mciGetDeviceID( pchAlias );
  504.               /* and send the CLIPLIST command to the device */
  505.               retCode=mciSendCommand(mciDevId, MCI_ESCAPE, MCI_WAIT, &vClip, 0);
  506. #else
  507.               VcaiClipList (&vClip);
  508. #endif
  509.  
  510.  
  511.               /* now clean up */
  512.               GpiDestroyRegion(winPS, visRegion);
  513.               WinReleasePS(winPS);
  514.               /* that is all */
  515.            }
  516.  
  517.            return 0; /* hide this message from MMPM as well */
  518.  
  519.             default :
  520.                 break;
  521.         }
  522.         return WinDefWindowProc (hwnd, msg, mp1, mp2);
  523. }
  524.  
  525. MRESULT EXPENTRY NotebookDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  526. {
  527.     static  BOOL    start;
  528.     HPS     hps;
  529.     RECTL   rcl;
  530.     ULONG   id, result;
  531.     MCI_DEVICESETTINGS_PARMS   mci;
  532.     HWND    hwndPage;
  533.     LONG    bx, by, cx, cy, ty, x, y;
  534.     SWP     swp;
  535.  
  536.         switch (msg)
  537.         {
  538.             case WM_INITDLG :
  539.                 HwndNotebook = WinWindowFromID (hwnd, IDD_NOTE_BOOK);
  540.                 WinSendMsg (HwndNotebook,
  541.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  542.                             MPFROMSHORT (BKA_BACKGROUNDPAGECOLORINDEX));
  543.                 WinSendMsg (HwndNotebook,
  544.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  545.                             MPFROMSHORT (BKA_BACKGROUNDMAJORCOLORINDEX));
  546.                 WinSendMsg (HwndNotebook,
  547.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  548.                             MPFROMSHORT (BKA_BACKGROUNDMINORCOLORINDEX));
  549.                 cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  550.                 if (cy <= 480)
  551.                 {
  552.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  553.                                 MPFROM2SHORT (100, 24),
  554.                                 MPFROMSHORT (BKA_MAJORTAB));
  555.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  556.                                 MPFROM2SHORT (75, 24),
  557.                                 MPFROMSHORT (BKA_MINORTAB));
  558.                 }
  559.                 else
  560.                 {
  561.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  562.                                 MPFROM2SHORT (150, 24),
  563.                                 MPFROMSHORT (BKA_MAJORTAB));
  564.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  565.                                 MPFROM2SHORT (100, 24),
  566.                                 MPFROMSHORT (BKA_MINORTAB));
  567.                 }
  568.                 mci.hwndCallback = HwndNBFrame;
  569.                 mci.hwndNotebook = HwndNotebook;
  570.                 mci.usDeviceType = 12;
  571.                 sprintf (txt, "TV0%ld", Connector);
  572.                 mci.pszDeviceName = txt;
  573.                 hwndPage = (HWND) InsertAddr (&mci);
  574.                 if (!hwndPage)
  575.                 {
  576.                     msg_box ("Error Loading Pages", "Error",
  577.                              MB_OK | MB_ERROR);
  578.                     return 0;
  579.                 }
  580.                 NotebookOpen = TRUE;
  581.                 start = TRUE;
  582.                 WinPostMsg (hwnd, WM_PAINT, NULL, NULL);
  583.                 break;
  584.             case WM_PAINT :
  585.                 if (start)
  586.                 {
  587.                     size_notebook ();
  588.                     start = FALSE;
  589.                 }
  590.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  591.                 WinQueryWindowRect (hwnd, &rcl);
  592.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  593.                 WinEndPaint (hps);
  594.                 break;
  595.             case WM_ADJUSTWINDOWPOS :
  596.             case WM_MOVE :
  597.             case WM_SIZE :
  598.             case WM_WINDOWPOSCHANGED :
  599.                 WinQueryWindowRect (HwndNBFrame, &rcl);
  600.                 bx = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER);
  601.                 by = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER);
  602.                 ty = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  603.                 WinSetWindowPos (HwndNotebook, HWND_TOP,
  604.                                  bx, by, rcl.xRight - (bx * 2),
  605.                                  rcl.yTop - ty - (by * 2),
  606.                                  SWP_SIZE | SWP_MOVE | SWP_SHOW);
  607.                 break;
  608.             case WM_COMMAND :
  609.                 return ((MRESULT) FALSE);
  610.             case WM_CLOSE :
  611.                 WinDestroySecondaryWindow (HwndNBFrame);
  612.                 return ((MRESULT) FALSE);
  613.             case WM_DESTROY :
  614.                 WinPostMsg (HwndFrame, WM_SIZE, NULL, NULL);
  615.                 NotebookOpen = FALSE;
  616.                 break;
  617.             default :
  618.                 break;
  619.         }
  620.         return WinDefSecondaryWindowProc (hwnd, msg, mp1, mp2);
  621. }
  622.  
  623. MRESULT EXPENTRY QuitDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  624. {
  625.         switch (msg)
  626.         {
  627.             case WM_COMMAND :
  628.                 switch (SHORT1FROMMP (mp1))
  629.                 {
  630.                     case DID_OK :
  631.                         WinPostMsg (HwndFrame, WM_CLOSE, NULL, NULL);
  632.                         WinDismissDlg (hwnd, TRUE);
  633.                         break;
  634.                     case DID_CANCEL :
  635.                         WinDismissDlg (hwnd, TRUE);
  636.                         break;
  637.                     default :
  638.                         break;
  639.                 }
  640.                 break;
  641.             default :
  642.                 break;
  643.         }
  644.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  645. }
  646.  
  647. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  648. {
  649.     HPS     hps;
  650.     RECTL   rcl;
  651.     LONG    x, y;
  652.     CHAR    txt[80];
  653.  
  654.         switch (msg)
  655.         {
  656.             case WM_PAINT :
  657.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  658.                 WinQueryWindowRect (hwnd, &rcl);
  659.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  660.                 sprintf (txt, "%30.30s", DevInfo.ProdInfo);
  661.                 WinSetDlgItemText (hwnd, IDD_ABOUT_PROD_INFO, txt);
  662.                 sprintf (txt, "%30.30s", DevInfo.ManInfo);
  663.                 WinSetDlgItemText (hwnd, IDD_ABOUT_MAN_INFO, txt);
  664.                 sprintf (txt, "%10.10s", DevInfo.Version);
  665.                 WinSetDlgItemText (hwnd, IDD_ABOUT_VERSION, txt);
  666.                 WinDrawBorder (hps, &rcl, x, y, 0L, 0L, DB_AREAATTRS |
  667.                                DB_DLGBORDER);
  668.                 WinEndPaint (hps);
  669.                 break;
  670.             case WM_COMMAND :
  671.                 switch (SHORT1FROMMP (mp1))
  672.                 {
  673.                     case DID_OK :
  674.                         WinDismissDlg (hwnd, TRUE);
  675.                         break;
  676.                     default :
  677.                         break;
  678.                 }
  679.                 break;
  680.             default :
  681.                 break;
  682.         }
  683.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  684. }
  685.  
  686. static void size_notebook ()
  687. {
  688.     LONG    bx, by, cx, cy, ty, x, y;
  689.     RECTL   rcl;
  690.  
  691.         cx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  692.         cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  693.         x = cx / 8L;
  694.         y = 0L;
  695.         if (cy <= 480)
  696.         {
  697.             cx = 480;
  698.             cy = 480;
  699.         }
  700.         else
  701.         {
  702.             cx = 640;
  703.             cy = 600;
  704.         }
  705.         WinSetWindowPos (HwndNBFrame, HWND_TOP,
  706.                          x, y, cx, cy,
  707.                          SWP_SIZE | SWP_MOVE | SWP_SHOW);
  708.         WinQueryWindowRect (HwndNBFrame, &rcl);
  709.         bx = WinQuerySysValue (HWND_DESKTOP,
  710.                                SV_CXSIZEBORDER);
  711.         by = WinQuerySysValue (HWND_DESKTOP,
  712.                                SV_CYSIZEBORDER);
  713.         ty = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  714.         WinSetWindowPos (HwndNotebook, HWND_TOP,
  715.                          bx, by, rcl.xRight - (bx * 2),
  716.                          rcl.yTop - ty - (by * 2),
  717.                          SWP_SIZE | SWP_MOVE | SWP_SHOW);
  718. }
  719.  
  720. static BOOL init_window ()
  721. {
  722.     CHAR    szClient[] = "Client";
  723.     ULONG   flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_ICON |
  724.                            FCF_SIZEBORDER | FCF_MINMAX | FCF_ACCELTABLE |
  725.                            FCF_SHELLPOSITION | FCF_TASKLIST;
  726.  
  727.         DevInfo.Length = sizeof (VCADEVINFO);
  728.         VcaiDeviceInfoGet (&DevInfo);
  729.         sprintf (txt, "Example 5 - %s %u", DevType, DevInstance);
  730.  
  731.  
  732.         if (!WinRegisterClass (Hab, szClient, ClientWndProc,
  733.                                CS_SIZEREDRAW | CS_MOVENOTIFY, 0))
  734.             return (FALSE);
  735.  
  736.         if (!WinRegisterGraphicButton ())
  737.             return (FALSE);
  738.  
  739.         HwndFrame = WinCreateStdWindow (HWND_DESKTOP,
  740.                                         WS_VISIBLE,
  741.                                         &flFrameFlags,
  742.                                         szClient,
  743.                                         txt,
  744. //                                        WS_SYNCPAINT | WS_VISIBLE,
  745.                                         0,
  746.                                         (HMODULE) NULLHANDLE,
  747.                                         IDR_MAIN,
  748.                                         &HwndClient);
  749.         if (!HwndFrame)
  750.             return (FALSE);
  751.  
  752.     // Turn on visible region notification.
  753.         WinSetVisibleRegionNotify (HwndClient, TRUE);
  754.  
  755.         WinPostMsg (HwndFrame, WM_VRNENABLED, 0L, 0L);
  756.  
  757.         HelpInit (HwndFrame);
  758.  
  759.         if (!init_video ())
  760.             return (FALSE);
  761.  
  762.         if (!init_audio ())
  763.             return (FALSE);
  764.  
  765.         return (TRUE);
  766. }
  767.  
  768. static void init_colour ()
  769. {
  770.     HDC     hdc;
  771.     DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL,
  772.                         NULL};
  773.  
  774.         hdc = DevOpenDC (Hab, OD_INFO, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
  775.         DevQueryCaps (hdc, CAPS_COLORS, 1L, &NumColours);
  776.         DevCloseDC (hdc);
  777. }
  778.  
  779. static void map_pallete (HPS hps)
  780. {
  781.     LONG    rc;
  782.     VCASCREENINFO vs;
  783.     USHORT cx, cy, i;
  784.  
  785.         if ((NumColours <= 256) && (NumColours > 0))
  786.         {
  787.             rc = GpiQueryRealColors (hps, 0L, 0L, NumColours, Colours);
  788.             if (rc == GPI_ALTERROR)
  789.             {
  790.                 err_msg ("GpiQueryRealColors");
  791.                 return;
  792.             }
  793.         }
  794.         cx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  795.         cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  796.         vs.ulLength = sizeof (VCASCREENINFO);
  797.         vs.ul_RESV01 = 0L;
  798.         vs.ulWidth = (ULONG) cx;
  799.         vs.ulHeight = (ULONG) cy;
  800.         vs.ulNumColours = (ULONG) NumColours;
  801.         vs.ulHFreq = 0L;
  802.         vs.ulVFreq = 0L;
  803.         if ((ULONG)NumColours <= 256)
  804.         {
  805.             for (i = 0; i < NumColours; i++)
  806.                 vs.ulRGB[i] = (ULONG) Colours[i];
  807.         }
  808.         else
  809.         {
  810.             for (i = 0; i < 256; i++)
  811.                 vs.ulRGB[i] = 0L;
  812.         }
  813.         VcaiScreenInfoSet (&vs);
  814.         rc = GpiCreateLogColorTable (hps, LCOL_RESET, LCOLF_RGB,
  815.                                      0L, 0L, (PLONG)0L);
  816.         if (!rc)
  817.         {
  818.             err_msg ("GpiCreateLogColorTable");
  819.             return;
  820.         }
  821. }
  822.  
  823. static void check_menu_item (short item_id, short state)
  824. {
  825.         WinPostMsg (HwndMenu, MM_SETITEMATTR,
  826.                     MPFROM2SHORT (item_id, TRUE),
  827.                     MPFROM2SHORT (MIA_CHECKED, state));
  828. }
  829.  
  830. static void enable_menu_item (short item_id, short state)
  831. {
  832.         WinPostMsg (HwndMenu, MM_SETITEMATTR,
  833.                     MPFROM2SHORT (item_id, TRUE),
  834.                     MPFROM2SHORT (MIA_DISABLED, state));
  835. }
  836.