i want to learn a bit about how to use hooks so im trying to make a program that will change the input of 'A' to 'B',
i'm trying to use the WH_KEYBOARD hook and according to msdn:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644984(v=vs.85).aspx
the WParam is "The virtual-key code of the key that generated the keystroke message.", so i tried to change it and use callNextHook.
LRESULT CALLBACK KeyboardProc(
_In_ int code,
_In_ WPARAM wParam,
_In_ LPARAM lParam
)
{
if (wParam == 65)
wParam++;
CallNextHookEx(NULL, ncode, wParam, lParam);
}
i have tried to do something like that, and even without the "if" the changing of wParam doesn't affects the result.
what did i do wrong here? how can i make it to work?
thank you
Related
I'm trying to change the text color whenever i receive WM_CTLCOLORSTATIC.
LRESULT ProcessWindowMessage(_In_ HWND hWnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam)
{
switch (uMsg)
{
case WM_CTLCOLORSTATIC:
::SetTextColor((HDC)wParam, RGB(m_color.red, m_color.green, m_color.blue));
::SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)GetStockObject(DKGRAY_BRUSH);
}
return m_orgWndProc(hWnd, uMsg, wParam, lParam);
}
As you can see, the color of 'Just a test' was changed, but with it, the background of the entire box was also changed.
I've tried returning almost all GetStockObject() combinations including
return (LRESULT)GetStockObject(COLOR_BACKGROUND + number)
&
GetCurrentObject((HDC)wparam,OBJ_BRUSH)
I've to say, that these commands manipulated the color of the background somehow, but never matched the default gray value used to be.
what am i missing here?
You didn't try
return (LRESULT)GetStockObject(NULL_BRUSH);
As Mark Ransom commented, that would not erase the background if you set the new text.
You should use:
return (LRESULT)GetSysColorBrush(CTLCOLOR_DLG);
as was suggested earlier.
I am currently facing issues when trying to compile my code that contains this WinProc function which is being used to process messages from our program. For example if a WM_DESTROY message is received via windows I want it to call PostQuitMessage(0) to signal Windows that the application has made a request to quit. Which will cause the WM_QUIT message to cause the WinMain to exit.
I have only been learning C++ a few weeks and don't have the experience or knowledge to fix this and would appreciate any help. I have looked around but so far I cannot find any solutions. I'm pretty new to this so I may have missed something really obvious.
LRESULT WINAPI WinProc (hWnd, msg, UNIT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY;
// Tell windows to kill the program
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam );
}
Below is the errors I experience wit the code that I have provided.
error: 'LRESULT WinProc' redeclared as different kind of symbol
error: previous declaration of 'LRESULT WinProc(HWND__*, UINT, WPARAM, LPARAM)'
error: 'hWnd' was not declared in this scope
error: 'msg' was not declared in this scope
error: 'UNIT' was not declared in this scope
Any help would be greatly appreciated.
Thanks
In the function declaration
LRESULT WINAPI WinProc (hWnd, msg, UNIT msg, WPARAM wParam, LPARAM lParam )
you forgot to set type specifiers for the first two parameters hWnd and msg
There must be
LRESULT WINAPI WinProc ( HWND hWnd, UNIT msg, WPARAM wParam, LPARAM lParam )
Also the label has to be followed by a colon while you placed a semicolon
case WM_DESTROY;
try using the callback calling convention instead of winapi
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633570(v=vs.85).aspx
also note the usage of " : " instead of " ; " on switch statement , also specify a type before the handle and message arguments
LRESULT CALLBACK WinProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_DESTROY:
// Tell windows to kill the program
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam );
}
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM )
This should be the function declaration. Your case has a ";" semicolon instead of a ":" colon.
Besides this, I don't see any problems. Try this:
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
// Tell windows to kill the program
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hWnd, msg, wParam, lParam );
}
I'm trying to make it so that a user can select text from a read-only edit box, but he won't see the blinking caret. I've been able to make the caret disappear from the edit, but it can still be seen for an instant.
This is my code for the subclass:
LRESULT CALLBACK UserInfoProc (HWND hUserInfoWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
HideCaret(hUserInfoWnd);
return DefSubclassProc(hUserInfoWnd, uMsg, wParam, lParam);
}
It's a modest bit of code, I know, but it almost does what I want.
So what happens is, that when I click the edit, the caret can be seen for an instant (50ms?). I want that it doesn't appear at all. How can I do this? I want the user to still be able to select the text from the edit.
You could try moving the HideCaret() call to after the DefSubclassProc(), since at the moment if a message triggers the caret it won't be until the next message that it's hidden again.
Also, I would guess that the only message that triggers the caret to be shown is WM_SETFOCUS, so you may want to test for that message only. For example,
LRESULT CALLBACK UserInfoProc (HWND hUserInfoWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
{
LRESULT lRes = DefSubclassProc(hUserInfoWnd, uMsg, wParam, lParam);
if (uMsg == WM_SETFOCUS) // maybe?
HideCaret(hUserInfoWnd);
return lRes;
}
There is a racing game, I need to collect telemetry and statistics. And to add an additional HUD
I compiled the Detours. And could make the hook to change the name of the application window.Like:
LRESULT (WINAPI * TrueSendMessageW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) = SendMessageW;
__declspec(dllexport) LRESULT WINAPI MySendMessageW(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
if (Msg == WM_SETTEXT)
return TrueSendMessageW(hWnd, Msg, wParam, (LPARAM)L"new name window");
return TrueSendMessageW(hWnd, Msg, wParam, lParam);
}
...
And run it with withdll.exe. All ok.
But I cannot figure out how to intercept direct3d. With the help of API monitor, I found that the program uses Microsoft.Xna.Framework.Graphics.dll IDirect3DDevice9::SetTexture
Can someone tell how to get this texture? In general, I would like to get something like link
Detour intercepts OS API calls and Direct3D is implemented via COM object concept. You probably can intercept the very first step of D3D device object creation but after this point you'll have to deal with COM object interfaces and Detour won't be helping you.
I have been having trouble with my program trying to gray out ( and disable ) a sub menu item.
What I'm looking for is that the "run" item be disabled unless the required .ini entry is not empty.
My code
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HMENU hmenu = GetMenu(hWnd);
// Reading in ini
if (0 == strcmp(webLocation, "")){
EnableMenuItem(hmenu,ID_WEBSERVICES_RUN,MF_DISABLED | MF_GRAYED);
WritePrivateProfileString(_T("WEBSERVICES"), _T("Location"), _T("Tool Not Found"), WpathStr);
}
I am unsure as to whether I am getting the HMENU correctly and why this code is not working for the desired effect.
Any help with this would be greatly appreciated.
You can't just put this in the WndProc at the top level. WndProc process events, whether the window has been constructed or not. It'll be called many times for many different reasons.
Your WndProc will almost certainly look like a big switch on message. The one you want here is WM_INITDIALOG:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
// jump to a new function that reads the .ini
// and disables the control etc.
return OnInitDialog(hWnd, wParam, lParam);
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}