Zooming windows macro (Mac-style)

Functions, classes, components, etc. Only high quality content.

Zooming windows macro (Mac-style)

Postby Lindsey on Tue Jun 07, 2005 2:04 am

Here’s a moderate length macro which I’ve grown very addicted to. This implements a rough version of Mac-style window zooming in Windows Explorer.

In other words, it automatically resizes Explorer (the file browser, not Internet Explorer) windows to be large enough to show the entire contents of the folder, but not waste too much extra space. I’ve set it to leave room for one extra item without needing to resize, so that I can copy or move in a new file without messing with the window.

I’ve got it set up with two triggers — One is automatic whenever the application "explorer" (only) makes a class "CabinetWClass" window "created & active". The other trigger runs whenever I click on the "maximize" box. That’s useful if I’ve added items to the window after opening it. (I very rarely run applications maximized — And when I do, I can just double click on the title bar, instead of using the maximize box.)

This macro is designed for my two monitor setup. They’re positioned with one left, one right, so all negative x coordinates are on the left monitor. But the macro should work for a single monitor, too. (You could probably speed it up inperceptibly by removing the two monitor logic.)

Since this is a quick-and-dirty macro made for my own use, there are a few numeric constants in there — I’ve tried to comment those, where they show up. In particular, look for three exclamation marks (!!!) where you’ll need to replace my constants. Usually these depend on the size of your monitors, or the details of your Windows theme (menubar height, font height, and the like).

Edit: One more note — I’ve written this to allow only the List and Details views, since those are all I really use, myself.

To trigger the macro automatically whenever an appropriate Windows Explorer window opens, use the trigger:
!ca"" "CabinetWClass" /explorer


To trigger the macro automatically whenever you press the maximize button, I’d suggest that you first add a couple lines to the start of the macro:
act win(xm ym)
key F5


That’ll make sure the window is active (in case you pressed the maximize button from another application), and then refresh its contents. That will make the macro work better in case you’ve put a new, long-named item in the folder since last opening it.

And here is the macro, itself:
int windowLeft windowTop windowWidth
int theWindowHdl = win()

GetWinXY theWindowHdl &windowLeft &windowTop &windowWidth
int maxRows

;;maxRows is the total number of rows of text which can fit on the screen. Ideally you’d
;;want to calculate it on the fly from the monitor height, taskbar height, font height, etc.
;;Instead, I’ve just entered the values which are correct for my screen.
;;!!! You’ll want to put your own value, here:

if (windowLeft + (windowWidth/2) < 0)
,maxRows = 54
else
,maxRows = 66

int detailsPanel = child("" "SysHeader32" theWindowHdl 0x401)
if (!detailsPanel)
,men 28715 ;;Make sure it’s List view

Acc thisItem = acc("" "LISTITEM" theWindowHdl "SysListView32" "" 0x1000)
int x y cx cy
int numItems = 0
;;These values are the minimum allowable size of a window.
;;You can change this to your own taste.
if(!thisItem.a)
,cx = 240
,cy = 17
else
,rep
,,numItems += 1
,,thisItem.Navigate("next")
,err+
numItems += 1
thisItem.Location(x y cx cy)
err
,ret

int endWidth endHeight
;;Is it a details window, or a list window
if (detailsPanel)
,if (numItems > maxRows)
,,numItems = maxRows
,,;;This is the width of the scrollbar for my choice of theme.
,,;;!!! You may need to change it slightly for your own theme.
,,cx += 14
,endWidth = cx+12
,;;This is the extra height (title bar + menu bar + details contols height)
,;;!!! You’ll probably want to change it for your own fonts and theme
,endHeight = cy*numItems+75
else
,int numColumns = 1+ (numItems/maxRows)
,int itemsPerColumn = (numItems+numColumns-1) / numColumns
,;;This logic avoids a really tall, skinny window
,if ((cy*itemsPerColumn)/iif((cx*numColumns>180) (cx*numColumns) 180)>2)
,,numColumns +=1
,,itemsPerColumn = (numItems+numColumns-1) / numColumns
,;;This sets a minimum width for the window, again
,if (cx*numColumns < 180)
,,cx = 180/numColumns
,endWidth = ((cx*numColumns)+12-iif((numColumns=1) 6 0))
,;;These lines set a maximum width for the window.
,;;!!! You’ll want to change this to match your own screen(s)
,if (windowLeft + (windowWidth/2) < 0) ;; If it's on the left screen
,,if (endWidth>1278)
,,,endWidth = 1278
,else
,,if (endWidth > 1598)
,,,endWidth = 1598
,;;Again, this is the extra height (title bar + menu bar)
,;;!!! You’ll probably want to change it for your own fonts and theme
,endHeight = (cy*itemsPerColumn)+69

;;Now we make sure the window isn’t too tall
;;The constants here are from the height of the monitor(s).
;;!!! You’ll want to change these to match the height of your own screen(s)
if (windowLeft + (windowWidth/2) < 0) ;; If it's on the left screen
,if (windowTop + endHeight > 1168) ;; Need to adjust vertical
,,windowTop = 1169 - endHeight
,if (windowLeft + endWidth > 0) ;; Need to adjust horizontal
,,windowLeft = 0 - endWidth
else ;; on the right screen
,if (windowTop + endHeight > 1198) ;; Need to adjust vertical
,,windowTop = 1197 - endHeight
,if (windowLeft + endWidth > 1599) ;; Need to adjust horizontal
,,windowLeft = 1599 - endWidth
MoveWindow theWindowHdl windowLeft windowTop endWidth endHeight 1
Lindsey
 
Posts: 19
Joined: Sat Mar 08, 2003 12:14 pm

Return to QM Extensions

Who is online

Users browsing this forum: No registered users and 1 guest