x2 status bar messaging?

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

x2 status bar messaging?

Post by sanferno »

Hi,

When I run a custom command, is it possible to show some message in x2 status bar? I mean, the same way x2 shows a text at the botton left corner of the main window, letting me know of any error or succesfully executed process .
Now I'm doing it with message boxes, but I would like to explore other ways.

Thanks.
User avatar
nikos
Site Admin
Site Admin
Posts: 15800
Joined: 2002 Feb 07, 15:57
Location: UK
Contact:

Re: x2 status bar messaging?

Post by nikos »

if your command is a dos program, you can use printf and the console to see the messages. Use $ prompt instead of > to run it
Kilmatead
Platinum Member
Platinum Member
Posts: 4578
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: x2 status bar messaging?

Post by Kilmatead »

The control ID for the statusbar in x2 is 59393, so for scripting languages, you can just use functions like ControlSetText(), etc once you have the current handle of the main x2 window. If you're using the WinAPI (for non-scripting languages) you'd probably use something like SetDlgItemText() or some variant of WM_SETTEXT or SB_SETTEXTW, and you would need to get the handle (from that control ID subsequent to the x2 window handle) first, etc.

If you can't get it to work yourself, I can play with the WinAPI method tonight just for fun, but it shouldn't be that difficult. :shrug:

It all depends on what kind of thing you're trying to do. And keep in mind that since x2 uses the statusbar itself from time to time, any information you write there can't be guaranteed to last very long - but it's fine for quick messages to the user. And not quite as old-skool clunky as Nikos' DOS windows. :wink:
sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

Re: x2 status bar messaging?

Post by sanferno »

Kilmatead wrote:It all depends on what kind of thing you're trying to do.
I'm running some executables derived from C#. By taking special folders or Access databases, they perform diferent data management routines without lauching more sophisticated software. For instance, those programs take as argument the path of one folder or a "*.mdb" file, then carry out some business and, finally, let the user know the work is done by showing a message box.
Kilmatead wrote:The control ID for the statusbar in x2 is 59393, so for scripting languages, you can just use functions like ControlSetText(), etc once you have the current handle of the main x2 window.
Although I'm not using script languages, this seems to be the approach I'm looking for, but I have never used it. Could you show me one example?
Kilmatead wrote:And not quite as old-skool clunky as Nikos' DOS windows.
In some way, this is the same scenario that I have with the message boxes.

It's not a big deal to use my current solution, but I thought it would be fun to try to show it in the status bar. My guessing sense said to me it would be relatively easy... maybe this is one more case that shows how bad is my intuition :lol:
Kilmatead
Platinum Member
Platinum Member
Posts: 4578
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: x2 status bar messaging?

Post by Kilmatead »

Using the AutoIt scripting language, the simplest example is this:

Code: Select all

Global Const $STATUSBAR = "[ID:59393]"
Global $hWin = WinActive("[REGEXPCLASS:ATL:(Explorer)|(Scrap)Frame]")
If IsHWnd($hWin) Then ControlSetText($hWin, "", $STATUSBAR, "The End of the World is Nigh")
...which is pretty self explanatory. Naturally, you'd have to launch/communicate your programme's return codes through the script itself, which is a bit weird, so it's easier to build it into your programme in the first place using whatever language you're in.

I don't know C# so I can't help you there, but it can use WinAPI stuff just as well as anything else, so it's just a matter of figuring it out. I'll see what I can do in C tonight with WinAPI and that should be easy enough for you to translate...
Kilmatead
Platinum Member
Platinum Member
Posts: 4578
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: x2 status bar messaging?

Post by Kilmatead »

Right, well that was easy - just use GetDlgItem() and WM_SETTEXT from the stock Win32 API...

Code: Select all

#include <windows.h>

#define STATUSBAR 59393

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) {
	HWND hWin = FindWindowW(L"ATL:ExplorerFrame", NULL);

	if (hWin) {
		HWND hStatusBar = GetDlgItem(hWin, STATUSBAR);

		if (hStatusBar) SendMessageW(hStatusBar, WM_SETTEXT, (WPARAM) 0, (LPARAM) L"The End is Nigh");
	}

	return 1;
}
Proof of concept: TheEndIsNigh.rar

For some reason SB_SETTEXTW (which is specially for STATUSCLASSNAME controls) didn't want to work correctly - probably because Nikos creates his statusbar with the WTL layer, so god only knows what it expects. Anyway, since WM_SETTEXT works fine, no reason to overcomplicate things. :D
sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

Re: x2 status bar messaging?

Post by sanferno »

Kilmatead wrote:..., no reason to overcomplicate things. :D
Holy S!

That was a badass trick... hope to get it working on C#. I'll try to upload the equivalent :wink:
sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

Re: x2 status bar messaging?

Post by sanferno »

Well, I have not found the final key to make it work, after a while I have come to this point (read comments "//" to get more info):

Code: Select all

class Program
{
	[DllImport("user32.dll", EntryPoint="FindWindow", CharSet = CharSet.Auto)]
	public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

