Access application, hidden application window with taskbar icon form

I have an access application with one basic form. When you open the application, the AutoExec macro hides the application through the apiShowWindow Windows API. AutoExec then opens the main form, which is installed in Popup. All of this works great; my guts of the database are hidden and the form opens and just floats.

However, when the access database is hiding, you lose the taskbar icon. I have a custom icon set in the "Settings \ Current Database \ Application" setting. If I do not hide the database, this icon appears on the taskbar very well.

I found an API workaround that will show a taskbar icon for the form only. It looks 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 

This approach really works; I get a taskbar icon dedicated only to the form. However, the taskbar icon is a standard access icon.

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

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

Done this way:

 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 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 

Keep in mind that I tried the above four lines of "SendMessages" in different orders inside and outside, above and below SubTasklist Sub, but to no avail.

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

For those familiar with this particular hurdle, let me list some other parameters outside of VBA that I tried.

1.) Taskbar \ Properties \ Taskbar buttons. I changed this menu item to "Never combine" and "Combine when the taskbar is full." So basically it works; Now I get my badge only for the folder and the small label. BUT (!), It only works if users set these options on their end. In my experience, almost no one uses any of the options except "Always combine, hide tags."

2.) Change registry settings. You can modify the following registry key to change the default icon used by the application: "HKEY_CLASSES_ROOT \ Access.Application.14 \ DefaultIcon (default)". However, most users (including me) do not have access to the HKEY_CLASSES_ROOT registry part. In addition, I would have to write code to find the correct key and then change it (which I could do), but it is not clear whether this change will be immediate - not to mention that I will have to change it when I exit Appendix.

3.) Right-clicking on the attached application, and then right-clicking on the application in the menu gives you a property menu with the "Change Icon ..." button on the "Shortcut" tab. However, for a program such as Access, this button is not available.

I am using Windows 7 and Access 2010.

Can I pin the Taskbar icon in the above scenario to something other than the standard access icon?

It seems to me that there is something on the air that I am missing, or an API function that can be used, or a better SendMessage constant, or that perhaps this is simply not possible.

Any help would be greatly appreciated.

Also, as a disclaimer (I think): obviously, the above code was removed from other posts from this forum and others. Most of them were unrecognized where I got it from. I made a few small tweaks to make it work in Access, unlike this other Microsoft Software product, which continues to receive search results, so I will not name it here.

Thanks!

+6
source share
1 answer

Good. Therefore, I am going to answer my question. Apparently, all I really need is a separation from the action and the choice of my problem. A short time after I posted this question, I returned to the horse and tried some more search queries. In the end, I came across a post that didnโ€™t really seem fruitful from the very beginning, because it was not clear to me if the poster and I were dealing with the same script.

I found my answer here:

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

First, your application should open with a shortcut. Luckily for me, I used the desktop shortcut from the start.

When I started creating the application, from the very beginning I knew that I would use VBScript to install the application (as well as updates when releasing a newer version). In this script, I create a desktop shortcut for the application that I store in the "User Documents" folder. I also save the application icon in this directory, which I attach to the application shortcut.

If you have never created a shortcut via vba / script, you will 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 labelโ€™s goal began like this:

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

Obviously, your users may have a different enterprise structure for arranging documents ...

What the above help post offers turns this shortcut into the psuedo script command line.

For this:

First, your actual goal will be by accessing a custom version of access (Runtime or full), for example:

 "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) 

Further (and you will not find this in the above message, I needed to find out), you need to install the Argument in the application directory, for example:

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

IMPORTANT! Again, you will have to wrap the arguments in double quotes, that is:

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

It is also important that your application is cool.

After you have installed this shortcut, in essence, you do it so that your application has its own workgroup in the taskbar. Ie, if Access is open at all, your application will have its own taskbar group. This group will have your cool, customizable icon associated with it. And as a huge unexpected bonus, you can snap your shortcut to the taskbar outside of Access. SWEEEEEET!

Good luck

+2
source

Source: https://habr.com/ru/post/977290/


All Articles