|
I've written a Win32 Dialog App that calls CreateDialog instead of CreateWindow. When it starts up I wanted to use FindWindow along with a class name to see if the app was already running. To do this I need a unique ClassName, but the class is created by the call to CreateDialog.
I have tried using the CLASS statement in the resource file, but then the call to CreateDialog fails.
The API documentation for DefDialogProc hints that RegisterClass can be used to set the ClassName for a Dialog. It further states that GetClassName can be used to get the WNDCLASS for a dialog, then the name can be changed and a new class registered.
I think this is standard Win32 stuff, but in case it matters, I'm working with WinCE.
Has anyone ever done this? Nothing works as expected for me. Is a different approach called for? Suggestions? Comments?
Brad Manske
|
|
|
|
|
A better way to limit multiple instances of the app is to create a named mutex. Only one app will be able to do this at a time. If the mutex already exists then you can assume that your program is alreay running, the same way you would if the window was already found.
There are some gotchas to both methods so look at this article.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
While your solution will work,I have one additional requirement that I left unstated.
Once you know that an instance of the app is running, it needs to be brought to the front of the Z-order before the current instance exits. FindWindow returns a handle to the window that you can use to do this.
FindWindow can also search by window Title and this is the solution I may go with but then you have the limitation of not being able to change the window text which is often done on the main window to convey info like the name of the open file.
Can you add any other thoughts? I'm writing this for an article for CodeProject and this has nothing to do with the main topic but I would like to make it clean before submitting it.
Brad Manske
|
|
|
|
|
I have an ActiveX control written using VC++ which is used to process a data file to generate a desired output.
This processing can sometimes takes a very long time, and I want to be able to cancel the processing part of the way through if I wish.
What is the best way to do this?
Cheers
|
|
|
|
|
You will need to have a second thread send a message or set a variable on the thread that has the long process. The thread that is running the long process should periodically check for the message to stop or check the variable that indicates that it should stop.
A good type of variable to use would be an Event. These can be given names and shared across processes if that is what your ActiveX control needs to do.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Hi,
PLEASE help!!! I am almost finished with this card game that I'm making, but after I had made a minor change I got a weird error that I can't make go away:
CVTRES : fatal error CVT1103: cannot read file
.\Debug\Pyramids.res : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
Error executing link.exe.
What can I do? Thank you SO much for your help,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
This may sound weird but on occasion, I have gotten the exact same erorr messages. Try rebuilding the entire project and see if it goes away. It usually works for me!
|
|
|
|
|
|
Whew... the rebuild all did it!
Thanks,
~ Selevercin
If you have a problem with my spelling, just remember that's not my fault. I [as well as everyone
else who learned to spell after 1976] blame it on
Robert A. Kolpek for U.S. Patent 4,136,395.
|
|
|
|
|
How do I enable controls when doing OLE embedding? I am trying to call MSWord and MSExcel and several of the buttons on the toolbars are grayed out. And I can only get one layout, the "print layout", I would like to select Normal under View menu option but it is grayed out as well. I didn't disable these controls, how did they get disabled? How can I enable them?;)
|
|
|
|
|
I have made a function to replace every occurence of a substring in a string with a new string. But if i put it in another function, then when that other function is done, an unhandled exception error appears. It's not my function performing an unhandled exception, it's the other function that does it when it's done, but only if i use the stringreplace function in that function:
Unhandled exception in app.exe: 0xC0000005: Access Violation.
here's the function:
void ReplaceString(char *target, const char *toreplace, const char *replacewith)
{
if ((!strcmp(target, "")) || (!strcmp(toreplace, "")) || (!strcmp(replacewith, "")))
return;
char *pos = strstr(target, toreplace);
int currentpos = pos-target;
char *after = new char[strlen(target)-1];
while (pos)
{
currentpos = pos-target;
strcpy(after, pos+strlen(toreplace));
strcpy(&target[currentpos], replacewith);
strcat(target, after);
pos = strstr(&target[currentpos+strlen(replacewith)], toreplace);
}
delete after;
}
Thanks in advance.
|
|
|
|
|
Check with the delete stuff if ure deleting the same area twice and make sure ure not passing somewhere out of bounds
Papa
Murex Co.
|
|
|
|
|
Always use the matching operator delete function
Check the line "delete after;". Anything strikes you as odd? Maybe if you look at how it's allocated? It should be delete[] after;
|
|
|
|
|
1. delete [] after (already mentioned)
2. after is too short. The -1 doesn't allow for the 0.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
when i write delete[] after, it does the same. and after should be one char smaller than target cause it is only supposed to hold the chars after the char to be found, fx
target = "ckndsfkndfksndf"
find = "c"
after = "kndsfkndfksndf"
|
|
|
|
|
But strcpy needs the 0 at the end of the string.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
As others have said, use delete[].
Also (unless I'm half asleep), you are not allocating enough space for the string (you are using strcpy which will copy the ending NULL). You need to allocate strlen(target), not strlen(target)-1.
|
|
|
|
|
See, Matt agrees with me.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
My scrollbars are gone. I am trying to do some embedding/automating with Word. When I do the _Application app and app.SetDisplayScrollBars(TRUE), they only appear for a couple of seconds, then the OnDraw function is performed and they are gone. What did I do wrong? It looks like when windows is sizing my document, it is losing the scrollbars. What is happening? How can I fix it? PLEASE HELP!!!!!
|
|
|
|
|
I have a system that runs multiple services on multiple servers. I have a program that will shutdown and restart a server.
I need to know how I can run this program on each server programmatically from one of the servers? AKA: Remote Process
|
|
|
|
|
DCOM
Win9x will not allow you to launch an on it from a remote machine though.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
For example if i have this string: "%A - %T.mp3" is there then any way of replacing the %A with a specified string and %T with another string? The user can enter what ever he likes, for example "%TN-%A - %T-%A.mp3".
Thanks in advance.
|
|
|
|
|
|
look at std::string or any of the dozens of non-MFC CString replacements on this site.
-c
Cheap Oil. It's worth it!
|
|
|
|
|
I know how to find the location of the system tray itself (thanks to Chris' article on the subject), but how can I find the location of a specific icon? Microsoft can do it, but I can't find any information on how to do it myself.
____________________
David Wulff
Jason Jystad wrote:
You sir, are a nut.
Jason Jystad also wrote:
You, sir, are very nearly the most terrifying individual I have ever had the honour of meeting.
|
|
|
|