Click here to Skip to main content
14,391,319 members

C / C++ / MFC

 
AnswerRe: How read XLSX file without office automation? Pin
leon de boer19-Nov-19 3:43
Memberleon de boer19-Nov-19 3:43 
GeneralRe: How read XLSX file without office automation? Pin
Le@rner20-Nov-19 23:29
MemberLe@rner20-Nov-19 23:29 
QuestionRe: How read XLSX file without office automation? Pin
David Crow19-Nov-19 3:52
MemberDavid Crow19-Nov-19 3:52 
AnswerRe: How read XLSX file without office automation? Pin
leon de boer19-Nov-19 20:23
Memberleon de boer19-Nov-19 20:23 
QuestionHelp with Resizing Bitmap loaded with LoadImage() and Attach to CImagelist object Pin
EternalWyrm18-Nov-19 14:02
MemberEternalWyrm18-Nov-19 14:02 
AnswerRe: Help with Resizing Bitmap loaded with LoadImage() and Attach to CImagelist object Pin
Victor Nijegorodov18-Nov-19 21:59
MemberVictor Nijegorodov18-Nov-19 21:59 
AnswerRe: Help with Resizing Bitmap loaded with LoadImage() and Attach to CImagelist object Pin
Richard MacCutchan18-Nov-19 22:26
mveRichard MacCutchan18-Nov-19 22:26 
AnswerRe: Help with Resizing Bitmap loaded with LoadImage() and Attach to CImagelist object Pin
leon de boer19-Nov-19 0:14
Memberleon de boer19-Nov-19 0:14 
At no point at you actually selecting the bitmap onto the DC, or bitblt or anything that would actually move the bitmap onto the DC

This is usual code for doing it
/*---------------------------------------------------------------------------
  This will create and Memory Device context and copy the bitmap given onto
  that memory context. Fail will return NULL as a memory context. 
  Caller takes responsibility for disposal of the device context.
  --------------------------------------------------------------------------*/
HDC BitmapToMemDc (HBITMAP hBmp)
{
   HDC hMemDC = 0;     // Preset memory context fail
   if (hBmp != 0)      // Check bitmap handle valid
   {
      hMemDC = CreateCompatibleDC(NULL);   // Create memory context
      if (hMemDC)                          // Check memory context success
      {
         SelectObject(hMemDC, hBmp);	   // Select the bitmap to the context	
      }
   }
   return hMemDC; // Return the memory context
}

For a bitmap file you have it right LoadImage and then use the above
/*---------------------------------------------------------------------------
  This will create and Memory Device context of the the bitmap filename given
  Caller must take responsibility for disposal of the device context.
  --------------------------------------------------------------------------*/
HDC MemDCFromBMPFile(char* Filename)
{
   HDC MemDC = 0;                               // Preset return value to fail
   HBITMAP bmp = LoadBitmapFromFile(Filename);	// Load the bitmap
   if (bmp != 0)                                // Load bitmap was successful
   {
      MemDC = BitmapToMemDc(bmp);		// Create a memory context of a valid bitmap  
      DeleteObject(bmp);                        // Release the bitmap no longer needed (image on memDC)
   }		
   return MemDC;   // Return result
}

For completeness GIF, JPG's etc are a little more tricky you need to use Ipic
Ipic will also load bmp and png and you can rescale any file with the Ipic->Render line and it isn't to bad
It's resize is much better than stretchblt Smile | :)
#include "olectl.h"   // OLE is used for JPG image loading

/*---------------------------------------------------------------------------
  Creates a Memory Device context of the the JPEG/GIF filename given.
  Due to the way OLE works filename must be fully qualified (ie c:\folder\a.jpg)
  You can not assume the loading directory is the current directory.
  Caller must take responsibility for disposal of the device context.
  --------------------------------------------------------------------------*/
