更改Windows 7任务栏的位置自动根据屏幕的形状或对接状态 [英] Change Windows 7 taskbar location automatically based on screen shape or on docking status

查看:375
本文介绍了更改Windows 7任务栏的位置自动根据屏幕的形状或对接状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是使用VBScript或其他编程语言可能以下几点:

Are the following things possible using VBScript or any other programming language:


  • 检测屏幕形状 - 或电脑是否停靠

  • 更改Windows任务栏的位置

我所试图实现的:

我的笔记本电脑有一个14宽屏:pretty宽,但不是很高,我觉得它最方便的位于屏幕左侧的Windows任务栏,因为我可以饶宽度而不是垂直的。空间。

My laptop has a 14" widescreen: pretty wide, but not very high. I find it most convenient to have the Windows taskbar located on the left of the screen, since I can spare the width but not the vertical space.

然而,当在办公室,我的电脑坐落在一个基座,并迷上了一个不错的大屏方形。在这里,我更preFER有在底部的默认位置,即任务栏。

However, when in the office, my computer sits in a docking station and is hooked up to a nice big squarish screen. Here I much prefer to have the taskbar in its default location i.e. at the bottom.

我知道如何手动任务栏属性两个任务栏的位置,当然,之间切换。但我每天都这样做了几次,这是相当烦人。我的问题是:我可以有自动在任务栏的位置变化?

I know how to switch between the two taskbar locations manually in Taskbar Properties, of course. But I do this a few times daily, which is rather annoying. My question is: can I have the taskbar location change automatically?

例如,在启动时(或唤醒从休眠向上)的脚本将运行,其检测任一

For example, at startup (or wake up from hibernation) a script would run which detects either:


  • 是屏幕的形状比4高:3? (或其他数字)

  • 是计算机停靠在扩展坞?

如果有,把任务栏底部,否则左侧。

If yes, put taskbar at bottom, else at left.

任何人都知道如何做到这一点还是可以把我在正确的轨道上?或者是有一个已经实用,有可以做到这一点?

Anyone know how to do this or can put me on the right track? Or is there already a utility out there that can do this?

推荐答案

//普通扩充

一个脚本语言可能不会在这里一个不错的选择,你需要的东西的该泵消息听WM_DISPLAYCHANGE

A scripting language may not be a good choice here, you need something that pumps the message to listen to WM_DISPLAYCHANGE.

当你得到消息,你需要计算根据您的监视器决议任务栏的所需方向。然后,使用RmShutdown关闭Windows资源管理器。

When you get the message you need to calculate the desired orientation of the task bar based on the resolutions of your monitors. Then you use RmShutdown to close Windows Explorer.

// 无证行为的开始,可能随时断裂

//undocumented behavior begins, may break anytime

任务栏对接边缘存储在13个字节(从 APPBARDATA )和位置存储在字节25-40作为一个Win32的 RECT 。您可以重新启动Explorer之前修改设置。

The taskbar docking edge is stored in byte 13 (as one of the ABE values from APPBARDATA ) and the position is stored in byte 25-40 as a win32 RECT. You can modify the setting before restarting the explorer.

//无证行为结束

