SAMPLE: Using mciSendString() to Change an .AVI Palette

Last reviewed: April 8, 1997
Article ID: Q139746

The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) version 3.1
  • Microsoft Win32 Software Development Kit (SDK) version 3.5
  • Microsoft Video for Windows Development Kit (VfWDK) version 1.1

SUMMARY

The SETPAL sample demonstrates how to use the "setvideo palette handle to" Media Control Interface (MCI) string to change the palette that will be used when an Audio-Video Interleaved (.avi) file is played.

The following file is available for download from the Microsoft Software Library:

 ~ Setpal.exe

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

The current video mode of the display must be a palettized video mode such as 256 colors for the technique to succeed because the "setvideo palette handle to" string is ignored in non-palettized video modes. Also, it is up to the video compressor/decompressor (codec) that decompresses the .avi file to handle the palette. Therefore, the exact behavior may depend on the codec in use. For example, the MS Video 1 codec is an 8-bit (256 color) palettized codec while the Indeo and Cinepak Codecs are 24-bit non- palettized Codecs, so their palette behavior may differ.

MORE INFORMATION

The basic steps to supply your own palette are as follows:

  1. Fill in a LOGPALETTE structure containing the color information for your palette.

  2. Create a logical palette using the CreatePalette() function.

  3. Call mciSendString() (or mciSendCommand()) to supply that palette to the AVI file using a string such as:

          setvideo <alias> palette handle to <palette handle>
    

The remainder of this article supplies more information and code excerpts from the SETPAL sample that perform these steps.

The SETPAL sample can be compiled as a 32-bit sample, called SETPAL32, or as a 16-bit sample, called SETPAL16. As a result, it is compatible with Windows 95, Windows NT, and Windows 3.1. Setpal32.mak and Setpal16.mak make files are provided. SETPAL16 requires the Video for Windows 1.1 Development Kit to build successfully.

SETPAL is a sample application that allows opening an .avi file via the open common dialog box. Menu choices allow the .avi file to be opened, played, stopped, or closed. MCI strings perform the underlying work. The following MCI string is used to supply a palette for the .avi file:

    setvideo <alias> palette handle to <palette handle>

Excerpts from Setpal.c

   // include files
   #include <windows.h>  // Required for all Windows applications
   #include "windowsx.h" // for GlobalAllocPtr/GlobalFreePtr in
                         // CreateSamplePalette.
   #include "mmsystem.h" // For the MCI calls.

   // global variables
   static HPALETTE g_hPal = NULL;    // Palette handle.
   .
   .
   .

   // CreateSamplePalette() demonstrates how to fill in a LOGPALETTE
   // structure and create a logical palette
   VOID CreateSamplePalette(void)

   {
       LPLOGPALETTE lpLogPal;
       int          i;
       int          nPalEntries = 236;   // Number of entries in our
                                         // palette.
                                         // 256 are possible, but the
                                         // system reserves 20 of them.

       lpLogPal = (LPLOGPALETTE) GlobalAllocPtr (GHND,
                   sizeof (LOGPALETTE) + nPalEntries * sizeof
                   (PALETTEENTRY));

          lpLogPal->palVersion    = 0x300;
       lpLogPal->palNumEntries = nPalEntries;

       for (i = nPalEntries; i > 0; i--)
       {
           // Fill in the red, green, and blue values for our palette.
           // This particular palette is a wash from green to black.
           lpLogPal->palPalEntry[i].peRed   = 0;
           lpLogPal->palPalEntry[i].peGreen = i;
           lpLogPal->palPalEntry[i].peBlue  = 0;

           // Create unique palette entries. This flag may change depending
           // on your purposes. See the Windows API documentation
           // concerning the PALETTEENTRY structure for more information.
           lpLogPal->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
       }

       // Create the logical palette.
       g_hPal = CreatePalette (lpLogPal);

       // Clean up.
       GlobalFreePtr (lpLogPal);
   }

   // The ProcessAVICommands() function in SETPAL.C handles the open, set
   // palette, play, and close for the AVI file. Once the AVI file has been
   // opened, issue an mciSendString() such as the following to set the
   // palette:

   static char szAlias[10] = "paltest";  // the movie alias to use in
   mciSendString                         // buffer to hold the MCI
   char szBuffer[128];                   // string we built.
   .
   .
   .
      wsprintf(szBuffer, "setvideo %s palette handle to %d",
              (LPSTR)szAlias, g_hPal);
      mciSendString(szBuffer, NULL, 0, NULL);


Additional query words: mciSendCommand MCI_SETVIDEO MCI_DGV_SETVIDEO_ITEM
MCI_DGV_SETVIDEO_PALHANDLE
Keywords : kbcode kbfile kbmm kbsample MMVideo
Version : 3.1 3.5 3.51 4.0
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.