Jump to content
  • Advertisement
Sign in to follow this  
noatom

Anyone good with Delphi & Win32?

This topic is 1962 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have some code in delphi that clicks a button in a window.The way it does that: it gets the hwnd of the window,then it enums all the childs,if any of them has text with "ok"(the button i want),it sends some messages.Full code:

 

function EnumChildProc_Register(AHWND: HWND; AParam: LParam): Boolean; stdcall;
const
  BUFFER_SIZE = 4096;
var
  text  : array[0..BUFFER_SIZE - 1] of Char;
  pparam: pointer;
  res   : DWORD;
begin
  pparam := pointer(AParam);
  SendMessageTimeout(AHWND, WM_GETTEXT, BUFFER_SIZE, NativeUint(@text[0]), SMTO_ABORTIFHUNG, 50, @res);
  if String(text) = 'OK' then
  begin
    PostMessage(AHWND, WM_KEYDOWN, VK_RETURN, 0);
    Sleep(10);
    PostMessage(AHWND, WM_KEYUP, VK_RETURN, 0);
    Boolean(pparam^) := FALSE;
  end;

  result := Boolean(pparam^);
end;

 

 

The big problem is,those 2 post messages do nothing in win32.I tested the code,and the button is not clicked.How could it work in delphi,and in c++ not?

Share this post


Link to post
Share on other sites
Advertisement

Cutting pasting from the last time you asked this question:

 

In the case of keyboard events more happens when you type than just a WM_*  msg popping up in some window's message queue and it is impossible for these events to arise in a non-foreground window under normal use, so merely fabricating windows messages usually doesn't do what you want it to do. The way to do this that actually works for keyboard events is to make the target window foreground and use SendInput(...) as someone said above; although, I don't think it is possible to foreground an arbitrary window across processes the way that it was years ago ... so not sure.

Edited by jwezorek

Share this post


Link to post
Share on other sites

Still...I'm amaazed at the fact that some code can do a thing in delphi,and the same code,do nothing in c++...

Share this post


Link to post
Share on other sites

What is your C++ version of this code? The same code should produce the same results, so it must be different somewhere.

Share this post


Link to post
Share on other sites

From past experience i can tell that SendMessage is more reliable than PostMessage in delphi, although i have no idea why... give it a try.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!