FIX: Palette Does Not Change with Picture on MDI Child
ID: Q149233
|
The information in this article applies to:
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 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.
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.
MORE INFORMATIONSteps to Reproduce
- Start Visual Basic 4.0. Form1 is created by default.
- Add an MDI form by selecting MDI Form from the Insert menu.
- Change the MDIChild property for Form1 to True.
- Add a single Image control to Form1.
- Change the Picture property of the image control to point to a 256-color
bitmap.
- 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
- 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.
Additional query words:
kbVBp kbdsd kbDSupport kbVBp400bug kbVBp600fix kbControl
Keywords : kbGrpVB
Version :
Platform : NT WINDOWS
Issue type : kbbug
|