Shoutbox

[help] Windows widths and heights... - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [help] Windows widths and heights... (/showthread.php?tid=93453)

[help] Windows widths and heights... by whiz on 01-06-2010 at 06:15 PM

I want to make a more visual method of creating windows in Interface Writer, and I need to know if I can get the width and height of a PlusWnd object.  I'm guessing that I would need to register the WM_SIZE notification on the window, and also that I would need to use Interop, but what function?

And also, can I set the width and height of the window?

Edit: is this on the right lines?


RE: [help] Windows widths and heights... by Mnjul on 01-06-2010 at 06:25 PM

You can also use MoveWindow instead of SetWindowPos.
As for retrieving the window's dimension, use GetWindowRect (if there's no need to get notified every time the dimension is changed)


RE: [help] Windows widths and heights... by Spunky on 01-06-2010 at 06:26 PM

quote:
Originally posted by Mnjul
if there's no need to get notified every time the dimension is changed

I would imagine he would so that he could update the xml to reflect the new size
RE: [help] Windows widths and heights... by Mnjul on 01-06-2010 at 06:28 PM

quote:
Originally posted by Spunky
quote:
Originally posted by Mnjul
if there's no need to get notified every time the dimension is changed

I would imagine he would so that he could update the xml to reflect the new size
Well, then, WM_SIZE is the way to go. Anyway its lParam encompasses the window dimension values so no need to GetWindowRect if you listen to WM_SIZE.
RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 06:33 PM

quote:
Originally posted by Spunky
quote:
Originally posted by Mnjul
if there's no need to get notified every time the dimension is changed

I would imagine he would so that he could update the xml to reflect the new size
Correct.  I'm making a window designer that uses a blank window, with a title text box, minimize/maximize/close checkboxes and so on, as well as two text boxes that reflect the current size of the window.

js code:
var WndTest = MsgPlus.CreateWnd("Interfaces\\Test.xml", "WndTest", 0);
WndTest.RegisterMessageNotification(0x5, true);
function OnWndTestEvent_MessageNotification(PlusWnd, Message, wParam, lParam)
{
    if (Message === 0x5)
    {
        WndTest.SetControlText("EdtWidth", "");
        WndTest.SetControlText("EdtWidth", "");
    }
}
The problem is...  the lParam contains a single, long, number.  How can I separate this into the width and height?

Example: start size equates to "19661199".
RE: [help] Windows widths and heights... by Matti on 01-06-2010 at 06:51 PM

quote:
Originally posted by MSDN
lParam
    The low-order word of lParam specifies the new width of the client area.
    The high-order word of lParam specifies the new height of the client area.
This is where bitwise operations come in handy. To get the low-order word, you need to get the first word from the number. A word is an unsigned number of 2 bytes or 16 bits. The maximum word value is thus 1111 1111 1111 1111 in binary or 65,535 in decimal or FFFF in hexadecimal. We can now use the & operator to do a bitwise AND operation. The AND operator takes two bits and returns 1 if both bits are 1, otherwise it gives 0. Applying this bit by bit on lParam and 0xFFFF, you'll get 0 for all bits further than bit 16 and bits 1 to 16 will give you the original bits from lParam in that position. This gives you the low-order word.
js code:
var width = lParam & 0xFFFF;
For the height, we need to get the other 16 bits. This can be done by shifting the bits of lParam 16 bit positions to the right using the bitwise right-shift operator >>. For example: bit 20 will be shifted to bit 4 for example and bits 1 to 16 will be discarded. This gives you the high-order word.
js code:
var height = (lParam >> 16);
If you want to be really sure that you're only getting 16 bits, you can do an & 0xFFFF operation on the result to discard any bits after bit 32. This won't be necessary for WM_SIZE since Windows promises you to only give you 32 bits.

Built-in operators are always lots faster than another call to GetWindowRect, so you better use them! :D
RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 07:09 PM

Ok, that works great!

