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!