访问应用程序,带有窗体任务栏图标的隐藏的应用程序窗口 [英] Access Application, Hidden Application Window With Form Taskbar Icon

查看:78
本文介绍了访问应用程序,带有窗体任务栏图标的隐藏的应用程序窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有一种主要形式的访问应用程序.当您打开应用程序时,AutoExec宏会通过Windows API apiShowWindow隐藏该应用程序.然后,AutoExec打开设置为Popup的主窗体.这一切都工作得很漂亮;我的数据库胆量被隐藏了,表单打开了,随即浮动.

I have an access application with one main form. When you open the application, an AutoExec macro hides the application via the Windows API apiShowWindow. Then, the AutoExec opens up the main form which is set to Popup. This all works beautifully; my database guts are hidden and the form opens up and just floats along.

但是,当访问数据库被隐藏时,您将松开任务栏图标.我在选项\当前数据库\应用程序图标"设置中设置了自定义图标.如果我不隐藏数据库,则该图标在任务栏中显示就很好.

However, when the access database gets hidden, you loose the taskbar icon. I have a custom icon set in the Options\Current Database\Application Icon setting. If I don't hide the database, this icon displays just fine in the task bar.

我找到了一个API解决方法,该方法仅在表单的任务栏中显示一个图标.它有点像这样:

I found an API workaround that will show an icon in the taskbar for just the form. It goes a little something like this:

Public Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
 ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
 ByVal nIndex As Long, _
 ByVal dwNewLong As Long) As Long

Public Declare Function SetWindowPos Lib "user32" _
(ByVal hWnd As Long, _
 ByVal hWndInsertAfter As Long, _
 ByVal X As Long, _
 ByVal Y As Long, _
 ByVal cx As Long, _
 ByVal cy As Long, _
 ByVal wFlags As Long) As Long

Public Sub AppTasklist(frmHwnd)
Dim WStyle  As Long
Dim Result  As Long

WStyle = GetWindowLong(frmHwnd, GWL_EXSTYLE)

WStyle = WStyle Or WS_EX_APPWINDOW

Result = SetWindowPos(frmHwnd, HWND_TOP, 0, 0, 0, 0, _
                      SWP_NOMOVE Or _
                      SWP_NOSIZE Or _
                      SWP_NOACTIVATE Or _
                      SWP_HIDEWINDOW)

Result = SetWindowLong(frmHwnd, GWL_EXSTYLE, WStyle)
Debug.Print Result

Result = SetWindowPos(frmHwnd, HWND_TOP, 0, 0, 0, 0, _
                      SWP_NOMOVE Or _
                      SWP_NOSIZE Or _
                      SWP_NOACTIVATE Or _
                      SWP_SHOWWINDOW)


End Sub

这种方法确实有效;我在任务栏中有一个仅用于表单的图标.但是,任务栏中的图标是标准的Access图标.

This approach does work; I get an icon in the taskbar dedicated to just the form. However, the icon in the taskbar is the standard Access icon.

为响应此问题,我使用SendMessageA添加了另一个API调用:

In response to this problem, I added another API call using the SendMessageA:

公共声明函数SendMessage32 Lib"user32"别名_ "SendMessageA"(ByVal hWnd一样长,ByVal wMsg一样长,_ ByVal wParam 一样长,ByVal lParam一样长)

Public Declare Function SendMessage32 Lib "user32" Alias _ "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, ByVal lParam As Long) As Long

这样执行:

Private Const WM_SETICON = &H80
Private Const ICON_SMALL = 0&
Private Const ICON_BIG = 1&

Dim icoPth  As String: icoPth = CurrentProject.Path & "\MyAppIcon.ico"
Dim NewIco  As Long: NewIco = ExtractIcon32(0, icoPth, 0)
Dim frmHwnd As Long: frmHwnd = Me.hwnd 'the form's handle

SendMessage32 frmHwnd, WM_SETICON, ICON_SMALL, NewIco
SendMessage32 frmHwnd, WM_SETICON, ICON_BIG, NewIco

SendMessage32 hWndAccessApp, WM_SETICON, ICON_SMALL, NewIco
SendMessage32 hWndAccessApp, WM_SETICON, ICON_BIG, NewIco

