title: Access Application, Hidden Application Window With Form Taskbar Icon
body: <p>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.</p>
  
  <p>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.</p>
  
  <p>I found an API workaround that will show an icon in the taskbar for just the form.  It goes a little something like this:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>In response to this problem, I added another API call using the SendMessageA:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>Executed thus:</p>
  
  <pre><code>Private Const WM_SETICON = &amp;H80
  Private Const ICON_SMALL = 0&amp;
  Private Const ICON_BIG = 1&amp;
  
  Dim icoPth  As String: icoPth = CurrentProject.Path &amp; "\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
  </code></pre>
  
  <p>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.</p>
  
  <p>It does appear to work at the application level, but it never seems to work at the form level.</p>
  
  <p>For those of you familiar with this particular predicament, let me list some of the other options outside of VBA that I have tried.</p>
  
  <p>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'.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>I am using Windows 7 and Access 2010.</p>
  
  <p>Is it possible to force the Taskbar Icon in the above scenario to something other than the standard Access Icon?</p>
  
  <p>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.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>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.</p>
  
  <p>Thanks!</p>