样code(在 https://github.com/jiangsheng完整的源/样品/树/主/ AppBarTest ):

//returns the process id and create time for the oldest explorer.exe 
RM_UNIQUE_PROCESS GetExplorerApplication()
{
    RM_UNIQUE_PROCESS  result={0};
    DWORD bytesReturned=0;
    DWORD processIdSize=4096;
    std::vector<DWORD> processIds;
    processIds.resize(1024);
    EnumProcesses(processIds.data(),processIdSize,&bytesReturned);
    while(bytesReturned==processIdSize)
    {
        processIdSize+=processIdSize;
        processIds.resize(processIdSize/4);
        EnumProcesses(processIds.data(),processIdSize,&bytesReturned);
    }

    std::for_each(processIds.begin(), processIds.end(), [&result] (DWORD processId) {
         HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,
                                   FALSE, processId);
         if (hProcess) {
            std::wstring imageName;
            imageName.resize(4096);
            if(GetProcessImageFileName (hProcess,(LPWSTR)imageName.data(),4096)>0)
            {
                if(wcscmp(L"explorer.exe",PathFindFileName(imageName.data()))==0)
                {
                    //this is assmuing the user is not running elevated and won't see explorer processes in other sessions
                    FILETIME ftCreate, ftExit, ftKernel, ftUser;
                    if (GetProcessTimes(hProcess, &ftCreate, &ftExit,&ftKernel, &ftUser))
                    {
                        if(result.dwProcessId==0)
                        {
                            result.dwProcessId=processId;
                            result.ProcessStartTime=ftCreate;
                        }
                        else if(CompareFileTime(&result.ProcessStartTime,&ftCreate)>0)
                        {
                            result.dwProcessId=processId;
                            result.ProcessStartTime=ftCreate;
                        }
                    }
                }
            }
            CloseHandle(hProcess);
         }
    });
    return result;
}
    //taskbar position calculating code omitted
    DWORD dwSession=0;
    WCHAR szSessionKey[CCH_RM_SESSION_KEY+1] = { 0 };
    DWORD dwError = RmStartSession(&dwSession, 0, szSessionKey);
    if (dwError == ERROR_SUCCESS) {
        RM_UNIQUE_PROCESS rgApplications[1]={GetExplorerApplication()};
        dwError=RmRegisterResources(
            dwSession,0,NULL,1,rgApplications,0,NULL);
        DWORD dwReason;
        UINT nProcInfoNeeded;
        UINT nProcInfo = 10;
        RM_PROCESS_INFO rgpi[10];
        dwError = RmGetList(dwSession, &nProcInfoNeeded,
                       &nProcInfo, rgpi, &dwReason);
        if(dwReason==RmRebootReasonNone)//now free to restart explorer
        {
            RmShutdown(dwSession,RmForceShutdown,NULL);//important, if we change the registry before shutting down explorer will override our change
            //using undocumented setting structure, could break any time
            //edge setting is stored at HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2!Settings
            HKEY hKey={0};
            DWORD result=0;
            result=::RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StuckRects2"),
                    0, KEY_READ|KEY_WRITE, &hKey) ;
            if (result== ERROR_SUCCESS)
            {
                std::vector<BYTE> data;
                data.resize(256);
                TCHAR settingValue[]= _T("Settings");
                DWORD dwKeyDataType=0;
                DWORD dwDataBufSize=data.size();
                result=::RegQueryValueEx(hKey,settingValue, NULL, &dwKeyDataType,
                    (LPBYTE) data.data(), &dwDataBufSize);
                while(ERROR_MORE_DATA==result)
                {
                    data.resize(256+data.size());
                    dwDataBufSize=data.size();
                    result=::RegQueryValueEx(hKey,settingValue, NULL, &dwKeyDataType, 
                        (LPBYTE) data.data(), &dwDataBufSize);
                }
                data.resize(dwDataBufSize);
                if(result==ERROR_SUCCESS)
                {
                    switch ( dwKeyDataType )
                    {
                        case REG_BINARY:
                            if(data.size()==40)
                            {
                                BYTE taskbarPosition=data[12];
                                taskbarPosition=edge;
                                data[12]=taskbarPosition;
                                RECT* taskbarRect=(RECT*)&data[24];
                                CopyRect (taskbarRect,&abd.rc);
                                result=::RegSetValueEx(hKey,settingValue,0,REG_BINARY,(LPBYTE) data.data(), dwDataBufSize);
                            }
                            break;
                    }
                }
                ::RegCloseKey( hKey );
            }
            RmRestart (dwSession,0,NULL);
        }
    }
    RmEndSession(dwSession);

这篇关于更改Windows 7任务栏的位置自动根据屏幕的形状或对接状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