how to use MFC to realize the function instead of C
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: how to use MFC to realize the function instead of C

  1. #1
    Join Date
    Aug 2011
    Posts
    21

    Wink how to use MFC to realize the function instead of C

    Dear all,

    I'm brand new to VC++, I want to realize the function using MFC instead of c, I will be appreciate it if you can give me some help . thank you in advance !
    Attached Files Attached Files

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,106

    Re: how to use MFC to realize the function instead of C

    If you were us reading that post and looking at that code, would you have any idea what you were talking about. If you mean you want to convert a C app to an MFC based Windows app, that's way beyond the scope of what you can get from a bulletin board. Head on down to the bookstore and buy any of the 1,000 page tutorial books and work through them.

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,990

    Re: how to use MFC to realize the function instead of C

    I'm brand new to VC++, I want to realize the function using MFC instead of c, I will be appreciate it if you can give me some help .
    There's nothing wrong in being brand new to something but wanting to do something more than trivial. In general what you need is to stop being brand new and gain some experience enough to accomplish what you want. To implement something in MFC you need to learn C++ and MFC. To re-implement a program you need to understand what and why it does to do what it does. To understand what original C program does you need to learn C and libraries it has in use if any.

    The forum is intended to give answers to concrete questions. So we won't be able to teach you MFC or C, but you need identify your problems, convert those to questions and comprehend our answers. Which expects from you some knowledge and experience above the just stated "brand new to VC++".

    Having all the said in mind, what kind of help do you expect from us right now?
    Best regards,
    Igor

  4. #4
    Join Date
    Aug 2011
    Posts
    21

    Re: how to use MFC to realize the function instead of C

    Thank you very much for your advices, I will try my best to learn C++ and MFC from now , I have to accomplish this task in a few days , maybe I will ask for your advices again if I meet some trouble ,thank you in advance . maybe you find what I said strange, that's because I am
    also new to English ,but as you said ,I will stop being brand new, I will try to express myself clearly in the near future. in a word ,thank you very much

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,106

    Re: how to use MFC to realize the function instead of C

    Quote Originally Posted by Angela2010 View Post
    Thank you very much for your advices, I will try my best to learn C++ and MFC from now , I have to accomplish this task in a few days , maybe I will ask for your advices again if I meet some trouble ,thank you in advance . maybe you find what I said strange, that's because I am
    also new to English ,but as you said ,I will stop being brand new, I will try to express myself clearly in the near future. in a word ,thank you very much
    Your English is fine. Your task isn't possible. You can't learn C++ and MFC in only a few days.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,990

    Re: how to use MFC to realize the function instead of C

    I will try my best to learn C++ and MFC from now
    The thing is that the description of requirements is really vague. The original program in a console app. And I cannot see any reason why would MFC be a requirement for a console app.

    Okay, I can imagine it was implied to re-implement it presenting some GUI which is what MFC really belongs with. And now the main problem should be clearly understood: typically it's highly non-trivial to design GUI app behavior/workflow having a console app as a sample. Absolutely different approaches to be in effect.
    Best regards,
    Igor

  7. #7
    Join Date
    Aug 2011
    Posts
    21

    Re: how to use MFC to realize the function instead of C

    Hi,Igor
    (--I wish it is polite to call your name like this, ) I have made a little progress today,now I have a little trouble.
    1、In C language it is expressed as " printf ("Camera USB driver version : %s\n", instr.version_cam_driver); ", I want to use MessageBox() in MFC to show "Camera USB driver version "and instr.version_cam_driver in one box. but I don't know how to show them together
    2、"WFS_RevisionQuery () " is a sensor's library function (assume it belongs to class T), can I use it immediately after including the header file , or I have to define an object like this:
    T test; test.WFS_RevisionQuery ()
    It's difficult for me to express these things clearly in English , I wish you can understand what I said, thank you for your help .

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,990

    Re: how to use MFC to realize the function instead of C

    1. You need to build/format a string prior to outputting it with MessageBox:
    Code:
    CString msg;
    msg.Format(_T("Camera USB driver version : %s\n"), instr.version_cam_driver); // pretty much the same :)
    AfxMessageBox(msg);
    2. Considering how WFS_RevisionQuery() is used in main() I suppose you can call it immediately. But don't forget to include the corresponding lib file into your project.
    Best regards,
    Igor

  9. #9
    Join Date
    Aug 2011
    Posts
    21

    Re: how to use MFC to realize the function instead of C

    Hi,Igor
    I solved the problem using your method ,thank you very much , I met another trouble:
    In C language, it can be written as:
    printf("Centroid_x = %6.3f mm\n", beam_centroid_x);
    printf("Centroid_y = %6.3f mm\n", beam_centroid_y);
    ...........
    There are so many data to be saved ,I want to save them into a txt file. I use the following method:
    ofstream out( "zernike.txt ");
    out<<"Centroid_x = %6.3f mm\n"<<beam_centroid_x;
    the thing is "%6.3f " isn't replaced with the value of beam_centroid_x , "Centroid_x = %6.3f mm\n" is directly printed. is there something wrong with my method,or are there any better methods ? Thank you in advance for your help;

  10. #10
    Join Date
    Apr 1999
    Posts
    27,429

    Re: how to use MFC to realize the function instead of C

    Quote Originally Posted by Angela2010 View Post
    There are so many data to be saved ,I want to save them into a txt file. I use the following method:
    ofstream out( "zernike.txt ");
    out<<"Centroid_x = %6.3f mm\n"<<beam_centroid_x;
    the thing is "%6.3f " isn't replaced with the value of beam_centroid_x , "Centroid_x = %6.3f mm\n" is directly printed. is there something wrong with my method,or are there any better methods ? Thank you in advance for your help;
    Streams are completely different than printf() or printf()-like functions. The only similarities is that both methods output data.
    Code:
    ofstream   out( "zernike.txt "); 
    out<<"Centroid_x = " << beam_centroid_x << "\n";
    Start with that first. Then learn that you have I/O manipulators such as setprecision(), to control how many decimal digits to output. You don't use "6.3f" or anything even remotely similar to that when using streams.

    http://www.cplusplus.com/reference/i.../setprecision/
    http://www.cplusplus.com/reference/iostream/

    Another alternative is to still use CString::Format(), and then just output the entire formatted string at once.
    Code:
    ofstream   out( "zernike.txt "); 
    CString str;
    str.Format( "Centroid_x = %6.3f mm\n", beam_centroid_x );
    out<< (LPCSTR)str;
    Yes, you can use Format() here, but the disadvantage using this (and with any printf()-like functions that have format specifiers) is if you make a mistake matching up the format specifier with the actual type of the variable being outputted, the program will exhibit undesired behaviour (either you get strange output, or the worse case scenario is that your program will crash). For example, you specify "6.3f" and the variable being outputted is a char or some other type that isn't a float.

    That's why streams are safer -- you cannot mess up with the format specifier because they do not exist for streams -- you just output the variable and use the manipulators to display the value as desired. But you need to know how to use them (as I've specified above).

    Regards,

    Paul McKenzie

  11. #11
    Join Date
    Aug 2011
    Posts
    21

    Re: how to use MFC to realize the function instead of C

    Thank you Paul McKenzie, I solved the problem using the second method you suggested. it works well. there's something wrong when I use the first method .It reminds something wrong with "cout << fixed;",even though I include the header file. but it doesn't matter. Now ,I have a new problem. the function of the code below is to show the detected available instruments and then select one from the lists. I want to know how can I convert the C language to MFC. I cannot use getchar() now because I don't know where to input the number of the instruments. But should I use the dialog box which seems to make the thing complicated.
    Code:
    // List available Microlens Arrays
        ............
       printf("\nAvailable Microlens Arrays:\n\n");
       for(i=0;i<instr.mla_cnt;i++)
       {
            WFS_GetInstrumentListInfo (i, &device_id, &in_use, instr_name, serNr);
            printf("&#37;2d   %s   %s   %s\n", device_id, instr_name, serNr, (!in_use) ? "" : "(inUse)");
            ..........
       }
       // Select MLA
        printf("\nSelect a Microlens Array: ");
        fflush(stdin);
           *selection = getchar() - '0';
        if(*selection < -1)
           *selection = -1; // nothing selected
       return *selection;
    Thank you in adance for your help.

  12. #12
    Join Date
    Aug 2011
    Posts
    21

    Re: how to use MFC to realize the function instead of C

    thanks to your help. I finish my work on time
    Best wishes

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center