Next question: can I set the width and height of the window?  I've tried this:

js code:
Interop.Call("user32.dll", "SetWindowPos", WndTest, null, 0, 0, 300, 200, SWP_NOMOVE | SWP_NOZORDER);
But nothing happens.  No error, just nothing.
RE: [help] Windows widths and heights... by Spunky on 01-06-2010 at 07:15 PM

You need to pass the handle to WndTest, not the object, don't you?

EDIT: Well I mean from WndTest to the function... before someone says something :p


RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 07:21 PM

True.  :P  Ok, but now I have another problem.

js code:
var SWP_NOMOVE = 2;
var SWP_NOZORDER = 4;

var WndTest = MsgPlus.CreateWnd("Interfaces\\Test.xml", "WndTest", 0);
WndTest.RegisterMessageNotification(0x5, true);
WndTest.SetControlText("EdtWidth", 400);
WndTest.SetControlText("EdtHeight", 300);

function OnWndTestEvent_MessageNotification(PlusWnd, Message, wParam, lParam)
{
    if (Message === 0x5)
    {
        WndTest.SetControlText("EdtWidth", (lParam & 0xFFFF));
        WndTest.SetControlText("EdtHeight", (lParam >> 16));
    }
}

function OnWndTestEvent_CtrlClicked(PlusWnd, ControlId)
{
    if (ControlId == "BtnSize")
    {
        Interop.Call("user32.dll", "SetWindowPos", WndTest.Handle, null, 0, 0, WndTest.GetControlText("EdtWidth"), WndTest.GetControlText("EdtHeight"), SWP_NOMOVE | SWP_NOZORDER);
    }
}
That's what I have so far.  But by clicking the size button after typing in, say, 300x200, I end up with an infinitely sized window.  Am I missing something?

Edit: never mind, found it.  Forgot parseInt().

Although, it doesn't actually size it right.  400x300 comes out as 394x268.  How come?
RE: [help] Windows widths and heights... by Spunky on 01-06-2010 at 07:26 PM

Have you tried Tracing the EdtWidth and EdtHeight values? I've got a feeling it might not be reading them right. Don't know, but it might have something to do with the type conversion, although I would have imagined it would convert to an integer ok.

EDIT: parseInt... Does that mean I was right (even if I was late :p)

I think the missing pixels in the size may be something to do with the window borders possibly? 32 pixels for a top border seems about right to be honest


RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 07:31 PM

Ok, I'm adding 6 to the width and 32 to the height, which counter-acts the borders.  Seems to work great!

One other thing...  is there a way to convert dialog units to pixels, and back again?


RE: [help] Windows widths and heights... by Spunky on 01-06-2010 at 07:37 PM

I think it's all dependant on screen resolution and some other factors, including font from what I've read, but the topics mostly all relate to VB and C++...

EDIT: http://www.freebasic.net/forum/viewtopic.php?p=83555 <-- Might Help


RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 07:55 PM

Looks a bit confusing...  :S

quote:
Originally posted by MSDN
MapDialogRect: http://msdn2.microsoft.com/en-us/library/ms645502.aspx

The MapDialogRect function converts the specified dialog box units to screen units (pixels). The function replaces the coordinates in the specified RECT structure with the converted coordinates, which allows the structure to be used to create a dialog box or position a control within a dialog box.
I need to convert pixels to dialog units, not dialog units to pixels...
RE: [help] Windows widths and heights... by Spunky on 01-06-2010 at 08:13 PM

I didn't check, but I thought maybe you could reverse the process?

If this is to convert the units from pixels (from the window) to dialog units (inside the xml), then can't you just force the measurements in pixels? I know it's probably not quite what you want, but it's guaranteed to look the same and will save having to add functions or classes to figure it out for you.


RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 08:53 PM

That's what I've thought about doing.  The user can always change it to dialog units if they want, but if they use the builder, then it'll have to be in pixels.  :P

