如何使用Visual C ++ Express2010在GUI中加载位图 [英] how to load bitmap in GUI using visual c++ express2010
本文介绍了如何使用Visual C ++ Express2010在GUI中加载位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,是否可以在我使用Visual C ++ Express 2010中的创建"窗口创建的对话框(或GUI)中添加位图(图像).
实际上,我在资源中添加了位图文件(通过右键单击资源->添加->现有项-> .bmp文件),但它没有显示该位图文件的ID.我认为,如果我具有该ID,则可以将位图文件以编程方式加载到GUI中.
在此先感谢
Anil
hello,is it possible to add bitmap(image) in dialog box(or GUI) which i created using create window in visual c++ express 2010.if so can you tell,the steps to do.
Actually I added the bitmap file in the resources( By right clicking on resouces -> Add -> Existing Item -> .bmp file) but it doesn''t show me an ID for that bitmap file. I think, If I have that ID I can load the bitmap file into GUI programatically.
Thanks in advance
Anil
推荐答案
CBitmap bmpHello;
bmpHello.LoadBitmap( IDB_HELLO );
// Calculate bitmap size using a BITMAP structure.
BITMAP bm;
bmpHello.GetObject( sizeof(BITMAP), &bm );
// Create a memory DC, select the bitmap into the
// memory DC, and BitBlt it into the view.
CDC dcMem;
dcMem.CreateCompatibleDC( pDC );
CBitmap* pbmpOld = dcMem.SelectObject( &bmpHello );
pDC->BitBlt( 10,10, bm.bmWidth, bm.bmHeight,
&dcMem, 0,0, SRCCOPY );
// Reselect the original bitmap into the memory DC.
dcMem.SelectObject( pbmpOld );
我假设您正在谈论的是传统Windows程序Win32.
在对话框中,我只需要从工具箱中将图片控件添加到对话框中,然后填写图像即可.请看这里开始使用对话框:
Win32对话框
[^ ]
在正常的窗口中,您必须自己绘画.为此,您需要处理 WM_PAINT消息 [ ^ ],然后借助 GDI(图形设备界面) [
I assume you are talking about Win32, a traditional Windows program.
In a dialog I would simply add a picture control from the toolbox to the dialog and fill in the image. Look here to get a start with dialogs:
Win32 dialogs
[^]
In a normal Window you must do the painting yourself. For that you will need to process the WM_PAINT Message[^] and then load and paint your Image with help of the GDI (graphics device interface)[^]
您也可以从文件中加载图像:
You can load images from files too:
HBITMAP hbmp = (HBITMAP)LoadImage(0,__T("myimage.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
// use the bitmap handle and finally destroy it
if(hbmp) DeleteObject(hbmp);
祝你好运.
Good luck.
这篇关于如何使用Visual C ++ Express2010在GUI中加载位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文