Results 1 to 9 of 9

Thread: MyFunction

  1. #1

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Question MyFunction

    Sorry this question maybe stupid and Iam really a Newbie in C++ programming. And this is more a Question about Microsoft Visual C++ as a Question for common Standarts.

    I want to Implement my own Function in a MFC Dialog Program.

    Therefore I had to know how the Declaration of the Function has to look like. I need access to all my Membervariables used by my Application.
    Secondly I need to know how the Functionbody must look like.
    At last how to call the Function.

    Any help is welcome, sorry about my direful English,

    Myvar

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is also a forum for questions about VC++ and MFC, and ALL other things related with C and C++, but you rather should learn C++ first before you dive into API and MFC.

    You r question shows that you son't really know how to program C++, so you should not try to program MFC. See the faq for links.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Knowlege

    I have already impemented Functions without MFC in Consoleprograms with C or C++.



    Now I have to implement a Function in a Application with MFC and a GUI.

    Thanks CornedBee for your advanced Help

    So in the FAQ i do not see any Example for Implementing a Function.

    May sombody else is able to help me with my Problem?

    Thanks,

    Myvar

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Have you written classes in the console too?
    And why should implementing a function in MFC should be any different from doing it in a console app? It's both C/C++ after all...

    Whatever, here's how to write a class with member functions:
    Code:
    class Blabla
    {
        int m_i;
      public:
        void SetMember(int i) {m_i = i;};  // implementing directly in class
        int GetMember();
        double DoLenghty(double d);
    };
    
    // inline member function implemented outside class, use for really short functions
    inline int Blabla::GetMember()
    {
      return m_i;
    }
    
    // normal member function outside class:
    double Blabla::DoLengthy(double d)
    {
       // do very complicated and mystic calculations
       return SomeDoubleValue;
    }
    And if you didn't know this then you ARE a newbie and shouldn't be programming MFC.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And I meant the links in the faq, not the examples.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396

    Re: MyFunction

    Originally posted by Myvar

    Therefore I had to know how the Declaration of the Function has to look like. I need access to all my Membervariables used by my Application.
    Declare the global function as a friend of the class.

    Here another way, make that function, a member function of the class whose data members you need to access.

    Either way, you have to manually edit the derived MFC yourself.

    Original posted by CornedBee

    Your question shows that you don't really know how to program C++, so you should not try to program MFC.

    I felt that CornedBee is correct.
    I'm a VB6 beginner.

  7. #7

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Question Microsoft Visual C++

    Thanks for replying.

    At this Time I do not need any pieces of Code or stuff like this.
    Iam able to write that by my own.
    What I need is to know where the Declaration had to be. Is more a Question about Microsoft Visual C++ as a Question for common Standarts. If you know Microsoft Visual Studio u know there are lots of Files containing in the Workspace of each Project. Thats confuses me. Not how I would declare a Structure or a Class is here the Problem. Ive done that as well in other (Console) Aplications. So please tell me where the Declaration of a own Function had to be declarared (if u know).

    In my Project aktually there are this Files:
    Sourcefiles:
    StdAfx.cpp
    Blah.cpp // in there is the Code i have written
    Blah.rc
    BlahDlg.cpp // in there i declared the Functions Body
    Headerfiles:
    Resource.h
    StdAfx.h
    Blah.h // in here i declared the Funktion as public: MyFunc();
    BlahDlg.h
    ... other Files like my integrated Resources arent interesting here.
    I do not want to use AfxGetApp()->MyFunc(); at all, if this is possible. Doing it by this way any other Variables arent seen by my Function. I need acess to all my other Membervariables uses by the Aplication.

    Isnt there a easy way to Implement that stupid Function (MyFunc)whitch was only written to make my Code more readable und shorter?

    Thanks anyway,

    Myvar

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I'm still not sure what you want. MFC is a collection of classes that work together in a very complicated scheme.
    A function that has access to all your member variables... of which class? CYourApp? CBlahDlg? Where do you want to call it? What does it do? There are so many things one has to consider in OOP.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Smile Success

    My Function must have access to the Membervariable in BlahDlg, for Example m_iCombo_Index, m_cStart_Button ....
    And i wanted to call the Function from within BlahDlg.cpp in a Memberfunction of the same class. Therefor as well I had to Declare the Function as public in BlahDlg.h and define Funktionsbody in BlahDlg.cpp and call it with MyFunc(); That was all.

    Thanks for dont let my stop thinking.

    Myvar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width