คำตอบ Add Database to old MFC app

  • 28 กุมภาพันธ์ 2555 17:36
     
     

    I'm a c# programer and have been given an old MFC c++ app that I need to add a database to in a Dialog form. I used the wizard to add a "MFC ODBC Consumer" to the app. This seems to work well and added the DataSet with the RFX definitions to the project. It did not add a view or the DFX. How would I add the view and link to my Dialog box controls?

    Thanks in advance.

ตอบทั้งหมด

  • 28 กุมภาพันธ์ 2555 18:04
     
     

    Wizard is not part of the C++ language. 

    No data binding wizard for dialog-based apps in VC. If you use something like MVVM, you can write your data exchange code in DoDataExchange.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


  • 28 กุมภาพันธ์ 2555 20:31
     
     

    I believe I'm down to one line to get this to work. The example I found has a line

    m_pSet = &GetDocument()->m_UDataSet;

    where you are setting the view class, m_pSet, to the dialog box, m_UDataSet.

    In the example,

    CUDataView - is main form or document.
    CUDataSet* m_pSet
    CUDataDoc
    CudataSet m_UDataSet ;

    In my code,

    USBDataView- data set
    CPub_Numbers* m_pSet

    NumWatch - pop up dialog
    CPub_Numbers m_Pub_Numbers ;

    So m_UDataSet is of a document, in my code, NumWatch is of a dialog. So when I use code

    m_pSet = &GetDocument()->m_NumWatch; <==error CDocument has no member "m_NumWatch"

    so how do I set m_pSet to a pointer pointing to the dialog NumWatch?

  • 2 มีนาคม 2555 5:56
     
     
    GetDocument is function which gets a pointer to the view's document. So m_NumWatch is not a member of GetDocument .
  • 4 มีนาคม 2555 23:29
     
     
    The sample code is for the MFC add variable wizard which only support a formview, not a dialog.


    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

  • 6 มีนาคม 2555 17:49
     
     
    Is there a way to get a pointer to NumWatch since it is a dialog?
  • 6 มีนาคม 2555 20:10
     
     คำตอบ

    There are n no of way if it is your own dialog you can create object of your NumWatch class and can perform operation . If not you can use FindWindow() method to get the handle of the window . and if you want any child window on that then you can use EnumChildWindowProc() on your main dialog handle.

    Thanks


    Rupesh Shukla

    • ทำเครื่องหมายเป็นคำตอบโดย Rob PanModerator 8 มีนาคม 2555 7:14
    •  
  • 6 มีนาคม 2555 20:15
     
     
    Do it yourself. When you create the dialog you can save a pointer to it for future use. Store the pointer in the class that will need it.