Keep AppBar in Position

Just starting out? Need help? Post your questions and find answers here.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Keep AppBar in Position

Post by Jac de Lad »

Hello,
I'm using the code floating, around somewhere here, which is used to create an AppBar under Windows. Unfortunately if I change my resolution the AppBar is moved and not sticked to side anymore. How can I make sure that it's still on the side? I have created a callback to process #WM_DISPLAYCHANGE. Also, destroying and recreating the AppBar doesn't work, the AppBar is still in moved position. Plus after some time the window in the AppBar moves to the outside area, which may be caused by resolution changing.

Code: Select all

Global *APPBD.APPBARDATA,X,Y,Width,Height

Procedure CreateAPPBar(Edge,Size); unterstützt #ABE_LEFT,#ABE_RIGHT,#ABE_TOP,#ABE_BOTTOM für Edge

  Protected *APPBD.APPBARDATA=AllocateMemory(SizeOf(APPBARDATA))

  Protected TBD.APPBARDATA

  SHAppBarMessage_(#ABM_GETTASKBARPOS,TBD)

  Protected TBEdge=TBD\uEdge

  SHAppBarMessage_(#ABM_NEW,*APPBD)

  *APPBD\uEdge=Edge

  Select Edge

    Case #ABE_LEFT

      If TBEdge=Edge

        *APPBD\rc\Left=TBD\rc\Right

        *APPBD\rc\Right=TBD\rc\Right+Size

        *APPBD\rc\Top=0

        *APPBD\rc\Bottom=GetSystemMetrics_(#SM_CYSCREEN)

      Else

        *APPBD\rc\Left=0

        *APPBD\rc\Right=Size

        *APPBD\rc\Top=0

        *APPBD\rc\Bottom=GetSystemMetrics_(#SM_CYSCREEN)

      EndIf

    Case #ABE_RIGHT

      If TBEdge=Edge

        *APPBD\rc\Left=TBD\rc\Left-Size

        *APPBD\rc\Right=TBD\rc\Left

        *APPBD\rc\Top=0

        *APPBD\rc\Bottom=GetSystemMetrics_(#SM_CYSCREEN)

      Else

        *APPBD\rc\Left=GetSystemMetrics_(#SM_CXSCREEN)-Size

        *APPBD\rc\Right=GetSystemMetrics_(#SM_CXSCREEN)

        *APPBD\rc\Top=0

        *APPBD\rc\Bottom=GetSystemMetrics_(#SM_CYSCREEN)

      EndIf

    Case #ABE_TOP

      If TBEdge=Edge

        *APPBD\rc\Left=0

        *APPBD\rc\Right=GetSystemMetrics_(#SM_CXSCREEN)

        *APPBD\rc\Top=TBD\rc\Bottom

        *APPBD\rc\Bottom=TBD\rc\Bottom+Size

      Else

        *APPBD\rc\Left=0

        *APPBD\rc\Right=GetSystemMetrics_(#SM_CXSCREEN)

        *APPBD\rc\Top=0

        *APPBD\rc\Bottom=Size

      EndIf

    Case #ABE_BOTTOM

      If TBEdge=Edge

        *APPBD\rc\Left=0

        *APPBD\rc\Right=GetSystemMetrics_(#SM_CXSCREEN)

        *APPBD\rc\Top=TBD\rc\Top-Size

        *APPBD\rc\Bottom=TBD\rc\Top

      Else

        *APPBD\rc\Left=0

        *APPBD\rc\Right=GetSystemMetrics_(#SM_CXSCREEN)

        *APPBD\rc\Top=GetSystemMetrics_(#SM_CYSCREEN)-Size

        *APPBD\rc\Bottom=GetSystemMetrics_(#SM_CYSCREEN)

      EndIf

  EndSelect

  SHAppBarMessage_(#ABM_SETPOS,*APPBD)

  ProcedureReturn *APPBD

EndProcedure

Procedure RemoveAPPBar(*APPBD.APPBARDATA)

  SHAppBarMessage_(#ABM_REMOVE,*APPBD)

  FreeMemory(*APPBD)

EndProcedure

Procedure APPBarX(*APPBD.APPBARDATA)

  ProcedureReturn *APPBD\rc\Left

EndProcedure

Procedure APPBarY(*APPBD.APPBARDATA)

  ProcedureReturn *APPBD\rc\Top

EndProcedure

Procedure APPBarWidth(*APPBD.APPBARDATA)

  ProcedureReturn *APPBD\rc\Right-*APPBD\rc\Left

EndProcedure

Procedure APPBarHeight(*APPBD.APPBARDATA)

  ProcedureReturn *APPBD\rc\Bottom-*APPBD\rc\Top

EndProcedure

 

Procedure WinCallback(hWnd, uMsg, wParam, lParam)

  If uMsg=#WM_DISPLAYCHANGE

    ;replace AppBar

  EndIf

  ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure

 

*APPBD.APPBARDATA=CreateAPPBar(#ABE_RIGHT,172)

X=APPBarX(*APPBD)

Y=APPBarY(*APPBD)

Width=APPBarWidth(*APPBD)

Height=APPBarHeight(*APPBD)

Window_0=OpenWindow(#PB_Any, x, y, width, height, "My Window", #PB_Window_BorderLess,WindowID(OpenWindow(#PB_Any,0,0,0,0,"",#PB_Window_Invisible)))

StickyWindow(window_0,#True)

 

SetWindowCallback(@WinCallback())

Define event

Repeat

  event=WaitWindowEvent()

Until Event=#PB_Event_CloseWindow

RemoveAPPBar(*APPBD) ;AppBar entfernen



This e-mail and any attachment is confidential and may be legally privileged or otherwise protected from disclosure. If you are not the intended recipient, please notify the sender immediately by returning this e-mail.
Neways Electronics NV is not responsible for the improper or incomplete transmission of any e-mail, or for any delay in its receipt.