Skip to content

Commit

Permalink
Added more managed code
Browse files Browse the repository at this point in the history
Fixed white lines in system tray
Fixed #14
Fixed #10
  • Loading branch information
Anis Errais committed Feb 28, 2021
1 parent 7995999 commit a6a5f83
Show file tree
Hide file tree
Showing 21 changed files with 254 additions and 93 deletions.

This file was deleted.

16 changes: 0 additions & 16 deletions SimpleClassicThemeTaskbar.UnmanagedCode/BackgroundThread.h

This file was deleted.

This file was deleted.

14 changes: 8 additions & 6 deletions SimpleClassicThemeTaskbar.UnmanagedCode/BaseComponentRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "UIComponents.h"
#include "StartWindow.h"
#include "TaskListWindow.h"

#include <gdiplus.h>
using namespace Gdiplus;
Expand All @@ -12,11 +13,12 @@ namespace SimpleClassicThemeTaskbar
{
class ComponentRenderer
{
virtual void Initialize() abstract;
virtual void DrawStartButton(StartWindow window) abstract;
virtual void DrawTaskbar(Taskbar taskbar) abstract;
virtual void DrawTaskList(TaskListWindow window) abstract;
virtual void Destroy() abstract;
public:
virtual void Initialize() = 0;
virtual void DrawTaskbar(HWND hWnd) = 0;
virtual void DrawStartButton(StartWindow* window, PDRAWITEMSTRUCT drawStruct) = 0;
virtual void DrawTaskList(TaskListWindow* window, PDRAWITEMSTRUCT drawStruct) = 0;
virtual void Destroy() = 0;
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,55 @@ namespace SimpleClassicThemeTaskbar

}

void ClassicComponentRenderer::DrawStartButton(StartWindow window)
void ClassicComponentRenderer::DrawTaskbar(HWND hWnd)
{

}

void ClassicComponentRenderer::DrawTaskbar(Taskbar taskbar)
{
HDC hdc;
HDC hDC;
RECT rc;
hDC = GetDC(hWnd);
GetClientRect(hWnd, &rc);

hdc = GetDC(taskbar.WindowHandle);
GetClientRect(taskbar.WindowHandle, &rc);
// Paint line
Graphics graphics(hdc);
Graphics graphics(hDC);
Pen pen(Color(GetSysColor(COLOR_BTNHIGHLIGHT) + 0xFF000000));
graphics.DrawLine(&pen, 0, 1, 1280, 1);

SwapBuffers(hdc);
ReleaseDC(taskbar.WindowHandle, hdc);
SwapBuffers(hDC);
ReleaseDC(hWnd, hDC);
}

void ClassicComponentRenderer::DrawTaskList(TaskListWindow window)
void ClassicComponentRenderer::DrawStartButton(StartWindow* window, PDRAWITEMSTRUCT lpDrawItemStruct)
{

}

void ClassicComponentRenderer::DrawTaskList(TaskListWindow* window, PDRAWITEMSTRUCT lpDrawItemStruct)
{
RECT rect = lpDrawItemStruct->rcItem;
int nTabIndex = lpDrawItemStruct->itemID;
if (nTabIndex < 0) return;
BOOL bSelected = (nTabIndex == window->GetCurSel());

TCHAR label[128];
TC_ITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE;
tci.pszText = label;
tci.cchTextMax = 127;
if (!window->GetItem(nTabIndex, &tci)) return;

HDC hDC = lpDrawItemStruct->hDC;
if (!hDC) return;
int nSavedDC = SaveDC(hDC);

//rect.top += GetSystemMetrics(SM_CYEDGE);
SetBkMode(hDC, TRANSPARENT);
FillRect(hDC, &rect, GetSysColorBrush(COLOR_MENUHILIGHT));
//DrawFrameControl(hDC, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | (bSelected ? DFCS_PUSHED : 0));



RestoreDC(hDC, nSavedDC);
}

void ClassicComponentRenderer::Destroy()
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ namespace SimpleClassicThemeTaskbar
{
namespace Unmanaged
{
class ClassicComponentRenderer : ComponentRenderer
class ClassicComponentRenderer : public ComponentRenderer
{
public:
void Initialize();
void DrawStartButton(StartWindow window);
void DrawTaskbar(Taskbar taskbar);
void DrawTaskList(TaskListWindow window);
void DrawTaskbar(HWND hWnd);
void DrawStartButton(StartWindow* window, PDRAWITEMSTRUCT drawStruct);
void DrawTaskList(TaskListWindow* window, PDRAWITEMSTRUCT drawStruct);
void Destroy();
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,8 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ApplicationWindow.cpp" />
<ClCompile Include="BackgroundThread.cpp" />
<ClCompile Include="BaseWindow.cpp" />
<ClCompile Include="ButtonWindow.cpp" />
<ClCompile Include="BaseComponentRenderer.cpp" />
<ClCompile Include="ClassicComponentRenderer.cpp" />
<ClCompile Include="StartWindow.cpp" />
<ClCompile Include="Taskbar.cpp" />
Expand All @@ -154,7 +152,6 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="ApplicationWindow.h" />
<ClInclude Include="BackgroundThread.h" />
<ClInclude Include="BaseWindow.h" />
<ClInclude Include="ButtonWindow.h" />
<ClInclude Include="BaseComponentRenderer.h" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
<ClCompile Include="Taskbar.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BackgroundThread.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ApplicationWindow.cpp">
<Filter>Source Files\UI Components</Filter>
</ClCompile>
Expand All @@ -54,9 +51,6 @@
<ClCompile Include="Win32Window.cpp">
<Filter>Source Files\UI Components</Filter>
</ClCompile>
<ClCompile Include="BaseComponentRenderer.cpp">
<Filter>Source Files\Renderers</Filter>
</ClCompile>
<ClCompile Include="ClassicComponentRenderer.cpp">
<Filter>Source Files\Renderers</Filter>
</ClCompile>
Expand All @@ -71,9 +65,6 @@
<ClInclude Include="Taskbar.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="BackgroundThread.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ApplicationWindow.h">
<Filter>Header Files\UI Components</Filter>
</ClInclude>
Expand Down
10 changes: 8 additions & 2 deletions SimpleClassicThemeTaskbar.UnmanagedCode/TaskListWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace SimpleClassicThemeTaskbar
{
createParams.lpszClass = WC_TABCONTROL;
createParams.style = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TCS_BUTTONS | TCS_FIXEDWIDTH | TCS_MULTILINE | TCS_FOCUSNEVER;
createParams.style = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS /*| TCS_BUTTONS*/ | TCS_FIXEDWIDTH | TCS_MULTILINE | TCS_FOCUSNEVER | TCS_OWNERDRAWFIXED;
createParams.hMenu = (HMENU)IDC_TASKLIST;
}

Expand All @@ -21,16 +22,21 @@ namespace SimpleClassicThemeTaskbar
return TabCtrl_GetItemCount(WindowHandle);
}

void TaskListWindow::GetItem(int index, LPTCITEM item)
BOOL TaskListWindow::GetItem(int index, LPTCITEM item)
{
TabCtrl_GetItem(WindowHandle, index, item);
return TabCtrl_GetItem(WindowHandle, index, item);
}

HIMAGELIST TaskListWindow::GetImageList()
{
return TabCtrl_GetImageList(WindowHandle);
}

int TaskListWindow::GetCurSel()
{
return TabCtrl_GetCurSel(WindowHandle);
}

BOOL TaskListWindow::SetItem(int index, LPTCITEM item)
{
return TabCtrl_SetItem(WindowHandle, index, item);
Expand Down
3 changes: 2 additions & 1 deletion SimpleClassicThemeTaskbar.UnmanagedCode/TaskListWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ namespace SimpleClassicThemeTaskbar
~TaskListWindow();

int GetItemCount();
void GetItem(int index, LPTCITEM item);
BOOL GetItem(int index, LPTCITEM item);
HIMAGELIST GetImageList();
int GetCurSel();

void InsertItem(LPTCITEM item);
void DeleteItem(int index);
Expand Down
74 changes: 49 additions & 25 deletions SimpleClassicThemeTaskbar.UnmanagedCode/Taskbar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Taskbar.h"

#include <VersionHelpers.h>
#include <dwmapi.h>
#pragma comment (lib, "dwmapi.lib")
Expand All @@ -7,10 +8,12 @@
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")

#include "ClassicComponentRenderer.h"

#define WM_UPDATETASKBAR WM_USER
#define WM_REPOSITIONTASKBAR WM_USER + 1
#define DEBUG_DRAWBG false
#define DEBUG_USETAB true
#define DEBUG_USETAB false

namespace SimpleClassicThemeTaskbar
{
Expand Down Expand Up @@ -61,11 +64,13 @@ namespace SimpleClassicThemeTaskbar

startWindow = new StartWindow();
taskListWindow = new TaskListWindow();

renderer = (ComponentRenderer*)new ClassicComponentRenderer();

CreateWindowHandle();

if (IsPrimary)
//if (IsPrimary)
SetTimer(WindowHandle, 0, 200, NULL);
//SendMessage(WindowHandle, WM_TIMER, 0, 0);
}

//Destructor
Expand All @@ -83,33 +88,45 @@ namespace SimpleClassicThemeTaskbar
//Check if the specified HWND is a window to be displayed
bool Taskbar::IsAltTabWindow(HWND hwnd, TCHAR* className)
{
TCHAR szText[128];

// Check if the OS is Windows 10
if (IsWindows10OrGreater())
// Check if the window is on the current Desktop
if (!cppCode.WindowIsOnCurrentDesktop(hwnd))
return false;

HWND root = GetAncestor(hwnd, 3);

// If the last active popup of the root owner is NOT this window: don't show it
// This method is described by Raymond Chen in this blogpost:
// https://devblogs.microsoft.com/oldnewthing/20071008-00/?p=24863
// Start at the root owner
HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);
// See if we are the last active visible popup
HWND hwndTry;
while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) {
if (IsWindowVisible(hwndTry)) break;
hwndWalk = hwndTry;
}
if (hwndWalk != hwnd)
return false;
//HWND root = GetAncestor(hwnd, 3);

//// If the last active popup of the root owner is NOT this window: don't show it
//// This method is described by Raymond Chen in this blogpost:
//// https://devblogs.microsoft.com/oldnewthing/20071008-00/?p=24863
//// Start at the root owner
//HWND hwndWalk = GetAncestor(hwnd, GA_ROOTOWNER);
//// See if we are the last active visible popup
//HWND hwndTry;
//while ((hwndTry = GetLastActivePopup(hwndWalk)) != hwndTry) {
// if (IsWindowVisible(hwndTry)) break;
// hwndWalk = hwndTry;
//}
//if (hwndWalk != hwnd)
// return false;

// Get WINDOWINFO
WINDOWINFO wi = { 0 };
wi.cbSize = sizeof(WINDOWINFO);
GetWindowInfo(hwnd, &wi);

GetWindowTextW(hwnd, szText, 128); /* Get the window text */
if ((wcslen(szText) <= 0) ||
!IsWindowVisible(hwnd) ||
(::GetParent(hwnd) != NULL) ||
(GetWindow(hwnd, GW_OWNER) != NULL) ||
(GetWindowLongPtrW(hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
{
return false; /* Skip this window */
}

// If it's a tool window: don't show it
if ((wi.dwExStyle & WS_EX_TOOLWINDOW) > 0)
return false;
Expand Down Expand Up @@ -189,6 +206,9 @@ namespace SimpleClassicThemeTaskbar
PAINTSTRUCT ps;
HDC hdc;
RECT rc;

ApplicationWindow* button;
bool isPushed;

HWND foregroundWindow;
MONITORINFO monitorInfo;
Expand All @@ -207,7 +227,7 @@ namespace SimpleClassicThemeTaskbar

// Initialize components
startWindow->SetParent(WindowHandle);
taskListWindow->SetParent(WindowHandle);
//taskListWindow->SetParent(WindowHandle);
//startWindow->SetText(L"Start");
case WM_REPOSITIONTASKBAR:
case WM_SYSCOLORCHANGE:
Expand Down Expand Up @@ -251,9 +271,9 @@ namespace SimpleClassicThemeTaskbar
startWindow->SetSize(startWindowSize);
startWindow->SetPosition(POINT{ 2, 4 });

taskListWindow->SetFont(font);
taskListWindow->SetSize(GetSize().cx - 2 - startWindowSize.cx - 4, startWindowSize.cy );
taskListWindow->SetPosition(POINT{ 2 + startWindowSize.cx + 4, 4 });
//taskListWindow->SetFont(font);
//taskListWindow->SetSize(GetSize().cx - 2 - startWindowSize.cx - 4, startWindowSize.cy );
//taskListWindow->SetPosition(POINT{ 2 + startWindowSize.cx + 4, 4 });

// Resize taskbar and TODO work area
monitorInfo = { 0 };
Expand Down Expand Up @@ -402,7 +422,7 @@ namespace SimpleClassicThemeTaskbar
{
case IDC_APPLICATION_WINDOW:
ApplicationWindow* button = applicationWindowHandleMap[(HWND)lParam];
button->ClickHandler();
//button->ClickHandler();
break;
}
break;
Expand All @@ -420,15 +440,15 @@ namespace SimpleClassicThemeTaskbar
HFONT oldFont;
SIZE buttonSize;
RECT textRect;
ApplicationWindow* button = applicationWindowHandleMap[dis->hwndItem];
button = applicationWindowHandleMap[dis->hwndItem];
if (!button)
return DefWindowProc(hwnd, msg, wParam, lParam);

buttonSize = button->GetSize();

// Draw button frame
//if (dis->itemAction == ODA_DRAWENTIRE)
bool isPushed = dis->itemState & ODS_SELECTED;
isPushed = dis->itemState & ODS_SELECTED;
DrawFrameControl(hdc, &rc, DFC_BUTTON, DFCS_BUTTONPUSH | (isPushed ? DFCS_PUSHED : NULL));

// Draw the icon
Expand All @@ -447,6 +467,10 @@ namespace SimpleClassicThemeTaskbar
DrawTextEx(hdc, button->GetText(), -1, &textRect, DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_LEFT, NULL);
SelectObject(hdc, oldFont);

break;
case IDC_TASKLIST:
renderer->DrawTaskList(taskListWindow, dis);

break;
}

Expand Down
Loading

0 comments on commit a6a5f83

Please sign in to comment.