Создание своего окна на окне TaskBar

Пример покажет как можно разместить свое окно на окне TaskBar , прикрепив его как дочернее. По сути при получении хенла taskbar, используется банальный способ поиска по классу.

Автор: bojan.dosen

customwintaskbar.png

#INCLUDE Once "windows.bi"

Dim Shared As HINSTANCE hInst
hInst = GetModuleHandle(NULL)

Dim Shared As HWND tbWnd

Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
  Select Case msg
     Case WM_CREATE
      
     Case WM_RBUTTONUP
      DestroyWindow(hWnd)
      
     Case WM_PAINT
      Dim As PAINTSTRUCT ps
      
      BeginPaint(hWnd, @ps)
        SetBkMode(ps.hdc, TRANSPARENT)
        SetTextColor(ps.hdc, BGR(255, 255, 255))
        SelectObject(ps.hdc, GetStockObject(DEFAULT_GUI_FONT))
        DrawText(ps.hdc, "Hello, Word!", -1, @ps.rcPaint, DT_SINGLELINE Or DT_CENTER Or DT_VCENTER)
      EndPaint(hWnd, @ps)
      
     Case WM_DESTROY
      PostQuitMessage(NULL)
      
  End Select
  
  Dim As RECT rc
  GetClientRect(tbWnd, @rc)
  MoveWindow(hWnd, rc.right-120, 5, 80, rc.bottom-10, FALSE)
  
  Return DefWindowProc(hWnd, msg, wParam, lParam)
End Function

Dim As MSG      uMsg
Dim As WNDCLASS  wcls
Dim As HWND      hWnd

With wcls
  .style          = CS_HREDRAW Or CS_VREDRAW
  .lpfnWndProc    = Cast(WNDPROC, @WndProc)
  .hInstance      = hInst
  .hIcon          = LoadIcon(NULL, IDI_APPLICATION)
  .hCursor        = LoadCursor(NULL, IDC_ARROW)
  .hbrBackground  = GetStockObject(BLACK_BRUSH)
  .lpszMenuName   = NULL
  .lpszClassName  = Strptr("WindowClass")
End With

If RegisterClass(@wcls) = FALSE Then
  MessageBox(NULL, "RegisterClass(@wcls) FAIL!", "Error!", MB_OK Or MB_ICONERROR)
  End
Endif

hWnd = FindWindow("Shell_TrayWnd", 0)
hWnd = FindWindowEx(hWnd, NULL, "RebarWindow32", 0)
hWnd = FindWindowEx(hWnd, NULL, "MSTaskSwWClass", 0)
tbWnd = FindWindowEx(hWnd, NULL, "MSTaskListWClass", 0)

Dim As RECT rc
GetClientRect(tbWnd, @rc)

hWnd = CreateWindowEx(WS_EX_TOOLWINDOW, wcls.lpszClassName, "Window", WS_CHILD, 0, 0, 0, 0, tbWnd, NULL, hInst, NULL)

ShowWindow(hWnd, SW_NORMAL)
UpdateWindow(hWnd)

While GetMessage(@uMsg, NULL, NULL, NULL) <> FALSE
  TranslateMessage(@uMsg)
  DispatchMessage(@uMsg)
Wend