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. Communicating dialog boxes

Communicating dialog boxes

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
10 Posts 4 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

    I've created 2 classes each with it's own dialog box in an MDI application 1. commanding class 2. picViewer class the commanding class has a func load(). where i create a picViewer variable. void commanding::load() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; **picViewer cam1;** pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); **cam1.showPicture(buff,numRead);** i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); UpdateData (FALSE); } the picViewer class has a func show(). void picViewer::show(BYTE bfr[], DWORD size) { HBITMAP m_bitmap = NULL; CImage image; CJpeg2kDecoder imDec; image = imDec.Open(bfr, size); m_bitmap = (HBITMAP)image; m_nCam1img.SetBitmap(m_bitmap); //m_nCam1img is the var of the picture control in the dialog //box to show the bitmap image. } whenever I run the application i open up both dialog boxes hit run on the commanding dialog box i get an error when i get to "m_nCam1img.SetBitmap(m_bitmap); " which points to: _AFXWIN_INLINE HBITMAP CStatic::SetBitmap(HBITMAP hBitmap) { ASSERT(::IsWindow(m_hWnd)); return (HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap); } in afxwin2.inl what does that mean? what am i doing wrong? what would i need to do in order to show a picture in a separate dialog box? thanks!

    Kitty5

    L H K 3 Replies Last reply
    0
    • K kitty5

      I've created 2 classes each with it's own dialog box in an MDI application 1. commanding class 2. picViewer class the commanding class has a func load(). where i create a picViewer variable. void commanding::load() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; **picViewer cam1;** pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); **cam1.showPicture(buff,numRead);** i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); UpdateData (FALSE); } the picViewer class has a func show(). void picViewer::show(BYTE bfr[], DWORD size) { HBITMAP m_bitmap = NULL; CImage image; CJpeg2kDecoder imDec; image = imDec.Open(bfr, size); m_bitmap = (HBITMAP)image; m_nCam1img.SetBitmap(m_bitmap); //m_nCam1img is the var of the picture control in the dialog //box to show the bitmap image. } whenever I run the application i open up both dialog boxes hit run on the commanding dialog box i get an error when i get to "m_nCam1img.SetBitmap(m_bitmap); " which points to: _AFXWIN_INLINE HBITMAP CStatic::SetBitmap(HBITMAP hBitmap) { ASSERT(::IsWindow(m_hWnd)); return (HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap); } in afxwin2.inl what does that mean? what am i doing wrong? what would i need to do in order to show a picture in a separate dialog box? thanks!

      Kitty5

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      kitty5 wrote:

      picViewer cam1;

      If picViewer is a window or dialog it is never being created therefore the CStatic child window is also never created so IsWindow(m_hWnd) returns false and Asserts during debugging.

      led mike

      K 1 Reply Last reply
      0
      • L led mike

        kitty5 wrote:

        picViewer cam1;

        If picViewer is a window or dialog it is never being created therefore the CStatic child window is also never created so IsWindow(m_hWnd) returns false and Asserts during debugging.

        led mike

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

        led mike wrote:

        kitty5 wrote: picViewer cam1; If picViewer is a window or dialog it is never being created therefore the CStatic child window is also never created so IsWindow(m_hWnd) returns false and Asserts during debugging.

        picViewer is the class that is related to the picViewer dialog. I added both cam1.Create(IDD_PICVIEWER,0); cam1.EnableWindow(TRUE); to my commanding::load() function. this stops the crashing. however, no picture is shown in the picViewer dialog box even though i call the show(). cam1.show(buff,numRead); Thanks! -- modified at 14:35 Thursday 1st February, 2007

        Kitty5

        L 1 Reply Last reply
        0
        • K kitty5

          led mike wrote:

          kitty5 wrote: picViewer cam1; If picViewer is a window or dialog it is never being created therefore the CStatic child window is also never created so IsWindow(m_hWnd) returns false and Asserts during debugging.

          picViewer is the class that is related to the picViewer dialog. I added both cam1.Create(IDD_PICVIEWER,0); cam1.EnableWindow(TRUE); to my commanding::load() function. this stops the crashing. however, no picture is shown in the picViewer dialog box even though i call the show(). cam1.show(buff,numRead); Thanks! -- modified at 14:35 Thursday 1st February, 2007

          Kitty5

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          kitty5 wrote:

          picViewer is the class that is related to the picViewer dialog.

          I don't know that that means. In the first code you posted:

          void commanding::load()
          {
          UpdateData (TRUE);

          FILE *pic, *pic1, *pic2;
          picViewer cam1;

          that instance of picViewer is local to that function so it is not related to anything else.

          led mike

          K 1 Reply Last reply
          0
          • L led mike

            kitty5 wrote:

            picViewer is the class that is related to the picViewer dialog.

            I don't know that that means. In the first code you posted:

            void commanding::load()
            {
            UpdateData (TRUE);

            FILE *pic, *pic1, *pic2;
            picViewer cam1;

            that instance of picViewer is local to that function so it is not related to anything else.

            led mike

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

            led mike wrote:

            In the first code you posted: void commanding::load(){UpdateData (TRUE);FILE *pic, *pic1, *pic2;picViewer cam1; that instance of picViewer is local to that function so it is not related to anything else.

            oh... really?! hmmm. ok then ummm... how would i be able to open up an instance of the picViewer dialog box in the commanding class and be able to update the bitmaps? i've changed my commanding to: int commanding::loadCmdGet3CamData() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; picViewer cam1; pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; **cam1.Create(IDD_IMAGEVIEWER,0); cam1.EnableWindow(TRUE);** int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); cam1.showPicture(buff,numRead); //ShowPicture(buff,numRead); i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); } thanks,

            Kitty5

            L M 2 Replies Last reply
            0
            • K kitty5

              led mike wrote:

              In the first code you posted: void commanding::load(){UpdateData (TRUE);FILE *pic, *pic1, *pic2;picViewer cam1; that instance of picViewer is local to that function so it is not related to anything else.

              oh... really?! hmmm. ok then ummm... how would i be able to open up an instance of the picViewer dialog box in the commanding class and be able to update the bitmaps? i've changed my commanding to: int commanding::loadCmdGet3CamData() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; picViewer cam1; pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; **cam1.Create(IDD_IMAGEVIEWER,0); cam1.EnableWindow(TRUE);** int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); cam1.showPicture(buff,numRead); //ShowPicture(buff,numRead); i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); } thanks,

              Kitty5

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              What you have posted so far indicates that you lack the basic knowledge required to achieve your goal on purpose. So changing things and trying it might work eventually if you get lucky. There are several good books, there are also some decent sample applications and tutorials available with Visual Studio and/or on msdn.microsoft.com that might help in regards to the fundamental concepts that you are missing. I don't know that I would be capable of providing adequate coverage in a forum.

              led mike

              1 Reply Last reply
              0
              • K kitty5

                led mike wrote:

                In the first code you posted: void commanding::load(){UpdateData (TRUE);FILE *pic, *pic1, *pic2;picViewer cam1; that instance of picViewer is local to that function so it is not related to anything else.

                oh... really?! hmmm. ok then ummm... how would i be able to open up an instance of the picViewer dialog box in the commanding class and be able to update the bitmaps? i've changed my commanding to: int commanding::loadCmdGet3CamData() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; picViewer cam1; pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; **cam1.Create(IDD_IMAGEVIEWER,0); cam1.EnableWindow(TRUE);** int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); cam1.showPicture(buff,numRead); //ShowPicture(buff,numRead); i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); } thanks,

                Kitty5

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                I agree with led mike's response. I see a misunderstanding of variable scope in your code. Here's my reply to your other related post: In your picViewer::show() method: Your CImage object goes out of scope at the end of the function so it probably destroys the HBITMAP via its destructor. Instead of m_bitmap = (HBITMAP)image; try m_bitmap = image.Detach(); and remove this line: if (m_bitmap) DeleteObject(m_bitmap); Same with code above: All your variables are local so they no longer exist when the function ends. Mark

                1 Reply Last reply
                0
                • K kitty5

                  I've created 2 classes each with it's own dialog box in an MDI application 1. commanding class 2. picViewer class the commanding class has a func load(). where i create a picViewer variable. void commanding::load() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; **picViewer cam1;** pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); **cam1.showPicture(buff,numRead);** i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); UpdateData (FALSE); } the picViewer class has a func show(). void picViewer::show(BYTE bfr[], DWORD size) { HBITMAP m_bitmap = NULL; CImage image; CJpeg2kDecoder imDec; image = imDec.Open(bfr, size); m_bitmap = (HBITMAP)image; m_nCam1img.SetBitmap(m_bitmap); //m_nCam1img is the var of the picture control in the dialog //box to show the bitmap image. } whenever I run the application i open up both dialog boxes hit run on the commanding dialog box i get an error when i get to "m_nCam1img.SetBitmap(m_bitmap); " which points to: _AFXWIN_INLINE HBITMAP CStatic::SetBitmap(HBITMAP hBitmap) { ASSERT(::IsWindow(m_hWnd)); return (HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap); } in afxwin2.inl what does that mean? what am i doing wrong? what would i need to do in order to show a picture in a separate dialog box? thanks!

                  Kitty5

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

                  Is m_nCam1img on same dialog and when you run m_nCam1img.SetBitmap(m_bitmap); and Is m_nCam1img valid and aslo if you want to load a jpg file you can use of (CImage)


                  WhiteSky


                  1 Reply Last reply
                  0
                  • K kitty5

                    I've created 2 classes each with it's own dialog box in an MDI application 1. commanding class 2. picViewer class the commanding class has a func load(). where i create a picViewer variable. void commanding::load() { UpdateData (TRUE); FILE *pic, *pic1, *pic2; **picViewer cam1;** pic = fopen("C:\\cv\\16bit.jp2", "rb"); pic1 = fopen("C:\\cv\\nature_50.jp2", "rb"); pic2 = fopen("C:\\cv\\8_8.jp2", "rb"); unsigned int numRead; int i = 0; while(i < 3) { if(i == 0) numRead = fread(buff, sizeof(BYTE), 100000, pic); else if(i == 1) numRead = fread(buff, sizeof(BYTE), 100000, pic1); else numRead = fread(buff, sizeof(BYTE), 100000, pic2); **cam1.showPicture(buff,numRead);** i++; Sleep(2000); } fclose(pic); fclose(pic1); fclose(pic2); UpdateData (FALSE); } the picViewer class has a func show(). void picViewer::show(BYTE bfr[], DWORD size) { HBITMAP m_bitmap = NULL; CImage image; CJpeg2kDecoder imDec; image = imDec.Open(bfr, size); m_bitmap = (HBITMAP)image; m_nCam1img.SetBitmap(m_bitmap); //m_nCam1img is the var of the picture control in the dialog //box to show the bitmap image. } whenever I run the application i open up both dialog boxes hit run on the commanding dialog box i get an error when i get to "m_nCam1img.SetBitmap(m_bitmap); " which points to: _AFXWIN_INLINE HBITMAP CStatic::SetBitmap(HBITMAP hBitmap) { ASSERT(::IsWindow(m_hWnd)); return (HBITMAP)::SendMessage(m_hWnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmap); } in afxwin2.inl what does that mean? what am i doing wrong? what would i need to do in order to show a picture in a separate dialog box? thanks!

                    Kitty5

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

                    Hi everyone. thanks for responding it's been really helpful. with much reading i figured it out and it all makes sense now. I added this to my commanding::load(): ImageViewer *imgViewDlg; imgViewDlg = new ImageViewer(); imgViewDlg->Create(IDD_IMAGEVIEWER, NULL); imgViewDlg->SetWindowPos(NULL, 0, 0, 700, 700,SWP_NOMOVE); imgViewDlg->ShowWindow(SW_SHOW); & then I call the showImage() imgViewDlg->showPicture(buff,numRead); and this seems like it is working. now i'm just looking to see if there's a function for "isWindowActive" or something that i can check if the particular dialog box is inactive because I don't nessesarily want to keep updating the pictures if the window is in the background and someother window is on top of it. thanks!

                    Kitty5

                    H 1 Reply Last reply
                    0
                    • K kitty5

                      Hi everyone. thanks for responding it's been really helpful. with much reading i figured it out and it all makes sense now. I added this to my commanding::load(): ImageViewer *imgViewDlg; imgViewDlg = new ImageViewer(); imgViewDlg->Create(IDD_IMAGEVIEWER, NULL); imgViewDlg->SetWindowPos(NULL, 0, 0, 700, 700,SWP_NOMOVE); imgViewDlg->ShowWindow(SW_SHOW); & then I call the showImage() imgViewDlg->showPicture(buff,numRead); and this seems like it is working. now i'm just looking to see if there's a function for "isWindowActive" or something that i can check if the particular dialog box is inactive because I don't nessesarily want to keep updating the pictures if the window is in the background and someother window is on top of it. thanks!

                      Kitty5

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

                      See GetActiveWindow


                      WhiteSky


                      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