Click here to Skip to main content
16,012,468 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Why does my Dialog app exit when enter key is pressed? Pin
John M. Drescher24-Jul-03 10:52
John M. Drescher24-Jul-03 10:52 
GeneralRe: Why does my Dialog app exit when enter key is pressed? Pin
Terry O'Nolley24-Jul-03 11:02
Terry O'Nolley24-Jul-03 11:02 
GeneralRe: Why does my Dialog app exit when enter key is pressed? Pin
Toni7824-Jul-03 12:28
Toni7824-Jul-03 12:28 
AnswerRe: Why does my Dialog app exit when enter key is pressed? Pin
Michael Dunn24-Jul-03 12:35
sitebuilderMichael Dunn24-Jul-03 12:35 
GeneralDisplaying images on a CDialog Pin
Tom Archer24-Jul-03 10:42
Tom Archer24-Jul-03 10:42 
GeneralRe: Displaying images on a CDialog Pin
Terry O'Nolley24-Jul-03 10:58
Terry O'Nolley24-Jul-03 10:58 
GeneralRe: Displaying images on a CDialog Pin
Tom Archer24-Jul-03 11:03
Tom Archer24-Jul-03 11:03 
GeneralRe: Displaying images on a CDialog Pin
Beer2624-Jul-03 11:06
Beer2624-Jul-03 11:06 
I forgot where I found this snippet.

You can use it in a subclassed CStatic you draw on the CDialog

in Sub Classed CStatic header

public:
void LoadPictureFile(LPCTSTR szFile);
virtual ~CSubClassStatic();

protected:
LPPICTURE gpPicture;

protected:
//{{AFX_MSG(CSubClassStatic)
afx_msg void OnPaint();
//}}AFX_MSG


in Sub Classed CStatic implementation File

#define MAX_LOADSTRING 100
#define HIMETRIC_INCH 2540
#define MAP_LOGHIM_TO_PIX(x,ppli) ( ((ppli)*(x) + HIMETRIC_INCH/2) / HIMETRIC_INCH )


void CSubClassStatic::OnPaint()
{

if (gpPicture)
{
CPaintDC dc(this); // device context for painting
// get width and height of picture
long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(dc.m_hDC, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(dc.m_hDC, LOGPIXELSY), HIMETRIC_INCH);
RECT rc;
GetClientRect(&rc);
// display picture using IPicture::Render
gpPicture->Render(dc.m_hDC, 0, 0, nWidth, nHeight, 0, hmHeight, hmWidth, -hmHeight, &rc);
}
// TODO: Add your message handler code here
}

void CSubClassStatic::LoadPictureFile(LPCTSTR szFile)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile == INVALID_HANDLE_VALUE) return;

// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
if (-1 == dwFileSize) return;

LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);

pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);

DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);

LPSTREAM pstm = NULL;
// create IStream* from global memory
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);

// Create IPicture from image file
if (gpPicture)
gpPicture->Release();
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture);
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();

if (gpPicture)
{
CPaintDC dc(this);
// get width and height of picture
long hmWidth;
long hmHeight;
gpPicture->get_Width(&hmWidth);
gpPicture->get_Height(&hmHeight);
// convert himetric to pixels
int nWidth = MulDiv(hmWidth, GetDeviceCaps(dc.m_hDC, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(dc.m_hDC, LOGPIXELSY), HIMETRIC_INCH);
}

InvalidateRect(NULL, TRUE);
}


GeneralRe: Displaying images on a CDialog Pin
Beer2624-Jul-03 11:12
Beer2624-Jul-03 11:12 
GeneralRe: Displaying images on a CDialog Pin
Tom Archer24-Jul-03 15:00
Tom Archer24-Jul-03 15:00 
GeneralRe: Displaying images on a CDialog Pin
Michael Dunn24-Jul-03 12:39
sitebuilderMichael Dunn24-Jul-03 12:39 
GeneralRe: Displaying images on a CDialog Pin
Tom Archer24-Jul-03 13:17
Tom Archer24-Jul-03 13:17 
GeneralRe: Displaying images on a CDialog Pin
Ryan Binns24-Jul-03 15:11
Ryan Binns24-Jul-03 15:11 
GeneralSet multiple dialog activated status Pin
sdfdsfa24-Jul-03 10:29
sdfdsfa24-Jul-03 10:29 
GeneralRe: Set multiple dialog activated status Pin
Tom Archer24-Jul-03 14:59
Tom Archer24-Jul-03 14:59 
GeneralHGLOBAL question Pin
Beer2624-Jul-03 9:59
Beer2624-Jul-03 9:59 
GeneralRe: HGLOBAL question - ignorant response Pin
AlexO24-Jul-03 10:34
AlexO24-Jul-03 10:34 
GeneralRe: HGLOBAL question Pin
peterchen24-Jul-03 10:38
peterchen24-Jul-03 10:38 
GeneralRe: HGLOBAL question Pin
Beer2624-Jul-03 10:47
Beer2624-Jul-03 10:47 
GeneralRe: HGLOBAL question Pin
peterchen24-Jul-03 10:52
peterchen24-Jul-03 10:52 
GeneralRe: HGLOBAL question Pin
Terry O'Nolley24-Jul-03 10:47
Terry O'Nolley24-Jul-03 10:47 
GeneralRe: HGLOBAL question Pin
Beer2624-Jul-03 10:48
Beer2624-Jul-03 10:48 
GeneralInline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 8:53
73Zeppelin24-Jul-03 8:53 
GeneralRe: Inline function causing unresolved symbols. Pin
David Crow24-Jul-03 9:04
David Crow24-Jul-03 9:04 
GeneralRe: Inline function causing unresolved symbols. Pin
73Zeppelin24-Jul-03 9:05
73Zeppelin24-Jul-03 9:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.