I'm trying to send WM_APPCOMMAND message to foreground window, but it's not working. Can someone explain to me how to do it correctly?
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern int GetForegroundWindow();
public const int WM_APPCOMMAND = 0x319;
public const int APPCOMMAND_UNDO = 34;
SendMessage(GetForegroundWindow(), WM_APPCOMMAND, 0, WM_UNDO * 65536);
EDIT:
Hans Passant: Most AppCommands are mapped to dedicated keys on the keyboard and automatically triggered when you press such a key. Since very few keyboards actually have an Undo key, the odds that an app will respond to APPCOMMAND_UNDO are zilch.
Thank you Hans. This is the answer.