home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / videotlk.zip / SAMPLES / EX3 / EX3.C next >
Text File  |  1999-01-26  |  23KB  |  641 lines

  1.  
  2. /*------------------------------------------------------------------*
  3.  *                                                                  *
  4.  *  Video Toolkit For OS/2 Version 2.0                              *
  5.  *  Example PM Application No. 3.                                   *
  6.  *  Date : 22/02/95.                                                *
  7.  *  Copyright (c) Abbotsbury Software Ltd., United Kingdom. 1995-98 *
  8.  *                                                                  *
  9.  *  Filename : ex3.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    "ex3.h"
  26. #include    "helpfunc.h"
  27. #include    "pmtv2rem.h"
  28. #include    "region.h"
  29.  
  30. extern  BOOL    RemOpen;
  31. extern  MRESULT EXPENTRY TuneDlgProc (HWND hwnd, ULONG msg,
  32.                                       MPARAM mp1, MPARAM mp2);
  33.  
  34. HAB     Hab;
  35. HWND    HwndFrame;
  36. DRIVERHANDLE    DevHandle;
  37. USHORT  DevInstance;
  38. CHAR    DevType[20];
  39. LONG    ColourKey;
  40. LONG    Colours[256];
  41. LONG    NumColours;
  42.  
  43. static  HWND    HwndClient, HwndRemote;
  44. static  HWND    HwndNotebook, HwndNBFrame;
  45. static  USHORT  Connector;
  46. static  VCADEVINFO  DevInfo;
  47. static  BOOL    NotebookOpen;
  48. static  PSZ     InsertName = "InsertPage";
  49. static  PFN     InsertAddr;
  50. static  HMODULE HmodInsert;
  51. static  PSZ     RemoteName = "RemoteDlgProc";
  52. static  PFN     RemoteAddr;
  53. static  HMODULE HmodRemote;
  54. static  CHAR    txt[256];
  55. static  UCHAR   *Copyright =
  56.   "Copyright (c) Abbotsbury Software Ltd., UK. 1994-1995. All Rights Reserved";
  57.  
  58. int     main (int argc, char **argv);
  59. void    msg_box (UCHAR *txt, UCHAR *title, ULONG options);
  60. void    err_msg (UCHAR *mess);
  61. LONG    get_colour (HPS hps);
  62. MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  63. MRESULT EXPENTRY NotebookDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  64. MRESULT EXPENTRY QuitDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  65. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  66.  
  67. static  void    size_notebook (void);
  68. static  BOOL    init_window (void);
  69. static  void    init_colour (void);
  70. static  void    map_pallete (HPS hps);
  71.  
  72. int main (int argc, char **argv)
  73. {
  74.     HMQ     hmq;
  75.     QMSG    qmsg;
  76.     CHAR    mod_txt[256];
  77.     PSZ     pmmbase, env = "MMBASE";
  78.     LONG    len;
  79.     APIRET  rc;
  80.  
  81.         if (argc < 3)
  82.             DosExit (EXIT_PROCESS, 1);
  83.  
  84.         Hab = WinInitialize (0);
  85.         if (!Hab)
  86.             DosExit (EXIT_PROCESS, 1);
  87.  
  88.         hmq = WinCreateMsgQueue (Hab, 0);
  89.         if (!hmq)
  90.             DosExit (EXIT_PROCESS, 1);
  91.  
  92.         strcpy (DevType, argv[1]);
  93.         DevInstance = (USHORT)atoi (argv[2]);
  94.         DevHandle = VcaiDeviceOpen (DevType, DevInstance);
  95.         if (DevHandle < 0)
  96.         {
  97.             sprintf (txt, "Cannot Open Device %u !", atoi(argv[2]));
  98.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  99.             DosExit (EXIT_PROCESS, 1);
  100.         }
  101.         Connector = (USHORT)atoi (argv[2]);
  102.  
  103.         rc = DosScanEnv (env, &pmmbase);
  104.         if (rc != 0)
  105.             DosExit (EXIT_PROCESS, 1);
  106.         len = strlen (pmmbase);
  107.         if (pmmbase[len-1] == ';')
  108.             pmmbase[len-1] = '\0';
  109.         sprintf (mod_txt, "%s\\DLL\\%5.5sNB.DLL", pmmbase, argv[1]);
  110.         rc = DosLoadModule (txt, sizeof (txt), mod_txt, &HmodInsert);
  111.         if (rc != 0)
  112.         {
  113.             sprintf (txt, "DosLoadModule <%s> - %ld", mod_txt, rc);
  114.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  115.             DosExit (EXIT_PROCESS, 1);
  116.         }
  117.         rc = DosQueryProcAddr (HmodInsert, 0L, InsertName, &InsertAddr);
  118.         if (rc != 0)
  119.         {
  120.             sprintf (txt, "DosQueryProcAddr (InsertPage) - %ld", rc);
  121.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  122.             DosExit (EXIT_PROCESS, 1);
  123.         }
  124.         sprintf (mod_txt, "%s\\DLL\\PMTV2REM.DLL", pmmbase);
  125.         rc = DosLoadModule (txt, sizeof (txt), mod_txt, &HmodRemote);
  126.         if (rc != 0)
  127.         {
  128.             sprintf (txt, "DosLoadModule (PMTV2REM.DLL) - %ld", rc);
  129.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  130.             DosExit (EXIT_PROCESS, 1);
  131.         }
  132.         rc = DosQueryProcAddr (HmodRemote, 0L, RemoteName, &RemoteAddr);
  133.         if (rc != 0)
  134.         {
  135.             sprintf (txt, "DosQueryProcAddr (RemoteDlgProc) - %ld", rc);
  136.             msg_box (txt, "Error", MB_OK | MB_ERROR);
  137.             DosExit (EXIT_PROCESS, 1);
  138.         }
  139.  
  140.         if (!init_window ())
  141.             DosExit (EXIT_PROCESS, 1);
  142.  
  143.         while (WinGetMsg (Hab, &qmsg, NULLHANDLE, 0, 0))
  144.             WinDispatchMsg (Hab, &qmsg);
  145.  
  146.         DestroyHelpInstance ();
  147.         WinDestroyWindow (HwndFrame);
  148.         WinDestroyMsgQueue (hmq);
  149.         WinTerminate (Hab);
  150.         DosExit (EXIT_PROCESS, 0);
  151. }
  152.  
  153. void msg_box (UCHAR *txt, UCHAR *title, ULONG options)
  154. {
  155.         WinMessageBox (HWND_DESKTOP,
  156.                        HWND_DESKTOP,
  157.                        txt,
  158.                        title,
  159.                        IDD_MSG,
  160.                        options);
  161. }
  162.  
  163. void err_msg (UCHAR *mess)
  164. {
  165.     CHAR    txt[256];
  166.     ERRORID err;
  167.  
  168.         err = WinGetLastError (Hab);
  169.         sprintf (txt, "%s - %lx", mess,  err & 0xffff);
  170.         msg_box (txt, "Error", MB_OK | MB_ERROR);
  171. }
  172.  
  173.                         // The colour value for the Video Colour Key
  174.                         // is a physical palette value.
  175.                         // For systems with 256 or less colours in the
  176.                         // palette, you MUST map the physical palette
  177.                         // to PM logical palette first.
  178.                         // If there are more than 256 colours this
  179.                         // step should be ignored.
  180. LONG get_colour (HPS hps)
  181. {
  182.     LONG index;
  183.  
  184.         map_pallete (hps);
  185.  
  186.         index = VcaiColourkeyGet();
  187.         if (index > (ULONG)NumColours)
  188.         {
  189.             index = COLOUR_KEY_DEFAULT;
  190.             VcaiColourkeySet (index);
  191.         }
  192.         return (LONG)index;
  193. }
  194.  
  195. MRESULT EXPENTRY ClientWndProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  196. {
  197.     static  HWND        hwnd_menu;
  198.     static  HPOINTER    hptr_rem;
  199.     static  BOOL    minimize = FALSE;
  200.     HPS     hps;
  201.     RECTL   rcl;
  202.     LONG    bx, by, cy, x, y, width, height;
  203.     VCADEVAUDIO ad;
  204.     MOUSEPOS mousepos;
  205.     PSWP    pswp;
  206.  
  207.         switch(msg)
  208.         {
  209.             case WM_CREATE :
  210.                 RemOpen = NotebookOpen = FALSE;
  211.                 VcaiOverlay (TRUE);
  212.                 VcaiFreeze (FALSE);
  213.                 hwnd_menu = WinLoadMenu (hwnd, NULLHANDLE, IDR_MAIN);
  214.                 hptr_rem = WinLoadPointer (HWND_DESKTOP, NULLHANDLE,
  215.                                            PTR_REMOTE);
  216.                 init_colour ();
  217.                 break;
  218.             case WM_PAINT :
  219.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  220.                 WinQueryWindowRect (hwnd, &rcl);
  221.                 ColourKey = get_colour (hps);
  222.                 if ((ULONG)NumColours <= 256)
  223.                     WinFillRect (hps, &rcl, Colours[ColourKey]);
  224.                 else
  225.                     WinFillRect (hps, &rcl, ColourKey);
  226.                 WinEndPaint (hps);
  227.                 break;
  228.             case MSG_SIZE_TV :
  229.             case WM_SIZE :
  230.             case WM_MOVE :
  231.             case WM_WINDOWPOSCHANGED :
  232.                 if (minimize)
  233.                     break;
  234.                 if (!WinQueryWindowRect (hwnd, &rcl))
  235.                     return 0;
  236.                 WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL)&rcl, 2);
  237.                 bx = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER);
  238.                 by = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER);
  239.                 cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  240.                 x = rcl.xLeft + bx;
  241.                 y = cy - rcl.yTop - by;
  242.                 width = rcl.xRight - rcl.xLeft;
  243.                 height = rcl.yTop - rcl.yBottom;
  244.                 VcaiVideoRectValidate (0, 0, 0, 0, (USHORT)x, (USHORT)y,
  245.                                        (USHORT)width, (USHORT)height);
  246.                 if (RemOpen)
  247.                     WinSetActiveWindow (HWND_DESKTOP, HwndRemote);
  248.                 break;
  249.             case WM_MINMAXFRAME :
  250.                 pswp = (PSWP)PVOIDFROMMP (mp1);
  251.                 if (!(pswp->fl & SWP_MINIMIZE))
  252.                 {
  253.                     minimize = FALSE;
  254.                     break;
  255.                 }
  256.                 minimize = TRUE;
  257.                 VcaiVideoRectValidate (0, 0, 0, 0, 0, 0, 0, 0);
  258.                 break;
  259.             case WM_BUTTON1CLICK :
  260.                 if (RemOpen)
  261.                     return 0;
  262.                 WinQueryWindowRect (hwnd, & rcl);
  263.                 WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL)&rcl, 2);
  264.                 mousepos.mp_x = MOUSEMSG (&msg)->x + rcl.xLeft;
  265.                 mousepos.mp_y = MOUSEMSG (&msg)->y + rcl.yBottom;
  266.                 init_audio ();
  267.                 init_video ();
  268.                 HwndRemote = WinLoadDlg (HWND_DESKTOP,
  269.                                          HWND_DESKTOP,
  270.                                          (PFNWP)RemoteAddr,
  271.                                          HmodRemote,
  272.                                          IDD_REM,
  273.                                          (PVOID)&mousepos);
  274.                 return 0;
  275.             case WM_BUTTON2CLICK :
  276.                 WinPopupMenu (hwnd, hwnd, hwnd_menu,
  277.                               MOUSEMSG (&msg)->x, MOUSEMSG (&msg)->y, 0L,
  278.                               PU_HCONSTRAIN | PU_VCONSTRAIN |
  279.                               PU_NONE | PU_MOUSEBUTTON1 |
  280.                               PU_KEYBOARD);
  281.                 return 0;
  282.             case WM_MOUSEMOVE :
  283.                 WinSetPointer (HWND_DESKTOP, hptr_rem);
  284.                 return MRFROMSHORT (1);
  285.  
  286.             case WM_CLOSE :
  287.                 VcaiDeviceClose (DevHandle);
  288.                 break;
  289.  
  290.             case WM_COMMAND :
  291.                 switch (SHORT1FROMMP (mp1))
  292.                 {
  293.                     case IDM_FILE_QUIT :
  294.                         WinDlgBox (HWND_DESKTOP,
  295.                                    HwndFrame,
  296.                                    (PFNWP)QuitDlgProc,
  297.                                    (HMODULE)NULLHANDLE,
  298.                                    IDD_QUIT,
  299.                                    NULL);
  300.                         WinInvalidateRegion (HwndFrame, NULLHANDLE, FALSE);
  301.                         break;
  302.                     case IDM_TUNE :
  303.                         WinDlgBox (HWND_DESKTOP,
  304.                                    HWND_DESKTOP,
  305.                                    (PFNWP)TuneDlgProc,
  306.                                    (HMODULE)NULLHANDLE,
  307.                                    IDD_TUNE,
  308.                                    NULL);
  309.                         break;
  310.                     case IDM_TV_SETUP :
  311.                         if (NotebookOpen)
  312.                             return 0;
  313.                         HwndNBFrame = WinLoadSecondaryWindow
  314.                                                (HWND_DESKTOP,
  315.                                                 HWND_DESKTOP,
  316.                                                 (PFNWP)NotebookDlgProc,
  317.                                                 (HMODULE)NULLHANDLE,
  318.                                                 IDD_NOTE,
  319.                                                 NULL);
  320.                         break;
  321.                     case IDM_HELPCONTENTS :
  322.                         HelpContents ();
  323.                         break;
  324.                     case IDM_HELPINDEX :
  325.                         HelpIndex ();
  326.                         break;
  327.                     case IDM_KEYSHELP :
  328.                         HelpKeys ();
  329.                         break;
  330.                     case IDM_GENERALHELP :
  331.                         HelpHelpForHelp ();
  332.                         break;
  333.                     case IDM_HELPPRODUCTINFO :
  334.                         HelpAbout ();
  335.                         break;
  336.                     default :
  337.                         break;
  338.                 }
  339.                 break;
  340.             case HM_QUERY_KEYS_HELP :
  341.                 return ((MRESULT)PANEL_KEYSHELP);
  342.             case MSG_UPDATE_WINDOW :
  343.                 WinQueryWindowRect (hwnd, &rcl);
  344.                 WinInvalidateRect (hwnd, &rcl, TRUE);
  345.                 WinPostMsg (hwnd, MSG_SIZE_TV, NULL, NULL);
  346.             default :
  347.                 break;
  348.         }
  349.         return WinDefWindowProc (hwnd, msg, mp1, mp2);
  350. }
  351.  
  352. MRESULT EXPENTRY NotebookDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  353. {
  354.     static  BOOL    start;
  355.     HPS     hps;
  356.     RECTL   rcl;
  357.     ULONG   id, result;
  358.     MCI_DEVICESETTINGS_PARMS   mci;
  359.     HWND    hwndPage;
  360.     LONG    bx, by, cx, cy, ty, x, y;
  361.     SWP     swp;
  362.  
  363.         switch (msg)
  364.         {
  365.             case WM_INITDLG :
  366.                 HwndNotebook = WinWindowFromID (hwnd, IDD_NOTE_BOOK);
  367.                 WinSendMsg (HwndNotebook,
  368.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  369.                             MPFROMSHORT (BKA_BACKGROUNDPAGECOLORINDEX));
  370.                 WinSendMsg (HwndNotebook,
  371.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  372.                             MPFROMSHORT (BKA_BACKGROUNDMAJORCOLORINDEX));
  373.                 WinSendMsg (HwndNotebook,
  374.                             BKM_SETNOTEBOOKCOLORS, MPFROMLONG (CLR_PALEGRAY),
  375.                             MPFROMSHORT (BKA_BACKGROUNDMINORCOLORINDEX));
  376.                 cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  377.                 if (cy <= 480)
  378.                 {
  379.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  380.                                 MPFROM2SHORT (100, 24),
  381.                                 MPFROMSHORT (BKA_MAJORTAB));
  382.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  383.                                 MPFROM2SHORT (75, 24),
  384.                                 MPFROMSHORT (BKA_MINORTAB));
  385.                 }
  386.                 else
  387.                 {
  388.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  389.                                 MPFROM2SHORT (150, 24),
  390.                                 MPFROMSHORT (BKA_MAJORTAB));
  391.                     WinSendMsg (HwndNotebook, BKM_SETDIMENSIONS,
  392.                                 MPFROM2SHORT (100, 24),
  393.                                 MPFROMSHORT (BKA_MINORTAB));
  394.                 }
  395.                 mci.hwndCallback = HwndNBFrame;
  396.                 mci.hwndNotebook = HwndNotebook;
  397.                 mci.usDeviceType = 12;
  398.                 sprintf (txt, "TV0%ld", Connector);
  399.                 mci.pszDeviceName = txt;
  400.                 hwndPage = (HWND)InsertAddr (&mci);
  401.                 if (!hwndPage)
  402.                 {
  403.                     msg_box ("Error Loading Pages", "Error",
  404.                              MB_OK | MB_ERROR);
  405.                     return 0;
  406.                 }
  407.                 NotebookOpen = TRUE;
  408.                 start = TRUE;
  409.                 WinPostMsg (hwnd, WM_PAINT, NULL, NULL);
  410.                 break;
  411.             case WM_PAINT :
  412.                 if (start)
  413.                 {
  414.                     size_notebook ();
  415.                     start = FALSE;
  416.                 }
  417.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  418.                 WinQueryWindowRect (hwnd, &rcl);
  419.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  420.                 WinEndPaint (hps);
  421.                 break;
  422.             case WM_ADJUSTWINDOWPOS :
  423.             case WM_MOVE :
  424.             case WM_SIZE :
  425.             case WM_WINDOWPOSCHANGED :
  426.                 WinQueryWindowRect (HwndNBFrame, &rcl);
  427.                 bx = WinQuerySysValue (HWND_DESKTOP, SV_CXSIZEBORDER);
  428.                 by = WinQuerySysValue (HWND_DESKTOP, SV_CYSIZEBORDER);
  429.                 ty = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  430.                 WinSetWindowPos (HwndNotebook, HWND_TOP,
  431.                                  bx, by, rcl.xRight - (bx * 2),
  432.                                  rcl.yTop - ty - (by * 2),
  433.                                  SWP_SIZE | SWP_MOVE | SWP_SHOW);
  434.                 break;
  435.             case WM_COMMAND :
  436.                 return ((MRESULT)FALSE);
  437.             case WM_CLOSE :
  438.                 WinDestroySecondaryWindow (HwndNBFrame);
  439.                 return ((MRESULT)FALSE);
  440.             case WM_DESTROY :
  441.                 WinPostMsg (HwndFrame, WM_SIZE, NULL, NULL);
  442.                 NotebookOpen = FALSE;
  443.                 break;
  444.             default :
  445.                 break;
  446.         }
  447.         return WinDefSecondaryWindowProc (hwnd, msg, mp1, mp2);
  448. }
  449.  
  450. MRESULT EXPENTRY QuitDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  451. {
  452.         switch (msg)
  453.         {
  454.             case WM_COMMAND :
  455.                 switch (SHORT1FROMMP (mp1))
  456.                 {
  457.                     case DID_OK :
  458.                         WinPostMsg (HwndFrame, WM_CLOSE, NULL, NULL);
  459.                         WinDismissDlg (hwnd, TRUE);
  460.                         break;
  461.                     case DID_CANCEL :
  462.                         WinDismissDlg (hwnd, TRUE);
  463.                         break;
  464.                     default :
  465.                         break;
  466.                 }
  467.                 break;
  468.             default :
  469.                 break;
  470.         }
  471.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  472. }
  473.  
  474. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  475. {
  476.     HPS     hps;
  477.     RECTL   rcl;
  478.     LONG    x, y;
  479.  
  480.         switch (msg)
  481.         {
  482.             case WM_PAINT :
  483.                 hps = WinBeginPaint (hwnd, NULLHANDLE, &rcl);
  484.                 WinQueryWindowRect (hwnd, &rcl);
  485.                 WinFillRect (hps, &rcl, CLR_PALEGRAY);
  486.                 sprintf (txt, "%30.30s", DevInfo.ProdInfo);
  487.                 WinSetDlgItemText (hwnd, IDD_ABOUT_PROD_INFO, txt);
  488.                 sprintf (txt, "%30.30s", DevInfo.ManInfo);
  489.                 WinSetDlgItemText (hwnd, IDD_ABOUT_MAN_INFO, txt);
  490.                 sprintf (txt, "%10.10s", DevInfo.Version);
  491.                 WinSetDlgItemText (hwnd, IDD_ABOUT_VERSION, txt);
  492.                 WinDrawBorder (hps, &rcl, x, y, 0L, 0L, DB_AREAATTRS |
  493.                                DB_DLGBORDER);
  494.                 WinEndPaint (hps);
  495.                 break;
  496.             case WM_COMMAND :
  497.                 switch (SHORT1FROMMP (mp1))
  498.                 {
  499.                     case DID_OK :
  500.                         WinDismissDlg (hwnd, TRUE);
  501.                         break;
  502.                     default :
  503.                         break;
  504.                 }
  505.                 break;
  506.             default :
  507.                 break;
  508.         }
  509.         return WinDefDlgProc (hwnd, msg, mp1, mp2);
  510. }
  511.  
  512. static void size_notebook ()
  513. {
  514.     LONG    bx, by, cx, cy, ty, x, y;
  515.     RECTL   rcl;
  516.  
  517.         cx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  518.         cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  519.         x = cx / 8L;
  520.         y = 0L;
  521.         if (cy <= 480)
  522.         {
  523.             cx = 480;
  524.             cy = 480;
  525.         }
  526.         else
  527.         {
  528.             cx = 640;
  529.             cy = 600;
  530.         }
  531.         WinSetWindowPos (HwndNBFrame, HWND_TOP, x, y, cx, cy,
  532.                          SWP_SIZE | SWP_MOVE | SWP_SHOW);
  533.         WinQueryWindowRect (HwndNBFrame, &rcl);
  534.         bx = WinQuerySysValue (HWND_DESKTOP,
  535.                                SV_CXSIZEBORDER);
  536.         by = WinQuerySysValue (HWND_DESKTOP,
  537.                                SV_CYSIZEBORDER);
  538.         ty = WinQuerySysValue (HWND_DESKTOP, SV_CYTITLEBAR);
  539.         WinSetWindowPos (HwndNotebook, HWND_TOP,
  540.                          bx, by, rcl.xRight - (bx * 2),
  541.                          rcl.yTop - ty - (by * 2),
  542.                          SWP_SIZE | SWP_MOVE | SWP_SHOW);
  543. }
  544.  
  545. static BOOL init_window ()
  546. {
  547.     CHAR    szClient[] = "Client";
  548.     ULONG   flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_ICON |
  549.                            FCF_SIZEBORDER | FCF_MINMAX | FCF_ACCELTABLE |
  550.                            FCF_SHELLPOSITION | FCF_TASKLIST;
  551.  
  552.         if (!WinRegisterClass (Hab, szClient, ClientWndProc,
  553.                                CS_SIZEREDRAW | CS_MOVENOTIFY, 0))
  554.             return (FALSE);
  555.  
  556.         if (!WinRegisterGraphicButton ())
  557.             return (FALSE);
  558.  
  559.         DevInfo.Length = sizeof (VCADEVINFO);
  560.         VcaiDeviceInfoGet (&DevInfo);
  561.  
  562.         sprintf (txt, "Example 3 - %s %u", DevType, DevInstance);
  563.  
  564.         HwndFrame = WinCreateStdWindow (HWND_DESKTOP,
  565.                                         WS_VISIBLE,
  566.                                         &flFrameFlags,
  567.                                         szClient,
  568.                                         txt,
  569.                                         0L,
  570.                                         (HMODULE)NULLHANDLE,
  571.                                         IDR_MAIN,
  572.                                         &HwndClient);
  573.         if (!HwndFrame)
  574.             return (FALSE);
  575.  
  576.         HelpInit (HwndFrame);
  577.  
  578.         if (!init_video ())
  579.             return (FALSE);
  580.  
  581.         if (!init_audio ())
  582.             return (FALSE);
  583.  
  584.         return (TRUE);
  585. }
  586.  
  587. static void init_colour ()
  588. {
  589.     HDC     hdc;
  590.     DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, NULL, NULL,
  591.                         NULL};
  592.  
  593.         hdc = DevOpenDC (Hab, OD_INFO, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
  594.         DevQueryCaps (hdc, CAPS_COLORS, 1L, &NumColours);
  595.         DevCloseDC (hdc);
  596. }
  597.  
  598. static void map_pallete (HPS hps)
  599. {
  600.     LONG    rc;
  601.     VCASCREENINFO vs;
  602.     USHORT cx, cy, i;
  603.  
  604.         if ((NumColours <= 256) && (NumColours > 0))
  605.         {
  606.             rc = GpiQueryRealColors (hps, 0L, 0L, NumColours, Colours);
  607.             if (rc == GPI_ALTERROR)
  608.             {
  609.                 err_msg ("GpiQueryRealColors");
  610.                 return;
  611.             }
  612.         }
  613.         cx = WinQuerySysValue (HWND_DESKTOP, SV_CXSCREEN);
  614.         cy = WinQuerySysValue (HWND_DESKTOP, SV_CYSCREEN);
  615.         vs.ulLength = sizeof (VCASCREENINFO);
  616.         vs.ul_RESV01 = 0L;
  617.         vs.ulWidth = (ULONG)cx;
  618.         vs.ulHeight = (ULONG)cy;
  619.         vs.ulNumColours = (ULONG)NumColours;
  620.         vs.ulHFreq = 0L;
  621.         vs.ulVFreq = 0L;
  622.         if ((ULONG)NumColours <= 256)
  623.         {
  624.             for (i = 0; i < NumColours; i++)
  625.                 vs.ulRGB[i] = (ULONG)Colours[i];
  626.         }
  627.         else
  628.         {
  629.             for (i = 0; i < 256; i++)
  630.                 vs.ulRGB[i] = 0L;
  631.         }
  632.         VcaiScreenInfoSet (&vs);
  633.         rc = GpiCreateLogColorTable (hps, LCOL_RESET, LCOLF_RGB,
  634.                                      0L, 0L, (PLONG)0L);
  635.         if (!rc)
  636.         {
  637.             err_msg ("GpiCreateLogColorTable");
  638.             return;
  639.         }
  640. }
  641.