Read and reflect the data files you want to place in the list control from the menu bar.
I am currently able to install a menu bar in the mainframe and read the file from the open menu, but I do not know how to communicate this information to the view.
I would appreciate it if someone could give me some advice.
(Modified view of SDI project created in VS2015 to place list control)
Headers and sources with the following names are automatically generated:
app
appDoc
appView
FileView
MainFrm
FileView has listCtrl.
The file loading process is handled by OnFileOpen() in app.cpp.I don't know how to reflect this result in FileView.
VS2015
MFC
C++
win10 64bit
MFC = Welcome to the world of relics of the past.
There are more .Net sites such as C# and CLI.
"With Win32, ""Windows programming that even cats can understand"""
There are sites that are mainly implemented, so it's hard to understand why MFC is now.
MFC is difficult to learn and many things are broken now, but
Please take your time.
As a precondition, I am
·I am using Visual Studio 2019 Preview.
Please forgive the environmental differences.
·In Visual Studio 2015, strings are divided by delimiters and arranged
I don't have a good Split function, so I think I have to make it myself.
The C++11 collection class std::vector is getting better and
I would recommend that you migrate to Visual Studio 2019.
·Be sure to set the locale settings. Even if you think you're using a function normally,
I often have strange movements.
Do not omit specifically around the file or the screen.
·Not only MFC but also VC++ is often out of reach of itchy places.
Please forgive me again.
This is a simplified version of the method, not the one shown by Hiroyuki.
The policy is to read and write in the view class without keeping data in the document class.
The original method is
as indicated by the link.
Read and save data in document class
You might want to view document class data in a view.
There were many abstract expressions on the reference site and there were not many examples of implementation.
Do you understand?
The policy is
①First, I will recreate the project.
②Configures the locale.
③Create a void OnUpdate (CViewpView, UINTlHint, CObjectpHint); in the view class to implement the read operation.
Let's go like this.
①Please recreate the project first.
There is an appView, but FileView is a mystery.
Re-create the project name with app.
1) On the Application Type tab,
In the
Application Type(T) drop-down list
Select Single Document.
2) The "Document Template Properties" tab is
as you like.
File Extensions (X), Filename (N), and Mainframe Caption (P)
Please set it up.
3) For the User Interface Features tab, see
Change your preferences.
4) Remove unnecessary panes from the Advanced Features tab.
□ Dockable Explorer Pane
□ Dockable Output Pane(&S)
□ Dockable Properties Pane
Uncheck the .
5) On the Generated Classes tab
Generated Class (&G) drop-down list contents
Change to View and
Change "Basic Class (A)" to "CListView" and
Press the Finish button.
ロケ Set the locale.
1) Add #include<locale.h> to the file appapp.cpp 」.
2) Add _tsetlocale(LC_ALL,T("Japanese")); to the constructor.
#include "pch.h"
# include "framework.h"
# include "afxwinappex.h"
# include "afxdialogex.h"
# include "app.h"
# include "MainFrm.h"
# include "appDoc.h"
# include "appView.h"
# ifdef_DEBUG
# define new DEBUG_NEW
#endif
// ▽▽▽From Coco▽▽▽
# include <locale.h>
// △△△ Up to Coco △△△
// CappApp
BEGIN_MESSAGE_MAP (CappApp, CWinAppEx)
ON_COMMAND (ID_APP_ABOUT, & CappApp:: OnAppAbout)
// Standard File Basic Documentation Commands
ON_COMMAND (ID_FILE_NEW, & CWinAppEx::OnFileNew)
ON_COMMAND (ID_FILE_OPEN, & CWinAppEx::OnFileOpen)
// Standard Print Setup Commands
ON_COMMAND (ID_FILE_PRINT_SETUP, & CWinAppEx::OnFilePrintSetup)
END_MESSAGE_MAP()
// Building a CappApp
CappApp::CappApp()noexcept
{
m_bHiColorIcons=TRUE;
// US>Support for Restart Manager
m_dwRestartManagerSupportFlags=AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
# ifdef_MANAGED
// If the application was created using Common Language Runtime Support (/clr):
// 1) This additional configuration is required for restart manager support to function properly.
// 2) To create it, you need to add a reference to System.Windows.Forms to the project.
System::Windows::Forms::Application::SetUnhandledExceptionMode (System::Windows::Forms::UnhandledExceptionMode::ThrowException);
#endif
// TODO—Replace the application ID string below with a unique ID string.recommended
// The string format is CompanyName.ProductName.SubProduct.VersionInformation.
SetAppID(_T("app.AppID.NoVersion"));
// TODO: Add a build code to this location.
// Describe all important initialization actions during InitInstance here.
// ▽▽▽From Coco▽▽▽
_tsetlocale(LC_ALL,_T("Japanese"));
// △△△ Up to Coco △△△
}
*The example shows [#include "pch.h"], but in VS2015, it is [#include "stdafx.h"].
Please forgive this area as it varies depending on the environment.
ビュー Implement by adding OnUpdate() to the view class.
1)Select
CappView from Class View and
from the Properties pane
Select the Override button.
If you select <Add>OnUpdate from the drop-down list to the right of OnUpdaye,
Functions and function declarations are added to the source and header.
2) Remove the lHint comment out of the second argument of OnUpdate() and implement it as follows:
//CappView Message Handler
// Splitter:
int Split (CSstringArray & arFields, LPCTSTR pFields = nullptr, LPCTSTR pDelimiters = nullptr)
{
int nResult = 0;
arFields.RemoveAll();
// Do not process empty strings.
if (pFields & *pFields & *pDelimiters & *pDelimiters)
{
CStringsFields=pFields, sDelimiters=pDelimiters;
intnEnter=0, nLeave=sFields.Find(pDelimiters, nEnter);
while(-1!=nLeave)
{
// Byusing SetAtGrow(), empty strings are automatically added to the array.
arFields.SetAtGrow(nResult, sFields.Mid(nEnter, nLeave-nEnter)));
nResult++;
nEnter=nLeave+sDelimiters.GetLength();
nLeave=sFields.Find(pDelimiters, nEnter);
}
arFields.SetAtGrow (nResult, sFields.Mid(nEnter));
nResult++;
}
returnnResult;
}
// Implementation of an override function to rewrite the view called upon successful OnFileNew() and OnFileOpen()
void CappView::OnUpdate(CView*/*pSender*/, LPARAM lHint, CObject*/*pHint*/)
{
// TODO: Add a specific code here or call the base class.
CListCtrl&rList=GetListCtrl();
BOOL bResult=TRUE;
intnMaxCols = 0;
if(!lHint)
{
CHEADERCtrl*pHead=rList.GetHeaderCtrl();
if(pHead)
{
nMaxCols=pHead->GetItemCount();
}
for (intnCol=nMaxCols-1;bResult&&0<=nCol;nCol--)
{
bResult=rList.DeleteColumn(nCol);
};
bResult=rList.DeleteAllItems();
}
CStringsValue=GetDocument()->GetPathName();
if(bResult&&!sValue.IsEmpty())
{
bResult=false;
FILE*fp=nullptr;
errno_tnError=_tfopen_s(&fp,sValue,_T("r"));
if(!nError&fp)
{
if(lHint)
{
}
else
{
bResult = true;
for (int nRow=-1; bResult & !feof(fp); nRow++)
{
bResult=nullptr!=_fgetts(sValue.GetBuffer(8193), 8192, fp);
sValue.ReleaseBuffer();
if(bResult)
{
sValue.Replace(_T("\n"),_T(""));
CSstringArrayar;
nMaxCols=Split(ar,sValue,_T(","));
for (intnCol=0; bResult&nCol<nMaxCols;nCol++)
{
bResult=false;
sValue = ar [nCol];
if (-1 == nRow)
{
bResult=nCol==rList.InsertColumn(nCol,sValue,LVCFMT_LEFT,96);
}
else
{
if(!nCol)
{
bResult=nRow==rList.InsertItem(nRow,sValue);
}
else
{
bResult=rList.SetItemText(nRow,nCol,sValue);
}
}
};
Split(ar);
}
else
{
bResult=!feof(fp);
}
};
}
fclose(fp);
}
}
}
Now it's done.
Try it.
Also,
3)Implement View Switching
4)Change initial attributes in PreCreateWindow
5)Set extended attributes in OnCreate()
6)Add Unread and Read Display Changes in OnInitialUpdate
and so on, but try your best.
© 2024 OneMinuteCode. All rights reserved.