HDC MemDCFromJPG_GIF_File(char* filename)
{
	const int HIMETRIC_PER_INCH = 2540;
	WCHAR OlePathName[512];
	SIZE sizeInHiMetric;
	IPicture* Ipic = NULL;

	HDC MemDC = 0;     // Preset return value to fail
	MultiByteToWideChar(CP_ACP, 0, filename,
		(int)strlen(filename) + 1, &OlePathName[0], 512);	// Convert console ansi filename to unicode
	HRESULT hr = OleLoadPicturePath(OlePathName, NULL, 0, 0,
		IID_IPicture, (LPVOID*)&Ipic);		   // Load the picture
	if ((hr == S_OK) & (Ipic != 0))    // Picture loaded okay						
	{
		int Wth, Ht;
		HDC Dc = GetDC(NULL);	// Get screen DC
		int nPixelsPerInchX = GetDeviceCaps(Dc, LOGPIXELSX);  // Screen X pixels per inch 
		int nPixelsPerInchY = GetDeviceCaps(Dc, LOGPIXELSY); // Screen Y pixels per inch
		ReleaseDC(NULL, Dc);	// Release screen DC
		Ipic->get_Width(&sizeInHiMetric.cx);	// Get picture witdh in HiMetric
		Ipic->get_Height(&sizeInHiMetric.cy);	// Get picture height in HiMetric
		Wth = (nPixelsPerInchX * sizeInHiMetric.cx +
			HIMETRIC_PER_INCH / 2) / HIMETRIC_PER_INCH;	// Calculate picture width in pixels
		Ht = (nPixelsPerInchY * sizeInHiMetric.cy +
			HIMETRIC_PER_INCH / 2) / HIMETRIC_PER_INCH;	// Calculate picture height in pixels
		MemDC = CreateCompatibleDC(0);		// Create a memory device context
		if (MemDC)
		{
			BITMAPINFO	bi = { 0 };
			DWORD* pBits = 0;
			bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);	// Set Structure Size
			bi.bmiHeader.biBitCount = 32;	// 32 Bit
			bi.bmiHeader.biWidth = Wth;  	// Image Width
			bi.bmiHeader.biHeight = Ht;		// Image Height
			bi.bmiHeader.biCompression = BI_RGB; // RGB Encoding
			bi.bmiHeader.biPlanes = 1;  	// 1 Bitplane
			HBITMAP bmp = CreateDIBSection(MemDC, &bi, DIB_RGB_COLORS,
				(void**)&pBits, 0, 0);		// Create a DIB section
			if (bmp)
			{
				SelectObject(MemDC, bmp); // Select the bitmap to the memory context															
				Ipic->Render(MemDC, 0, 0, Wth, Ht, 0,
					sizeInHiMetric.cy, sizeInHiMetric.cx,
					-sizeInHiMetric.cy, NULL);	// Render the image to the DC
				DeleteObject(bmp);	  // Delete the bitmap we are done with it
			}
		}
		Ipic->Release();      // Finished with IPic
	}
	return MemDC;  // Return the memory context
}

In vino veritas


modified 19-Nov-19 5:23am.

QuestionRe: Help with Resizing Bitmap loaded with LoadImage() and Attach to CImagelist object Pin
EternalWyrm20-Nov-19 7:58
MemberEternalWyrm20-Nov-19 7:58 
AnswerRe: Help with Resizing Bitmap loaded with LoadImage() and Attach to CImagelist object Pin
leon de boer8-Dec-19 14:24
Memberleon de boer8-Dec-19 14:24 
QuestionVS2008 Map files, this can't be this hard! Pin
charlieg18-Nov-19 13:48
Membercharlieg18-Nov-19 13:48 
AnswerRe: VS2008 Map files, this can't be this hard! Pin
Randor 24-Nov-19 17:04
professional Randor 24-Nov-19 17:04 
GeneralRe: VS2008 Map files, this can't be this hard! Pin
charlieg25-Nov-19 6:45
Membercharlieg25-Nov-19 6:45 
GeneralRe: VS2008 Map files, this can't be this hard! Pin
Randor 25-Nov-19 8:08
professional Randor 25-Nov-19 8:08 
Questionc++ string_view Pin
T Bones Jones14-Nov-19 12:38
MemberT Bones Jones14-Nov-19 12:38 
AnswerRe: c++ string_view Pin
Graham Breach14-Nov-19 13:10
MemberGraham Breach14-Nov-19 13:10 
GeneralRe: c++ string_view Pin
T Bones Jones15-Nov-19 4:44
MemberT Bones Jones15-Nov-19 4:44 
QuestionPROGRAMMER'S MOM- Needs your help =) Pin
Member 1465597214-Nov-19 8:57
MemberMember 1465597214-Nov-19 8:57 
AnswerRe: PROGRAMMER'S MOM- Needs your help =) Pin
OriginalGriff14-Nov-19 8:59
mveOriginalGriff14-Nov-19 8:59 
Questionpassword in star form Pin
Member 1461560312-Nov-19 0:34
MemberMember 1461560312-Nov-19 0:34 
AnswerRe: password in star form Pin
CPallini12-Nov-19 1:33
mveCPallini12-Nov-19 1:33 
SuggestionRe: password in star form Pin
David Crow12-Nov-19 6:48
MemberDavid Crow12-Nov-19 6:48 
AnswerRe: password in star form Pin
Stefan_Lang12-Nov-19 22:07
MemberStefan_Lang12-Nov-19 22:07 
QuestionHow to make the heap address(by new) have the same every time the program runs? Pin
Member 1308136910-Nov-19 16:36
MemberMember 1308136910-Nov-19 16:36 
AnswerRe: How to make the heap address(by new) have the same every time the program runs? Pin
k505410-Nov-19 17:19
Memberk505410-Nov-19 17:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.