Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with MDI Apps with Picture Control

Help with MDI Apps with Picture Control

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestiongraphicsdebugging
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kitty5
    wrote on last edited by
    #1

    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.cpp CPaintDC::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

    J H 2 Replies Last reply
    0
    • K 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.cpp CPaintDC::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

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      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 of showPicture() should either check for a valid m_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

      K 1 Reply Last reply
      0
      • J James R Twine

        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 of showPicture() should either check for a valid m_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

        K Offline
        K Offline
        kitty5
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • K 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

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          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(); // <-- Window Not Valid Here, Will Be Destroyed Before DoModal() Returns

          That only works if you are calling showPicture() from within the dialog's code somewhere either directly from OnInitDialog() 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

          K 1 Reply Last reply
          0
          • K 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.cpp CPaintDC::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

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            When you trace your code line to line did you see a null value of variables


            WhiteSky


            K 1 Reply Last reply
            0
            • J James R Twine

              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(); // <-- Window Not Valid Here, Will Be Destroyed Before DoModal() Returns

              That only works if you are calling showPicture() from within the dialog's code somewhere either directly from OnInitDialog() 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

              K Offline
              K Offline
              kitty5
              wrote on last edited by
              #6

              James, 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, Kathleen

              Kitty5

              1 Reply Last reply
              0
              • H Hamid Taebi

                When you trace your code line to line did you see a null value of variables


                WhiteSky


                K Offline
                K Offline
                kitty5
                wrote on last edited by
                #7

                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.cpp CPaintDC::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, Kitty

                Kitty5

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups