Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Simple Problems

gyanaroragyanarora Member Posts: 48
Hi
I am a novice in MFC programming.I have two different problems

1)I have made a simple SDI application using app wizard in which a class I have added MyDialogClass to handle IDD_DIALOG1.
Now I have some data which is stored in variables of Doc class.These variables I want to use in the constructor of MyDialogClass.So I need Doc class's pointer in this class.
How can i do that.

2)I need to know the Path of My Exe in one of my functions.
We have a variable in CWinApp::m_pszHelpFilePath to find the path of applicatons Help file But I want the Path of My Exe.
Regards
--Gyan

Comments

  • pingpongpingpong Member Posts: 937
    Hello,

    : 1)I have made a simple SDI application using app wizard in which a class I have added MyDialogClass to handle IDD_DIALOG1.
    : Now I have some data which is stored in variables of Doc class.These variables I want to use in the constructor of MyDialogClass.So I need Doc class's pointer in this class.
    : How can i do that.

    Depends where are you starting the dialog from? Let's take the worst case, from your CWinApp:

    AfxGetMainWnd() get a pointer to the main window (A CFrameWnd class).
    And in CFrameWnd, theres a CView* GetActiveView() function.
    And in CView theres a CDocument* GetDocument() function.
    So you need:

    [code]
    CMyDoc* pDocument = (CMyDoc*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView()->GetDocument();
    [/code]

    Where CMyDoc is the name of your document class.

    #include "MyDoc.h" if needed.

    :
    : 2)I need to know the Path of My Exe in one of my functions.
    : We have a variable in CWinApp::m_pszHelpFilePath to find the path of applicatons Help file But I want the Path of My Exe.

    Both of these work

    [code]
    TCHAR szExePath[_MAX_PATH];
    lstrcpy(szExePath, __argv[0]);
    AfxMessageBox(szExePath);
    [/code]

    [code]
    TCHAR szExePath[_MAX_PATH];
    lstrcpy(szExePath, (TCHAR*)(GetCommandLine() + 1));
    int i = 0;
    while(szExePath[i] != '"') i++;
    szExePath[i] = '';
    AfxMessageBox(szExePath);
    [/code]

    First version uses __argv, so it only works in VC++ as far as I know.
    Second version has no special code and should work in BCB, Dev++ etc.

  • gyanaroragyanarora Member Posts: 48
    Hi friend
    Thanks for your cooperation I helped me lot.
    --Gyan
    : Hello,
    :
    : : 1)I have made a simple SDI application using app wizard in which a class I have added MyDialogClass to handle IDD_DIALOG1.
    : : Now I have some data which is stored in variables of Doc class.These variables I want to use in the constructor of MyDialogClass.So I need Doc class's pointer in this class.
    : : How can i do that.
    :
    : Depends where are you starting the dialog from? Let's take the worst case, from your CWinApp:
    :
    : AfxGetMainWnd() get a pointer to the main window (A CFrameWnd class).
    : And in CFrameWnd, theres a CView* GetActiveView() function.
    : And in CView theres a CDocument* GetDocument() function.
    : So you need:
    :
    : [code]
    : CMyDoc* pDocument = (CMyDoc*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView()->GetDocument();
    : [/code]
    :
    : Where CMyDoc is the name of your document class.
    :
    : #include "MyDoc.h" if needed.
    :
    : :
    : : 2)I need to know the Path of My Exe in one of my functions.
    : : We have a variable in CWinApp::m_pszHelpFilePath to find the path of applicatons Help file But I want the Path of My Exe.
    :
    : Both of these work
    :
    : [code]
    : TCHAR szExePath[_MAX_PATH];
    : lstrcpy(szExePath, __argv[0]);
    : AfxMessageBox(szExePath);
    : [/code]
    :
    : [code]
    : TCHAR szExePath[_MAX_PATH];
    : lstrcpy(szExePath, (TCHAR*)(GetCommandLine() + 1));
    : int i = 0;
    : while(szExePath[i] != '"') i++;
    : szExePath[i] = '';
    : AfxMessageBox(szExePath);
    : [/code]
    :
    : First version uses __argv, so it only works in VC++ as far as I know.
    : Second version has no special code and should work in BCB, Dev++ etc.
    :
    :

  • Chris BrownChris Brown USAMember Posts: 4,624 ✭✭

    ____ // http://forcoder.org // free video tutorials and ebooks about ( Delphi, Objective-C, Go, Scratch, C#, R, C++, Visual Basic, PL/SQL, Assembly, Perl, Java, Ruby, PHP, C, Python, Swift, JavaScript, MATLAB, Visual Basic .NET FoxPro, Ada, Clojure, Scala, Rust, Scheme, ABAP, Crystal, Bash, Lisp, Fortran, Lua, F#, Kotlin, Transact-SQL, Logo, Prolog, Awk, Dart, Alice, Hack, VBScript, SAS, Julia, COBOL, D, Erlang, LabVIEW, ML, Apex ) _____

Sign In or Register to comment.