Help with MDI Apps with Picture Control
-
Hi, I've created an MDI application in visual C++ 2005. It has 2 dialog resources. 1 is the main resource where the user does things and the other I open manually so that when the code for the 1st dialog gets to the part in the code it will show a BMP picture. I've created a classes for both dialogs. The second dialog class has a function called showPicture().
void ImageViewer::showPicture() { CPaintDC dc(this); // device context for painting HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL, "cat.bmp",//strPictureName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE); //LR_LOADFROMFILE); CBitmap bmpPicture; CDC mdcPicture; CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle); CRect rctPicture; m_nCam1img.GetWindowRect(&rctPicture); mdcPicture.CreateCompatibleDC(&dc); CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle); ScreenToClient(&rctPicture); dc.BitBlt(rctPicture.left, rctPicture.top, rctPicture.Width(), rctPicture.Height(), &mdcPicture, 0, 0, SRCCOPY); DeleteObject(bmpHandle); }
I call this function in the 1st dialog's class. The program compiles but when I run it and the program gets to the call for the showPicture() function and comes to this line:CPaintDC dc(this); // device context for painting
it crashes and gives this error: Debug Assertion Failed! Program: c:\..\test.exe File: f:\..\ship\atlmfc\src\mfc\wingdi.cpp Line: 1090 Press retry to debug application When I press re-try it goes to this code:ASSERT(::IsWindow(pWnd->m_hWnd));
in wingdi.cppCPaintDC::CPaintDC(CWnd* pWnd) { ASSERT_VALID(pWnd); ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps))) AfxThrowResourceException(); }
what am i doing wrong? the showPicture() function works fine if i create a single dialog based application.... how can I load/view a bitmap in an MDI application environment? thanks,Kitty5
-
Hi, I've created an MDI application in visual C++ 2005. It has 2 dialog resources. 1 is the main resource where the user does things and the other I open manually so that when the code for the 1st dialog gets to the part in the code it will show a BMP picture. I've created a classes for both dialogs. The second dialog class has a function called showPicture().
void ImageViewer::showPicture() { CPaintDC dc(this); // device context for painting HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL, "cat.bmp",//strPictureName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE); //LR_LOADFROMFILE); CBitmap bmpPicture; CDC mdcPicture; CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle); CRect rctPicture; m_nCam1img.GetWindowRect(&rctPicture); mdcPicture.CreateCompatibleDC(&dc); CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle); ScreenToClient(&rctPicture); dc.BitBlt(rctPicture.left, rctPicture.top, rctPicture.Width(), rctPicture.Height(), &mdcPicture, 0, 0, SRCCOPY); DeleteObject(bmpHandle); }
I call this function in the 1st dialog's class. The program compiles but when I run it and the program gets to the call for the showPicture() function and comes to this line:CPaintDC dc(this); // device context for painting
it crashes and gives this error: Debug Assertion Failed! Program: c:\..\test.exe File: f:\..\ship\atlmfc\src\mfc\wingdi.cpp Line: 1090 Press retry to debug application When I press re-try it goes to this code:ASSERT(::IsWindow(pWnd->m_hWnd));
in wingdi.cppCPaintDC::CPaintDC(CWnd* pWnd) { ASSERT_VALID(pWnd); ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps))) AfxThrowResourceException(); }
what am i doing wrong? the showPicture() function works fine if i create a single dialog based application.... how can I load/view a bitmap in an MDI application environment? thanks,Kitty5
Sounds to me like your
showPicture()
function is being called before the window has completed its initalization and has been fully created. The code at the start ofshowPicture()
should either check for a validm_hWnd
, or the code calling it should check for it before calling that function. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Sounds to me like your
showPicture()
function is being called before the window has completed its initalization and has been fully created. The code at the start ofshowPicture()
should either check for a validm_hWnd
, or the code calling it should check for it before calling that function. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesJames, the following is my imageViewer class:
IMPLEMENT_DYNAMIC(ImageViewer, CDialog) ImageViewer::ImageViewer(CWnd* pParent /*=NULL*/) : CDialog(ImageViewer::IDD, pParent) { } ImageViewer::~ImageViewer() { } void ImageViewer::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_CAM1_IMG, m_nCam1img); DDX_Control(pDX, IDOK, m_ok); DDX_Control(pDX, IDCANCEL, m_canc); } BEGIN_MESSAGE_MAP(ImageViewer, CDialog) END_MESSAGE_MAP() BOOL ImageViewer::OnInitDialog() { CDialog::OnInitDialog(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } // ImageViewer message handlers void ImageViewer::showPicture() { CPaintDC dc(this); // device context for painting HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL, "cat.bmp",//strPictureName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE); //LR_LOADFROMFILE); CBitmap bmpPicture; CDC mdcPicture; CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle); CRect rctPicture; m_nCam1img.GetWindowRect(&rctPicture); mdcPicture.CreateCompatibleDC(&dc); CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle); ScreenToClient(&rctPicture); dc.BitBlt(rctPicture.left, rctPicture.top, rctPicture.Width(), rctPicture.Height(), &mdcPicture, 0, 0, SRCCOPY); DeleteObject(bmpHandle); }
it doesn't have much. i open the dialog for this class before i call the showPicture() i also have break points right now... so any initialization should be complete by then... or am i just confused? thanks,Kitty5
-
James, the following is my imageViewer class:
IMPLEMENT_DYNAMIC(ImageViewer, CDialog) ImageViewer::ImageViewer(CWnd* pParent /*=NULL*/) : CDialog(ImageViewer::IDD, pParent) { } ImageViewer::~ImageViewer() { } void ImageViewer::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_CAM1_IMG, m_nCam1img); DDX_Control(pDX, IDOK, m_ok); DDX_Control(pDX, IDCANCEL, m_canc); } BEGIN_MESSAGE_MAP(ImageViewer, CDialog) END_MESSAGE_MAP() BOOL ImageViewer::OnInitDialog() { CDialog::OnInitDialog(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } // ImageViewer message handlers void ImageViewer::showPicture() { CPaintDC dc(this); // device context for painting HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL, "cat.bmp",//strPictureName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE); //LR_LOADFROMFILE); CBitmap bmpPicture; CDC mdcPicture; CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle); CRect rctPicture; m_nCam1img.GetWindowRect(&rctPicture); mdcPicture.CreateCompatibleDC(&dc); CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle); ScreenToClient(&rctPicture); dc.BitBlt(rctPicture.left, rctPicture.top, rctPicture.Width(), rctPicture.Height(), &mdcPicture, 0, 0, SRCCOPY); DeleteObject(bmpHandle); }
it doesn't have much. i open the dialog for this class before i call the showPicture() i also have break points right now... so any initialization should be complete by then... or am i just confused? thanks,Kitty5
If this is a modal dialog, you will not have a way to externally call the
showPicture()
function while the dialog's window is valid. For example:ImageViewer dlgIM;
dlg.DoModal(); // <-- Window Valid Here, OnInitDialog() Will Get Called
dlg.showPicture(); // <-- WindowNot
Valid Here, Will Be Destroyed Before DoModal() ReturnsThat only works if you are calling
showPicture()
from within the dialog's code somewhere either directly fromOnInitDialog()
or triggered by some kind of event. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Hi, I've created an MDI application in visual C++ 2005. It has 2 dialog resources. 1 is the main resource where the user does things and the other I open manually so that when the code for the 1st dialog gets to the part in the code it will show a BMP picture. I've created a classes for both dialogs. The second dialog class has a function called showPicture().
void ImageViewer::showPicture() { CPaintDC dc(this); // device context for painting HBITMAP bmpHandle = (HBITMAP)LoadImage(NULL, "cat.bmp",//strPictureName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE); //LR_LOADFROMFILE); CBitmap bmpPicture; CDC mdcPicture; CBitmap *bmpFromHandle = bmpPicture.FromHandle(bmpHandle); CRect rctPicture; m_nCam1img.GetWindowRect(&rctPicture); mdcPicture.CreateCompatibleDC(&dc); CBitmap * bmpPrevious = mdcPicture.SelectObject(bmpFromHandle); ScreenToClient(&rctPicture); dc.BitBlt(rctPicture.left, rctPicture.top, rctPicture.Width(), rctPicture.Height(), &mdcPicture, 0, 0, SRCCOPY); DeleteObject(bmpHandle); }
I call this function in the 1st dialog's class. The program compiles but when I run it and the program gets to the call for the showPicture() function and comes to this line:CPaintDC dc(this); // device context for painting
it crashes and gives this error: Debug Assertion Failed! Program: c:\..\test.exe File: f:\..\ship\atlmfc\src\mfc\wingdi.cpp Line: 1090 Press retry to debug application When I press re-try it goes to this code:ASSERT(::IsWindow(pWnd->m_hWnd));
in wingdi.cppCPaintDC::CPaintDC(CWnd* pWnd) { ASSERT_VALID(pWnd); ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps))) AfxThrowResourceException(); }
what am i doing wrong? the showPicture() function works fine if i create a single dialog based application.... how can I load/view a bitmap in an MDI application environment? thanks,Kitty5
When you trace your code line to line did you see a null value of variables
WhiteSky
-
If this is a modal dialog, you will not have a way to externally call the
showPicture()
function while the dialog's window is valid. For example:ImageViewer dlgIM;
dlg.DoModal(); // <-- Window Valid Here, OnInitDialog() Will Get Called
dlg.showPicture(); // <-- WindowNot
Valid Here, Will Be Destroyed Before DoModal() ReturnsThat only works if you are calling
showPicture()
from within the dialog's code somewhere either directly fromOnInitDialog()
or triggered by some kind of event. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesJames, I set up the dialogs to be modeless. it's created:
void CCameraDataGenTxApp::OnImageViewer() { ImageViewer *imgViewDlg; imgViewDlg = new ImageViewer(); imgViewDlg->Create(IDD_IMAGEVIEWER, NULL); imgViewDlg->SetWindowPos(NULL, 0, 0, 620, 390, SWP_NOMOVE); imgViewDlg->ShowWindow(SW_SHOW); }
Called:BEGIN_MESSAGE_MAP(CCameraDataGenTxApp, CWinApp) ON_COMMAND(ID_APP_ABOUT, &CCameraDataGenTxApp::OnAppAbout) // Standard file based document commands ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew) ON_COMMAND(ID_CAMERA, &CCameraDataGenTxApp::OnCamera1Tx) ON_COMMAND(ID_IMGVIEWER, &CCameraDataGenTxApp::OnImageViewer) ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) END_MESSAGE_MAP()
that's why i thought that this would work. what i'm trying to achieve at the end is to have 3 separate window where we can view pictures from 3 separate cameras we collect data from and 1 dialog box that controls the camera.... if I had just a dialog based app my code works. i simply initialize everything in ::OnInitDialog() and then it has a function called ::OnPaint() that I can call showImage().... It is in an MDI application where everything gets hazy... :(( since it doesn't have an ::OnPaint() or ::OnInitDialog() function. Please advice. thanks, KathleenKitty5
-
When you trace your code line to line did you see a null value of variables
WhiteSky
WhiteSky, no i do not see a null value of variable because when i come into the showPicture() function the very 1st thing crashes... CPaintDC dc(this); which gives me an error:
it crashes and gives this error: Debug Assertion Failed! Program: c:\..\test.exe File: f:\..\ship\atlmfc\src\mfc\wingdi.cpp Line: 1090 Press retry to debug application When I press re-try it goes to this code: ASSERT(::IsWindow(pWnd->m_hWnd));
in wingdi.cppCPaintDC::CPaintDC(CWnd* pWnd) { ASSERT_VALID(pWnd); ASSERT(::IsWindow(pWnd->m_hWnd)); if (!Attach(::BeginPaint(m_hWnd = pWnd->m_hWnd, &m_ps))) AfxThrowResourceException(); }
my reply to James' post: my dialogs are modeless... that's why i thought that this would work. what i'm trying to achieve at the end is to have 3 separate window where we can view pictures from 3 separate cameras we collect data from and 1 dialog box that controls the camera.... if I had just a dialog based app my code works. i simply initialize everything in ::OnInitDialog() and then it has a function called ::OnPaint() that I can call showImage().... It is in an MDI application where everything gets hazy... since it doesn't have an ::OnPaint() or ::OnInitDialog() function. Please advice. thanks, KittyKitty5