请各位大虾帮帮忙
9 个解决方案
#1
myPic.SetBitmap( HBITMAP hBitmap );
hBitmap可用loadBitmap(...)获得。
#2
Delphi中有现成的组件!
#3
Delphi中有现成的组件!
#4
关于图形操作,建议下载www.codeproject.com 上面的cximage库,它操作非常简单,支持多种常用图形格式,处理楼主的这种问题的做法就是:
使用建立一个CXIMAGE对象image,然后调用对象的加载图片功能loadimagefromfile,然后获得Picture的dc,调用CXIMAGE的绘制函数,把DC传递给它就可以了。
使用建立一个CXIMAGE对象image,然后调用对象的加载图片功能loadimagefromfile,然后获得Picture的dc,调用CXIMAGE的绘制函数,把DC传递给它就可以了。
#5
再提供一种方法
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);//IDC_STATIC1是你picture控件ID
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),"你的位图文件",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,290,290,&MemDC,0,0,200,200,SRCCOPY);
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);//IDC_STATIC1是你picture控件ID
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),"你的位图文件",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,290,290,&MemDC,0,0,200,200,SRCCOPY);
#6
fxniao:
Thank you very much for your help ! But something wrong has happened unavoidably! MSDN tells me that "Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."and then the second method you told me can not work.
As for your first method , MSDN says that "CStatic::SetBitmap() does not display the bitmap correctly on a picture control in Windows NT 3.51 if the picture control is subclassed. "
How can I do?
Thank you very much for your help ! But something wrong has happened unavoidably! MSDN tells me that "Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."and then the second method you told me can not work.
As for your first method , MSDN says that "CStatic::SetBitmap() does not display the bitmap correctly on a picture control in Windows NT 3.51 if the picture control is subclassed. "
How can I do?
#7
第一种方法不对,loadbitmap只能装载资源里面的位图。
下面将第二种方法
给你说详细点吧。我已经做过了,没问题。如果还不行我可以发整个源码给你。
在对话框里面加入cpicture控件,Type为Frame。标识为IDC_STATIC1
//此按钮消息响应函数,打开一个文件对话框,选择bmp文件
void CSDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp||";
CFileDialog fOpenDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter );
int nRet = -1;
nRet = fOpenDlg.DoModal();
if(nRet==IDCANCEL) return;
filename=fOpenDlg.GetPathName( );
if (filename.IsEmpty()) return;
filename.Replace("\\","\\\\");//单斜杠转换为双斜杠
Invalidate();
}
//重写OnPaint()
void CSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
if (filename.IsEmpty()) return;
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,cr.Width(),cr.Height(),&MemDC,0,0,BM.bmWidth,BM.bmHeight,SRCCOPY);
}
}
--------------------
下面将第二种方法
给你说详细点吧。我已经做过了,没问题。如果还不行我可以发整个源码给你。
在对话框里面加入cpicture控件,Type为Frame。标识为IDC_STATIC1
//此按钮消息响应函数,打开一个文件对话框,选择bmp文件
void CSDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp||";
CFileDialog fOpenDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter );
int nRet = -1;
nRet = fOpenDlg.DoModal();
if(nRet==IDCANCEL) return;
filename=fOpenDlg.GetPathName( );
if (filename.IsEmpty()) return;
filename.Replace("\\","\\\\");//单斜杠转换为双斜杠
Invalidate();
}
//重写OnPaint()
void CSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
if (filename.IsEmpty()) return;
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,cr.Width(),cr.Height(),&MemDC,0,0,BM.bmWidth,BM.bmHeight,SRCCOPY);
}
}
--------------------
#8
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
在OnPaint函数中无法调用到onbutton1函数中的打开文件对话框所获得的文件名
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
而且如我前面所说,"Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."
我使用的是Win32 platform,所以GetDlgItem() 函数不起作用啊
我都快急死了!!!
在OnPaint函数中无法调用到onbutton1函数中的打开文件对话框所获得的文件名
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
而且如我前面所说,"Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."
我使用的是Win32 platform,所以GetDlgItem() 函数不起作用啊
我都快急死了!!!
#9
我使用的是Win32 platform,所以GetDlgItem() 函数不起作用啊
谁说不起作用,见下面该函数API用法:
HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Parameters
hDlg
[in] Handle to the dialog box that contains the control.
nIDDlgItem
[in] Specifies the identifier of the control to be retrieved.
这样吧,告诉我你的邮箱。发份源码给你!
谁说不起作用,见下面该函数API用法:
HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Parameters
hDlg
[in] Handle to the dialog box that contains the control.
nIDDlgItem
[in] Specifies the identifier of the control to be retrieved.
这样吧,告诉我你的邮箱。发份源码给你!
#1
myPic.SetBitmap( HBITMAP hBitmap );
hBitmap可用loadBitmap(...)获得。
#2
Delphi中有现成的组件!
#3
Delphi中有现成的组件!
#4
关于图形操作,建议下载www.codeproject.com 上面的cximage库,它操作非常简单,支持多种常用图形格式,处理楼主的这种问题的做法就是:
使用建立一个CXIMAGE对象image,然后调用对象的加载图片功能loadimagefromfile,然后获得Picture的dc,调用CXIMAGE的绘制函数,把DC传递给它就可以了。
使用建立一个CXIMAGE对象image,然后调用对象的加载图片功能loadimagefromfile,然后获得Picture的dc,调用CXIMAGE的绘制函数,把DC传递给它就可以了。
#5
再提供一种方法
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);//IDC_STATIC1是你picture控件ID
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),"你的位图文件",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,290,290,&MemDC,0,0,200,200,SRCCOPY);
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);//IDC_STATIC1是你picture控件ID
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),"你的位图文件",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,290,290,&MemDC,0,0,200,200,SRCCOPY);
#6
fxniao:
Thank you very much for your help ! But something wrong has happened unavoidably! MSDN tells me that "Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."and then the second method you told me can not work.
As for your first method , MSDN says that "CStatic::SetBitmap() does not display the bitmap correctly on a picture control in Windows NT 3.51 if the picture control is subclassed. "
How can I do?
Thank you very much for your help ! But something wrong has happened unavoidably! MSDN tells me that "Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."and then the second method you told me can not work.
As for your first method , MSDN says that "CStatic::SetBitmap() does not display the bitmap correctly on a picture control in Windows NT 3.51 if the picture control is subclassed. "
How can I do?
#7
第一种方法不对,loadbitmap只能装载资源里面的位图。
下面将第二种方法
给你说详细点吧。我已经做过了,没问题。如果还不行我可以发整个源码给你。
在对话框里面加入cpicture控件,Type为Frame。标识为IDC_STATIC1
//此按钮消息响应函数,打开一个文件对话框,选择bmp文件
void CSDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp||";
CFileDialog fOpenDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter );
int nRet = -1;
nRet = fOpenDlg.DoModal();
if(nRet==IDCANCEL) return;
filename=fOpenDlg.GetPathName( );
if (filename.IsEmpty()) return;
filename.Replace("\\","\\\\");//单斜杠转换为双斜杠
Invalidate();
}
//重写OnPaint()
void CSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
if (filename.IsEmpty()) return;
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,cr.Width(),cr.Height(),&MemDC,0,0,BM.bmWidth,BM.bmHeight,SRCCOPY);
}
}
--------------------
下面将第二种方法
给你说详细点吧。我已经做过了,没问题。如果还不行我可以发整个源码给你。
在对话框里面加入cpicture控件,Type为Frame。标识为IDC_STATIC1
//此按钮消息响应函数,打开一个文件对话框,选择bmp文件
void CSDlg::OnButton1()
{
// TODO: Add your control notification handler code here
char BASED_CODE szFilter[] = "BMP Files (*.bmp)|*.bmp||";
CFileDialog fOpenDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter );
int nRet = -1;
nRet = fOpenDlg.DoModal();
if(nRet==IDCANCEL) return;
filename=fOpenDlg.GetPathName( );
if (filename.IsEmpty()) return;
filename.Replace("\\","\\\\");//单斜杠转换为双斜杠
Invalidate();
}
//重写OnPaint()
void CSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
if (filename.IsEmpty()) return;
BITMAP BM;
HBITMAP *hBitmap; //定义位图对象句柄
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
CClientDC ClientDC(pWnd);
CRect cr;
pWnd->GetClientRect(&cr);
CDC MemDC;
MemDC.CreateCompatibleDC(&ClientDC);
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
MemDC.SelectObject(hBitmap);
:: GetObject(hBitmap,sizeof(BM),&BM);
ClientDC.StretchBlt(0,0,cr.Width(),cr.Height(),&MemDC,0,0,BM.bmWidth,BM.bmHeight,SRCCOPY);
}
}
--------------------
#8
hBitmap=(HBITMAP*)::LoadImage(AfxGetInstanceHandle(),filename,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
在OnPaint函数中无法调用到onbutton1函数中的打开文件对话框所获得的文件名
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
而且如我前面所说,"Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."
我使用的是Win32 platform,所以GetDlgItem() 函数不起作用啊
我都快急死了!!!
在OnPaint函数中无法调用到onbutton1函数中的打开文件对话框所获得的文件名
CWnd *pWnd=GetDlgItem( IDC_STATIC1);
而且如我前面所说,"Calling GetDlgItem() to get the CWnd pointer of a control in a dialog can fail and return NULL under Win32s."
我使用的是Win32 platform,所以GetDlgItem() 函数不起作用啊
我都快急死了!!!
#9
我使用的是Win32 platform,所以GetDlgItem() 函数不起作用啊
谁说不起作用,见下面该函数API用法:
HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Parameters
hDlg
[in] Handle to the dialog box that contains the control.
nIDDlgItem
[in] Specifies the identifier of the control to be retrieved.
这样吧,告诉我你的邮箱。发份源码给你!
谁说不起作用,见下面该函数API用法:
HWND GetDlgItem(
HWND hDlg, // handle to dialog box
int nIDDlgItem // control identifier
);
Parameters
hDlg
[in] Handle to the dialog box that contains the control.
nIDDlgItem
[in] Specifies the identifier of the control to be retrieved.
这样吧,告诉我你的邮箱。发份源码给你!