请记住,我已经按照AppTasklist Sub的内部和外部,顶部和底部的各种顺序尝试了上述"SendMessages"的四行,但无济于事.

Keep in mind that I have tried the above four lines of 'SendMessages' in various orders inside of and outside of, top of and bottom of the AppTasklist Sub to no avail.

它看起来确实可以在应用程序级别上运行,但是似乎永远无法在表单级别上运行.

It does appear to work at the application level, but it never seems to work at the form level.

对于那些熟悉这一特殊困境的人,让我列出我尝试过的VBA之外的其他一些选择.

For those of you familiar with this particular predicament, let me list some of the other options outside of VBA that I have tried.

1.)任务栏\属性\任务栏按钮.我已将此菜单选项更改为从不合并"和任务栏已满时合并".因此,基本上,这确实有效;现在,我仅获得文件夹和小标签的图标. BUT(!),仅当用户在其末端检查了这些设置后才起作用.根据我的经验,除了始终合并,隐藏标签"之外,几乎没有人使用任何其他选项.

1.) Taskbar\Properties\Taskbar buttons. I've changed this menu option to 'Never Combine' and 'Combine When Taskbar Is Full'. So, basically, this does work; I now get my icon for just the folder and the little label. BUT(!), it only works if the users have these settings checked on their end. In my experience, almost no one uses any of the options except 'Always combine, hide labels'.

2.)更改注册表设置.您可以更改以下注册表项,以更改应用程序使用的默认图标:"HKEY_CLASSES_ROOT \ Access.Application.14 \ DefaultIcon(Default)."但是,大多数用户(包括我自己)没有访问注册表的HKEY_CLASSES_ROOT部分的权限.此外,我将不得不编写一些代码以找到正确的密钥,然后对其进行更改(我可以这样做),但是目前尚不清楚此更改是否会立即生效-更不用说退出该应用程序时我必须将其更改回原样.应用程序.

2.) Changing the Registry settings. You can change the following registry key to change the default icon an application uses: "HKEY_CLASSES_ROOT\Access.Application.14\DefaultIcon(Default)." However, most users (myself included) don't have access to the HKEY_CLASSES_ROOT part of the registry. Furthermore, I would have to write some code to find the proper key and then change it (which I could do) but, it's unclear if this change would be immediate--not to mention I'd have to change it back when exiting the application.

3.)右键单击固定的应用程序,然后在菜单中右键单击该应用程序,这会为您提供一个属性菜单,在快捷方式"选项卡中带有一个名为更改图标..."的按钮.但是,对于Access之类的程序,此按钮显示为灰色.

3.) Right-clicking the pinned application, then right clicking the application in the menu does give you a properties menu with a button called 'Change Icon...' in the 'Shortcut' tab. However, for a program like Access, this button is greyed out.

我正在使用Windows 7和Access 2010.

I am using Windows 7 and Access 2010.

是否可以在上述情况下将任务栏图标强制为标准访问图标以外的其他选项?

Is it possible to force the Taskbar Icon in the above scenario to something other than the standard Access Icon?

我觉得我缺少了一些东西,或者可以使用的API函数,或者更好的SendMessage常量,或者,也许就是做不到.

I feel like there's ether a little something I'm missing, or an API function that could be used, or a better SendMessage constant, or that, maybe, it just can't be done.

任何帮助将不胜感激.

此外,作为免责声明(我想):显然,以上代码是从该论坛的其他帖子及其他文章中提取的.大部分不是我从那里获得的.我花了一些时间来使它在Access中工作,而不是与其他不断出现在搜索结果中的Microsoft软件相反,因此在这里我将不对其进行命名.

Also, as a disclaimer (I guess): obviously the above code was pulled from other posts from this forum and others. Most of it was unattributed from whence I got it. I've made some minor tweeks to make it work in Access as opposed to that other piece of Microsoft Software that keeps getting in my search results so I will not name it here.

谢谢!

推荐答案

好的.所以我要回答我自己的问题.显然,我真正需要的只是休息一下,并提出我的问题.在发布问题后不久,我又重新开始尝试其他搜索字词.最终,我碰到了一篇实际上一开始似乎并没有取得成果的帖子,因为我不清楚发帖人和我自己是否在处理相同的情况.

