|
You can use some software, like MSPaint, or the GIMP[^], to scale the images outside of the application. If you need to scale it internally, you can use GDI/GDI+ to draw the bitmap scaled directly into the appropriate area of the Imagelist control.
This is a bit tricky if you have a large number of images. Basically, you preallocate the space for the images in the Imagelist control using the ImageList_SetImageCount(...) macro, extract IMAGEINFO structures for each image "space" using the ImageList_GetImageInfo(...) macro, and then drawing the scaled-down image directly into the IMAGEINFO::hbmImage bitmap area.
Got all that? :P
Also, the "mask" is a color (or an area of the image) that is considered transparent when the image is drawn. In other words, the "mask" color (or area) is not drawn when the image is drawn onto the control.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks~
But I am confused that I don't know how to resize the bitmaps before insert them to imagelist,is there any fuctions to do this?
And I have refer to the example http://www.codeproject.com/listctrl/thumbnail.asp?df=100&forumid=1951&fr=51[^] in cp.I found it do nothing to resize the bitmaps,but they are automaticly showed in thumbnails.Why`
James R. Twine wrote: extract IMAGEINFO structures for each image "space" using the ImageList_GetImageInfo(...) macro, and then drawing the scaled-down image directly into the IMAGEINFO::hbmImage bitmap area.
What is the purpose of this?I can only get the information in imagelist through this.And if I change the IMAGEINFO what I get from it ,nothing changed.
|
|
|
|
|
You need to look at the code for that project before asking... That project uses GDI+ code to generate the thumbnails and then adds the thumbnails to the imagelist control used by the listview control.
Bitmap img( A2W(strPath) );
Bitmap* pThumbnail = static_cast<Bitmap*>(<code>img.GetThumbnailImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, NULL, NULL)</code>);
pThumbnail->GetHBITMAP(NULL, &hBmp);
pImage = new CBitmap();
pImage->Attach(hBmp);
m_ImageListThumb.Replace(i, pImage, NULL); The Bitmap::GetThumbnailImage(...) function scales the image for you returning a new one.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Oh~~~~~~~~~~~~I seldom do the GDI+ and I haven't use the "Bitmap" before.When I do this in my project:
HBITMAP hBitmap=LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
m_imagelist->Create(200,200,ILC_COLOR24|ILC_MASK,1,4);
Bitmap img(hBitmap);
Bitmap* pThumbnail = static_cast<Bitmap*>(img.GetThumbnailImage(200, 200, NULL, NULL));
pThumbnail->GetHBITMAP(NULL, &hBitmap);
CBitmap bitmap;
bitmap.Attach(hBitmap);
m_imagelist->SetImageCount(1);
m_imagelist->Replace(0,&bitmap,NULL);
m_listctrl.SetImageList(m_imagelist,LVSIL_NORMAL);
m_listctrl.InsertItem(0,"1",0);
There are errors:
D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(143) : error C2065: 'Bitmap' : undeclared identifier
D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(143) : error C2146: syntax error : missing ';' before identifier 'img'
D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(143) : error C2065: 'img' : undeclared identifier
D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(144) : error C2065: 'pThumbnail' : undeclared identifier
D:\Code\I Do\ListControl2\ListControl2Dlg.cpp(144) : error C2061: syntax error : identifier 'Bitmap'
pThumbnail->GetHBITMAP(NULL, &hBitmap);
|
|
|
|
|
Maybe I should include the head file gdiplus.h`
Do you have it?Please send to my email~
Thanks~
|
|
|
|
|
Mm..I have downloaded the gdiplus.h ~But many new errors occur~My god`
Basically the errors are about the file gdiplusinit.h~
For example:
c:\program files\microsoft visual studio\vc98\include\gdiplusinit.h(39) : error C2065: 'ULONG_PTR' : undeclared identifier
|
|
|
|
|
You need to download the entire platform SDK (which may now be called the Windows SDK?), and then install and configure it.
Then you should be able to use GDI+.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
I have installed it.And I find that GDI+ is a good thing.
Do you know how to use Bitmap( Class type, String resource )?
Because my bitmap is in the resource,but I don't know how to set the parameter "Class type"~
|
|
|
|
|
You can use the thumbnail project mentioned earlier for examples on how to use some parts of GDI+.
The GDI+ documentation is going to be where you need to go now for more details on how to use it.
Good luck!
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Thanks a lot for helping me so much~
|
|
|
|
|
James R. Twine wrote: Also note that since you specified ILC_COLOR24 when creating the Imagelist control, setting a Mask value in the call to Add(...) will have no effect - Masks only work on 8-bit (or lower) bitmaps.
It works fine on 24-bit bitmaps if you use the ILC_MASK flag...
m_imagelist->Create(200,200,ILC_COLOR24|ILC_MASK,1,4);
m_imagelist->Add(&bitmap,RGB(255,0,0));
Try it
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Actually, you need that parameter for masks to work correctly even in 8-bit images. For any images with a higher bit depth, I have had too much trouble trying to get mixed colors exactly right for that to work correctly for me. Couple that with art software that does dithering (with higher depth images) when not asked to and the problem gets real bad real quick.
Was easier to just build a mask bitmap and set it directly in the control.
Peace!
-=- James Please rate this message - let me know if I helped or not!<HR> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
James R. Twine wrote: I have had too much trouble trying to get mixed colors exactly right for that to work correctly for me. Couple that with art software that does dithering (with higher depth images) when not asked to and the problem gets real bad real quick.
That's when I'd hand the problem off to the art department (ie, my graphic-designer
girlfriend LOL).
There's 16777216 colors...how hard can it be to find ONE to use as a transparent color?
Cheers!
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hai,
Any one can Help me to provide the funtions for zooming in VC++?
I am using PRSDK (For canon Powershot A640 Camera).
Canon provide one sample. But in that sample they are provide only the
zooming option for CDSDK. which is not supported by Powershot A640.
So if any one have knowledge about this please help me.
If anyone have SDK which supports canon Powershot A640 Camera then i will
very thankfull for that.
Please replay to this mail
jonson.joseph@gmail.com.
Thanking you
Johnson
Johnson
|
|
|
|
|
Hi there,
I have a CEdit Control which I have put on a form at design-time. The CEdit control does not have any text initially. Now on run-time, I am inserting text to the CEdit control and I want the CEdit Control size to fit the text that I entered. It has to fit EXACTLY the text (resizing the CEdit to have a width which will just be enough to show the text). How do I do this dynamically?
Any help would be highly appreciated
Best Regards,
Soleil Couchant
|
|
|
|
|
As far as I know, you have to count the pixels used by your text through the font size, and then resize the CEdit text accordingly.
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
|
|
|
|
|
For sizing a control, see SetWindowPos() or MoveWindow() .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The focus of this article is italic fonts, but the author attempts to resize the controls to the text size so it may be up the same alley.
here[^]
|
|
|
|
|
Here's some code you can play with - it's the closest I could get on a single-line edit control.
Multiline edit controls may work better since they allow you to change the formatting rect.
Hopefully this will give you a general idea of a way to do it
CString str = _T("Test Text");
CFont *pFont = m_Edit1Edit.GetFont();
CWindowDC dc(this);
CFont *pOldFont = dc.SelectObject(pFont);
CSize TextSize = dc.GetTextExtent(str);
dc.SelectObject(pOldFont);
CRect WindowRect;
CRect ClientRect;
CRect FormatRect;
m_Edit1Edit.GetWindowRect(&WindowRect);
m_Edit1Edit.GetClientRect(&ClientRect);
m_Edit1Edit.GetRect(&FormatRect);
CSize BorderSize;
BorderSize.cx = WindowRect.Width() - FormatRect.Width();
BorderSize.cy = WindowRect.Height() - ClientRect.Height();
m_Edit1Edit.SetWindowPos(0, 0, 0, TextSize.cx + BorderSize.cx, TextSize.cy + BorderSize.cy, SWP_NOZORDER | SWP_NOMOVE);
m_Edit1Edit.SetWindowText(str);
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
I have created one static txt control and now I have to set text in multiple fonts in multiple lines
I am creating and setting fonts like that:
m_MyStaticText.Create("",WS_VISIBLE|BS_TEXT|WS_CHILD,CRect(0,0,520,58),this,IDC_STATICTEXT_PARTITION);
if (TRUE == m_font.CreatePointFont( 140, _T ("MS Sans Serif")))
{
m_MyStaticText.SetFont(&m_font);
}
m_MyStaticTextPartition.SetWindowText("\t\t\nPartition Selection");
but I have to set different font in different lines in this static text control.
So can any body tell me how it is possible.
thanks
bankey
|
|
|
|
|
Banks K wrote: how it is possible
I do not think it is. You will have to switch to a rich edit control for this, I think.
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
|
|
|
|
|
thanks for youe quick response.
can i set fonts for prticular line of text in rich edit text
if it is possible than please tell me...
thanks
bankey
|
|
|
|
|
Yes, you can set separate fonts for different parts of text in a RichEdit control. That can be different lines, different letters...
Answering the question of "how" is far too long to reasonably expect someone to type here for you. But a search on codeproject will help.
An article by Johan Rosengren I found very useful:
CRulerRichEditCtrl - a complete RTF mini-editor[^]
There are others in http://www.codeproject.com/richedit/[^] also.
Good luck,
Iain.
|
|
|
|
|
|
hi, anyone can help me figure out how to read data from a text file like this:
10980012907200228082002
and extract the data according to this kind of format:
Record type 1
TY-RECORD PIC (1).
ID-PARTICIPANT PIC (6).
DT-START PIC (8).
DT-END PIC (8).
i would want the program to extract the data and display them in a table, according to their fields:
TY-RECORD ID-PARTICIPANT DT-START DT-END
1 098001 29072002 28082002
and to save them in an excel format. I have plenty of record types (0 - 9) and need to display them in separate tables.
does anyone has a source code for this? or at least somebody pls guide me to figure out ways to create the program.
many thanks!
|
|
|
|