|
HHOOK WINAPI SetWindowsHookEx(
__in int idHook,
__in HOOKPROC lpfn,
__in HINSTANCE hMod,
__in DWORD dwThreadId
);
http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx[^]
and then look at: WH_MOUSE or WH_MOUSE_LL to get what you need. WH_MOUSE_LL gives a little bit more information, but may not be needed in your application.
|
|
|
|
|
Thanks for the answer. I could use one more hint. To modify the mouse data with let's say WH_MOUSE_LL I have to use my own custom CallBack function and modify the POINT pt of the MSLLHOOKSTRUCT pointed to by lParam, which has been passed to the CallBack function, right? Or did I get something wrong about how to restrict the movement correctly?
|
|
|
|
|
If i remember correctly yes that would be how you would restrict the movement.
|
|
|
|
|
Additionally to what elchupathingy said, you might also try to globally hook[^] GetCursorPos[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Selectively injecting a DLL and hooking the functions you need is IMO the better solution. More complicated than using SetWindowHookEx, but will not have the overhead and annoying problems that are associated with global hooks...IE getting the mouse stuck on your horizontal plane, which I think is not what is to happen.
|
|
|
|
|
Wouldn't he still need to use a hook to modify the mouse-input messages? I mean, the coords "encoded" in the message params probably come from somewhere else than GetCursorPos, do they not? Wouldn't btw selectively injecting the DLL instead of trying this globally with every process make it less "global"?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
He could hook the actual function it self by using a DLL, messy but could work well and to make this global you can keep an array of processes and check for new ones and inject into the new ones.
Or, looking back at what you have said another way to do it would be to use SetWindowHookEx and pass the thread ID of the process that is to be injected into. [^]
I just feel that this particular program could cause problems in other programs if it were a global hook, and that it only needs to be applied to specific processes rather than all running processes. From the example of the op with mspaint.
Also the call chain for GetCursorPos is:
GetCursorPos -> NtUserCallOneParam( DWORD dwParam, DWORD routine )
So, a hook on NtUserCallOneParam could be used to modify the mouse position that is returned.
|
|
|
|
|
Hi,
my application is a win32 appln. I have added try-catch loop. But its showing the following error.Please help me to resolve this error.
Code:
try
{
fn();
}
catch(CException exp)
{
exp->GetErrorMessage(lpszErr,sizeof(lpszErr),NULL);
wsprintf(lpszLogMsg,"%s\\%s",lpszErr,"fn");
WriteLog(0,lpszLogMsg);
return;
}
Error:
error C2061: syntax error : identifier 'CException'
error C2310: catch handlers must specify one type
error C2227: left of '->GetErrorMessage' must point to class/struct/union
error C2317: 'try' block starting on line '474' has no catch handlers
|
|
|
|
|
try
{
fn();
}
catch(Exception *exp)
{
exp->GetErrorMessage(lpszErr,sizeof(lpszErr),NULL);
wsprintf(lpszLogMsg,"%s\\%s",lpszErr,"fn");
WriteLog(0,lpszLogMsg);
return;
}
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
now the errors has gone.Can you please tell me how to get the error message.
ni CExeception we are having GetErrorMessage() fn. Similarly, what is the fn in exception class to get the error message?
|
|
|
|
|
Print this line to get the error message
exp->Message
Yes U Can ...If U Can ,Dream it , U can do it ...ICAN
|
|
|
|
|
The exception type you are trying to catch has to be defined. The error simply reads: I don't know what CException is.
You might be missing an #include , defining CException .
There is no predefined exception class in C++ as in many other languages. In C++ you can throw whatever object you want; int, const char*, CMyComplexClass...
Always try to catch exceptions by reference instead of by value. That will avoid a lot of unnecessary copying of data. catch(CException &exp)
|
|
|
|
|
To amplify Niklas' answer a bit...
Throw by value, catch by reference. If you do this:
- It removes copying of the exception, reducing the chance of further exceptions being thrown
- You can catch families of exceptions polymorphically
Cheers,
Ash
|
|
|
|
|
HI All,
I have drawn an image using GDI+. I want a rectangle in the middle of image and alpha blending on remaining part of image.
I got stuck and want idae from yourside. please guide to do that.
|
|
|
|
|
Here is a nice article with example that might help.
Alpha Blending using GDI+[^]
PURPOSE: Delays program execution until designated condition is indicated.
|
|
|
|
|
Hi friends, here is my query...
I am working on win32. I am writing an application to read some data from registry. It is working on 32 bit machines. But it is not working on 64 bit machines. I am using the below API to read the data.
RegQueryValueEx(hKey, pszEntry, NULL, NULL, (LPBYTE)pData, 200)
Is there any problem with the last parameter size (200). What size to be passed as parameter.
Thanks in advance.
Regards
Sairam M.
|
|
|
|
|
msr_codeproject wrote: Is there any problem with the last parameter size (200). What size to be passed as parameter.
This parameter should be the address of (pointer to) a variable that contains the length of the buffer, as described here[^]. If this size is not large enough for the result then the call will fail and the required size will be entered into the variable. Thus if you make a call with the variable set to zero you can find out how big the buffer needs to be and allocate as appropriate.
BTW I'm not sure why your question got downvoted so I have upped it to compensate.
It's time for a new signature.
|
|
|
|
|
The strange thing is that your code actually worked in the 32 bit edition. Any call to RegQueryValueEx using your parameters would result in an attempt to write something at memory address 200. Not good.
|
|
|
|
|
Mattias G wrote: The strange thing is that your code actually worked
Firstly, that was the OP's code, not mine.
Secondly, I don't think it did work correctly.
It's time for a new signature.
|
|
|
|
|
Right, "your" was referring to the OP, naturally. Could have been more clear on that
|
|
|
|
|
What I meant was you should have posted your reply to the OP, not to me.
It's time for a new signature.
|
|
|
|
|
Hi Guys, my trails are not working. I am giving you the path of the key. Please write small code to read it.
Key Path:
HKEY_CURRENT_USER\Software\ABCD\ABCD UD PCL6_00-00-00-00-00-00\printer_ui\icc_profile\0
Name of the filed: szResId
Type of the field: REG_DWORD
Data at the field: 0x000084d6(34006)
Now I want to read 0x000084d6. I tried in so many ways. But it wasn't worked. Help me.
Regards
msr_codeproject
|
|
|
|
|
msr_codeproject wrote: I tried in so many ways. But it wasn't worked. Help me.
Show the code you've tried so far.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Try the following:
static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";
LONG lResult;
HKEY hkMyKey;
DWORD dwDisposition;
DWORD dwType;
DWORD dwData;
DWORD dwSize;
lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
pszKeyName,
0,
NULL,
0,
KEY_READ,
NULL,
&hkMyKey,
&dwDisposition
);
if (ERROR_SUCCESS == lResult)
{
dwSize = sizeof dwData;
lResult = RegGetValue(hkMyKey,
L"0",
L"szResId",
RRF_RT_ANY,
&dwType,
&dwData,
&dwSize
);
}
Note: this is a Win32 solution, I don't have access to a 64-bit system.
It's time for a new signature.
|
|
|
|
|
Richard MacCutchan wrote: static PWSTR pszKeyName = L"Software\\ABCD\\ABCD UD PCL6_00-00-00-00-00-00\\printer_ui\\icc_profile";
I think you should make pszKeyName constant (i.e. static LPCWSTR), considering you're referencing it to memory (the string literal) that could be read-only.
|
|
|
|