You should try these: WM_XBUTTONDOWN and related window messages, WM_INPUT window message, directinput, and here is a hack on codeproject that might come handy: How to use your extra mouse buttons in games or apps[^]. Note: I havent used WM_XBUTTON messages and used WM_INPUT only to get mouse movement delta instead of mouse pos but trying these isnt a big waste of time.
i am writing a program that opens an explorer window, when CreateProcess open new window the main program must be minimized when i will close Explorer.exe i want that program return in SW_SHOW state.
I simply need to detect when Explorer.exe will be Close.
I have seen that when i use createprocess with microsoft MSDN example it will check only one time.
What i have to do to complete my task please help me :(
It is possible to wait for a program to exit when you start it with CreateProcess() but in your case you shouldn't do that. Many text editor and browser and whatever programs work like this: They allow you to open many documents on tabs. When you use CreateProcess() to start the editing or viewing of a document (or a webpage in your case) you launch an instance of the editor program that does the following: It checks if another instance of that program is already running and if that is the case then the process you created is just passing some info to the already running process and the process you started exits immediately. The already running process shows your document/webpage on a new tab. You shouldn't check for closing the explorer because you can't for the reasons I listed previously, moreover, I know that many users never exit their web browser - they use it open all they with hundreds of tabs for some reason.
I'm having a very strange problem with a third party dll. When I try to use this dll in my program an exception is thrown even before WinMain is called, yet other programs use it without any problems.
Eventually, I narrowed it down. If any program uses the dll and also calls a certain Windows function (for example SHGetSpecialFolderPath, or timeGetTime) then the the exception happens.
This problems seems really bizarre to me. Does anyone know what could be causing it?
You stated that the exception is thrown before your WinMain(). Statically linked dlls are loaded by windows for your executables and DLLs. The DllMain() of statically linked DLLs execute eralier than the main of the module (dll or exe) that actually uses the DLL. I would suspect that something is screwed up in your 3rd party DLL and it might be sensitive to DLL loading order. If you exe uses SHGetSpecialFolderPath() from shell32.dll and the 3rd party library also uses a function from shell.dll then the loading of shell32.dll might happen before or after the loading of your 3rd party depending on whether your program loads shell32.dll or the 3rd party first. However this whole situation seems to be totally screwed up for me. Try to set a breakpoint on "module load" events and debug the loading order of your DLLs, maybe you find out something useful. Try to search for the exception code too in google.
How about reading the time table? I've found it to be surprisingly efficient at predicting what track each train would be incoming at.
1. go to the 'algorithms' sub forum. Until you have an algorithm, there is no C/C++ question to solve.
2. specify precisely the input you have and the output you want. Without that information it is impossible to find an algorithm. For all I know now, my answer above may in fact be sufficient (although I doubt it)
3. use the internet search engine of your choice and search for similar projects. You probably won't find exactly what you need, but if you see something similar, you can try and adapt it to your project, or ask for help in doing so.
I have a dialog box. I have 10 buttons on that dialog box. I am using CSkinButton class to use images for those buttons. I want to provide scrollbar to the dialog box dynamically. For example, if I use 6 buttons, will fit the size of the dialog box. If I want to use 10 buttons, then vertical and horizontal scroll bar should appear on the dialog box automatically. As I using Images (Bitmaps) for buttons, scroll bar doesn't appear automatically.
I have tried to set the property of the dialog box for scroll bar. It doesn't work.
Anybody have anny idea regarding this.?
Please let me know if you have any doubt in understanding the above questions.
I want to create an MFC MDI Application, which is used to draw engineering 2D drawing. A similar one to Auto CAD 2D software.
Can anyone of you suggest us the best open source library which we can use to implement 2D mfc drawings.
I know some of libraries like OpenGL, DirectX but i am not sure a) whether we can use these libraries to create 2D drawings. b) whether we need to purchase these libraries as we are developing a commercial application. c) there may be better libraries available for 2D drawing and it may be for free.
We have in many places in our code things like :
if ( string.compare(A) == 0 )
// do something for A
elseif ( string.compare(B) == 0 )
// do something for B
elseif (string.compare(C) == 0 )
// do something for C
I know that we cannot use switch cases for strings, but is there a better way to do cascading If comparisons on strings ?
Two optimization tricks:
1. You store the possible values (A, B, and C, ...) in a sorted array and you search your string in that array with binary halving. Alternatively you can store A,B,C in one of these: map/hashmap/search tree.
2. If you opt for using == and/or != with if/else then you can speed up these operations for strings by storing the hash value for each string. When you compare two strings you first compare the hash values. If the hash is different then you have your result immediately (false for == and true for !=). If the hash for the strings is different then you have to perform the actual comparison on the strings. I usually write a special string class that contains the hash as well. It has the drawback that the hash must be updated before comparisons if the string has been modified since the last hash calculations. Sometimes purely written old legacy code can be tweaked very well with this trick. Use djb2 to hash your strings, for unicode use utf8: http://www.cse.yorku.ca/~oz/hash.html[^]
EDIT: Just noticed my answer isn't exactly the what you are searching for, but I think there is no fine solution to your problem. This problem is similar to the typical factory patterns that are used to instantiate a specific type by name:
You can choose to store strings in buffers of length 4*n. That way you can compare two DWORD vectors. It will be case sensitive, but faster than strcmp. You can also use switch on the first DWORD, but !!!ONLY!!! if no two strings share the same 4 bytes at the begining.
t is there a better way to do cascading If comparisons on strings
Where "better" means what?
If you just don't like looking at the code then you could do code generation.
If there is a actual profiled performance problem traced to this then you can used collected data to order the comparisons with most used first and least used last. Depending on the number of strings, and the data in the strings other optimizations are possible.
One solution again dependent on data and usage is to parse the input, when first received, into a value such as an enumeration and only use that in the rest of the code.
If there is a lot of churn with these then generation can still help but dynamic collections might solve that, with care. However such solutions might not be as performant and add some level of complexity.
// A,b, .. is also strings
if(NULL != List.Find(string))
// we have the string, so you can do whatever you want
What do you mean with 'better'?
If you mean 'more good looking', then I suppose your code becomes 'ugly' only if some of your // do someting for ... is long (I mean, switch, in my opinion, isn't much better than the if-chain).
A completely different approach would be transforming the // do something for .. pieces of code into functions (or function objects) and then use a std::map to map the strings to the function pointers (or function objects).
1. for each string in your list, register a domain name: A.com, B.com, C.com, etc..
2. on each site, install a web service that will return the code to be used in the "// do something for A" and "// do something for B", sections.
3. your code then calls out to the web service hosted at: "http://" + string + ".com"
4. it will receive the code it needs to execute
Can you reduce the scope of your problem space?
By that I mean: The broad example presumes that the input can be essentially anything.
Change that such that the input can begin with only certain strings or must contain certain keywords. Then you can divide the code up into different sections depending on how the input string can be grouped.
Note that the two solutions are not equivalent. In the second solution the current directory of your batch file will be C:\ while in the first case cmd.exe will inherit the current directory of the program from which you call ShellExecute().
I am trying to write one string to a file.But i am getting only one character
saved in my Text.txt file.Output text file contains only "a" in it.
How can i get whole string saved in my text file.
Here is the code i am trying:
The Text parameter you pass to fprintf() is a CString object, and and the %s format specifier expects a (const char*) or (char*) there. Instead of this you are pushing the whole CString object to the stack and the first 4 bytes of that CString instance are used as a (const char*). You have to convert the CString to either (const char*) or (char*) before using it with fprintf(). A more strict compiler like g++ would warn you about passing a non-pod object to a vararg function.