[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

MFC program, load and display image

My orignial program went through some conflict so I need one part of it.
I need a code for a MFC program that has two windows.

The main window has a button that loads a bitmap file and has an edit box to display where the file has been loaded, and the other window has nothing except for displaying the bitmap image.
  • 2
  • 2
1 Solution
You may take help of following samples ...refer with src


Also have a look at various examples at codeguru bitmap section :


killaz4lifeAuthor Commented:
Mahest I think you remember my other question about converting a raw image to bmp. This apparently became my problem since its not working. The 1st website, i already know, 2nd website, is very hard to follow understand the 3rd website is irrelevant to my question. ALL i mainly need is a function that displays the image on the 2nd window and if any other function has any relationship what other code should i add!
killaz4lifeAuthor Commented:
Sorry there is a line missing, My problem was that i cannot convert an image since i cannot display an image to begin with! Thats why i need the code for displaying an image
>> i mainly need is a function that displays the image on the 2nd window

Simple function to display BITMAP will be something like this :

pass hDC of your window, bitmap file path strBitmap, position X,Y

BOOL DisplayBitmap(HDC hDC, CString strBitmap,int X, int Y)
 * Steps to displaying a bitmap:
 * 1. Create a compatible display context.
 * 2. Select bitmap into compatible display context.
 * 3. Do a bit-block-transfer (BitBlt) command.
 * 4. Clean-up afterwards.
      HDC     hCompatDC;
      HBITMAP hOldBitmap;
      BITMAP  BM;
      BOOL    result;

                HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), strBitmap, IMAGE_BITMAP, 0, 0,      

      // Create compatible display context
      hCompatDC = CreateCompatibleDC(hDC);

      // Select bitmap into compatible display context
      hOldBitmap = SelectBitmap(hCompatDC, hBitmap);

      // Get dimensions of bitmap
      GetObject(hBitmap, sizeof(BM), &BM);

      // Blast those bits to the screen
      result = BitBlt(hDC, X, Y, BM.bmWidth, BM.bmHeight, hCompatDC, 0, 0, SRCCOPY);

      // De-select the bitmap
      SelectBitmap(hCompatDC, hOldBitmap);

      // Clean up after we are done

      return result;

>>My problem was that i cannot convert an image since i cannot display an image to begin with !

For conversion purpose you do not need to display image all you need is bitmap data buffer (DIB) to process on...

Deepu AbrahamR & D Engineering ManagerCommented:
Seems like you need an MDI application, Or SDI with a splitter window and you can use GDI+ too. That looks cool on your application.

Please follow this link you might get what you want ...!


Best Regards,

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now