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. Modeless dialog communicating with parent dialog

Modeless dialog communicating with parent dialog

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 2 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.
  • F Offline
    F Offline
    fjlv2005
    wrote on last edited by
    #1

    Good day, I'm reposting my problem since i havent got an answer. I have a two dialog(main, child), the main is the normal dialog when you start to create a dialog application in EVC. The child dialog is a modeless dialog here is how the child is called. CMyChild* childform=new CMyChild(this); childform->Create(CMyChild::IDD); childform->ShowWindow(SW_SHOW); The child also has a public function UpdateProgress bar which updates the progress bar of child dialog. I have also a function in child dialog which updates the text much the same as updating the progress bar. here is how it is called. CMainDlg::MyMainFunc() { CMyChild* childform=new CMyChild(this); childform->Create(CMyChild::IDD); childform->ShowWindow(SW_SHOW); childform->UpdateProgress(10); //updates the progress bar by 10 steps.. childform->UpdateProgressStatusText("Loading 10%"); // updates the static text But doesnt work.. childform->UpdateProgress(210); //updates the progress bar by 10 steps.. childform->UpdateProgressStatusText("Loading 20%"); // updates the static text But doesnt work.. } I'm sure that I change IDC_STATIC to IDC_LOADINGTEXT so id will not be the issue. My problem is why is that progress bar is updated with what i pass but UpdateProgressStatus is not updated with the text that I pass? Here is the two child functionss. void CMyChild::UpdateProgress(int pStep) { m_ctrlProgress.SetPos(pStep); } void CMyChild::UpdateProgressStatusText(char* text) { CString tmp; tmp=text; GetDlgItem(IDC_LOADINGTEXT)->SetWindowText(tmp); } Im sure that i set the property of IDC_LOADINGTEXT to visible. Still why is that the modeless dialog is not updated with the text I pass and the progress bar is updated.??:confused: Pls. Help. Thanks.

    K 1 Reply Last reply
    0
    • F fjlv2005

      Good day, I'm reposting my problem since i havent got an answer. I have a two dialog(main, child), the main is the normal dialog when you start to create a dialog application in EVC. The child dialog is a modeless dialog here is how the child is called. CMyChild* childform=new CMyChild(this); childform->Create(CMyChild::IDD); childform->ShowWindow(SW_SHOW); The child also has a public function UpdateProgress bar which updates the progress bar of child dialog. I have also a function in child dialog which updates the text much the same as updating the progress bar. here is how it is called. CMainDlg::MyMainFunc() { CMyChild* childform=new CMyChild(this); childform->Create(CMyChild::IDD); childform->ShowWindow(SW_SHOW); childform->UpdateProgress(10); //updates the progress bar by 10 steps.. childform->UpdateProgressStatusText("Loading 10%"); // updates the static text But doesnt work.. childform->UpdateProgress(210); //updates the progress bar by 10 steps.. childform->UpdateProgressStatusText("Loading 20%"); // updates the static text But doesnt work.. } I'm sure that I change IDC_STATIC to IDC_LOADINGTEXT so id will not be the issue. My problem is why is that progress bar is updated with what i pass but UpdateProgressStatus is not updated with the text that I pass? Here is the two child functionss. void CMyChild::UpdateProgress(int pStep) { m_ctrlProgress.SetPos(pStep); } void CMyChild::UpdateProgressStatusText(char* text) { CString tmp; tmp=text; GetDlgItem(IDC_LOADINGTEXT)->SetWindowText(tmp); } Im sure that i set the property of IDC_LOADINGTEXT to visible. Still why is that the modeless dialog is not updated with the text I pass and the progress bar is updated.??:confused: Pls. Help. Thanks.

      K Offline
      K Offline
      karmendra_js
      wrote on last edited by
      #2

      hi, I am not an expert but i have experinced through your knid of problem. here when you create the dialog box, you see there is an option redraw in its properties. Try executing it after changing the redraw property to no redraw. If then also it doesn't work, following is the solution (This is what i used). what i did was i created the modeless dialog box in the main thread and started a new thread. this new thread will do the work i wanted and then it calls the incrementprogress function of the dialog box class. Now the problem here is in the thread the dilog object wont be visible. to do this 1. easiest, you can delare the dialog object golbal. 2. recomended, you pass the object reference(this pointer) to the thread parameters. Tell me if it works, an ya don't forget to rate it.:-D

      F K 2 Replies Last reply
      0
      • K karmendra_js

        hi, I am not an expert but i have experinced through your knid of problem. here when you create the dialog box, you see there is an option redraw in its properties. Try executing it after changing the redraw property to no redraw. If then also it doesn't work, following is the solution (This is what i used). what i did was i created the modeless dialog box in the main thread and started a new thread. this new thread will do the work i wanted and then it calls the incrementprogress function of the dialog box class. Now the problem here is in the thread the dilog object wont be visible. to do this 1. easiest, you can delare the dialog object golbal. 2. recomended, you pass the object reference(this pointer) to the thread parameters. Tell me if it works, an ya don't forget to rate it.:-D

        F Offline
        F Offline
        fjlv2005
        wrote on last edited by
        #3

        Hello, I found another way to solve my problem though it may be not a solution to CStatic problem but this can be a work-around of displaying a progress text status. Though i have solve my own problem still I want to share info so that if someone encounter this problem, He/She may try our solutions (By No Redraw Sol., or By Thread Sol , or By Drawing Text Solution.).. Here is how I display the status to the child modeless dialog. void child::UpdateStatusMessage(char* pmessage) { CString strmsg; strmsg=pmessage; CDC* cDC=GetDC(); CFont HeaderTitle; RECT r; HeaderTitle.CreateFont(12,0,0,0,FW_BOLD,FALSE,FALSE,0,ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS, _T("Arial")); r.top=120; r.bottom=140; r.left=30; r.right=100; cDC->SelectObject(HeaderTitle); cDC->DrawText(strmsg,&r,DT_NOCLIP); ReleaseDC(cDC); } Thanks.

        K 1 Reply Last reply
        0
        • F fjlv2005

          Hello, I found another way to solve my problem though it may be not a solution to CStatic problem but this can be a work-around of displaying a progress text status. Though i have solve my own problem still I want to share info so that if someone encounter this problem, He/She may try our solutions (By No Redraw Sol., or By Thread Sol , or By Drawing Text Solution.).. Here is how I display the status to the child modeless dialog. void child::UpdateStatusMessage(char* pmessage) { CString strmsg; strmsg=pmessage; CDC* cDC=GetDC(); CFont HeaderTitle; RECT r; HeaderTitle.CreateFont(12,0,0,0,FW_BOLD,FALSE,FALSE,0,ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH | FF_SWISS, _T("Arial")); r.top=120; r.bottom=140; r.left=30; r.right=100; cDC->SelectObject(HeaderTitle); cDC->DrawText(strmsg,&r,DT_NOCLIP); ReleaseDC(cDC); } Thanks.

          K Offline
          K Offline
          karmendra_js
          wrote on last edited by
          #4

          hey buddy you need not do all this. just Change the ID of the static message from IDC_STATIC to anything else (IDC_TEXT). now go to class wizard and add a CString variable (msg) for IDC_TEXT. now when ever you want to update it just say

          UpdateData(true);
          msg="new messgae"
          UpdateData(false);
          

          :) Tell me if it works, yaa don't forget to rate it.

          1 Reply Last reply
          0
          • K karmendra_js

            hi, I am not an expert but i have experinced through your knid of problem. here when you create the dialog box, you see there is an option redraw in its properties. Try executing it after changing the redraw property to no redraw. If then also it doesn't work, following is the solution (This is what i used). what i did was i created the modeless dialog box in the main thread and started a new thread. this new thread will do the work i wanted and then it calls the incrementprogress function of the dialog box class. Now the problem here is in the thread the dilog object wont be visible. to do this 1. easiest, you can delare the dialog object golbal. 2. recomended, you pass the object reference(this pointer) to the thread parameters. Tell me if it works, an ya don't forget to rate it.:-D

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

            well if u don't know much threading then you are same as i was a month back. For threading search codeproject articles ( i don't have collection of it to tell you). any way i will paste my code here if you can make sense out of it.

            //defined in CMainFrame class
            DlgProgress *dlglocprog;
            
            //this type of threading is used forcalling a member function in a seperate thread
            
            //This thread function calls a member function FunctionClients of class MainFrm
            DWORD WINAPI PseudoThreadFunction( IN LPVOID vThreadParm )
            {
            	CMainFrame* pThreadParam = ( CMainFrame* ) vThreadParm;
            	pThreadParam->FunctionClients();
            	return 1;
            }
            
            //This Funnction will call PseudoThreadFunction() as a new thread.
            bool CMainFrame::ExecuteLocateThread(void)
            {
            
            	HANDLE hThread = NULL;
            	DWORD dwThreadID = 0;
            	int nTimeout = 5000;
            
            	try
            	{
            		hThread = CreateThread( NULL, // Pointer to thread security attributes
            					0, // Initial thread stack size, in bytes
            					PseudoThreadFunction,
            					this, // The argument for the new thread is a pointer to your MyThread
            					0, // Creation flags
            					&dwThreadID ); // Pointer to returned thread identifier
            	}
            	catch( CException* /* pException */ )
            	{
            		return false;
            	}
            
            	bool bFinished = false;
            	do
            	{
            
            		DWORD dwWaitResult = MsgWaitForMultipleObjects(
            								1,
            								& hThread,
            								FALSE,
            								nTimeout,
            								QS_ALLEVENTS | QS_SENDMESSAGE);
            
            		switch ( dwWaitResult )
            		{
            			case WAIT_OBJECT_0 :
            			case WAIT_ABANDONED_0 :
            				{
            					bFinished = true;
            					break;
            				}
            			case WAIT_OBJECT_0 + 1 : // message(s) in queue
            				{
            					MSG msg;
            					while ( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) == TRUE )
            					if ( !AfxGetApp( )->PumpMessage( ) )
            					{
            						::PostQuitMessage( 0 );
            					}
            					break;
            				}
            			default :
            				{
            					bFinished = true;
            				}
            		}
            	} while ( ! bFinished );
            
            	return true;
            
            }
            
            void CMainFrame::FunctionClients(void) 
            {
            		
            	for(unsigned short addr=1;addr<256;addr++)
            	{
            		vi_Progress=addr;
            		dlglocprog->IncrementProgress();//Increments the progress value and updates the message
            		Sleep(10);
            	}
            	dlglocprog->EndDialog(0);//ShowWindow(SW_HIDE);//DestroyWindow();//
            	b_LocateProgress=false;
            }
            
            void CMainFrame::OnClientoptionsLocateallactiveclients()
            {
            	// TODO: Add your command handler code here
            	if(!b_LocateProgress)
            	{
            		b_LocateProgress=true;
            		dlglocprog = new  CLocateProgress();
            		dlglocprog->Create(IDD_LOCATING_CLIENTS);
            		dlglocprog->ShowWindow(SW_SHOW);
            		dlglocprog->Ce
            
            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