[Image: attachment.php?pid=983973]

That's what the builder will look like.  ;)  Suggestions welcome.

Edit: I really doubt the feasibility of this, but I'm going to ask anyway.  Is there a way of working out the co-ordinates of a rectangle drawn with the mouse onto a Plus! window?  Would this need a certain control?  If this isn't possible, would I be able to record two clicks (one for the top-left, one for the bottom-right)?


RE: [help] Windows widths and heights... by T-PO on 01-06-2010 at 09:17 PM

Looks great!

Keep up the good work!

T-PO


RE: [help] Windows widths and heights... by Eljay on 01-06-2010 at 09:31 PM

quote:
Originally posted by whiz
Edit: I really doubt the feasibility of this, but I'm going to ask anyway.  Is there a way of working out the co-ordinates of a rectangle drawn with the mouse onto a Plus! window?  Would this need a certain control?  If this isn't possible, would I be able to record two clicks (one for the top-left, one for the bottom-right)?

It certainly should be possible. You would have to deal with drawing the rectangle yourself using GDI or whatever, but you would basically just have to handle mouse messages (WM_LBUTTONDOWN,WM_MOUSEMOVE,etc.) and redraw the rectangle each time. Unfortunately there's no magic control that does this for you that I know of, but it shouldn't be too hard to implement.
RE: [help] Windows widths and heights... by whiz on 01-06-2010 at 09:49 PM

Hmm...  :)  I'll have to think about it.  For now, I need some sleep and preparation for exams.  ;)


RE: [help] Windows widths and heights... (solved for now) by matty on 01-06-2010 at 11:10 PM

quote:
Originally posted by whiz
Edit: I really doubt the feasibility of this, but I'm going to ask anyway.  Is there a way of working out the co-ordinates of a rectangle drawn with the mouse onto a Plus! window?  Would this need a certain control?  If this isn't possible, would I be able to record two clicks (one for the top-left, one for the bottom-right)?
Screenshot Sender has this capability for sending the Selected Area.

Have a look at the code: http://beta.screenshotsender.com/code/WindowHandl...ectArea_handler.js
And the Window: http://beta.screenshotsender.com/code/Languages/en/SelectArea.xml

Cheers!
RE: [help] Windows widths and heights... (solved for now) by whiz on 01-07-2010 at 02:04 PM

quote:
Originally posted by matty
Screenshot Sender has this capability for sending the Selected Area.

Have a look at the code: http://beta.screenshotsender.com/code/WindowHandl...ectArea_handler.js
And the Window: http://beta.screenshotsender.com/code/Languages/en/SelectArea.xml

Cheers!
I've had a look at the two files, but I'm not exactly sure how to implement it.  How would I be able to draw a rectangle over a Plus! window, and get the left/top/width/height values in relation to that window?
RE: [help] Windows widths and heights... (solved for now) by matty on 01-07-2010 at 04:00 PM

quote:
Originally posted by whiz
quote:
Originally posted by matty
Screenshot Sender has this capability for sending the Selected Area.

Have a look at the code: http://beta.screenshotsender.com/code/WindowHandl...ectArea_handler.js
And the Window: http://beta.screenshotsender.com/code/Languages/en/SelectArea.xml

Cheers!
I've had a look at the two files, but I'm not exactly sure how to implement it.  How would I be able to draw a rectangle over a Plus! window, and get the left/top/width/height values in relation to that window?
Are you doing this so that you can create a control based on the part in which you are dragging?
RE: [help] Windows widths and heights... (solved for now) by whiz on 01-07-2010 at 04:51 PM

quote:
Originally posted by matty
Are you doing this so that you can create a control based on the part in which you are dragging?
Yes, but I know I can't physically make it.  I just need the co-ordinates.  I want to be able to export the window of which the user selects to add a control to, and then open it, allowing them to draw where they want the control on their window.  This would then open the Add Control window, with the co-ordinates set.