How i can know what is the Msg type of a button on another process e.g. WM_COMMAND
My goal is
I want to click that button even if its disabled. I know i can simply enable the targeted button using EnableWindow
then using
PostMessage(hButton, WM_KEYDOWN, VK_RETURN, 0);
The problem is if there is a thread to validate something e.g.
if TRUE then
buttonX.enabled := True
else
buttonX.enabled := False;
Is it possible to click that button even if the thread is running like this.
PostMessage(hTargetApp, WM_COMMAND, XXXX, 0);
This is my DLL
function WindowProcMain(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): Longint; stdcall;
begin
case Msg of
WM_COMMAND:MessageBoxW(HWND_DESKTOP, PChar('The WM_COMMAND code is: '+IntToStr(wParam)), 'WM_COMMAND', MB_OK);
end;
Result := CallWindowProc(MainWndProc, hWnd, Msg, wParam, lParam);
end;
I have inject it to a process have this buton
procedure TMainForm.btn1Click(Sender: TObject);
begin
ShowMessage('You Click Me');
end;
But nothing is appears
Please correct if my understanding is wrong, And point me in the right direction.
The correct way to simulate a button click with a
WM_COMMAND
message is like this:However, that is no guarantee that the button's click handler will be called if the button window is actually disabled. For a VCL
TButton
component, it will be called. But if you inject your code into a non-VCL process, who knows what rules it will follow.