Changing the text of another program's form's title bar tex.

  • Thread starter Thread starter supster
  • Start date Start date
S

supster

I'de like to know how to change the title bar text of a window that my
program does not own. I remember doing this a long time ago in C++ and
the Windows API calls were ugly, I hope its gotten easier.


I'de also like to simulate a keypress in a window that I do not own,
any help is appreciated, thanks.
 
You simply need to send windows message using SendMessage or
PostMessage API. It hasn't really gotten much easier, but you can
go check out www.pinvoke.net and get information on how to write
the PInvoke wrappers for the methods you'll need.

There is a SendKeys class, but you'll need to make sure the
application you are targeting has focus for this class to work properly.
Most of the old C++/VB stuff works if you make the appropriate
mappings to the classes available in .NET.

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

supster said:
I'de like to know how to change the title bar text of a window that my
program does not own. I remember doing this a long time ago in C++ and
the Windows API calls were ugly, I hope its gotten easier.


I'de also like to simulate a keypress in a window that I do not own,
any help is appreciated, thanks.
 
In order to do the below you need to subclass the WndProc for the application
you are targetting, trap drawing messages for WM_NCPAINT (I think, it's been
a while), let the base handler paint, then paint your stuff over the top. In
order to
get the region you'll be painting over, you'll have to do some special work to
get
the area the title bar occupies, some additional special work to pad out your
drawing so you don't mess up the system glyphs on the right, etc... It isn't a
very
easy task if I recall, and it would require a large number of PInvoke calls.

A simpler mechanism is simply to overdraw that region. You can always get the
hDC of the desktop which enables you to paint over any region of the screen.
You can attach a Graphics object and simply do your drawing in that manner.
You'll have to look for when the application moves or repaints it's own title
bar
so that you can update your stuff appropriately (normally the title bar only
repaints if something is moved over it I believe). Still, not an easy task
considering
you'll still have to find the right margin for drawing based on system glyphs,
etc...

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

supster said:
Thanks for your input.

I was actually hoping to display some System.Drawing objects such as a
series of different colored/sized rectangles on the title bar.

I'm checking out www.pinvoke.net, but I don't think its what I was
looking for.

edit:
heres a photoshop of what I want to do:
http://members.cox.net/preluge/titlebar.png
 
Back
Top