|
<br />
CFile f;<br />
CFileStatus fs;<br />
<br />
if(f.GetStatus(lpszFileName, fs))<br />
{<br />
}<br />
else<br />
Arjan
|
|
|
|
|
GetFileAttributes(path) != (DWORD)-1
But this makes sense only if you can drop additional code between the check and the file open request
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
|
_access() is one of several ways.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I think opening the file with fopen() or CFile() would be easy and fast. I use that function too:
BOOL FileExists(LPCTSTR lpFileName)
{<br />
DWORD dwFileAttr = GetFileAttributes(lpFileName);<br />
<br />
if ((dwFileAttr != 0xFFFFFFFF) &&<br />
!(dwFileAttr & FILE_ATTRIBUTE_DIRECTORY))<br />
return TRUE;<br />
else<br />
return FALSE;<br />
}
I think that should be enough solutions for that problem.
|
|
|
|
|
Joel Holdsworth wrote:
I want to check if a file path I have is valid and refers to a file before actually going ahead and opening it. Is there a quick and easy way using MFC, the Platform SDK, or the runtime library to check this?
there is api called PathFileExist(),try that
-----------------------------
"I Think It will Work"
Formerly Known As "Alok The Programmer" at CP
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I've to check the status of a TCP connection (managed using CSocket objects) in order to know the status of the remote client/server and the status of the physical connection.
I've implemented a dedicated thread that periodically tryes to send a zero byte packet to the client/server.
It works good to check the status of the remote client/server but, if the physical connection is broken (cable disconnected) it doesn't works! The send operation doesn't fail !
How can I detect the physical disconnection ?
Are there some specific settings for the CSockect object ?
Thanks a lot !
|
|
|
|
|
I am not familiar with CSocket. In raw winsock, one solution is via select().
Kuphryn
|
|
|
|
|
You derive from it and override CAsyncSocket::OnClose()
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Hi,
Is there a rule of MFC that does not allow thread creation from CMainFrame?
The situation is the following:
I have a menu function that wants to create a thread using
::CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) ThreadAnalyse, &m_stThreadArg, 0, &dw);
The ThreadAnalyse Function is a static global function, not a member of CMainFrame. The m_stThreadArg is a member of CMainFrame and contains 4 pointer to the CMainFrame Object and 3 pointers to other data.
However it appears that once the menu handler function has returned the whole computer hangs up and runs very slowly. If I place a break point in the Thread function the function is not called for a very long time. Once the function returns the computer returns to normal operational conditions and timings.
Does anyone know why this is?
regards,
RichardS
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Where in CMainFrm() does the program call CreateThread()?
Kuphryn
|
|
|
|
|
The function is an afx message handler from a menu.
void CMainFrame::OnFileOpenstream (void) is the prototype.
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
contains 4 pointer to the CMainFrame Object
Do not pass MFC objects across threads. This is a well known issue and is documented on MSDN.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
I have found that if I put a :Sleep (10) after creating tehe thread it runs fine. Do you know where the MSDN documentation for this is?
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
RichardS wrote:
I have found that if I put a :Sleep (10) after creating tehe thread it runs fine. Do you know where the MSDN documentation for this is?
There should be no reason for that to change the behavior of your thread unless there is some problem in your code. No it is not documented that I know of since I don't believe it is any type of feature.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Why are you not using AfxBeginThread() ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
I am used to writing non-MFC applications/libraries so CreateThread was the only alternative that I knew about.
"Programming today is a race between software engineers striving to build bigger and
better idiot-proff programs, and the Universe trying to produce bigger and better idiots.
So far the Universe is winning." -- Rich Cook
|
|
|
|
|
Hi,
In my code i use a dialog which contains a propertysheet with multiple propertypages.
All propertypages contain comboboxes and editboxes for the user to fill in.
I would like to have all the propertypages validated [B]as soon as the Ok button
of the dialog is pressed[/B]. This means probably that i can not place validation code in DoDataExchange(), because this function is called everytime when a tab is switched.
The Address Book of Microsoft which can be found in 'Programs->Accessories' also uses this kind of validation. It validates the pages as soon as OK is pressed, not between switching tabs.
How can i do this?
|
|
|
|
|
Do your validating in OnOK()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
How, by the WinApi facilities, knowing handler of window, attach other window to him, for example button.
//======================================
HWND hWnd1 = FindWindow(NULL, "TestWnd");
HWND hWnd2 = CreateWindow("button", "TestButton", WS_CHILD, 0,0,100,100, hWnd1, NULL, NULL, NULL);
ShowWindow(hWnd2, SW_SHOW);
UpdateWindow(hWnd2);
//======================================
Show me please, where I wrong.
|
|
|
|
|
As far as I know, you can not make windows in another process other than your own.
wWw.KruncherInc.cOm - My cool programs
|
|
|
|
|
In Report style fot a list ctrl .
When I insert items , every new item enters at the top , so if I enter 1,2,3,4 in list control one by one it will look like
4
3
2
1
although i choose the Sorting to None.
But I want that every new item should be entered at bottom and i also dont want sorting , sequence in my case is very important.
So how to insert every new item at the last of list ctrl. to have such kind of result
1
2
3
4
where 1 entered first , 2 secondly and so on.
Unmanaged in a .NET world
|
|
|
|
|
int InsertItem( int nItem, LPCTSTR lpszItem );
nItem is the index in the ListCtrl where your item gets if you insert, it sound like you have hardcoded it to 0.
to enter 1, 2, 3, 4 do
InsertItem(0, "1");
InsertItem(1, "2");
InsertItem(2, "3");
InsertItem(3, "4");
Arjan
|
|
|
|
|
if I'm not mistaken AddString or something should add items at the bottom off the list. InsertItem will insert the item at a given position.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
V. wrote:
if I'm not mistaken AddString...
... is a CListBox() method.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|