The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: Gunner on March 23, 2010, 09:19:05 PM

Title: adding a control to another program
Post by: Gunner on March 23, 2010, 09:19:05 PM
Is it possible to add a button or a control to another program and respond to messages from that control?  I have an idea for a newsreader that I use and it doesn't get updated anymore and would like to add a button to that program to implement a feature.
Title: Re: adding a control to another program
Post by: qWord on March 23, 2010, 10:18:53 PM
'adding' and new controll is possible when having the handel to parent window (hParent): here an snippet adding an Button to notepad:
mov esi,rv(FindWindowEx,rv(FindWindow,"Notepad",0),0,"Edit",0)
.if !esi
fn MessageBox,0,"cant find notepad","error",0
.else
fn CreateWindowEx,0,"button","xyz",WS_CHILD or WS_VISIBLE,0,0,100,100,esi,0,rv(GetModuleHandle,0),0
invoke GetWindowLong,esi,GWL_STYLE
or eax,WS_CLIPCHILDREN
invoke SetWindowLong,esi,GWL_STYLE,eax
.endif

The problem is receiving message from this control - a way is to set a message hook to its parent using SetWindowsHookEx().
Title: Re: adding a control to another program
Post by: Gunner on March 23, 2010, 11:14:13 PM
Ah, thank you.
Title: Re: adding a control to another program
Post by: oex on March 23, 2010, 11:23:29 PM
I just tried the code snippet and it hangs notepad lol, maybe just how I implemented it :lol should it be in a thread or something? Have implemented before just renewing the grey matter
Title: Re: adding a control to another program
Post by: hutch-- on March 23, 2010, 11:41:57 PM
The problem will be that techniques to access other running binaries are being closed off for security reasons and while many of these have worked in the past with earlier OS versions, thread isolation, seperate memory space and security issues make them unreliable in the longer term.
Title: Re: adding a control to another program
Post by: qWord on March 24, 2010, 12:02:29 AM
Quote from: oex on March 23, 2010, 11:23:29 PMI just tried the code snippet and it hangs notepad
for vista and xp it works ...
Title: Re: adding a control to another program
Post by: oex on March 24, 2010, 12:22:49 AM
I tried with console app on XP, it's not really important for me, no need for fix for me but I dont know why it doesnt and thought there may be idiot reason :lol

EDIT: Realised idiot reason :lol.... multiple notepad windows open, it drew it on the last one :green