home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / videotlk.zip / SAMPLES / EX5 / EX5.C next >
Text File  |  1999-06-27  |  31KB  |  824 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.               {
  480.                   vClip.VisRect[l].X_Left=r[l].xLeft;
  481.                   vClip.VisRect[l].X_Width=r[l].xRight-r[l].xLeft;
  482.                   vClip.VisRect[l].Y_Top=r[l].yTop;
  483.                   vClip.VisRect[l].Y_Height=r[l].yTop-r[l].yBottom;
  484.               }
  485.               vClip.ulNum_Rects=rectControl.crcReturned;
  486.               vClip.ulFlags=0;
  487.               vClip.ulLength=sizeof vClip;
  488.  
  489. #undef MCI
  490. #ifdef MCI
  491.               mciDevId=mciGetDeviceID( pchAlias );
  492.               /* and send the CLIPLIST command to the device */
  493.               retCode=mciSendCommand(mciDevId, MCI_ESCAPE, MCI_WAIT, &vClip, 0);
  494. #else
  495.               VcaiClipList (vClip);
  496. #endif
  497.  
  498.  
  499.               /* now clean up */
  500.               GpiDestroyRegion(winPS, visRegion);
  501.               WinReleasePS(winPS);
  502.               /* that is all */
  503.            }
  504.  
  505.            return 0; /* hide this message from MMPM as well */
  506.  
  507.             default :
  508.                 break;
  509.         }
  510.         return WinDefWindowProc (hwnd, msg, mp1, mp2);
  511. }
  512.  
  513. MRESULT EXPENTRY NotebookDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  514. {
  515.     static  BOOL    start;
  516.     HPS     hps;
  517.     RECTL   rcl;
  518.     ULONG   id, result;
  519.     MCI_DEVICESETTINGS_PARMS   mci;
  520.     HWND    hwndPage;
  521.     LONG    bx, by, cx, cy, ty, x, y;
  522.     SWP     swp;
  523.  
  524.         switch (msg)
  525.         {
  526.             case WM_INITDLG :
  527.                 HwndNotebook = WinWindowFromID (hwnd, IDD_NOTE_BOOK);
  528.                 WinSendMsg (HwndNotebook,
  529.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  530.                             MPFROMSHORT (BKA_BACKGROUNDPAGECOLORINDEX));
  531.                 WinSendMsg (HwndNotebook,
  532.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  533.                             MPFROMSHORT (BKA_BACKGROUNDMAJORCOLORINDEX));
  534.                 WinSendMsg (HwndNotebook,
  535.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  536.                             MPFROMSHORT (BKA_BACKGROUNDMINORCOLORINDEX));
  537.                 cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  538.                 if (cy <= 480)
  539.                 {
  540.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  541.                                 MPFROM2SHORT (100, 24),
  542.                                 MPFROMSHORT (BKA_MAJORTAB));
  543.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  544.                                 MPFROM2SHORT (75, 24),
  545.                                 MPFROMSHORT (BKA_MINORTAB));
  546.                 }
  547.                 else
  548.                 {
  549.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  550.                                 MPFROM2SHORT (150, 24),
  551.                                 MPFROMSHORT (BKA_MAJORTAB));
  552.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  553.                                 MPFROM2SHORT (100, 24),
  554.                                 MPFROMSHORT (BKA_MINORTAB));
  555.                 }
  556.                 mci.hwndCallback = HwndNBFrame;
  557.                 mci.hwndNotebook = HwndNotebook;
  558.                 mci.usDeviceType = 12;
  559.                 sprintf (txt, "TV0%ld", Connector);
  560.                 mci.pszDeviceName = txt;
  561.                 hwndPage = (HWND) InsertAddr (&mci);
  562.                 if (!hwndPage)
  563.                 {
  564.                     msg_box ("Error Loading Pages", "Error",
  565.                              MB_OK | MB_ERROR);
  566.                     return 0;
  567.                 }
  568.                 NotebookOpen = TRUE;
  569.                 start = TRUE;
  570.                 WinPostMsg (hwnd, WM_PAINT, NULL, NULL);
  571.                 break;
  572.             case WM_PAINT :
  573.                 if (start)
  574.                 {
  575.                     size_notebook ();
  576.                     start = FALSE;
  577.                 }
  578.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  579.                 WinQueryWindowRect (hwnd, &rcl);
  580.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  581.                 WinEndPaint (hps);
  582.                 break;
  583.             case WM_ADJUSTWINDOWPOS :
  584.             case WM_MOVE :
  585.             case WM_SIZE :
  586.             case WM_WINDOWPOSCHANGED :
  587.                 WinQueryWindowRect (HwndNBFrame, &rcl);
  588.                 bx = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER);
  589.                 by = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER);
  590.                 ty = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  591.                 WinSetWindowPos (HwndNotebook, HWND_TOP,
  592.                                  bx, by, rcl.xRight - (bx * 2),
  593.                                  rcl.yTop - ty - (by * 2),
  594.                                  SWP_SIZE | SWP_MOVE | SWP_SHOW);
  595.                 break;
  596.             case WM_COMMAND :
  597.                 return ((MRESULT) FALSE);
  598.             case WM_CLOSE :
  599.                 WinDestroySecondaryWindow (HwndNBFrame);
  600.                 return ((MRESULT) FALSE);
  601.             case WM_DESTROY :
  602.                 WinPostMsg (HwndFrame, WM_SIZE, NULL, NULL);
  603.                 NotebookOpen = FALSE;
  604.                 break;
  605.             default :
  606.                 break;
  607.         }
  608.         return WinDefSecondaryWindowProc (hwnd, msg, mp1, mp2);
  609. }
  610.  
  611. MRESULT EXPENTRY QuitDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  612. {
  613.         switch (msg)
  614.         {
  615.             case WM_COMMAND :
  616.                 switch (SHORT1FROMMP (mp1))
  617.                 {
  618.                     case DID_OK :
  619.                         WinPostMsg (HwndFrame, WM_CLOSE, NULL, NULL);
  620.                         WinDismissDlg (hwnd, TRUE);
  621.                         break;
  622.                     case DID_CANCEL :
  623.                         WinDismissDlg (hwnd, TRUE);
  624.                         break;
  625.                     default :
  626.                         break;
  627.                 }
  628.                 break;
  629.             default :
  630.                 break;
  631.         }
  632.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  633. }
  634.  
  635. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  636. {
  637.     HPS     hps;
  638.     RECTL   rcl;
  639.     LONG    x, y;
  640.     CHAR    txt[80];
  641.  
  642.         switch (msg)
  643.         {
  644.             case WM_PAINT :
  645.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  646.                 WinQueryWindowRect (hwnd, &rcl);
  647.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  648.                 sprintf (txt, "%30.30s", DevInfo.ProdInfo);
  649.                 WinSetDlgItemText (hwnd, IDD_ABOUT_PROD_INFO, txt);
  650.                 sprintf (txt, "%30.30s", DevInfo.ManInfo);
  651.                 WinSetDlgItemText (hwnd, IDD_ABOUT_MAN_INFO, txt);
  652.                 sprintf (txt, "%10.10s", DevInfo.Version);
  653.                 WinSetDlgItemText (hwnd, IDD_ABOUT_VERSION, txt);
  654.                 WinDrawBorder (hps, &rcl, x, y, 0L, 0L, DB_AREAATTRS |
  655.                                DB_DLGBORDER);
  656.                 WinEndPaint (hps);
  657.                 break;
  658.             case WM_COMMAND :
  659.                 switch (SHORT1FROMMP (mp1))
  660.                 {
  661.                     case DID_OK :
  662.                         WinDismissDlg (hwnd, TRUE);
  663.                         break;
  664.                     default :
  665.                         break;
  666.                 }
  667.                 break;
  668.             default :
  669.                 break;
  670.         }
  671.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  672. }
  673.  
  674. static void size_notebook ()
  675. {
  676.     LONG    bx, by, cx, cy, ty, x, y;
  677.     RECTL   rcl;
  678.  
  679.         cx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  680.         cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  681.         x = cx / 8L;
  682.         y = 0L;
  683.         if (cy <= 480)
  684.         {
  685.             cx = 480;
  686.             cy = 480;
  687.         }
  688.         else
  689.         {
  690.             cx = 640;
  691.             cy = 600;
  692.         }
  693.         WinSetWindowPos (HwndNBFrame, HWND_TOP,
  694.                          x, y, cx, cy,
  695.                          SWP_SIZE | SWP_MOVE | SWP_SHOW);
  696.         WinQueryWindowRect (HwndNBFrame, &rcl);
  697.         bx = WinQuerySysValue (HWND_DESKTOP,
  698.                                SV_CXSIZEBORDER);
  699.         by = WinQuerySysValue (HWND_DESKTOP,
  700.                                SV_CYSIZEBORDER);
  701.         ty = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  702.         WinSetWindowPos (HwndNotebook, HWND_TOP,
  703.                          bx, by, rcl.xRight - (bx * 2),
  704.                          rcl.yTop - ty - (by * 2),
  705.                          SWP_SIZE | SWP_MOVE | SWP_SHOW);
  706. }
  707.  
  708. static BOOL init_window ()
  709. {
  710.     CHAR    szClient[] = "Client";
  711.     ULONG   flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_ICON |
  712.                            FCF_SIZEBORDER | FCF_MINMAX | FCF_ACCELTABLE |
  713.                            FCF_SHELLPOSITION | FCF_TASKLIST;
  714.  
  715.         DevInfo.Length = sizeof (VCADEVINFO);
  716.         VcaiDeviceInfoGet (&DevInfo);
  717.         sprintf (txt, "Example 5 - %s %u", DevType, DevInstance);
  718.  
  719.  
  720.         if (!WinRegisterClass (Hab, szClient, ClientWndProc,
  721.                                CS_SIZEREDRAW | CS_MOVENOTIFY, 0))
  722.             return (FALSE);
  723.  
  724.         if (!WinRegisterGraphicButton ())
  725.             return (FALSE);
  726.  
  727.         HwndFrame = WinCreateStdWindow (HWND_DESKTOP,
  728.                                         WS_VISIBLE,
  729.                                         &flFrameFlags,
  730.                                         szClient,
  731.                                         txt,
  732. //                                        WS_SYNCPAINT | WS_VISIBLE,
  733.                                         0,
  734.                                         (HMODULE) NULLHANDLE,
  735.                                         IDR_MAIN,
  736.                                         &HwndClient);
  737.         if (!HwndFrame)
  738.             return (FALSE);
  739.  
  740.     // Turn on visible region notification.
  741.         WinSetVisibleRegionNotify (HwndClient, TRUE);
  742.  
  743.         WinPostMsg (HwndFrame, WM_VRNENABLED, 0L, 0L);
  744.  
  745.         HelpInit (HwndFrame);
  746.  
  747.         if (!init_video ())
  748.             return (FALSE);
  749.  
  750.         if (!init_audio ())
  751.             return (FALSE);
  752.  
  753.         return (TRUE);
  754. }
  755.  
  756. static void init_colour ()
  757. {
  758.     HDC     hdc;
  759.     DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL,
  760.                         NULL};
  761.  
  762.         hdc = DevOpenDC (Hab, OD_INFO, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
  763.         DevQueryCaps (hdc, CAPS_COLORS, 1L, &NumColours);
  764.         DevCloseDC (hdc);
  765. }
  766.  
  767. static void map_pallete (HPS hps)
  768. {
  769.     LONG    rc;
  770.     VCASCREENINFO vs;
  771.     USHORT cx, cy, i;
  772.  
  773.         if ((NumColours <= 256) && (NumColours > 0))
  774.         {
  775.             rc = GpiQueryRealColors (hps, 0L, 0L, NumColours, Colours);
  776.             if (rc == GPI_ALTERROR)
  777.             {
  778.                 err_msg ("GpiQueryRealColors");
  779.                 return;
  780.             }
  781.         }
  782.         cx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  783.         cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  784.         vs.ulLength = sizeof (VCASCREENINFO);
  785.         vs.ul_RESV01 = 0L;
  786.         vs.ulWidth = (ULONG) cx;
  787.         vs.ulHeight = (ULONG) cy;
  788.         vs.ulNumColours = (ULONG) NumColours;
  789.         vs.ulHFreq = 0L;
  790.         vs.ulVFreq = 0L;
  791.         if ((ULONG)NumColours <= 256)
  792.         {
  793.             for (i = 0; i < NumColours; i++)
  794.                 vs.ulRGB[i] = (ULONG) Colours[i];
  795.         }
  796.         else
  797.         {
  798.             for (i = 0; i < 256; i++)
  799.                 vs.ulRGB[i] = 0L;
  800.         }
  801.         VcaiScreenInfoSet (&vs);
  802.         rc = GpiCreateLogColorTable (hps, LCOL_RESET, LCOLF_RGB,
  803.                                      0L, 0L, (PLONG)0L);
  804.         if (!rc)
  805.         {
  806.             err_msg ("GpiCreateLogColorTable");
  807.             return;
  808.         }
  809. }
  810.  
  811. static void check_menu_item (short item_id, short state)
  812. {
  813.         WinPostMsg (HwndMenu, MM_SETITEMATTR,
  814.                     MPFROM2SHORT (item_id, TRUE),
  815.                     MPFROM2SHORT (MIA_CHECKED, state));
  816. }
  817.  
  818. static void enable_menu_item (short item_id, short state)
  819. {
  820.         WinPostMsg (HwndMenu, MM_SETITEMATTR,
  821.                     MPFROM2SHORT (item_id, TRUE),
  822.                     MPFROM2SHORT (MIA_DISABLED, state));
  823. }
  824.