Okay. So I'm going to answer my own question. Apparently all I really needed was a break from the action and to type out my problem. A short time after I posted the question, I got back on the horse and tried some more search terms. I eventually came across a post which really didn't seem fruitfull at the outset because it wasn't clear to me if the poster and myself were dealing with the same scenario.

我在这里找到了答案:

http://www.access-programmers.co. uk/forums/showthread.php?t = 231422

首先,您的应用程序必须通过快捷方式打开.对我来说幸运的是,从一开始我就一直在使用桌面快捷方式.

First off, your application must open via a shortcut. Fortunately for me, I've been using a Desktop shortcut from the begining.

当我开始构建应用程序时,我从一开始就知道我将使用VBScript进行应用程序的安装(以及在发布较新版本时进行更新).在该脚本中,我创建了一个指向应用程序的桌面快捷方式,该快捷方式存储在用户的Documents目录中.我还将应用程序图标存储在附加到应用程序快捷方式的目录中.

When I started building the application, I knew from the outset that I would be using a VBScript to do the installation of the application (as well as updating when a newer version get's released). In that script, I create a Desktop shortcut to the application which I store in the user's Documents directory. I also store the application icon in that directory which I attach to the application shortcut.

如果您从未通过vba/script创建快捷方式,则实际上将执行以下操作(用vbScript编写):

If you've never created a shortcut via vba/script, you'll essentially do something like this (written in vbScript):

Dim WinShell
Dim ShtCut

Set WinShell = CreateObject("WScript.Shell")
Set ShtCut = WinShell.CreateShortcut(strDesktopPath & "\MyCoolApp.lnk")

With ShtCut
     .TargetPath = (See below)
     .Arguments = (See below)
     .IconLocation = ...
     .Desciption = "This is the coolest app, yo!"
     .WorkingDirectory = strAppPath
     .WindowStyle = 1
     .Save
End With

现在,快捷方式的目标开始是这样的:

Now, the target of the shortcut started out being something like this:

"C:\Users\UserName\Public\Documents\MyCoolApp\MyCoolApp.accdb"

很明显,您的用户的文档位置可能具有不同的企业结构...

Obviously your users may have a different enterprise structure for the Documents location...

以上参考文章建议的操作是将该快捷方式转换为伪指令命令行脚本.

What the above reference post suggests doing is turning that shortcut into a psuedo command line script.

要这样做:

首先,您的实际目标将是用户访问版本(运行时或完全访问)的路径,例如:

First, your actual target is going to be the path to the user's version of access (Runtime or full), like such:

"C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE"

重要!您必须将此目标用双引号引起来,即:

IMPORTANT! You will have to wrap this target in double-quotes, i.e.:

.TargetPath = Chr(34) & strAccessPath & Chr(34)

下一步(您将无法在上面的帖子中找到它,我必须弄清楚),您需要将Argument设置为应用程序的目录,例如:

Next (and you won't find this in the above post, I had to figure it out), you'll need to set the Argument to the directory of the application, like such:

"C:\Users\UserName\Public\Documents\MyCoolApp\MyCoolApp.accdb"

重要!同样,您必须将参数用双引号引起来,即:

IMPORTANT! Again, you'll have to wrap the arguments in double-quotes, i.e.:

.Arguments = Chr(34) & strAppPath & Chr(34)

同样重要的是,我希望您的应用很酷.

Also important, I hope your app IS cool.

一旦设置了此快捷方式,实质上就是在进行设置,因此您的应用程序将在任务栏上拥有自己的工作组.也就是说,如果通常打开Access,则您的应用程序将在任务栏上拥有其自己的组.该组将具有与之关联的很酷的自定义图标.而且,作为一项意外的巨大奖励,您将能够将快捷方式固定到Access之外的任务栏.甜点!

Once you have this shortcut set up, essentially you're making it so your application will have it's own workgroup on the taskbar. I.e., if Access is open in general, your application will have it's own group on the taskbar. This group will have your cool, custom icon associated with it. And as a huge unexpected bonus, you'll be able to pin your shortcut to the taskbar outside of Access. SWEEEEEET!

祝你好运!

这篇关于访问应用程序,带有窗体任务栏图标的隐藏的应用程序窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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