如何在GUI中加载位图(VS 2010) [英] how to load bitmap in GUI (VS 2010)
本文介绍了如何在GUI中加载位图(VS 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何正确加载位图?
这是我的按钮,我正在编辑控件中输入文件名,并读取它:
how to load bitmap correctly?
it''s my button, i''m typing file name in edit control, reading it:
case button:
{
buffer.resize(GetWindowTextLength(GetDlgItem(hWnd,text_edit))+1);
GetWindowText(GetDlgItem(hWnd,text_edit),&buffer[0],buffer.size()+1);
for(int i=0;i<buffer.size();i++)
img_name+=buffer[i];
WndProc(hWnd,WM_PAINT,NULL,NULL);
}
break;
然后尝试加载bmp文件(263 * 289)并绘制它,但是它不起作用
then trying to load bmp file(263*289) and draw it, but it doesn''t work
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
HDC tdc =CreateCompatibleDC(hdc);
HBITMAP bitmap=(HBITMAP)LoadImage(NULL,img_name,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
HBITMAP old = (HBITMAP) SelectObject(tdc,bitmap);
BitBlt(hdc,0,0,263,289,tdc,0,0,SRCCOPY);
SelectObject(tdc,old);
DeleteObject(bitmap);
DeleteDC(tdc);
EndPaint(hWnd, &ps);
}
break;
推荐答案
您没有解释您的问题,说没有".工作"并没有太大帮助.所以我在这里写的都是猜测.
我不确定以下几行应该做什么
You did not explain your problem, saying "it doesn''t work" is not much help. So anything I write here is guesswork.
I''m not sure what the following lines are supposed to do
for(int i=0;i<buffer.size();i++)>
img_name+=buffer[i];
您确定他们产生了预期的结果吗?
这是错误的:
are you sure they produced the desired result?
This is wrong:
WndProc(hWnd,WM_PAINT,NULL,NULL);
如果您希望表示对窗口内容的更新,则应致电
if you wish to signal an update to the window''s content you should call InvalidateRect
[^].
这篇关于如何在GUI中加载位图(VS 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文