	[DllImport("user32.dll", EntryPoint = "GetDlgItem", CharSet = CharSet.Auto)]
	public static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);

	[DllImport("user32.dll")]
	public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, int wParam, string lParam);

	static void Main(string[] args)
	{
		const int STATUSBAR = 59393;
		const UInt32 WM_SETTEXT = 0x000C;    // Not sure this value is correct

		// return = 3082668
		IntPtr hWnd = FindWindow("ATL:ExplorerFrame", null);

		// return = 0
		IntPtr hStatusBar = GetDlgItem(hWnd, STATUSBAR);

		// return = 0 and no text is shown
		IntPtr LRESULT = SendMessage(hStatusBar, WM_SETTEXT, 0, "The End is Nigh");
	}
}
Any clue, K? :?

EDIT: upper code is actually working.
Last edited by sanferno on 2016 Jul 30, 10:55, edited 4 times in total.
Kilmatead
Platinum Member
Platinum Member
Posts: 4578
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: x2 status bar messaging?

Post by Kilmatead »

Well, at a guess I'd say a typo... "const int STATUSBAR = 59383;" should probably read 59393.
sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

Re: x2 status bar messaging?

Post by sanferno »

Kilmatead wrote:59393.
That was it, finally made it!
Good sample code to have when need it.

Here is the source code (also corrected in my former post) and a little exe (console application) to view the result:
TheEndIsNigh_DotNet.7z
Thank you Kilmatead :beer:
Kilmatead
Platinum Member
Platinum Member
Posts: 4578
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: x2 status bar messaging?

Post by Kilmatead »

Glad to see you didn't get your PhD out of a box of Cornflakes after all. :wink:

In the interest of completeness, note that only the main x2 window is actually ATL:ExplorerFrame... if you run something from within a scrap window (and that scrap window has a status bar), the message will only be relayed to the main window's status bar, not the scrap's status bar. Scrap windows are ATL:ScrapFrame. This of course leads into the whole question of user-expectation, "active"/"last active" windows, etc... so the code snippet cannot be considered robust as-is. But hey, it works, so everything else is minor.

Just sayin'. :D

(And if I really wanted to get pedantic, that SendMessage actually returns an LRESULT type not a handle type, so "hResult" is not a contextually correct label. And I liked your first one better "resultado" sounds exotic and cool... "hResult" just sounds... middle-class. But hey... :D)
sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

Re: x2 status bar messaging?

Post by sanferno »

At least I have learned new interesting things today, so that pays the effort. I'm not planning for the Nobel, mortals as me have to enjoy this little pleasure pills.

Windows API seems to me a new level of complexity in programming but, hey, today there are plenty of didatic resources in the internet. For instance, I get lost with all this LRESULT, WPARAM, LPARAM... among others such as the "ATLs" codes, where do the come from? :roll:

After showing this amount of knowledge, if I were you, I would not bet on where did I get my PhD (maybe inside a Big Mac) :oops:
Kilmatead
Platinum Member
Platinum Member
Posts: 4578
Joined: 2008 Sep 30, 06:52
Location: Dublin

Re: x2 status bar messaging?

Post by Kilmatead »

sanferno wrote:Windows API seems to me a new level of complexity in programming but, hey, today there are plenty of didatic resources in the internet. For instance, I get lost with all this LRESULT, WPARAM, LPARAM... among others such as the "ATLs" codes, where do the come from?
Yes, the minutia of things on the WinAPI level is rather amazing, and seemingly endless. The more you look into how things actually work, the more you see that you never imagined existed. That's why there are so many frameworks around designed to make things easier [too easy] (.Net, Java, innumerable cross-platform libraries, etc) - most of them built to actually abstract away from learning the "real thing". That said, sometimes the WinAPI does otherwise simple things in a distinctly "back-asswards way", which doesn't help matters. But... like any good masochist, I find it all rather entertaining. :D
sanferno wrote:After showing this amount of knowledge I have shown, if I were you, I would not bet on where did I get my PhD (maybe inside a Big Mac)
Well, you're the one listening to programming advice from a common-labourer/gardener (me), so who's the worse bet here? :D
sanferno
Silver Member
Silver Member
Posts: 288
Joined: 2013 Nov 30, 18:40

Re: x2 status bar messaging?

Post by sanferno »

Kilmatead wrote:Well, you're the one listening to programming advice from a common-labourer/gardener (me), so who's the worse bet here? :D
Two drifters, off to see the world
There's such a lot of world to see
We're after the same rainbow's end, waitin' 'round the bend
My huckleberry friend, Moon River, and me

Henry Macini - Moon River (Stevie Wonder playing his harmónica beautifully):
https://www.youtube.com/watch?v=7BLwnpreKq4

This could be a good footnote for, apart from learning programming, listen some good music. Meanwhile, I'll begin the search of the new question to keep us away from wasting our time. :shifty:
namsupo
Member
Member
Posts: 49
Joined: 2007 Aug 29, 02:02

Re: x2 status bar messaging?

Post by namsupo »

Kilmatead wrote:For some reason SB_SETTEXTW (which is specially for STATUSCLASSNAME controls) didn't want to work correctly - probably because Nikos creates his statusbar with the WTL layer, so god only knows what it expects.
More likely, because while WM_SETTEXT is one of a limited number of messages that Windows provides transparent cross-process marshalling for, SB_SETTEXTW isn't. You would need to inject your code into the x2 process in order to send SB_SETTEXTW from another process successfully.
Post Reply