Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a couple of applications where I use a bitmap as background on the main window. It gives the programs a nice and professional appearance. However, on the latest lap-tops, where the screen resolution have been increased, the main windows becomes enlargened but not the bitmaps. The bitmaps now only partially cover the main window, and the appearance is neither nice nor professional.

Is there a way to fix the size of a main window so that it keeps its proportions also when moving from one screen resolution to another?

I use Visual Studio C++ 6.0.

Thank you in advance!


maladuk
Posted
Updated 11-Dec-14 5:52am
v3

A workaround would be resizing/resampling the bitmap to fit on to the increased available space. With a good resampling function you may obtain a nice and professional look. See, for instance my article: "Plain C Resampling DLL"[^].
 
Share this answer
 
Comments
maladuk 14-Dec-14 10:24am    
Thank you for answering! Since I use MFC the code is a little different from the code in your test app. And I am too unfamiliar with windows programming to identify what must be changed. Below is the ::OnPaint function where my BitMap is loaded, and my attempt to use your Resample-function. It compiles, but no resampled bitmap is loaded onto the canvas. If you have some suggestions I will be very grateful.

maladuk

void CSaulandDlg::OnPaint()
{
if (IsIconic())
{
....
}
else
{
CPaintDC dc( this ); // Device context for painting
CBitmap bmpBackground, *poldbmp;
/*new*/ CBitmap bmpResampled;
CDC memdc;


// Load the bitmap resource
bmpBackground.LoadBitmap( IDB_BACKGROUND );


// Create a compatible memory DC
memdc.CreateCompatibleDC( &dc );

/*new*/ //Create resampled bitmap
/*new*/ bmpResampled.FromHandle(CreateResampledBitmap(dc, (HBITMAP) bmpBackground.m_hObject, 1024, 768, STOCK_FILTER_BOX));

// Select the bitmap into the DC
//poldbmp = memdc.SelectObject( &bmpBackground );
/*new*/ poldbmp = memdc.SelectObject( &bmpResampled );

// Copy (BitBlt) bitmap from memory DC to screen DC
dc.BitBlt( 0, 0, 4700, 4700, &memdc, 0, 0, SRCCOPY );

memdc.SelectObject( poldbmp );
CDialog::OnPaint();
}
}
CPallini 14-Dec-14 10:39am    
You passed to CreateResampledBitmap 1024x768 as resampling size, why then you called BitBlt passing 4700x4700 ?
BTW, the library is not able to handle such a huge (4700x4700) image.
maladuk 14-Dec-14 10:55am    
OK... I have reused some code that I found elsewhere. I guess it is set that big to simply ensure there is enough memory allocated. But changing it to 1024x768 does not make any difference. The Bitmap still does not show.

m
Yes you can. You must fetch and store the display resolution with SystemParametersInfo and when it changes you get the message WM_SETTINGCHANGE and then you can call your own resizing code. You must register for that msg and write a msg handler.
 
Share this answer
 
Comments
maladuk 14-Dec-14 10:30am    
Thank you for answering! I like this solution since it seems that it makes it possible to keep the original width x height on the main window when moving on to new screen resolutions. However, since I am rather unfamiliar with windows programming I would need some axample code to look at. So, if you have an example code as well, I would surely appreciate it.

maladuk
First, consider upgrading from VC6 to a current community edition of the VS tools.

Second, try this ...

http://msdn.microsoft.com/en-us/library/windows/desktop/dd145121%28v=vs.85%29.aspx[^]

... to stretch the pixels onto canvas area.
 
Share this answer
 
Comments
maladuk 14-Dec-14 10:37am    
Thank you for answering. Yes, I should have upgraded to newer VS-tools long time ago, but as a project worker there is never enough time for it. And since the programs involved are made up of several thousands lines of code this will not be an option this time. Thank you anyway!

maladuk

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900