|
Can u please show me any example or demo application its really help me.
|
|
|
|
|
You really should learn how to use MSDN/Google/Bing for yourself. Try here[^] for some explanations and samples.
It's time for a new signature.
|
|
|
|
|
how to check the window is opened or not in a win32 application
|
|
|
|
|
FindWindow and FindWindowEx are what you want. You have to know the window class or the title of the window you're digging for but not both.
Cheers,
Ash
|
|
|
|
|
If "opened" stands for "visible" than IsWindowVisible is the API.
If "opened" means "existent" than IsWindow is the API.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
VS2008 puts a manifest file in my exe automatically (the "embedding manifest" build step). But when I start the exe it shows the dialogs in the classic theme. I opened the exe in the resource editor and noticed that the manifest lacked "Common Controls" section. How can I fix that?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
WTF?! Why does the New Project Wizard add the #ifdef _UNICODE...#endif
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
in the code that adds the XP style buttons.
This code was created by the wizard, no changes from me. It basically means "I'll create a manifest for you unless your program is ANSI, in which case f**k you". When I removed the #ifdef everything worked without problems. The only purpose for putting it seems to be to make me waste an hour wondering why I don't have visual styles, and creating 2 projects one with manifest one without, and comparing them with WinMerge, before noticing this little insidious #ifdef. And I'm sure there are people who don't know about the whole manifest thing, they'd be stuck with ugly controls if they make an ANSI project. I've made my project ANSI from the beginning since I had to add a lot of code that won't compile if it's unicode.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
sashoalm wrote: WTF?! Why does the New Project Wizard add the #ifdef _UNICODE...#endif
Because technically... common controls 6 and above does not have full ANSI support. Some window messages will be returning Unicode text buffers if you use common controls 6 in an ANSI build. Depending on your application architecture... you may or may not bump into this limitation.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi Everybody,
How to find a text file is already opened or not?
I have used the following code. but it is not working correctly.
ifstream inFile;
inFile.open("C:\\test.txt");
if (!inFile)
{
AfxMessageBox("file is opened");
}
else
{
AfxMessageBox("file not opened");
}
can anyone help me to how to find a file opened or not?
Thanks....
G.Paulraj
|
|
|
|
|
It all depends on how you opened the file. There's no reason why you can't have two streams based on the same file. e.g. on my system:
int main()
{
std::ifstream str1( "c:\\test.txt" );
std::ifstream str2( "c:\\test.txt" );
int n = 0;
int m = 0;
if( ( str1 >> n ) && ( str2 >> m ) )
{
std::cout << "Woo hoo! Opened both!" << std::endl;
}
}
Always comes up with the "Woo hoo!" message and both n and m are set to the integer that's in the first token of the file.
Unfortunately there's no way of opening a file using the standard library that locks it against further reading so if you're using streams you're not going to be able to tell easily if someone else has got it open.
Cheers,
Ash
|
|
|
|
|
Paulraj G wrote: I have used the following code. but it is not working correctly.
What do you mean by not working? Your example shows an open of a single file with no sharing restriction. Please explain what you are trying to do and what results you receive.
It's time for a new signature.
|
|
|
|
|
Paulraj G wrote: How to find a text file is already opened or not?
Try opening the file in exclusive mode... filebuf::sh_none
If you are unable to open the file exclusively then it means another application has an open handle.
Best Wishes,
-David Delaune
|
|
|
|
|
Quick caveat here: filebuf::sh_none is not standard C++. You might end up with problems if you need to compile your code on another compiler.
Cheers,
Ash
|
|
|
|
|
Paulraj G wrote: How to find a text file is already opened or not?
It quite difficult, try to open file in write and sharedenyall , if it fails that means somebody else already open the file otherwise none.
Preconditon: file must exists at stated path
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
You can use CreateFile Function[] with "OPEN_EXISTING" flag in 5th argument(__in DWORD dwCreationDisposition) and use GetLastError Function to determine f the file opened already or not. Read complete documentation for the above.
--
"Programming is an art that fights back!"
|
|
|
|
|
Hello All,
I have a code snippet as follows
struct ItemNode
{
CString szID;
};
void DoSomething()
{
ItemNode *a = NULL;
TRY {
CString s;
s.Format (_T("%s"), a->szID);
}
CATCH(CException b){
MessageBox (_T("Exception occured"));
b->Delete ();
}
END_CATCH
return;
}
Here, I am not able to catch the exception. The app crashes saying "There is an access violation.... "
What is the correct way to catch the exception??
I am using C++, MFC and the development is in VisualStudio 2005.
|
|
|
|
|
Try like this for instance:
void DoSomething()
{
ItemNode *a = NULL;
TRY {
CString s;
s.Format (_T("%s"), a->szID);
}
CATCH(...){
MessageBox (_T("Exception occured"));
}
END_CATCH
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
shouldn't try...catch catch only C++ exceptions? An access violation is a crash, not an exception.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
As far as i know access violation raises an exception, the crash occurs if this exception is nowhere cought in the program itself. I did use try...catch to catch access violations in the past and it worked fine, althorough doing so isn't a very..."nice" solution, but sometimes it can be necesarry.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
Yeah. I thought, that the CException class should be able to catch all the exceptions.
But in my example, the app crashes without the exception being caught.
Im looking for a way to be able to catch that exception.
|
|
|
|
|
I was talking about the "not nice" part too. That's why I called it crash not exception. IMHO C++ exceptions should be an error reporting mechanism, whereas an access violation means your program just got corrupted.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
True, but he asked how he could catch that exception, that is a way.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
Tried this, but it is giving errors as "not enough actual parameters for macro 'CATCH'"
|
|
|
|
|
Try this way then
void DoSomething()
{
ItemNode *a = NULL;
try {
CString s;
s.Format (_T("%s"), a->szID);
}
catch(...){
MessageBox (_T("Exception occured"));
}
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Computers are evil, EVIL i tell you!! <
|
|
|
|
|
catch( ... ) is generally a really bad idea, it just eats anything and doesn't really tell you a lot. About the only place you should use it is around main so you at least get a hint that something out of the ordinary has occured and you've got a well serious problem:
int main()
try
{
}
catch( std::exception &e )
{
std::cout << "An error occurred: " << e.what() << std::endl;
}
catch( ... )
{
std::cout << "An error occurred: No idea what!" << std::endl;
}
Cheers,
Ash
PS: Using catch( ... ) around thread functions, message handlers and module boundaries can also be good as you don't want to throw through C-style or OS interfaces.
|
|
|
|