PRB: Picture Property Not Displayed on THREED Button

Last reviewed: July 22, 1997
Article ID: Q119905
1.00 1.50 WINDOWS kbprg kbprb

The information in this article applies to:

   The Microsoft Foundation Classes (MFC) included with:
    - Microsoft Visual C++ for Windows, version 1.0 and 1.5

SYMPTOMS

When the function CVBControl::Create() is used to create a Visual Basic custom control (VBX) and a AfxSetPict() is used to set the picture property (as described in MFC Tech Note #27), the picture is not displayed.

CAUSE

There are two primary causes for this problem:

  • The picture property is not set properly. Corrections to MFC Tech Note #27 can be found in the following article:

    ARTICLE-ID: Q104642

       TITLE     : DOCERR: How to Manage VBX Picture Properties with MFC 2.0
    
    
  • The BS_OWNERDRAW style was not used. This problem is discussed in this article.

RESOLUTION

Although the control will work properly, you must specify the BS_OWNERDRAW style for your picture to be displayed. For example, the standard styles that would be passed as the dwStyle parameter when calling CVBControl::Create() to create a button are as follows:

  • WS_VISIBLE
  • WS_CHILD
  • WS_TABSTOP
  • BS_OWNERDRAW

MORE INFORMATION

The sample code below shows how you can create a THREED SSCommand button with a displayed picture property.

NOTE: This problem does not occur when the control is created by the dialog manager (that is, using App Studio to place the control on a dialog-box template). The reason for this is that the BS_OWNERDRAW style is included as one of the default initialization parameters in the model style that is included in the DLGINIT resource in the .RC file.

Sample Code

/* Compile options needed: Default AppWizard options
*/

   BOOL CAboutDlg::OnInitDialog()
   {
       CDialog::OnInitDialog();

       CVBControl *pControl = new CVBControl();
       pControl->Create( "THREED.VBX; SSCommand; Command3D1",
           WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_OWNERDRAW,
           CRect(10,10,50,50),this,IDC_COMMAND3D1,NULL,TRUE);

       HPIC hPic;
       HBITMAP hBmp = LoadBitmap(AfxGetInstanceHandle(),
           MAKEINTRESOURCE(IDB_BITMAP1));
       PIC picture;
       picture.picData.bmp.hbitmap = hBmp;
       picture.picType = PICTYPE_BITMAP;

       hPic = AfxSetPict( NULL, &picture );
       pControl->SetPictureProperty( "picture", hPic );

       return TRUE;
   }


Additional reference words: 1.00 1.50 2.00 2.50
KBCategory: kbprg kbprb
KBSubcategory: MfcVBX
Keywords : kb16bitonly
Technology : kbMfc


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: July 22, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.