BUG: Palette Does Not Change with Picture on MDI Child

Last reviewed: March 29, 1996
Article ID: Q149233
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

Changing from one 256-color bitmap to another 256-color bitmap at run time causes the second bitmap to be rendered with the palette from the first bitmap. This causes the second bitmap to look wrong, unless both bitmaps have similar or identical colors. This problem occurs only when the picture or image control resides on an MDI child form.

WORKAROUND

To work around this problem, send a WM_QUERYNEWPALETTE message to the MDI child form immediately after changing the bitmap. Follow these steps to implement this fix:

  1. Add a single module to the project to hold the declaration for SendMessage and the WM_QUERYNEWPALETTE constant. If a module already exists in the project it can be used instead of adding a new one.

  2. Add the following function and constant declarations for the appropriate bitness to the module:

    For Win16 or Win32:

    Public Const WM_QUERYNEWPALETTE = &H30F

    For Win32 (only):

       Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
       Long) As Long
    
       For Win16 (only):
    
       Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, _
       ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
    
    

  3. Immediately after the code where the bitmap is changed, add this single call to SendMessage (assuming Form1 is the MDI child where the picture or image control is located):

    SendMessage Form1.hWnd, WM_QUERYNEWPALETTE, 0, 0

    When the form receives this message it will correctly set the palette so that the new image is displayed correctly. These declarations were obtained from the 16-bit and 32-bit versions of the API Text Viewer.

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce

  1. Start Visual Basic 4.0. Form1 is created by default.

  2. Add an MDI form by selecting MDI Form from the Insert menu.

  3. Change the MDIChild property for Form1 to True.

  4. Add a single Image control to Form1.

  5. Change the Picture property of the image control to point to a 256-color bitmap.

  6. Add this code to the Form_Click event of Form1 (where PICTURE.BMP is the filename of a 256-color bitmap with a different palette than the one selected in step 5):

       Private Sub Form_Click()
          Image1.Picture = LoadPicture("PICTURE.BMP")
       End Sub
    
    

  7. Press F5 or select Start from the Run menu to run the application. Click Form1 and see that the picture changes but that the colors are not correct. Sending a WM_QUERYNEWPALETTE message immediately after changing the bitmap will fix the problem.


KBCategory: kbprg kbbuglist
KBSubcategory: PrgOther
Additional reference words: 4.00 vb4win vb4all




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: March 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.