How do I update my main window from a dialog? [modified]
-
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"
-
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"
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 mentionedRegisterAppView
class. Can you tell what's it's base class, how it is related to logon dialog?Prasad Notifier using ATL
-
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 mentionedRegisterAppView
class. Can you tell what's it's base class, how it is related to logon dialog?Prasad Notifier using ATL
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
-
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
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
-
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
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
-
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
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
-
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
It works now!! thanks a lot for your help :)