|
remove the "const" from your function definition. you are modifying the internal state of the object, so you can't have a const function... right?
-c
Being just contaminates the void. --Robyn Hitchcock
|
|
|
|
|
|
What is the best way to differentiate the mouse movements I call in my program (using SendInput or SetCursorPos) from other mouse movement messages?
I'm using a system wide Mouse hook in a .dll that receives all mouse messages / movements and I want to distinguish mouse movements as a result of the physical mouse as different from the mouse movements and clicks I send to Windows through my program.
My program moves the mouse around using SendInput and SetCursorPos and clicks using mouse_event. I want my program to relinquish control of the mouse when the user moves the physical mouse. How can I tell the difference in a system wide hook?
I've tried embedding dwextrainfo into the movement and click calls that my program makes to tell them apart from the other messages, but my program calls seem to generate other, additional and simultaneous messages that do not contain the dwextrainfo. As a result, my program relinquishes control when it tries to click the mouse.
Any help? I'm sure someone has already accomplished this, but I can't seem to find any references.
-Jeff
|
|
|
|
|
I suspect you'd need to set a flag in the program you're sending messages to, so it knows they are from you.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Well, that's no help! If it were that simple, I wouldn't be asking about it.
Your signature is comical in it's irony!
What I've learned so far and what my next questions are:
_____________________________________
The short answer is that you can not distinguish messages that are a result of physical mouse movements from those that are a result of SendInput or mouse_event calls. They get the same kind of handling by the operating system. Sent and posted messages on the other hand, can be distinguished from hardware input events and mouse_event messages, as they are appended to different queues in the thread.
OK, so how should I send/post messages (instead of using SendInput/mouse_event ) to control the mouse...
And how do I distinguish the messages in my system wide mouse hook?
Or should I say system wide message hook? WH_MOUSE vs. WH_GETMESSAGE: which can access the correct information to make a determination? (How do I access the queues and thread information?)
|
|
|
|
|
carp wrote:
Well, that's no help! If it were that simple, I wouldn't be asking about it.
It IS that simple.
carp wrote:
The short answer is that you can not distinguish messages that are a result of physical mouse movements from those that are a result of SendInput or mouse_event calls. They get the same kind of handling by the operating system.
Correct - there is only one way for a program to respond to mouse movement, regardless of how the message got there.
carp wrote:
OK, so how should I send/post messages (instead of using SendInput/mouse_event ) to control the mouse...
Use ::SendMessage and create messages with values of WM_USER, WM_USER+1, etc.
carp wrote:
And how do I distinguish the messages in my system wide mouse hook?
All messages have a value, you'd #define your own.
Christian
I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002
|
|
|
|
|
Hi:
I would like to write a function that accepts a variable number of arguments. I have tried to use va_list and va_arg macros, but the problem with them is that they don't know where to stop (i.e., how many arguments were supplied) unless you specifically state the number of optional arguments as one of the inputs.
Any ideas?
A reasonable man adapts himself to the world. An unreasonable one persists, trying to adapt the world to himself. That is why all the progress in the world depends on the unreasonable men.
|
|
|
|
|
And, by the way, I do not want to use any terminating values at the end of the optional arguments
A reasonable man adapts himself to the world. An unreasonable one persists, trying to adapt the world to himself. That is why all the progress in the world depends on the unreasonable men.
|
|
|
|
|
put your arguments in an array/list?
-c
Being just contaminates the void. --Robyn Hitchcock
|
|
|
|
|
Interesting point. Thanks
A reasonable man adapts himself to the world. An unreasonable one persists, trying to adapt the world to himself. That is why all the progress in the world depends on the unreasonable men.
|
|
|
|
|
Hi!
I keep getting linker warnings when using the directive /ALIGN:4096 or some other linker options that result in warnings but have no effect on the application. That's why I try to disable these warnings since they are quite annoying in the debug window.
The only thing that works for me is specifying /ignore:4108 in the linker options of my project. This really eliminates the warning about the /ALIGN directive. But I want to use a #pragma command instead of the /ignore command in the linker options.
I tried to put the line
#pragma warning(disable : 4108)
both in my source and header files, but this didn't remove the warnings in the debug/output window.
So what's the correct way to use this pragma directive?
regards
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I think you'll find that #pragma warning only works for compiler warnings - to quote from the VC++ documentation...
Allows selective modification of the behavior of compiler warning messages
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
#pragma warning is only for compiler messages. For the linker use:
#pragma comment(linker, "/ignore:4108")
--Mike--
Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Thanks a lot! Works perfectly
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Recently I got a bug with a program I wrote under W98 and ported to XP.
Actually, I just changed the allocation of my data arrays to GlobalAlloc - instead of malloc - and the program ran fine again.
I'm happy because I found the solution but now I wonder about all the other allocations I made using either the new operator or malloc and wonder which of them I should change to GloballAlloc and which of them are good. How many of them
So, is there an article over there explaining the strategy to follow ? What are the exact rules ? Differences between Wx and NT and so on.
Thanks,
Yarp
|
|
|
|
|
In all honestly, changing the allocation to GlobalAlloc didn't fix the bug, you just changed the execution enough to where the bug didn't bite you.
IMHO, you have a memory overrun somewhere. 9x and NT/W2K/XP execute programs very differently. Their memory footprint differ. Thus memory corruption problems might only show up in one flavor of the OS.
Change your GlobalAlloc back to malloc and try to find the real problem.
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?
|
|
|
|
|
It's a problem between GetDIBIts and StretchDIBits, the DIB is probably selected in a DC when I try to overwrite the bits and that was the reason why the program fails. Locking the memory solved the problem the other way out is using some CriticalSection somewhere.
Thank for the info, I'm quite surprised but unfortunately I was trying to fix this bug since 1 month and couldn't find the way out.
Yarp
|
|
|
|
|
I saw a similar problem a while back on some code written for Win98 and rebuilt on XP.
I agree with Tim Smith. You didn't find a solution to the problem, you just found a way to hide the symptom of a nasty memory bug.
If you don't find it now you'll never be sure when it will come back to haunt you!
If you continue to do the same things you always did, don't be surprised if you get the same results you always got.
|
|
|
|
|
You didn't idenitify the bug associated with using the malloc function, but the _malloc_dbg might be useful in resolving the bug to a specific malloc call.
If the bug occurs when you read or write to the memory, you may be trying to read or write to unallocated memory. I know that GlobalAlloc has a 16 byte granularity. In other words if you allocate 1 byte of memory using GlobalAlloc, Win32 actually allocates 16 bytes. If you try to read or write to the 2nd or 3rd byte, etc then you probably won't get into trouble. I am not sure if this is true for malloc. Maybe something to look into.
I may be way off base, if so, then I am sure the CP gurus will correct me
|
|
|
|
|
It's a problem between GetDIBIts and StretchDIBits, the DIB is probably selected in a DC when I try to overwrite the bits and that was the reason why the program fails. Locking the memory solved the problem the other way out is using some CriticalSection somewhere.
Thank for the info, I will try _malloc_dbg.
Yarp
|
|
|
|
|
I had created "excel", that fromat, and print excel file. it is based on the article,
http://support.microsoft.com/directory/article.asp?ID=kb;en-us;Q178749 .
I followed every steps what it said on the article. and the execl program is working perfectly.
i also have another application that does printing job. it print any kind of files using shellexecuteex. anyway, i
1) opened classWizard
2) clicked on Automation tab
3) clicked on add class-> from a library
4) find execl9.olb , which is in c:\program\microsoft office\office
5) selected the classes that i need from excel9 lib.
6) added, the following codes in CMyprintApp::IniInstance() function, which loads and enables the COM services library;
<br />
if(!AfxOleInit())<br />
{<br />
AfxMessageBox("Could not initialize COM dll");<br />
return FALSE;<br />
}<br />
<br />
AfxEnableControlContainer();<br />
.......<br />
<br />
7) in printExcel function, which is for MyPrint program, and onRun button function, which is for the execl program. i added the following code
[code]
_Application app; // app is an application object.
_Workbook book; // workbook object
_Worksheet sheet; // worksheet object
Workbooks books;
Worksheets sheets;
Range range; // used for Microsoft excel 97 component
LPDISPATCH lpDisp; //often reused variable.
//common OLE variants. Easy variants to use for calling arguments.
COleVariant covTrue((short)TRUE),covFalse((short)FALSE),covOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
//start microsoft excel, get application object, and attach to app object,
if(!app.CreateDispatch("Excel.Application"))
{
AfxMessageBox("Couldn't CreateDispatch() for Excel");
return;
}
[/code]
those steps are the steps that i did for the excel program. but the function is working fine for excel program but not for Myprint program.
I got the message "Couldn't CreateDispatch() for Excel " for myPrint program.
can anyone tell me why??
|
|
|
|
|
Ok, I'm developing a graphics application (think along the lines of InDesign) and have hit a problem with saving Grayscale TIFF images. When I import a grayscale image, it comes in with the colorspace flag set to ImageFlagsColorSpaceGRAY. When I use the function Save on this image, the image output is an ImagesFlagsColorSpaceRGB. The encoder used is image/tiff and it doesn't matter if I save it to a file or stream. Do I need to include any encoder params with this call (I currently pass NULL) or is this another problem with GDI+.
Thanks
Andy Brace
SW Development Engineer II
Qwest
A clear conscience is usually the sign of a bad memory.
|
|
|
|
|
Hey Folks,
Does anybody know of a way of determining which DLLs an EXE depends on pragmatically? Tools like Dependancy Walker work great, but I'm in the process of writing an About->File Info dialog, which lists all the DLLs/Versions. I could easily hardcode these values, but would much prefer to do it pragmatically, rather than updating the static list when the list changes.
Was leafing through a few development magazines recently, saw various references to CP, good to see
Thanks.
Mike.
doner@obtain.com
|
|
|
|
|
If you want functionality like Dependency Walker, you would have to read the PE header of the executable and locate the imports table. It lists the various modules the EXE depends on along with the functions from the modules that are needed. I can't say specifically where you can get that info but I've come across it on several occassions in the past.
There was an overview of the PE executable format in a recent MSDN magazine.
http://msdn.microsoft.com/msdnmag/issues/02/02/PE/PE.asp
Another approach is to examine the moudules that are currently in use. You can use the toolhelp32 functions for that. Basically you would create a snapshot with CreateToolhelp32Snapshot to get a snapshot of the modules in use by the process. Then call Module32First and successviely call Module32Next to get info about each module used by the process. Don't forget to call CloseHandle on the snapshot's handle when done.
|
|
|
|
|
Thanks for the info, great article to read... Managed to get it working!
Mike.
|
|
|
|