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. How do I update my main window from a dialog? [modified]

How do I update my main window from a dialog? [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++questionannouncementcareerlearning
7 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.
  • J Offline
    J Offline
    Jarley D G
    wrote on last edited by
    #1

    Hi, I´m new here and im self learning vc++ and mfc programming, add to this that I´m spanish speaking native, so please excuse my english, I will do my best so you all can understand me. Well, what I´m doing in resume is this : I have a CDialog logon screen in my program, where the user enter his password and username. So I need to save the user and update the Main window with who just logged in. By the way, I´m working in a Dialog Based App. So in my class RegisterApp : public CWinApp I do this :

    class RegisterApp : public CWinApp
    {
    public:
    RegisterApp();
    CString sActiveUser;//A member var to save the active user.
    .
    .

    I Initialize it :

    RegisterApp::RegisterApp()
    {
    sActiveUser = "No user logged";
    }

    Then at my RegisterAppView::OnPaint() I show before the login that there´s no user: I can see it well at the Main window that is at the background, and at front "OnTop" I got the little logon window.

    RegisterApp* pApp;
    pApp = (RegisterApp*)AfxGetApp();
    dc.TextOut(105,60,"Usuario activo : " + pApp->sActiveUser);

    I don´t know if this is the best way, but it works and shows what I want at this moment "No user logged" . Now, when the user logs in I do this :

    bool CDlgLogon::FiltraDatos()
    {
    RegisterApp* pApp;
    pApp = (RegisterApp*)AfxGetApp();
    CString sIdUsuario;
    GetDlgItemText(IDC_EDTLOGONUSER, sIdUsuario);
    .
    .//some code to check the user...
    .

        pApp->sActiveUser = sIdUsuario;
    

    .
    .
    }

    Ok, I´ve just updated sActiveUser, I got the user in a var out of the logon dialog function, So I think I will not loose it(I´m right?), but now I need to update the Main Window with this value, in graphical mode using dc.TextOut... Is correct that I should call the RegisterAppView::OnPaint() method again to show the actual user?. If it is, How do I do that from my dialog? Is this the correct way to do this? thanks in advance :) Jarley "Don't panic!. All will become clear in time"

    P 1 Reply Last reply
    0
    • J Jarley D G

      Hi, I´m new here and im self learning vc++ and mfc programming, add to this that I´m spanish speaking native, so please excuse my english, I will do my best so you all can understand me. Well, what I´m doing in resume is this : I have a CDialog logon screen in my program, where the user enter his password and username. So I need to save the user and update the Main window with who just logged in. By the way, I´m working in a Dialog Based App. So in my class RegisterApp : public CWinApp I do this :

      class RegisterApp : public CWinApp
      {
      public:
      RegisterApp();
      CString sActiveUser;//A member var to save the active user.
      .
      .

      I Initialize it :

      RegisterApp::RegisterApp()
      {
      sActiveUser = "No user logged";
      }

      Then at my RegisterAppView::OnPaint() I show before the login that there´s no user: I can see it well at the Main window that is at the background, and at front "OnTop" I got the little logon window.

      RegisterApp* pApp;
      pApp = (RegisterApp*)AfxGetApp();
      dc.TextOut(105,60,"Usuario activo : " + pApp->sActiveUser);

      I don´t know if this is the best way, but it works and shows what I want at this moment "No user logged" . Now, when the user logs in I do this :

      bool CDlgLogon::FiltraDatos()
      {
      RegisterApp* pApp;
      pApp = (RegisterApp*)AfxGetApp();
      CString sIdUsuario;
      GetDlgItemText(IDC_EDTLOGONUSER, sIdUsuario);
      .
      .//some code to check the user...
      .

          pApp->sActiveUser = sIdUsuario;
      

      .
      .
      }

      Ok, I´ve just updated sActiveUser, I got the user in a var out of the logon dialog function, So I think I will not loose it(I´m right?), but now I need to update the Main Window with this value, in graphical mode using dc.TextOut... Is correct that I should call the RegisterAppView::OnPaint() method again to show the actual user?. If it is, How do I do that from my dialog? Is this the correct way to do this? thanks in advance :) Jarley "Don't panic!. All will become clear in time"

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      In your code, what I understand is, you want to update main window(which shows user related stuff), once user logs in. OnPaint as you mentioned in right place to draw that stuff. But again you have mentioned RegisterAppView class. Can you tell what's it's base class, how it is related to logon dialog?

      Prasad Notifier using ATL

      J 1 Reply Last reply
      0
      • P prasad_som

        In your code, what I understand is, you want to update main window(which shows user related stuff), once user logs in. OnPaint as you mentioned in right place to draw that stuff. But again you have mentioned RegisterAppView class. Can you tell what's it's base class, how it is related to logon dialog?

        Prasad Notifier using ATL

        J Offline
        J Offline
        Jarley D G
        wrote on last edited by
        #3

        It´s not related, just that in this class is where i do all my drawing stuff and the first time i write the user at the main window, I do it from this class.

        class CRegisterAppView : public CScrollView
        {
        protected: // Crear sólo a partir de serialización
        CRegisterAppView();
        DECLARE_DYNCREATE(CRegisterAppView)
        .
        .
        .
        }

        thanks

        P 1 Reply Last reply
        0
        • J Jarley D G

          It´s not related, just that in this class is where i do all my drawing stuff and the first time i write the user at the main window, I do it from this class.

          class CRegisterAppView : public CScrollView
          {
          protected: // Crear sólo a partir de serialización
          CRegisterAppView();
          DECLARE_DYNCREATE(CRegisterAppView)
          .
          .
          .
          }

          thanks

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          jarleydg wrote:

          class CRegisterAppView : public CScrollView

          Oh !, you mentioned application in dialog based, isn't it? How come you got a view class. This application supports doc/view, is it?

          Prasad Notifier using ATL

          J 1 Reply Last reply
          0
          • P prasad_som

            jarleydg wrote:

            class CRegisterAppView : public CScrollView

            Oh !, you mentioned application in dialog based, isn't it? How come you got a view class. This application supports doc/view, is it?

            Prasad Notifier using ATL

            J Offline
            J Offline
            Jarley D G
            wrote on last edited by
            #5

            Yes, is dialog based and I have doc/view classes too. The wizard created me a View class, and i read that there I should do my drawings, I´m going by the book... Hope it isn´t wrong :S ... I just realize that when I logon the user and then resize the main window manually, the new user is displayed correctly. It works :) but how do I call that ::OnPaint method in my View Class from the logon dialog when I press Ok? That´s what i don´t know to do... thank´s

            P 1 Reply Last reply
            0
            • J Jarley D G

              Yes, is dialog based and I have doc/view classes too. The wizard created me a View class, and i read that there I should do my drawings, I´m going by the book... Hope it isn´t wrong :S ... I just realize that when I logon the user and then resize the main window manually, the new user is displayed correctly. It works :) but how do I call that ::OnPaint method in my View Class from the logon dialog when I press Ok? That´s what i don´t know to do... thank´s

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              Ok,Its because, its causing OnPain to call. when you want to modify window use this code,

              ((CFrameWnd*)AfxGetMainWnd())->GetActiveDocument()->UpdateAllViews(NULL);

              Prasad Notifier using ATL

              J 1 Reply Last reply
              0
              • P prasad_som

                Ok,Its because, its causing OnPain to call. when you want to modify window use this code,

                ((CFrameWnd*)AfxGetMainWnd())->GetActiveDocument()->UpdateAllViews(NULL);

                Prasad Notifier using ATL

                J Offline
                J Offline
                Jarley D G
                wrote on last edited by
                #7

                It works now!! thanks a lot for your help :)

                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