📄 recordnew.cpp
字号:
LPVOID lpBuf = ::GlobalLock( hMem );
file.ReadHuge( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高
CSize sz( nWidth, nHeight );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
long x, y, cx, cy;
//自动适应窗口
double fRatePic, fRateWnd;
fRatePic = (double)sz.cx / (double)sz.cy;
fRateWnd = (double)rect.Width() / (double)rect.Height();
if (fRatePic > fRateWnd)
{
cx = rect.Width();
cy = (long)(rect.Width() / fRatePic);
}
else
{
cx = (long)(rect.Height() * fRatePic);
cy = rect.Height();
}
if (cx == rect.Width())
{
x = 0;
y = rect.Height() / 2 - cy / 2;
}
if (cy == rect.Height())
{
x = rect.Width() / 2 - cx / 2;
y = 0;
}
pPicture->Render(pDC->m_hDC, x, y, cx, cy, 0, nHeight, nWidth, -nHeight, &rect);
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem
}
}
/*void CRecordNew::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();
}
}*/
void CRecordNew::OnNewpicture2button()
{
// TODO: Add your control notification handler code here
// InsertPhoto();
// if (m_Picture.Load(m_strPhotoPath))//载入图片路径,在picturebox中显示图片
// m_Picture.Draw();
CFile file;
CString FilePathName;
CFileException e;
HRESULT hr;
//获得picture控件的大小
CWnd *pWnd=GetDlgItem(IDC_PICTURE2);
CDC *pDC=pWnd->GetDC();
CRect rect;
pWnd->GetClientRect(&rect);
//填充背景
HBRUSH brush = (HBRUSH)::GetStockObject(GRAY_BRUSH);
::FillRect(pDC->m_hDC,rect,brush);
CFileDialog dlg(TRUE,NULL,NULL,0,"BMP Files (*.bmp)|*.bmp|jpg Files (*.jpg)|*.jpg||",this);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
if(dlg.DoModal()==IDOK)
{
FilePathName=dlg.GetPathName();
m_strPhotoPath2=FilePathName;
file.Open(FilePathName, CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容
//获得picture大小
DWORD dwSize = file.GetLength();
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
LPVOID lpBuf = ::GlobalLock( hMem );
file.ReadHuge( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高
CSize sz( nWidth, nHeight );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
long x, y, cx, cy;
//自动适应窗口
double fRatePic, fRateWnd;
fRatePic = (double)sz.cx / (double)sz.cy;
fRateWnd = (double)rect.Width() / (double)rect.Height();
if (fRatePic > fRateWnd)
{
cx = rect.Width();
cy = (long)(rect.Width() / fRatePic);
}
else
{
cx = (long)(rect.Height() * fRatePic);
cy = rect.Height();
}
if (cx == rect.Width())
{
x = 0;
y = rect.Height() / 2 - cy / 2;
}
if (cy == rect.Height())
{
x = rect.Width() / 2 - cx / 2;
y = 0;
}
pPicture->Render(pDC->m_hDC, x, y, cx, cy, 0, nHeight, nWidth, -nHeight, &rect);
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem
}
}
void CRecordNew::OnNewpicture3button()
{
// TODO: Add your control notification handler code here
// InsertPhoto();
// if (m_Picture.Load(m_strPhotoPath))//载入图片路径,在picturebox中显示图片
// m_Picture.Draw();
CFile file;
CString FilePathName;
CFileException e;
HRESULT hr;
//获得picture控件的大小
CWnd *pWnd=GetDlgItem(IDC_PICTURE3);
CDC *pDC=pWnd->GetDC();
CRect rect;
pWnd->GetClientRect(&rect);
//填充背景
HBRUSH brush = (HBRUSH)::GetStockObject(GRAY_BRUSH);
::FillRect(pDC->m_hDC,rect,brush);
CFileDialog dlg(TRUE,NULL,NULL,0,"BMP Files (*.bmp)|*.bmp|jpg Files (*.jpg)|*.jpg||",this);///TRUE为OPEN对话框,FALSE为SAVE AS对话框
if(dlg.DoModal()==IDOK)
{
FilePathName=dlg.GetPathName();
m_strPhotoPath3=FilePathName;
file.Open(FilePathName, CFile::modeRead | CFile::shareDenyNone ); // 读入文件内容
//获得picture大小
DWORD dwSize = file.GetLength();
HGLOBAL hMem = ::GlobalAlloc( GMEM_MOVEABLE, dwSize );
LPVOID lpBuf = ::GlobalLock( hMem );
file.ReadHuge( lpBuf, dwSize );
file.Close();
::GlobalUnlock( hMem );
// 由 HGLOBAL 得到 IStream,参数 TRUE 表示释放 IStream 的同时,释放内存
hr = ::CreateStreamOnHGlobal( hMem, TRUE, &pStream );
hr = ::OleLoadPicture( pStream, dwSize, TRUE, IID_IPicture, ( LPVOID * )&pPicture );
long nWidth,nHeight; // 宽高,MM_HIMETRIC 模式,单位是0.01毫米
pPicture->get_Width( &nWidth ); // 宽
pPicture->get_Height( &nHeight ); // 高
CSize sz( nWidth, nHeight );
pDC->HIMETRICtoDP( &sz ); // 转换 MM_HIMETRIC 模式单位为 MM_TEXT 像素单位
long x, y, cx, cy;
//自动适应窗口
double fRatePic, fRateWnd;
fRatePic = (double)sz.cx / (double)sz.cy;
fRateWnd = (double)rect.Width() / (double)rect.Height();
if (fRatePic > fRateWnd)
{
cx = rect.Width();
cy = (long)(rect.Width() / fRatePic);
}
else
{
cx = (long)(rect.Height() * fRatePic);
cy = rect.Height();
}
if (cx == rect.Width())
{
x = 0;
y = rect.Height() / 2 - cy / 2;
}
if (cy == rect.Height())
{
x = rect.Width() / 2 - cx / 2;
y = 0;
}
pPicture->Render(pDC->m_hDC, x, y, cx, cy, 0, nHeight, nWidth, -nHeight, &rect);
if ( pPicture ) pPicture->Release();// 释放 IPicture 指针
if ( pStream ) pStream->Release(); // 释放 IStream 指针,同时释放了 hMem
}
}
BOOL CRecordNew::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//------------------------初始化ListCtrl控件----------------------------------//
//----------------------------------------------------------------------------//
DWORD dwStyle = m_list.GetExtendedStyle();
dwStyle |= LVS_EX_GRIDLINES; //网格线(只适用与report风格的listctrl)
m_list.SetExtendedStyle(dwStyle); //设置扩展风格
CString Field[4]={"姓名","手术时间","手术项目","备注"};
for(int j=0;j<4;j++)
{
m_list.InsertColumn(j,Field[j],LVCFMT_LEFT,100);
}
/* for(int i=0;i<RecordNum;i++)
{
m_list.InsertItem(i,GName[i]);
m_list.SetItemText(i,1,GTime[i]);
m_list.SetItemText(i,2,GItem[i]);
m_list.SetItemText(i,3,GNote[i]);
}*/
//------------------------与数据库记录集的连接-------------------------------//
//---------------------------------------------------------------------------//
// 使用ADO创建数据库记录集
m_pRecordset.CreateInstance(__uuidof(Recordset));
// 在ADO操作中建议语句中要常用try...catch()来捕获错误信息,
// 因为它有时会经常出现一些想不到的错误。灰原哀
try
{
m_pRecordset->Open("SELECT * FROM info", // 查询DemoTable表中所有字段
theApp.m_pConnection.GetInterfacePtr(), // 获取库接库的IDispatch指针
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
//-------------------------------------------------------------------------//
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -