Microsoft KB Archive/149233

= FIX: Palette Does Not Change with Picture on MDI Child =

Article ID: 149233

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q149233



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.



RESOLUTION
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:

 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.  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   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 a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.



Steps to Reproduce
 Start Visual Basic 4.0. Form1 is created by default. Add an MDI form by selecting MDI Form from the Insert menu.</li> Change the MDIChild property for Form1 to True.</li> Add a single Image control to Form1.</li> Change the Picture property of the image control to point to a 256-color bitmap.</li>  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 </li> 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.</li></ol>

Additional query words: kbVBp kbdsd kbDSupport kbVBp400bug kbVBp600fix kbControl

Keywords: kbbug kbfix KB149233

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.