|
This sounds most promising...
|
|
|
|
|
Try mapping the file to memory. Also if you know the exact layout of the file you could define a struct and cast the pointer directly.
|
|
|
|
|
i have several sliders, i want to save the slider position to a file, and load the position from a file as well. I've never worked with I/O before, i'm quite lost.
here's the code:
<pre>
in the .h file:
int DataBuffer[2];
int nCount;
BOOL CIODlg::OnInitDialog(){
....
// TODO: Add extra initialization here
nCount=2;
}
void CIODlg::OnBnClickedSaveButton()
{
// TODO: Add your control notification handler code here
this->UpdateData();
CFile f;
CString strFilter;
strFilter.Format(_T( "TEXT Files (*.txt)|*.txt|All Files (*.*)|*.*||")) ;
CFileDialog FileDlg(FALSE, _T("*.txt"), NULL, 0, strFilter);
if( FileDlg.DoModal() == IDOK )
{
f.Open(FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
CArchive ar(&f, CArchive::store);
for(int i=0;i<2;i++)
{
DataBuffer[i]=m_Slider_Data[i].GetPos();
}
ar << nCount;
for(int i=0;i<nCount;i++)
ar<<DataBuffer[i];
ar.Close();
}
else
return;
f.Close();
}
void CIODlg::OnBnClickedOpenButton()
{
// TODO: Add your control notification handler code here
this->UpdateData();
CFile f;
CString strFilter;
strFilter.Format( _T("TEXT Files (*.txt)|*.txt|All Files (*.*)|*.*||" ));
CFileDialog FileDlg(TRUE, _T("*.txt"), NULL, 0, strFilter);
if( FileDlg.DoModal() == IDOK )
{
if( f.Open(FileDlg.GetFileName(), CFile::modeRead) == FALSE )
return;
CArchive ar(&f, CArchive::load);
ar >>nCount;
for(int i=0; i<nCount; i++)
{
ar<<DataBuffer[i];
m_Slider_Data[i].SetPos(DataBuffer[i]);
}
ar.Close();
}
else
return;
f.Close();
this->UpdateData(FALSE);
}</pre>
i got two questions:
1. is .txt a appropriate format for saving slider positions?
2. how come i got a Error trying to open the .txt file? (saving a file is fine, i guess)
<i>CArchive exception: readOnly.
First-chance exception at 0x7c812a5b in IO.exe: Microsoft C++ exception: CArchiveException at memory location 0x0012ef54..</i>
|
|
|
|
|
alberthyc wrote: 1. is .txt a appropriate format for saving slider positions?
That's up to you, but .txt files typically have text in them, while you are storing binary
data.
alberthyc wrote: 2. how come i got a Error trying to open the .txt file?
It looks like you used a wrong operator in CIODlg::OnBnClickedOpenButton():
ar<<DataBuffer[i];
should be
ar>>DataBuffer[i];
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you can simply use this pseudo code.
//to save the slider positions,
int sliderpositions[3];
for(int i=0;i<3;i++)
sliderpositions[i]=m_Slider_Data[i].GetPos();
FILE *fp;
fp=fopen("filename","wb");
fwrite(sliderpositions,4,3,fp);
fclose(fp);
//to retrieve slider postition
FILE *fp;
fp=fopen("filename","rb");
fread(sliderpositions,4,3,fp);
fclose(fp);
for(int i=0;i<3;i++)
m_Slider_Data[i].SetPos(sliderpositions[i]);
|
|
|
|
|
... you're not quite the sharpest tool in the shed, eh?
modified on Wednesday, December 8, 2010 9:53 AM
|
|
|
|
|
The calls to UpdateData() are not necessary.
You need to put a breakpoint in the two functions and single-step through them using the debugger. That will give you a BIG clue as to what is happening.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hello,
Is there somewhere on the web a description of the functions that hide behind the cryptic decorated function names in the C++ libraries like MSVCP60.DLL?
Searching with Google didn't help much.
|
|
|
|
|
Can you use Dumpbin or Depends?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thank you for the help.
I found depends.exe and it helps.
I did not find Dumpbin.exe however.
Is there a site where I can find this utility?
tia
|
|
|
|
|
fledgeling@be wrote: I did not find Dumpbin.exe however.
Where did you look? Mine is located in the C:\Program Files\Microsoft Visual Studio\VC98\Bin folder.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Run Depends on the DLL and use its feature that converts the decorated names to the equivalent prototype.
|
|
|
|
|
Thank you for the quick help.
Found depends.exe v2.2 which helps in clarifying the decorated names.
However, some "decorated" names are not processed : in MSVCP60.DLL the first 219 names are not translated.
Is there a newer version of depends.exe?
|
|
|
|
|
hmm, I got the undecorated names here using version 2.2.6000. You can get the latest version from dependencywalker.com[^]
|
|
|
|
|
When app uses ::HtmlHelp() function to display a html help window (for chm file), the window may be closed by user after view.
My Q is:
how to detect (in app programmatically) if user closed the html help window?
|
|
|
|
|
One way would be to put this code in another thread and have the thread signal you when it completes...
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "open";
ShExecInfo.lpFile = "test.chm";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
TRACE("The process has finished\n");
|
|
|
|
|
I'm making the VC++ project to create and edit the data(*.mdb) with SQL server.
I worry about, if this project is finish and want to run in another PC, or maybe I give this program to another person, how can he use my program.
He need to install SQL Server in his PC.
or have another way for embed a part of SQL Server in my program.
I have ever use the file *.mdb that make by Microsoft Access.
and I just embed this file in my exe.
but I'm not sure this also work in SQL Server.
Please advise me about this issue.
Thanks
-- modified at 8:29 Sunday 26th August, 2007
|
|
|
|
|
Max++ wrote: I'm making the VC++ project to create and edit the data (*.mdb) with SQL server.
Why?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am developing a MFC app (Windows Explorer style).
How can I control window's resizing behavior?
I want to make treeview and listview invisible and when they are
invisible the window size should be automatically reduced.
I am trying OnSize() but it's not working...
|
|
|
|
|
To get that kind've behavior, with adaptable frames, you could go all out and use a Docking control bar. Their more flexible than splitters since they are not attached to the view.
Docking[^]
|
|
|
|
|
In GDI i can draw rounded rectangle by pDC->RoundRect(...) method.
But i need to draw same using GDI+.
Please help.
|
|
|
|
|
GDI+ is just build on top of GDI.
If you look at the Graphics object, it has a GetHDC member, so you can do:
::RoundRect (pGfx->GetHDC(), ....)
or (maybe)
::RoundRect (*pGfx, ....);
I can't be bothered to check, but I think it has a HDC operator functiom, which means you can use it anywhere you can use a HDC.
Iain.
|
|
|
|
|
Iain Clarke wrote: GDI+ is just build on top of GDI.
In general this isn't the case. Here's an except from MSDN (underlines are mine):
Microsoft Windows GDI+ is a class-based API for C/C++ programmers. It enables applications to use graphics and formatted text on both the video display and the printer. Applications based on the Microsoft Win32 API do not access graphics hardware directly. Instead, GDI+ interacts with device drivers on behalf of applications. GDI+ is also supported by Microsoft Win64
GDI+ talks to the display driver using an interface know as DCI.
Steve
|
|
|
|
|
I knew it had some side paths - but I learn new things every day. Thanks for filling in the gaps I left.
Iain.
|
|
|
|
|
In addition to Iain's reply....
Make sure to call Graphics::ReleaseHDC() when you're done with the DC.
Any calls using the Graphics object will fail until you do
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|