stdVBA icon indicating copy to clipboard operation
stdVBA copied to clipboard

`stdWindow` - Improvements

Open sancarn opened this issue 2 years ago • 3 comments

Tracker

  • [x] Set window owner
  • [X] Show menu bar buttons
  • [x] Set icon of window
  • [ ] Set taskbar visibility

Change window owner

SetWindowLongPtr(GWL_HWNDPARENT, hwnd) can be used to change the owner of a window. If SetWindowLongPtr(GWL_HWNDPARENT,0) is used the owner is affectively removed, and the window is treated as it's own "top level application" in a sense. Where as SetWindowLongPtr(GWL_HWNDPARENT, Application.hwnd) will make the window only appear when Application is also visible.

Show menu bar buttons

Example:

Call SetWindowLong(hform, GWL_STYLE, existing Or WS_MINIMIZEBOX)
Call DrawMenuBar(hform)

Set icon of window

hIcon = Form.Image1.Picture.Handle
Call SendMessage(hwnd, WM_SETICON, ICON_SMALL, ByVal hIcon)
Call SendMessage(hwnd, WM_SETICON, ICON_BIG, ByVal hIcon)

Enable addition and removal of window from TaskBar maybe more relevant for stdCOM...

See https://www.mrexcel.com/board/threads/display-userform-in-taskbar-with-custom-icon-and-hide-excel-mimicking-a-standalone-application.1123368/page-2

    Call CLSIDFromString(StrPtr(IID_PropertyStore), tIID)
    If SHGetPropertyStoreForWindow(hform, tIID, pPstore) = S_OK Then
        Call CLSIDFromString(StrPtr(CLSID_TASKLIST), tClsID)
        Call CLSIDFromString(StrPtr(IID_TASKLIST3), tIID)
        If CoCreateInstance(tClsID, 0, CLSCTX_INPROC_SERVER, tIID, pTBarList) = S_OK Then
            SetProp Application.hwnd, "pTBarList", pTBarList
            Call vtblCall(pTBarList, ITASKLIST3_HrInit, vbLong, CC_STDCALL) 'HrInit Method
            Call vtblCall(pTBarList, ITASKLIST3_DeleteTab, vbLong, CC_STDCALL, hform) 'DeleteTab Method
            Call vtblCall(pTBarList, ITASKLIST3_AddTab, vbLong, CC_STDCALL, hform) 'AddTab Method
            Call vtblCall(pTBarList, ITASKLIST3_ActivateTab, vbLong, CC_STDCALL, hform) 'ActivateTab Method
            If Len(ThumbnailTooltip) Then
                Call vtblCall(pTBarList, ITASKLIST3_SetThumbnailTooltip, vbLong, CC_STDCALL, hform, StrPtr(ThumbnailTooltip)) 'ActivateTab Method
            End If
        End If
    End If

sancarn avatar Nov 09 '23 23:11 sancarn

Hi. I'm not used to github :|) so i don't know if this is the place to write. Did you ever get anywhere with the Hooking part of the stdWindow class?

Adelina-Trandafir avatar Apr 23 '24 10:04 Adelina-Trandafir

Hi. I'm not used to github :|) so i don't know if this is the place to write. Did you ever get anywhere with the Hooking part of the stdWindow class?

Hi Adelina, not as yet, unfortunately this would require thunks, and I just don't have the time to put in the effort at the moment to get this working as desired.

sancarn avatar Apr 26 '24 11:04 sancarn

Added HICON and stdImage:

Private Sub UserForm_Initialize()
  With stdWindow.CreateFromIUnknown(Me)
    Call .setOwnerHandle(0)
    .HICON = stdWindow.CreateFromHwnd(Application.VBE.MainWindow.hWnd).HICON
    .HICON = stdImage.CreateFromStdPicture(Image1.picture).HICON
    .HICON = stdImage.CreateFromShape(Sheet1.Shapes("Picture 2")).HICON
    .HICON = stdImage.CreateFromFile("C:\Users\sancarn\Pictures\yuumi.png").HICON
  End With
End Sub

sancarn avatar May 20 '24 00:05 sancarn