Reputation: 285
We can set window text with:
BOOL WINAPI SetWindowText(
__in HWND hWnd,
__in_opt LPCTSTR lpString
);
and this windows text by another application
int WINAPI GetWindowText(
__in HWND hWnd,
__out LPTSTR lpString,
__in int nMaxCount
);
I don't want to change my forms caption but I want to keep a custom text in window and get this text by another instance of same program. How can I achieve this?
Upvotes: 2
Views: 375
Reputation: 613322
Probably the easiest way to do this is to define a windows message in the WM_APP range and send it from one instance to the other. You'd have to do your own marshalling though with something like GlobalAlloc.
Upvotes: 1
Reputation: 437604
A simple way to do this is:
This scheme allows you to send arbitrary data (as long as it doesn't include pointers) provided that the data is reasonably small (say a few KB tops). It's also easy to implement. What it does lack is security controls, so if you have to prevent the bad guys from retrieving this data from your application you will need to use something more heavy-duty.
Upvotes: 3
Reputation: 4585
I am not sure, but I think you will have to open the other process using openProcess
and then use some function on the process handle to get the title text. Once you have the text, you can very well use that in your application. For getting the process if of the required process, you can use EnumProcess
, here is a complete example: http://msdn.microsoft.com/en-us/library/ms686701%28v=vs.85%29.aspx
Upvotes: 1