|
Hello
I am writing below code for reading file from disk, But again agian
i am getted failed.
CString str;
CString strLine = "";
CString buffer = "";
CFileDialog Obj(TRUE);
if(Obj.DoModal() ==IDC_BUTTON3)
{
m_Upload = Obj.GetFileName();
}
str.Empty();
str = Obj.GetPathName();
SetDlgItemText(IDC_EDIT1,str);
CStdioFile fileObj;
fileObj.Open("str", CFile::modeRead | CFile::shareDenyWrite);
while(fileObj.ReadString(strLine))
{
fileObj.ReadString(strLine);
buffer += strLine + "\r\n";
}
fileObj.Close();
MessageBox(buffer);
can any one in this community soly this problem .
Regard's
Kaushik
|
|
|
|
|
fileObj.Open("str", CFile::modeRead | CFile::shareDenyWrite);
remove these double quotation mark from str n then try it
fileObj.Open(str, CFile::modeRead | CFile::shareDenyWrite);
|
|
|
|
|
Thanks you so much Sir.
Again thank you. ( it was realy silly mistake by me)
Can you told me how we copy this file to another folder.
Actually i am writing a program in which user can browse .doc and .txt file from Harddisk and save it in database.
Now : i am doing to save .doc or .txt file in a folder on local PC and its name save in database.
I can save its name in database . I am unable to save file in to folder
if you can plz help me
Regard's
Kaushik
|
|
|
|
|
if you want to make a copy of this file in another folder
you have to create a new file using open function and passing the name in 1st parameter then passing second parameter as CFile::modeCreate....
then you read content of already created file an write in this newly created file ......
and your database point is not clear to me...
|
|
|
|
|
suppose new file name is temp. and i want to copy it to UserFile (UserFile is the name of folder located in c:\UserFolder ) then if we write code
for copy file in to folder how we assign the path of folder to file
fileObj.Open(temp,CFile::modeCreate);
its not clear how new file read data from old one and how we assing path its for saving temp to folder.
Regard's
Kaushik
|
|
|
|
|
you can't copy file in a folder but you can create a new file in the folder and then write contents to that file.
For creating new file in the folder u have code
CStdioFile file_ptr;
file_ptr.open("c:\\UserFolder\\UserFile\\temp.txt",CFile::modeCreate|mode::ReadWrite,NULL);
this will create a file in the specified folder with name temp.txt
now if you want to write the content into it open the previous file that contains content.Read the content a write it simultaneously....
|
|
|
|
|
Sir Ji I am very near for solving this problem ( Actually i am making such type of thing first time )
if i wrote this code
CString fname;
fname = fileObj.GetFileName();
MessageBox(fname);
it will be show file name
when i write
fileObj.Open("c:\\UserFolder\\temp.txt",CFile::modeCreate,NULL);
i can create file successfully
But in that case
fileObj.Open("c:\\UserFolder\\fname.txt",CFile::modeCreate,NULL);
file name become fname (Not actual file name) Why??
How can we read contant of old file and copy to new one simultaniously..
can you give me some hint regarding this .
Regard's
Kaushik
|
|
|
|
|
Y_Kaushik wrote: But in that case
fileObj.Open("c:\\UserFolder\\fname.txt",CFile::modeCreate,NULL);
file name become fname (Not actual file name) Why??
Because that's exactly what you told it to do.
Y_Kaushik wrote: How can we read contant of old file and copy to new one simultaniously..
Use the Read() and Write() methods. Start reading the documentation so that you are not asking the most basic of questions.
"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
|
|
|
|
|
Hi,
I have a MFC app with a main form (CMainFrame) and a dialog. How can I call a member function of CMainFrame from another dialog?
|
|
|
|
|
One way is to pass the CMainFrame into your dialog. Another is to use the m_pMainWnd member from your application object like this:
CMainFrame* mainFrame = dynamic_cast<cmainframe *="">(AfxGetApp()->m_pMainWnd);
mainFrame->doThisMemberMethod();
|
|
|
|
|
Hey, I tried that. But while compiling I am getting error:
error C2059: syntax error : ')'
I can't figure out why. Can u please help me?
|
|
|
|
|
Oh!
I looked at MSDN and found the correct way to use it.
The code should be as follows:
<code>
CMainFrame* mainFrame = dynamic_cast<CMainFrame*>(AfxGetApp()->m_pMainWnd);
mainFrame->doThisMemberMethod();
</code>
Thanks.
-- modified at 6:26 Sunday 17th June, 2007
|
|
|
|
|
Ooops. I copied the code from one of my own projects and had to rename things from my class name to CMainFrame. I accidentally erased <cmainframe *="">. Very sorry about that. Glad you still figured it out.
I ran into my own pet peeve of someone giving a code example which doesn't work.
|
|
|
|
|
Hmmm, strange. Apparently I did not erase it. It seems the forum is completely deleting my code. I just typed it again in my previous message and it does not show up in the post.
Somehow it worked when you typed it in your post. I wonder why.
|
|
|
|
|
StevenS_Dev wrote: It seems the forum is completely deleting my code.
No, it's there, albeit not shown. You are just failing to use the angle brackets above the smileys.
"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
|
|
|
|
|
Hi everyone. This is my first post ever :P
I am currently programming a MSVC(no MFC), WIN98/WINXP, TaskManager-like application that enumerates all running processes through PE32, and displays total and hidden HWNDs per PID and running status. Options for killing a PID, show/hide/close hwnds are also available. So far so good.
This program detects via SendMessageTimeout any HWND that is not responding, but what about the ones without any HWNDs? How can I detect if a PID is not responding if it is windowless?
CTRL-ALT-DEL shows (not responding) for the hanged windowless process, and maybe I could use that as a workaround, but I do not know how to access this information either.
Three days so far in the web without success. HELP!!!
|
|
|
|
|
Dear all
who can provide any a cube class snippet? thanks...
Li Zhiyuan
5/10/2006
|
|
|
|
|
class Cube
{
}
What did you want it to do ? Sounds like homework to me.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: class Cube
{
}
It won't work, you forgot the ; after the class
|
|
|
|
|
You beat me to it!
Kevin
|
|
|
|
|
Your code is helpful but it has a problem why other elements are transparent ?
|
|
|
|
|
You asked this question previous and but you said cube can you more explain?
|
|
|
|
|
Hi,
In my application,we have the GraphicsView function, which displays number of graphics page.
I have 40 graphics page as page1,page2....etc.,.
I have the shortcut key to go for graphics main page as F5.
From that i have to move to 40 pages subsequently by pressing pagedown button are directly click next button in my graphics pages.
My problem is....when iam pressing the pagedown key...and if the pages reaches 30 or 32 pages one error is ooured like Out of Space.
When i searched for the error occurence..I got the PageFile Usage in my TaskManager is get increased and once it reached certain MB like morethan 500 MB it shows me this error.
I coded my pagedown functon as follows...
BOOL CGraphView::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
UINT nChar = (UINT)pMsg->wParam;
UINT nKeyDown = (UINT)pMsg->lParam;
if((nChar == 33 || nChar == 34) && (nKeyDown == 21561345 || nKeyDown == 22085633))
{
short iTempPgNo = giSchPNo;
if(nChar == 33)
{
iTempPgNo--;
if(iTempPgNo < 0)
iTempPgNo = giSchPNo;
}
else
{
iTempPgNo++;
if(iTempPgNo >= iNoPages)
iTempPgNo = iTempPgNo - 1;
}
if(iTempPgNo != giSchPNo)
{
if(glg_animation[giSchPNo].GetSafeHwnd())
{
glg_animation[giSchPNo].ShowWindow(SW_HIDE);
giSchPNo = iTempPgNo;
((CMainFrame *)AfxGetMainWnd())->AddHistory(GRAPHIC,iTempPgNo);
}
}
return TRUE;
}
return CView::PreTranslateMessage(pMsg);
}
Here i know im coding only to hide the previous graphics page and not to destroy.So that only the memory get increased for each diaplay.
But i have OnDestroy() only after closing the entire graphicsView.
I donot know how to destroy the memory in that coding???Pls help me out.
Anu
|
|
|
|
|
Why, oh WHY, are you using PreTranslateMesssage() to read keystrokes?
You haven't even checked the MSG to see if is a keyboard message!
Maybe something like this...
ON_WM_KEYDOWN()
...
void CGraphView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(nChar == VK_PRIOR || nChar == VK_NEXT)
{
short iTempPgNo = giSchPNo;
if(nChar == VK_PRIOR)
{
iTempPgNo--;
if(iTempPgNo < 0)
iTempPgNo = giSchPNo;
}
else
{
iTempPgNo++;
if(iTempPgNo >= iNoPages)
iTempPgNo = iTempPgNo - 1;
}
if(iTempPgNo != giSchPNo)
{
if(glg_animation[giSchPNo].GetSafeHwnd())
{
glg_animation[giSchPNo].ShowWindow(SW_HIDE);
giSchPNo = iTempPgNo;
((CMainFrame *)AfxGetMainWnd())->AddHistory(GRAPHIC,iTempPgNo);
}
}
}
else
{
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
}
This may not fix your memory problems but it will make it easier to track for sure!
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
The code below will cause a heap error:
Error: HEAP[Core.exe]: Invalid Address specified to RtlFreeHeap( 00510000, 01CB45C8 )
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ThreadPool* pThreadPool = 0;
pThreadPool = ThreadHandlerEntry();
pThreadPool->Release();
return 0;
}
Inside pThreadPool->Release(), delete this is called, and that's where it fails. If I change the code to the below, where delete this has been taken out of pThreadPool->Release() and replaced with delete pThreadPool in WinMain(), it works.
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
ThreadPool* pThreadPool = 0;
pThreadPool = ThreadHandlerEntry();
pThreadPool->Release();
delete pThreadPool;
return 0;
}
Anyone know why this is?
|
|
|
|