Saturday, 10 February 2007

XSI, C# and Hiding the windows title bar

Very simple idea. 'Run xsi fullscreen'

The relevant code :

public bool Execute(Context in_ctxt)
{
int hwnd = 0;
IntPtr HWND_TOP = IntPtr.Zero;
int style;
string str;

// 1. Get a handle to XSI
Process[] pXSi = Process.GetProcessesByName("XSI");

// no messing about here : just get the 1st instance found
if (pXSi.Length != 0){ str = pXSi[0].MainWindowTitle; }
else{return false;}

hwnd = FindWindow(null, str);

// store the current windows style
style = GetWindowLong( (IntPtr) hwnd, GWL_STYLE);

// 2. flip the WS_CAPTION bits
SetWindowLong((IntPtr)hwnd, GWL_STYLE, (style ^= WS_CAPTION));

// refresh the window
SetWindowPos((IntPtr)hwnd, HWND_TOP, 0, 0, 0, 0,
SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);

return true;
}
1. GetProcessByName returns us an array of all the running instances of XSI. (if the array is empty we are in serious trouble as this plugin runs from inside xsi ;)
I'm only really interested in the first one found so, i just get the title and pass that to the FindWindow function - imported from User32.dll.

I know there are better ways of getting a handle and such but, that's not the point of these little tools. They only serve to serve me.
I couldn't care less about good OOP practices, speed, when .Net's GC kicks in...and all the millions of other things that a good coder should be considering.
XSI title bars, as you probably know are convolouted buggers. Essentially, the only thing not listed there is the contents of your 'sexify' directories. so messing about with xsi's sdk to get the current project, app path or whatever the hell i'd need just to get the hwnd didn't even register on my TODO list.
If it works, it's good enough for now :)

2.
soo..I have a spanking new handle to xsi's main window wich i use to find out what style is currently being used ( style = GetWindowLong). then it's just a matter of XOR-ing the bit flags using SetWindowLong (it is a toggle type plugin after all) and refreshing the window (SetWindowPos) and we are done.

simple eh :)

now i just need to work out how to attach the source to this blog

0 comments: