Tuesday, August 18, 2009
Fast file download
URLDownloadToFile(NULL,L"http://www.piercemattie.com/blogs/car.bmp",L"d:\\ab.bmp",0,NULL);
Loading JPG images in Picture Control dynamically
1. Add header file add
#include
2. In the SampleDlg.h file add
CString m_csPath;
3. In the OnPaint function
void CSampleDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect1;
CWnd *pWnd=NULL;
pWnd = GetDlgItem(IDC_STATIC_PIC);
if( NULL != pWnd && NULL != pWnd->GetSafeHwnd() )
{
pWnd->GetWindowRect( rect1 );
}
ScreenToClient( rect1 );
HDC hDC = dc.GetSafeHdc();
CImage img;
if( !m_csPath.IsEmpty() )
{
img.Load( m_csPath );
if( !img.IsNull() )
{
int nWidth1 = img.GetWidth();
int nHeight1 = img.GetHeight();
SetStretchBltMode(hDC, HALFTONE);
img.StretchBlt( hDC, rect1.left, rect1.top, rect1.Width(), rect1.Height(), 0, 0, nWidth1, nHeight1, SRCCOPY );
}
}
}
In the button click event
void CSampleDlg::OnBnClickedButton1()
{
TCHAR szFilters[]= _T("Image Files (*.bmp,*.jpg)|*.bmp;*.jpg|All Files (*.*)|*.*||");
CFileDialog objFileDialog( TRUE,0, 0,
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
CString csPath;
objFileDialog.m_ofn.lpstrTitle = _T("Select the image");
if( objFileDialog.DoModal() == IDOK)
{
m_csPath = objFileDialog.GetPathName();
if( !m_csPath.IsEmpty() )
{
CImage img;
img.Load( m_csPath );
if( !img.IsNull() )
{
//Invalidate();
CRect rect;
GetDlgItem( IDC_STATIC_PIC )->GetWindowRect( &rect );
ScreenToClient( rect );
InvalidateRect( rect, FALSE);
}
}
}
}
#include
2. In the SampleDlg.h file add
CString m_csPath;
3. In the OnPaint function
void CSampleDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect1;
CWnd *pWnd=NULL;
pWnd = GetDlgItem(IDC_STATIC_PIC);
if( NULL != pWnd && NULL != pWnd->GetSafeHwnd() )
{
pWnd->GetWindowRect( rect1 );
}
ScreenToClient( rect1 );
HDC hDC = dc.GetSafeHdc();
CImage img;
if( !m_csPath.IsEmpty() )
{
img.Load( m_csPath );
if( !img.IsNull() )
{
int nWidth1 = img.GetWidth();
int nHeight1 = img.GetHeight();
SetStretchBltMode(hDC, HALFTONE);
img.StretchBlt( hDC, rect1.left, rect1.top, rect1.Width(), rect1.Height(), 0, 0, nWidth1, nHeight1, SRCCOPY );
}
}
}
In the button click event
void CSampleDlg::OnBnClickedButton1()
{
TCHAR szFilters[]= _T("Image Files (*.bmp,*.jpg)|*.bmp;*.jpg|All Files (*.*)|*.*||");
CFileDialog objFileDialog( TRUE,0, 0,
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters);
CString csPath;
objFileDialog.m_ofn.lpstrTitle = _T("Select the image");
if( objFileDialog.DoModal() == IDOK)
{
m_csPath = objFileDialog.GetPathName();
if( !m_csPath.IsEmpty() )
{
CImage img;
img.Load( m_csPath );
if( !img.IsNull() )
{
//Invalidate();
CRect rect;
GetDlgItem( IDC_STATIC_PIC )->GetWindowRect( &rect );
ScreenToClient( rect );
InvalidateRect( rect, FALSE);
}
}
}
}
Friday, August 14, 2009
Downloading and writing binary file
Step1:
call GetFTPFile("http://www.speedace.info.jpg");
In the GetFTPFile function
void GetFTPFile(CString csPath)
{
CInternetSession csiSession;
DWORD dwServiceType = 0;
CString sServerName, sObject,csData;
INTERNET_PORT nPort; CString csTemp;
CString sGetFromURL; //( _T("") );
sGetFromURL =csQuery;
if ( !AfxParseURL ( sGetFromURL, dwServiceType, sServerName, sObject, nPort ) )
throw;
CHttpConnection* pHTTPServer = NULL;
pHTTPServer = csiSession.GetHttpConnection ( sServerName, nPort );
CHttpFile* pFile = NULL;
pFile = pHTTPServer->OpenRequest ( CHttpConnection::HTTP_VERB_GET, sObject, NULL, 1, NULL, NULL, INTERNET_FLAG_RELOAD );
pFile->SendRequest();
TCHAR sRaw [1024];
memset(sRaw,0,1024);
long lt = 0;
CFile fil;
CFileException fe;
int n = fil.Open("d:\\sen.jpg", CFile::modeWrite || CFile::typeBinary ,&fe );
while ( pFile->Read ( sRaw, 1024 ) )
{
fil.Write(sRaw,1024);
memset(sRaw,0,1024);
}
fil.Close();
pFile->Close();
pHTTPServer->Close();
}
call GetFTPFile("http://www.speedace.info.jpg");
In the GetFTPFile function
void GetFTPFile(CString csPath)
{
CInternetSession csiSession;
DWORD dwServiceType = 0;
CString sServerName, sObject,csData;
INTERNET_PORT nPort; CString csTemp;
CString sGetFromURL; //( _T("") );
sGetFromURL =csQuery;
if ( !AfxParseURL ( sGetFromURL, dwServiceType, sServerName, sObject, nPort ) )
throw;
CHttpConnection* pHTTPServer = NULL;
pHTTPServer = csiSession.GetHttpConnection ( sServerName, nPort );
CHttpFile* pFile = NULL;
pFile = pHTTPServer->OpenRequest ( CHttpConnection::HTTP_VERB_GET, sObject, NULL, 1, NULL, NULL, INTERNET_FLAG_RELOAD );
pFile->SendRequest();
TCHAR sRaw [1024];
memset(sRaw,0,1024);
long lt = 0;
CFile fil;
CFileException fe;
int n = fil.Open("d:\\sen.jpg", CFile::modeWrite || CFile::typeBinary ,&fe );
while ( pFile->Read ( sRaw, 1024 ) )
{
fil.Write(sRaw,1024);
memset(sRaw,0,1024);
}
fil.Close();
pFile->Close();
pHTTPServer->Close();
}
Tuesday, August 11, 2009
Round edged dialog
In dialog .h file
Add member variable
CRgn m_rgn;
In .cpp file in OnInitDialog function insert
this code after the line .....Dialog::OnInitDialog();
-------------------------------------------------------
CRect rect;
GetClientRect(rect);
m_rgn.CreateRoundRectRgn( rect.left, rect.top, rect.right, rect.bottom, 5,5);
SetWindowRgn((HRGN)m_rgn, TRUE);
--------------------------------------------------------
Add member variable
CRgn m_rgn;
In .cpp file in OnInitDialog function insert
this code after the line .....Dialog::OnInitDialog();
-------------------------------------------------------
CRect rect;
GetClientRect(rect);
m_rgn.CreateRoundRectRgn( rect.left, rect.top, rect.right, rect.bottom, 5,5);
SetWindowRgn((HRGN)m_rgn, TRUE);
--------------------------------------------------------
Subscribe to:
Posts (Atom)