Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to make program that reverses color with VC++?

Status
Not open for further replies.

hmsheng

Full Member level 4
Joined
Dec 17, 2003
Messages
219
Helped
26
Reputation
52
Reaction score
10
Trophy points
1,298
Location
China
Activity points
1,556
reverse coler with VC++

I need such a program, which can watch another program window, such as MS word, and can reverse color of the program window client area dynamically.
How to realize this function in VC++?
 

reverse coler with VC++

Hi,
What you have is a problem whose complexity will depend on whose window client color you want to reverse, if its you app window then its pretty cool, get the window handle and paint it using a brush, but if its a another app window you want to reverse then its a bit complex, and if its is a ms word app window then its really complex :-( and mostly ms word will not allow you to do this.
 

Re: reverse coler with VC++

Hi hmsheng.

As was previously mentioned this is not a trivial task.

You may divide it into two sub-tasks:
1. Finding the Window Handle of MSWord
2. Using the Window Handle to send it messages and control its behaviour.

Another approach may be:
1. Find the Process Id of MSWord
2. Use any number of methods to inject code into its process and alter its behaviour.

Start with "EnumWindows" and "FindWindow" APIs, to locate the MSWord window.
You can also use the "Spy++" application that is bundled with Visual Studio's tools.

Once you have the Window Handle of MSWord, it becomes tricky although the options are truly limitless.
You can actually "impersonate" a user clicking buttons, send messages to the window (or a child window - use EnumChildWindows), Get the device context of the main window and alter it directly...

The other approach is much more complex but will definitely give you complete control over the MSWord process since your code will be running as MSWord. Doing this is a bit out of scope for this post although the easiest way would be to load your code with MSWord as a DLL.


These are only a few "hints" to point you in the right direction.

HTH,
DjinnG.
 

reverse coler with VC++

Hi ...
It's all right...
FindWindow(LPCTSTR lpszClassName, LPCTSTR lpszWindowName ) function is a good method to find a window ... and the "CLASS NAME" (LPCTSTR lpClassName ... first parameter) is a good idea to search a window !
The class name of MSWord 2003 is "OpusApp" ... I think which also previous versions of MSWord have same ClassName ... but you can to use SPY++ to verify this.
Well ... now you know how to get the HANDLE: you have the pointer to CWnd object and the relative HANDLE (m_hWnd) .
You need, also, to create your personal CWnd class to handle the WM_PAINT message, WM_CTLCOLOR, WM_ERASEBKGND, or other re-coloring/paint messages events wich you want reHandle... if you wont to repaint NonClientArea (caption,systemmenu ... etc) you need to handle the appropriate messages ;)
Now subclass the MSWord window: when a window is dynamically subclassed, windows messages will route through the CWnd message map and call message handlers in the CWnd class first. Messages that are passed to the base class will be passed to the default message handler in the window.
A (very) little example:

CWnd m_MyWindow; //your WndClass alredy defined

CWnd pWnd=FindWindow("OpusApp",NULL);
m_MyWindow.SubclassWindow(pWnd->GetSafeHwnd());

Now your MyWindow class can to hande every message directed to MainFrame of MSWorrd ... MyWindow can to handle the messages after or befor to redirect the message to Word window, but ... pay attention: if you want to handle message directed to child window, you need to subclass that window ... or windows!!

... and remebrer to call ...
m_MyWindow.UnsubclassWindow();

... when you destroy ... OnDestroy ... your application.

Bye ... mik27
 

Re: reverse coler with VC++

Thank you all for your good advice.
But I'm not a experienced programmer, I can only create simple program using VC++. It seems beyond my ability to realize such a function. So could you please give a simple example to reverse the client area color of Notepad realtime?

Best regards,
HM
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top