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

x
  • 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.
0
killaz4life
Asked:
killaz4life
  • 2
  • 2
1 Solution
 
mahesh1402Commented:
You may take help of following samples ...refer with src

http://www.functionx.com/visualc/applications/displaybitmap.htm
http://www.codeproject.com/useritems/BitmapDialog.asp

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

http://www.codeguru.com/cpp/g-m/bitmap/

-MAHESH
0
 
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!
0
 
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
0
 
mahesh1402Commented:
>> 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,      
                LR_LOADFROMFILE | LR_CREATEDIBSECTION);

      // 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
      DeleteDC(hCompatDC);

      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...

-MAHESH
0
 
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 ...!

http://www.codeguru.com/cpp/w-d/dislog/commondialogs/article.php/c11527__1/

Best Regards,
DeepuAbrahamK
0

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