首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >根据屏幕形状或停靠状态自动更改Windows 7任务栏位置

根据屏幕形状或停靠状态自动更改Windows 7任务栏位置
EN

Stack Overflow用户
提问于 2012-09-15 07:32:48
回答 2查看 5.2K关注 0票数 10

是否可以使用VBScript或任何其他编程语言:

  • 检测屏幕形状或计算机是否停靠。
  • 更改Windows任务栏位置

我想要达到的目标:

我的笔记本电脑有一个14英寸的宽屏:相当宽,但不是很高。我觉得把Windows任务栏放在屏幕的左边是最方便的,因为我可以节省宽度,而不是垂直空间。

然而,当我在办公室,我的电脑坐在一个对接站,并连接到一个漂亮的大方形屏幕。在这里,我更喜欢任务栏的默认位置,即底部。

当然,我知道如何在任务栏属性中手动切换两个任务栏位置。但是我每天做几次这样的事情,这是相当烦人的。我的问题是:我能自动更改任务栏的位置吗?

例如,在启动时(或从休眠中醒来),将运行一个脚本,该脚本可以检测到以下两种情况:

  • 屏幕形状比4:3高吗?(或任何数目)
  • 计算机停靠在停靠站了吗?

如果是,将任务栏放在底部,其他放在左边。

有人知道怎么做还是能让我走上正轨?还是已经有一个实用工具可以做到这一点?

EN

回答 2

Stack Overflow用户

发布于 2013-01-16 22:52:39

//正常补充为什么在别人的机器上省略了这不是一个好主意

在这里,脚本语言可能不是一个好的选择,您需要一些二叠纪

当您收到消息时,您需要根据监视器的分辨率计算任务栏的所需方向。然后使用RmShutdown关闭Windows。

//undocumented行为开始,随时可能中断

任务栏对接边存储在字节13中(作为来自APPBARDATA的ABE值之一),位置以win32 直角的形式存储在字节25-40中。可以在重新启动资源管理器之前修改该设置。

//无文档的行为结束

示例代码(https://github.com/jiangsheng/Samples/tree/master/AppBarTest上的完整源代码):

代码语言:javascript
运行
复制
//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);
票数 8
EN

Stack Overflow用户

发布于 2013-01-17 00:49:02

您可以通过简单的批处理或脚本来完成此操作。根据屏幕的当前分辨率设置注册表值以定位任务栏(如果在停靠时会更高),然后重新启动explorer.exe。因此,例如在屏幕左侧设置任务栏的批处理(假设您在d:\ bottom.reg文件夹中有该文件)。

代码语言:javascript
运行
复制
reg add d:\scripts\Bottom.reg
@echo off taskkill /f /IM explorer.exe
explorer.exe

bottom.reg的内容如下

代码语言:javascript
运行
复制
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2]
"Settings"=hex:28,00,00,00,ff,ff,ff,ff,02,00,00,00,03,00,00,00,3e,00,00,00,2e,\
  00,00,00,00,00,00,00,82,04,00,00,80,07,00,00,b0,04,00,00

对于left.reg

代码语言:javascript
运行
复制
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2]
"Settings"=hex:28,00,00,00,ff,ff,ff,ff,02,00,00,00,00,00,00,00,3e,00,00,00,2e,\
  00,00,00,00,00,00,00,00,00,00,00,3e,00,00,00,b0,04,00,00

您将有一些闪烁,但由于您将这样做,当您启动窗口,这不会是一个问题,我想。我在Windows 7上测试了这个。

编辑:制作了一个vbscript,它基于屏幕分辨率做同样的事情

代码语言:javascript
运行
复制
HKEY_CURRENT_USER = &H80000001
Set WshShell = CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set ObjRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

'Get curr. user name
Set colItems = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")
For Each objItem in colItems
  strCurrentUserName = objItem.UserName
Next

Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor where DeviceID = 'DesktopMonitor1'",,0) 
For Each objItem in colItems 
  intHorizontal = objItem.ScreenWidth 
  intVertical = objItem.ScreenHeight 
Next 

bottom = Array(&H28,&H00,&H00,&H00,&Hff,&Hff,&Hff,&Hff,&H02,&H00,&H00,&H00,&H03,&H00,&H00,&H00,&H3e,&H00,&H00,&H00,&H2e,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H82,&H04,&H00,&H00,&H80,&H07,&H00,&H00,&Hb0,&H04,&H00,&H00)
left_   = Array(&H28,&H00,&H00,&H00,&Hff,&Hff,&Hff,&Hff,&H02,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H3e,&H00,&H00,&H00,&H2e,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H3e,&H00,&H00,&H00,&Hb0,&H04,&H00,&H00)

if intHorizontal >= 1920 then
  regdata = bottom
else
  regdata = left_
end if

ObjRegistry.SetBinaryValue HKEY_CURRENT_USER, "Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2\", "Settings", regdata

'Restart user shell
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'Explorer.exe'")
For Each objProcess in colProcessList
    colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
  wscript.echo colProperties
    If strUserDomain & "\" & strNameOfUser = strCurrentUserName then
    wscript.echo "restarting"
        objProcess.Terminate()
    end if
Next
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12435503

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档