Microsoft KB Archive/119905

From BetaArchive Wiki

PRB: Picture Property Not Displayed on THREED Button

Q119905



The information in this article applies to:


  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++, versions 1.0, 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:

    Q104642 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 query words: 1.00 1.50 2.00 2.50

Keywords : kb16bitonly kbprb
Issue type : kbprb
Technology : kbAudDeveloper kbMFC


Last Reviewed: May 8, 2001
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.