Find mfc mainframe OnCommand message for "33614080" - c++

Edit 3: This is no good--the Right arrow key is sent every time the window loses focus--bad behavior.
I tried intercepting when the user clicks the close box, but so far I have not been able to find it in the class wizard. If anyone knows how to detect this event, please let me know.
Original post(s):
Edit 2: I have edited the code for a solution that does not use a magic number, but as Mark Ransom has noted, this is not the proper way to select a specific button for an input prompt, so this may work correctly, but it is a hack.
I have a legacy application in MFC that has a prompt when exiting to save changes. When the input prompt opens, the 'No' button should be selected when it prompts the user to save changes in the CMainFrame window. This is so that the user can press the Enter key to exit without having to use the mouse to select it. And yes, I am aware that the user can simply press the 'N' key to activate the 'No' button, but the 'No' button needs be selected so the user can press the Enter key to exit.
Using the message loop in:
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
I can detect a message when the window is closing, before being prompted to save changes.
So I added this numeric value and I am sending the right arrow key to select 'No' in the input message prompt.
EDIT: Added beginning of switch statement to show what is being evaluated.
// this is part of 'BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)'
BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch( wParam )
{
...
//case 33614080:
//SendRightArrowKey();
//break;
default:
WORD loWord = LOWORD(wParam);
if (ID_RECORD_FIRST == loWord)
{
WORD HiWord = HIWORD(wParam);
unsigned short value = HiWord;
char buff[32];
_itoa(value, buff, 10);
if (EN_KILLFOCUS == value )
{
SendRightArrowKey();
}
return TRUE;
}
}
return CFrameWnd::OnCommand(wParam, lParam);
}
void SendRightArrowKey()
{
INPUT output[2];
ZeroMemory(&output, sizeof(output));
// Right arrow key down
output[0].type = INPUT_KEYBOARD;
output[0].ki.wVk = VK_RIGHT;
output[0].ki.time = 0;
output[0].ki.dwExtraInfo = 0;
// Right arrow key up
output[1].type = INPUT_KEYBOARD;
output[1].ki.wVk = VK_RIGHT;
output[1].ki.dwFlags = KEYEVENTF_KEYUP;
output[1].ki.time = 0;
output[1].ki.dwExtraInfo = 0;
int retval1 = SendInput(2, output, sizeof(INPUT));
}
This works for win32 and x64, but it feels like a hack--especially because I can't find any definition for the numeric code 33614080. There should be constant or a macro for the windows message that gets sent for the WParam, in case Microsoft ever changes this value.
Does anyone know of a constant that this WParam value might represent,
or another way to have the 'No' button selected by default?
Thanks in advance for any replies.
Thanks Adrian for figuring out the values.

Related

why my windows receive en_setfocus 12 times

I want to be notified when user click the password text field.
But when I do click the password text field, the following function is called more than once:
void CUserDlg::OnSetfocusPasswordEdit()
{
// TODO: Add your control notification handler code here
cout << "focus on password text field";
}
Why does this happen ?
I also tried :
LRESULT CFakeUserDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch (message)
{
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_PASSWORD_EDIT:
if (HIWORD(wParam) == EN_SETFOCUS)
{
cout << "";
}
cout << "";
break;
}
.
.
.
This also happens many times when I click the text field only once.
I just tried to spy++, but it shows that spy++ caputure edit control messages, but EN_SETFOCUS is not message, it is edit control notification.
I got answer by myself.
Edit control does keep sending EN_SETFOCUS when it gets the focus.

How to make Windows Hot Keys work in Direct X environments?

I am programming a really simple MFC C++ Application which is working with HotKeys. To set a HotKey I use the following method from the WinAPI for my application:
BOOL RegisterHotKey(
HWND hWnd, // window to receive hot-key notification
int id, // identifier of hot key
UINT fsModifiers, // key-modifier flags
UINT vk // virtual-key code
);
To catch any HotKey Message I use: ON_MESSAGE(WM_HOTKEY,OnHotKey) in the message map and this Callback Method to test it's functionality:
LRESULT OnHotKey(WPARAM wParam, LPARAM lParam)
{
if (wParam == MY_HOTKEY_KEY_CODE)
{
MessageBox(L"HotKey was pressed!");
return TRUE;
}
return FALSE;
}
When a HotKey is pressed it enters the OnHotKey Method and does not process the key normally. For example if I write some text in Notepad and press "O" as HotKey, the "O" wont append to my text but the Message "HotKey was pressed!" appears, which is nice.
But when I am in any Direct X Game and press my HotKey, it is not sent to my application. Also when typing something in a Direct X environment the HotKey just works as normal key.
Is Direct X binding all key inputs somehow? Is there a way to make Windows HotKeys work with Direct X environments?

get mouse coordinates when user press Ctrl and click

