Communicating dialog boxes
-
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
-
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
-
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
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, 2007Kitty5
-
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, 2007Kitty5
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
See
GetActiveWindow
WhiteSky