Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Knowledge Base > Code Library > C++ LoadBitmap

Thread Tools Display Modes
Old 11-21-2002, 10:47 PM
usetheforce2's Avatar
usetheforce2 usetheforce2 is offline
Senior Contributor

Retired Moderator
* Expert *
Join Date: Jul 2000
Location: Toronto, Ontario, Canada
Posts: 1,410
Default C++ LoadBitmap


this code could be easially tailored to work with other common controls. But for this example i'm use the CStatic (for you vbr's "Label") control to display the image.

// programmer:  usetheforce2
// date:    november, 2002
// purpose:    load image into a static control
// Important:  If you copy paste this code make sure:
//        1. its a Win32 application type
//        2. press alt-f7 (project->settings) and choose the
//           "Use MFC in a shared DLL" from the MFC drop down

#include<afxwin.h>            // has all the code to do the dirty work 

class bmpApp : public CWinApp
  virtual BOOL InitInstance();    // used to initialize the app (and main window)
bmpApp mainBmp;              // declare main app object

class bmpWindow : public CFrameWnd
  CStatic* m_sBmpImage;        // private member static control
BOOL bmpApp::InitInstance()
  m_pMainWnd = new bmpWindow();    // assign our class window to the app main window
  m_pMainWnd->ShowWindow(m_nCmdShow); // load window
  m_pMainWnd->UpdateWindow();      // refresh window to ensure control are drawn properly
  return TRUE;            // return true to signify that the initiate completed properly
  // Create main window
  Create(NULL,"Load Bitmap image!",WS_OVERLAPPEDWINDOW,CRect(200,200,545,300),this);

  // Create static control
  m_sBmpImage = new CStatic;
  m_sBmpImage->Create("MAP:",WS_VISIBLE|WS_CHILD|SS_BITMAP, CRect(10,6,0,0),this);

  // load bitmap into static control
  // HBITMAP: accepts a handle to a bitmap created by the afxwin (loadimage()) function
  // which returns a bitmap handle. the load image function has to be typecasted to return 
  // the HBITMAP handle type.

  HBITMAP hnd;
  if(hnd == 0) // error trap
    AfxMessageBox("Unable to create bitmap handle!");
    m_sBmpImage->SetBitmap(hnd);  // once a handle is obtained to a bitmap object
                    // we can use the SetBitmap() method 
attached is the image used in the demo...
Attached Images
File Type: bmp logo.bmp (21.6 KB, 57 views)
winsock siteHERE||EliteVBHERE||C++ & VB Markup UtilityHERE
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..