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.
killaz4lifeAsked:
Who is Participating?
 
mahesh1402Connect With a Mentor Commented:
>> 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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.