Exploring the depths and potentials of ASP.NET RSS 2.0 or Subscribe to .BenRush by Email
 Saturday, February 18, 2006

I encountered a user interface "problem" today. At work I have multiple monitors, and at home I only have the one on my machine (I own Dell 9300, and so it's my desktop at both places). As a result, sometimes when going back and forth between the multiple monitors and my single, I sometimes wind up with an app that'll draw itself OFF the desktop window when I suddenly fire it up on my single monitor (if I open the app, it'll show up, but like on some wacky negative x/y coordinate way off in la la land).

There's a way, apparently, to bring the window BACK onto my visible desktop through Alt-SPACE-M or something like that, but I couldn't get it to work for some odd reason. So I wrote an app that'll simply re-align all my desktop windows to the 0/0 x/y position. It's a rough hack because all I wanted was to get my app to draw its window in a sane position again - so, I wouldn't take the code as-is and use it wherever. It worked for me, and it was an interesting way to step back and realize "Man, I'm a geek".

using System;
using System.Collections.Generic;
using System.Text;

namespace StraightenWindows
{
    class Interop
    {
        public delegate System.Boolean EnumWindowsProc(
            System.IntPtr hWnd,
            System.Int32 lParam);
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern System.Boolean EnumDesktopWindows(
            System.IntPtr hDesktop,
            Interop.EnumWindowsProc lpfn,
            System.Int32 lParam);
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern System.Boolean IsWindow(System.IntPtr hWnd);
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern System.Boolean IsWindowVisible(System.IntPtr hWnd);
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern System.IntPtr GetParent(System.IntPtr hWnd);
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern System.Int32 GetWindowText(
            System.IntPtr hWnd,
            [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr, SizeConst = 255)]
            System.Text.StringBuilder lpString,
            System.Int32 nMaxCount);
        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern System.Boolean MoveWindow(
            System.IntPtr hWnd,
            System.Int32 x, System.Int32 y,
            System.Int32 nWidth, System.Int32 nHeight, System.Boolean bRepaint);
    }
    class Program
    {
        static System.Boolean EnumWindowsCallback(System.IntPtr hWnd, System.Int32 lParam)
        {
            // verify it's a window and it's visible
            if (Interop.IsWindow(hWnd) && Interop.IsWindowVisible(hWnd))
            {
                // verify it's a parent window
                if (Interop.GetParent(hWnd) == System.IntPtr.Zero)
                {
                    // the get parent can also return zero on error, so check for that condition.
                    if (System.Runtime.InteropServices.Marshal.GetLastWin32Error() == 0)
                    {
                        System.Text.StringBuilder sb = new StringBuilder(255);
                        if (Interop.GetWindowText(hWnd, sb, 255) > 0)
                        {
                            Console.WriteLine("Window " + hWnd.ToString() + " has text '" + sb.ToString() + "'");
                            Console.WriteLine();
                            Console.WriteLine();
                            // fix
                            Interop.MoveWindow(
                                hWnd,
                                0, 0, 500, 500, true);
                        }
                    }
                }
            }

           
            return true;
        }
        static void Main(string[] args)
        {
            Interop.EnumWindowsProc p = new Interop.EnumWindowsProc(EnumWindowsCallback);
            Interop.EnumDesktopWindows(System.IntPtr.Zero, // use current desktop
                p, 0);
            Console.Write("Press any key to continue...");
            Console.ReadKey();
            return;
        }
    }
}


kick it on DotNetKicks.com
Saturday, February 18, 2006 3:27:45 PM (Central Standard Time, UTC-06:00)  #    Comments [2] - Trackback
Computing | Personal Adventures
Tracked by:
http://freewebs.com/aspxfaq/11/sitemap19.html [Pingback]
http://freewebs.com/toltom/08/sitemap13.html [Pingback]
http://freewebs.com/toltom/02/aol-yellow-pages.html [Pingback]
http://freewebs.com/toltom/13/sitemap14.html [Pingback]
http://freewebs.com/toltom/05/parent-plus-loans.html [Pingback]
"http://kevruublog.tripod.com/12.html" (http://kevruublog.tripod.com/12.html) [Pingback]
"http://kevruublog.tripod.com/95.html" (http://kevruublog.tripod.com/95.html) [Pingback]
"http://awlelm.org/sitemap3.html" (http://awlelm.org/sitemap3.html) [Pingback]
"http://hzwu9e.org/www-3abn-org.html" (http://hzwu9e.org/www-3abn-org.html) [Pingback]
"http://topslots.nl.eu.org/04/sitemap14.html" (http://topslots.nl.eu.org/04/site... [Pingback]
"http://freewebs.com/amexa/13/small-business-government-loans.html" (http://free... [Pingback]
"http://freewebs.com/amexa/12/www-first-premier-bank.html" (http://freewebs.com/... [Pingback]
"http://freewebs.com/amexa/23/free-driving-directions.html" (http://freewebs.com... [Pingback]
"http://pinofranc.homestead.com/00/casinoonnet.html" (http://pinofranc.homestead... [Pingback]
"http://pinofranc.homestead.com/00/magnesium-citrate.html" (http://pinofranc.hom... [Pingback]
"http://pinofranc.homestead.com/01/honeybaked-ham.html" (http://pinofranc.homest... [Pingback]
"http://wdall-xxx.com/housewife-whores.html" (http://wdall-xxx.com/housewife-who... [Pingback]
"http://qkzei-www.com/hairy-sluts.html" (http://qkzei-www.com/hairy-sluts.html) [Pingback]
"http://talpeenews.tripod.com/171.html" (http://talpeenews.tripod.com/171.html) [Pingback]
"http://pasbeenews.tripod.com/106.html" (http://pasbeenews.tripod.com/106.html) [Pingback]
"http://pasbeenews.tripod.com/173.html" (http://pasbeenews.tripod.com/173.html) [Pingback]
"http://iauci-ooo.com/gay-men-cumming.html" (http://iauci-ooo.com/gay-men-cummin... [Pingback]
"http://pasbeenews.tripod.com/73.html" (http://pasbeenews.tripod.com/73.html) [Pingback]
"http://wepyv-hhh.com/free-porn-movies-no-credit-card.html" (http://wepyv-hhh.co... [Pingback]
"http://adtih-xxx.biz/naked-guys-having-sex.html" (http://adtih-xxx.biz/naked-gu... [Pingback]
"http://tjkbb-www.biz/free-wives-fucking.html" (http://tjkbb-www.biz/free-wives-... [Pingback]
"http://p4g2f-eee.com/robot-girl.html" (http://p4g2f-eee.com/robot-girl.html) [Pingback]
"http://freewebs.com/amexa/31/california-board-of-vocational-nursing.html" (http... [Pingback]
"http://freewebs.com/tiltak/16/cheapflights.html" (http://freewebs.com/tiltak/16... [Pingback]
"http://freewebs.com/pentac/09/serotonin-syndrome.html" (http://freewebs.com/pen... [Pingback]
"http://freewebs.com/niret/05/travelosity-com.html" (http://freewebs.com/niret/0... [Pingback]
"http://freewebs.com/tiltak/11/googgle.html" (http://freewebs.com/tiltak/11/goog... [Pingback]
"http://tixpf-rrr.com/cumming-teens.html" (http://tixpf-rrr.com/cumming-teens.ht... [Pingback]
"http://unibetkom.fw.bz/00823-blog.html" (http://unibetkom.fw.bz/00823-blog.html... [Pingback]
"http://ramambo.nl.eu.org/15/midflorida.html" (http://ramambo.nl.eu.org/15/midfl... [Pingback]
"http://ramambo.nl.eu.org/www-ghtravel-com.html" (http://ramambo.nl.eu.org/www-g... [Pingback]
"http://harum.nl.eu.org/www-generalcinema-com.html" (http://harum.nl.eu.org/www-... [Pingback]
"http://opmg8at.biz/random-sex.html" (http://opmg8at.biz/random-sex.html) [Pingback]
"http://mordor.nl.eu.org/sitemap26.html" (http://mordor.nl.eu.org/sitemap26.html... [Pingback]
"http://krpefgb.com/lioncountrysafari-com.html" (http://krpefgb.com/lioncountrys... [Pingback]
"http://meritblog.nl.eu.org/avenge-sevenfold-pictuers.html" (http://meritblog.nl... [Pingback]
"http://swe--kom.nl.eu.org/cute-teen-model.html" (http://swe--kom.nl.eu.org/cute... [Pingback]
"http://freewebs.com/gabeganews/134.html" (http://freewebs.com/gabeganews/134.ht... [Pingback]
"http://cyisevw.com/balloon-repairs-of-east-texas.html" (http://cyisevw.com/ball... [Pingback]
"http://ana--blog.nl.eu.org/celebrity-addresses.html" (http://ana--blog.nl.eu.or... [Pingback]
"http://liko--blog.nl.eu.org/bbs-little.html" (http://liko--blog.nl.eu.org/bbs-l... [Pingback]
"http://teno--blog.nl.eu.org/free-adult-clips.html" (http://teno--blog.nl.eu.org... [Pingback]
"http://nasferablog.netfirms.com/532.html" (http://nasferablog.netfirms.com/532.... [Pingback]
"http://cypvori.biz/i2-peapod-com.html" (http://cypvori.biz/i2-peapod-com.html) [Pingback]
"http://nasferablog.netfirms.com/553.html" (http://nasferablog.netfirms.com/553.... [Pingback]
"http://ger--kom.nl.eu.org/black-suck.html" (http://ger--kom.nl.eu.org/black-suc... [Pingback]
"http://wbml1ig.biz/female-spanking.html" (http://wbml1ig.biz/female-spanking.ht... [Pingback]
"http://mdvcjaj.biz/clevelandplaindealer.html" (http://mdvcjaj.biz/clevelandplai... [Pingback]
"http://gqkkthz.biz/il-department-of-corrections.html" (http://gqkkthz.biz/il-de... [Pingback]
"http://nasferablog.netfirms.com/315.html" (http://nasferablog.netfirms.com/315.... [Pingback]
"http://zf1y1fs.biz/yahoomessagner.html" (http://zf1y1fs.biz/yahoomessagner.html... [Pingback]
"http://hjftsic.biz/isneychannel.html" (http://hjftsic.biz/isneychannel.html) [Pingback]
"http://freewebs.com/fremapblog/sitemap5.html" (http://freewebs.com/fremapblog/s... [Pingback]
"http://freewebs.com/sruone/arental-controls.html" (http://freewebs.com/sruone/a... [Pingback]
"http://freewebs.com/sruone/sitemap117.html" (http://freewebs.com/sruone/sitemap... [Pingback]
"http://lopbafrea.homestead.com/73.html" (http://lopbafrea.homestead.com/73.html... [Pingback]
"http://gz2w3gv.info/villanova-basketball.html" (http://gz2w3gv.info/villanova-b... [Pingback]
"http://freewebs.com/vuter/16/www-car-rental.html" (http://freewebs.com/vuter/16... [Pingback]
"http://euter.homestead.com/01/linfield-college.html" (http://euter.homestead.co... [Pingback]
"http://freewebs.com/vuter/04/sitemap8.html" (http://freewebs.com/vuter/04/sitem... [Pingback]
"http://buter.homestead.com/00/diapers.html" (http://buter.homestead.com/00/diap... [Pingback]
"http://freewebs.com/datingblogger/1686.html" (http://freewebs.com/datingblogger... [Pingback]
"http://freewebs.com/datingblogger/784.html" (http://freewebs.com/datingblogger/... [Pingback]
"http://fasxen.netfirms.com/20.html" (http://fasxen.netfirms.com/20.html) [Pingback]
Monday, February 20, 2006 11:19:43 AM (Central Standard Time, UTC-06:00)
if the window has an icon (=o|... is that what is called?, I just realized I don't know what to call them) on the task bar all you have to do is right clik on it, select move, then use the keyboard arrows to move it into a visual position
Tuesday, February 21, 2006 6:35:03 PM (Central Standard Time, UTC-06:00)
...you rock, thanks.
Ben Rush
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview

Computers Blogs - Blog Top Sites

Archive
<January 2009>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567
Blogroll
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2009
Benjamin Rush
Sign In
Statistics
Total Posts: 444
This Year: 0
This Month: 0
This Week: 0
Comments: 128
Themes
Pick a theme:
All Content © 2009, Benjamin Rush
DasBlog theme 'Business' created by Christoph De Baene (delarou)