I want to get mouse click coordinates X and Y when user press Ctrl and click at same time.
User may click anywhere on the screen or programs. I want my program to catch the event and get coordinates when Ctrl key is down pressed and mouse click occurs at same time. I want to get system coordinates X and Y, not the window coordinates of other programs.
I'm using C++ .
How to do that ?
Windows OS, WIN API code
I'm doing next which is not working:
HHOOK MouseHook;
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam){
PKBDLLHOOKSTRUCT k = (PKBDLLHOOKSTRUCT)(lParam);
POINT p;
if(wParam == WM_RBUTTONDOWN)
{
// right button clicked
GetCursorPos(&p);
//p.x
//p.y
//my program is never getting here, why ?
}
}
MouseHook = SetWindowsHookEx(WH_MOUSE_LL,(HOOKPROC)MouseHookProc,0,0);
if I change the above line to: MouseHook = SetWindowsHookEx(WH_MOUSE,(HOOKPROC)MouseHookProc,GetModuleHandle(NULL),0);
then it will work only for my own program window, but not hooking clicks outside of my program
Have you read this article? link
First of all, if you want to catch system entire mouse + keyboard event, your hooking function must be placed on a dll.
1)If nCode is less than zero, the hook procedure must return the value returned by CallNextHookEx.
Like below,
if(nCode < 0)
{
CallNextHookEx(hook, nCode, wParam, lParam);
return 0;
}
If CallNextHookEx is not called, there is a chance that other processes that have installed hook may not get the events correctly.
2)And then, check nCode again, whether it is HC_ACTION.
switch (nCode)
{
case HC_ACTION:
...
3)Finally, you can check WPARAM for WM_RBUTTONDOWN, and LPARAM for MSLLHOOKSTRUCT
The way I would approach is I would create a global variable say
int ctrl_pressed = 0
/*
0 -- ctrl nt pressed
1 -- Crtl Pressed
*/
Step 1: Now I would handle both WM_KEYDOWN and WM_KEYUP for ctrl
Step 2: In the callback of WM_KEYDOWN (if lparam is ctrl ) I would set ctrl_pressed to 1.
And in case of WM_KEYUP I would set ctrl_pressed to 0.
Step 3: Now Finally ill handle WM_MOUSECLICKED
and then check if ctrl_pressed(global) is 1 , which if true I can just get the coordinates.
This is just an approach may be not the most efficient solution.
Wait for more experienced WIN32 Developers to give their input on this.

Getting value from edit field (C++ WINAPI)

I am writing my first simple program in C++/WINAPI, with a lot of check boxes and a few edit fields, which will set up some calculations on a button press. All of my check boxes work/store info through individual cases, ie
switch (msg)
{
...
case WM_COMMAND:
{
switch (wParam)
{
case IDBC_BoxCheck1:
{...}
case IDBC_BoxCheck2:
{...}
...
} ...
...but I assumed edit fields didn't work as a case statement like a button press, since the value has to be read at the end once it has been changed as many times as the user wants. I looked online and attempted to use the SendMessage(hwnd, ...) and GetWindowText(hwnd, ...) functions to send a WM_GETTEXT command to the edit field and store it to a lpstr string, but I ran into the same problem with both of them - the hwnd for the edit fields aren't declared in the scope where the WM_GETTEXT command is being sent from, and I'm not sure how to get it there. Here is an overview of the structure being used in my program, which comes from a mix of some tutorials I was working with:
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_CREATE:
{
return OnCreate(hwnd, reinterpret_cast<CREATESTRUCT*>(lParam));
// OnCreate is a sub function that handles the creation of all the buttons/controls,
// since there are so many of them, with the format:
// HWND editControl1 = CreateControl(...); // CreateControl being another sub fnct
// that creates edit field ctrls
// editControl1 is the hwnd I'm trying
// to read the value from
// HWND checkControl1 = CreateButton(...); // Creates button ctrls, including ck box
...
}
...
case WM_COMMAND:
{
switch (wParam)
{
case IDBC_BoxCheck1: // These control IDs are defined at the top of the file
{
LPSTR Check1;
StoreInfo(Check1); // Just a sub fnct to store info for later calculations
}
case IDBC_BoxCheck2:
{
LPSTR Check2;
StoreInfo(Check2);
} // etc... there are 20 or so check boxes/buttons
case IDBC_Calculate:
{
LPSTR edit1;
GetWindowText(editControl1, edit1, 100); // or SendMessage(editControl1, ...)
// This kicks out the error of editControl1 not being declared in this scope
StoreInfo(edit1);
// Calculation function goes here
} ...
} ....
}
default: DefWindowProc(hwnd, msg, wParam, lParam);
}
}
IDBC_Calculate is the final button pressed before the calculations run. I figured the best place to read and store the values from the edit fields would be after this button is pressed, right before the calculation function is called, but tied to the same command. This is where the hwnd editControl1 is undefined, but I don't know how to send the definition to this scope, or where else I should be reading and storing the edit field values.
Any help or pointers on getting the values from these edit fields to my other functions would be appreciated! I've seen many different ways to check button states in various tutorials/lessons, so I'd love to know if there's a better way to do what I've written above in general.
Your edit fields have IDs right? Then you can use GetDlgItem.
editControl1 = GetDlgItem(hwnd, CONTROL_ID_1);
GetDlgItem is badly named, it doesn't just work in dialog boxes. It gets the handle of any child window from a parent window, using the ID of the child window.
And what Anders K says is correct. The way you are using GetWindowText will crash your program.

dialog box controls - detect changes

I want to detect when any control on a dialog box is changed by user action. For example, when data is entered in a text box, a date is entered in a date-time picker, a check box is checked or unchecked, etc. Up to now I have ignored such notifications and simply retrieved the state of the controls when the user pushes some button but now I want to know a change has taken place (I want to enable the Apply button on a property sheet). I don't really care what change has taken place, all I want to know is that something has changed. By change I do NOT mean a change in focus but some actual action by the user to change a control.
I use plain old c++, no MFC or anything fancy.
How do I go about this?
You can test whether a checkbox has been checked with the BN_CLICKED notification code which you'd get through WM_COMMAND.
switch( uMsg ) {
...
case WM_COMMAND: {
switch( HIWORD( wParam ) ) {
case BN_CLICKED: {
if( Button_GetCheck( lParam ) == BST_CHECKED ) {
...
}
break;
}
default:
return false;
}
break;
}
default:
return false;
}
return true;
That is an example of how your DialogProc might be set up. You can switch on lParam or LOWORD( wParam ) to identify which button.