sancarn / stdVBA

VBA Standard Library - A Collection of libraries to form a common standard layer for modern VBA applications.
MIT License
288 stars 60 forks source link

`stdWindow` - Improvements #86

Open sancarn opened 10 months ago

sancarn commented 10 months ago

Tracker

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
Adelina-Trandafir commented 5 months ago

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?

sancarn commented 4 months ago

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 commented 4 months ago

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