diff --git a/src/FolderWindow.cpp b/src/FolderWindow.cpp index 4c7758b..1dd3cbe 100644 --- a/src/FolderWindow.cpp +++ b/src/FolderWindow.cpp @@ -17,8 +17,6 @@ namespace chromafiler { -const wchar_t FOLDER_WINDOW_CLASS[] = L"ChromaFile Folder"; - const wchar_t PROP_SHELL_VISITED[] = L"Visited"; const wchar_t PROP_ICON_POS[] = L"IconPos"; @@ -59,8 +57,6 @@ bool FolderWindow::spatialView(IFolderView *const folderView) { } void FolderWindow::init() { - RegisterClass(tempPtr(createWindowClass(FOLDER_WINDOW_CLASS))); - for (int i = 0; i < _countof(HIDDEN_ITEM_PARSE_NAMES); i++) { CComPtr item; if (SUCCEEDED(SHCreateItemFromParsingName(HIDDEN_ITEM_PARSE_NAMES[i], nullptr, @@ -76,10 +72,6 @@ void FolderWindow::init() { FolderWindow::FolderWindow(ItemWindow *const parent, IShellItem *const item) : ItemWindow(parent, item) {} -const wchar_t * FolderWindow::className() const { - return FOLDER_WINDOW_CLASS; -} - bool FolderWindow::persistSizeInParent() const { return false; } diff --git a/src/FolderWindow.h b/src/FolderWindow.h index 77504ae..78d5e96 100644 --- a/src/FolderWindow.h +++ b/src/FolderWindow.h @@ -161,8 +161,6 @@ class FolderWindow : public ItemWindow, public IServiceProvider, public ICommDlg std::unique_ptr itemPositions; }; - const wchar_t * className() const override; - void listViewCreated(); static LRESULT CALLBACK listViewSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, UINT_PTR subclassID, DWORD_PTR refData); diff --git a/src/ItemWindow.cpp b/src/ItemWindow.cpp index c18bc30..1634891 100644 --- a/src/ItemWindow.cpp +++ b/src/ItemWindow.cpp @@ -20,6 +20,7 @@ namespace chromafiler { +const wchar_t ITEM_WINDOW_CLASS[] = L"ChromaFiler Item Window"; const wchar_t TESTPOS_CLASS[] = L"ChromaFiler Test Window"; const wchar_t WINDOW_THEME[] = L"CompositedWindow::Window"; const UINT SC_DRAGMOVE = SC_MOVE | 2; // https://stackoverflow.com/a/35880547/11525734 @@ -97,6 +98,17 @@ void ItemWindow::init() { HINSTANCE hInstance = GetModuleHandle(nullptr); + WNDCLASS itemClass = {}; + itemClass.lpfnWndProc = windowProc; + itemClass.hInstance = hInstance; + itemClass.lpszClassName = ITEM_WINDOW_CLASS; + if (!compositionEnabled) + itemClass.style = CS_HREDRAW; // redraw caption when resizing + // change toolbar color + if (IsWindows10OrGreater()) + itemClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + RegisterClass(&itemClass); + WNDCLASS testPosClass = {}; testPosClass.lpszClassName = TESTPOS_CLASS; testPosClass.lpfnWndProc = DefWindowProc; @@ -163,19 +175,6 @@ void ItemWindow::uninit() { RemoveFontMemResourceEx(symbolFontHandle); } -WNDCLASS ItemWindow::createWindowClass(const wchar_t *name) { - WNDCLASS wndClass = {}; - wndClass.lpfnWndProc = windowProc; - wndClass.hInstance = GetModuleHandle(nullptr); - wndClass.lpszClassName = name; - if (!compositionEnabled) - wndClass.style = CS_HREDRAW; // redraw caption when resizing - // change toolbar color - if (IsWindows10OrGreater()) - wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); - return wndClass; -} - void ItemWindow::flashWindow(HWND hwnd) { PostMessage(hwnd, MSG_FLASH_WINDOW, 0, 0); } @@ -185,6 +184,10 @@ ItemWindow::ItemWindow(ItemWindow *const parent, IShellItem *const item) item(item), proxyIcon(this) {} +const wchar_t * ItemWindow::className() const { + return ITEM_WINDOW_CLASS; +} + void ItemWindow::setScratch(bool value) { scratch = value; } diff --git a/src/ItemWindow.h b/src/ItemWindow.h index 007937b..d6ff4e0 100644 --- a/src/ItemWindow.h +++ b/src/ItemWindow.h @@ -65,7 +65,6 @@ class ItemWindow : public WindowImpl, public IUnknownImpl { MSG_FLASH_WINDOW, MSG_LAST }; - static WNDCLASS createWindowClass(const wchar_t *name); LRESULT handleMessage(UINT message, WPARAM wParam, LPARAM lParam) override; virtual SIZE defaultSize() const; @@ -155,7 +154,7 @@ class ItemWindow : public WindowImpl, public IUnknownImpl { CComQIPtr contextMenu3; private: - virtual const wchar_t * className() const = 0; + virtual const wchar_t * className() const; bool centeredProxy() const; // requires useCustomFrame() == true diff --git a/src/PreviewWindow.cpp b/src/PreviewWindow.cpp index 4713bdb..8efbd2f 100644 --- a/src/PreviewWindow.cpp +++ b/src/PreviewWindow.cpp @@ -8,7 +8,6 @@ namespace chromafiler { // https://geelaw.blog/entries/ipreviewhandlerframe-wpf-2-interop/ -const wchar_t PREVIEW_WINDOW_CLASS[] = L"ChromaFile Preview"; const wchar_t PREVIEW_CONTAINER_CLASS[] = L"ChromaFile Preview Container"; const int FACTORY_CACHE_SIZE = 4; @@ -31,8 +30,6 @@ static FactoryCacheEntry factoryCache[FACTORY_CACHE_SIZE] = {}; static int factoryCacheIndex = 0; void PreviewWindow::init() { - RegisterClass(tempPtr(createWindowClass(PREVIEW_WINDOW_CLASS))); - WNDCLASS containerClass = {}; containerClass.lpszClassName = PREVIEW_CONTAINER_CLASS; containerClass.lpfnWndProc = DefWindowProc; @@ -57,10 +54,6 @@ PreviewWindow::PreviewWindow(ItemWindow *const parent, IShellItem *const item, C : ItemWindow(parent, item), previewID(previewID) {} -const wchar_t * PreviewWindow::className() const { - return PREVIEW_WINDOW_CLASS; -} - void PreviewWindow::onCreate() { ItemWindow::onCreate(); diff --git a/src/PreviewWindow.h b/src/PreviewWindow.h index 769645d..617148c 100644 --- a/src/PreviewWindow.h +++ b/src/PreviewWindow.h @@ -51,8 +51,6 @@ class PreviewWindow : public ItemWindow, public IPreviewHandlerFrame { void refresh() override; private: - const wchar_t * className() const override; - void destroyPreview(); CLSID previewID; diff --git a/src/TextWindow.cpp b/src/TextWindow.cpp index 145ef20..68c17e0 100644 --- a/src/TextWindow.cpp +++ b/src/TextWindow.cpp @@ -12,8 +12,6 @@ namespace chromafiler { -const wchar_t TEXT_WINDOW_CLASS[] = L"ChromaFile Text"; - const wchar_t PROP_WORD_WRAP[] = L"WordWrap"; const ULONG MAX_FILE_SIZE = 50'000'000; @@ -36,8 +34,6 @@ static UINT updateSettingsMessage, findReplaceMessage; static HMODULE hMsftedit = nullptr; void TextWindow::init() { - RegisterClass(tempPtr(createWindowClass(TEXT_WINDOW_CLASS))); - textAccelTable = LoadAccelerators(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_TEXT_ACCEL)); updateSettingsMessage = checkLE(RegisterWindowMessage(L"chromafiler_TextUpdateSettings")); @@ -61,10 +57,6 @@ TextWindow::TextWindow(ItemWindow *const parent, IShellItem *const item) replaceBuffer[0] = 0; } -const wchar_t * TextWindow::className() const { - return TEXT_WINDOW_CLASS; -} - const wchar_t * TextWindow::appUserModelID() const { return L"chroma.text"; } diff --git a/src/TextWindow.h b/src/TextWindow.h index a5d5116..88c974a 100644 --- a/src/TextWindow.h +++ b/src/TextWindow.h @@ -58,8 +58,6 @@ class TextWindow : public ItemWindow { void trackContextMenu(POINT pos) override; private: - const wchar_t * className() const override; - HWND createRichEdit(bool readOnly, bool wordWrap); bool isEditable(); CComPtr getTOMDocument(); diff --git a/src/ThumbnailWindow.cpp b/src/ThumbnailWindow.cpp index fa1c4bc..a14ce08 100644 --- a/src/ThumbnailWindow.cpp +++ b/src/ThumbnailWindow.cpp @@ -6,14 +6,6 @@ namespace chromafiler { -const wchar_t THUMBNAIL_WINDOW_CLASS[] = L"ChromaFile Thumbnail"; - -void ThumbnailWindow::init() { - WNDCLASS wndClass = createWindowClass(THUMBNAIL_WINDOW_CLASS); - wndClass.style |= CS_HREDRAW | CS_VREDRAW; // redraw whenever size changes - RegisterClass(&wndClass); -} - ThumbnailWindow::ThumbnailWindow(ItemWindow *const parent, IShellItem *const item) : ItemWindow(parent, item) {} @@ -25,10 +17,6 @@ ThumbnailWindow::~ThumbnailWindow() { } } -const wchar_t * ThumbnailWindow::className() const { - return THUMBNAIL_WINDOW_CLASS; -} - void ThumbnailWindow::onCreate() { ItemWindow::onCreate(); thumbnailThread.Attach(new ThumbnailThread(item, this)); @@ -45,6 +33,7 @@ void ThumbnailWindow::onSize(SIZE size) { RECT bodyRect = windowBody(); SIZE bodySize = rectSize(bodyRect); thumbnailThread->requestThumbnail(bodySize); + // TODO invalidate? } void ThumbnailWindow::onItemChanged() { diff --git a/src/ThumbnailWindow.h b/src/ThumbnailWindow.h index f18c3a4..a6d0f46 100644 --- a/src/ThumbnailWindow.h +++ b/src/ThumbnailWindow.h @@ -7,8 +7,6 @@ namespace chromafiler { class ThumbnailWindow : public ItemWindow { public: - static void init(); - ThumbnailWindow(ItemWindow *parent, IShellItem *item); ~ThumbnailWindow(); @@ -29,8 +27,6 @@ class ThumbnailWindow : public ItemWindow { void refresh() override; private: - const wchar_t * className() const override; - SRWLOCK thumbnailBitmapLock = SRWLOCK_INIT; HBITMAP thumbnailBitmap = nullptr; diff --git a/src/TrayWindow.cpp b/src/TrayWindow.cpp index 2642108..8f9d809 100644 --- a/src/TrayWindow.cpp +++ b/src/TrayWindow.cpp @@ -9,7 +9,7 @@ namespace chromafiler { -const wchar_t TRAY_WINDOW_CLASS[] = L"ChromaFile Tray"; +const wchar_t TRAY_WINDOW_CLASS[] = L"ChromaFile Tray"; // used by installer, do not change! const int HOTKEY_FOCUS_TRAY = 1; @@ -43,8 +43,10 @@ static void snapAxis(LONG value, LONG edge, LONG *snapOffset, LONG *snapDist) { } void TrayWindow::init() { - WNDCLASS wndClass = createWindowClass(TRAY_WINDOW_CLASS); - wndClass.style = 0; // clear redraw style + WNDCLASS wndClass = {}; + wndClass.lpfnWndProc = windowProc; + wndClass.hInstance = GetModuleHandle(nullptr); + wndClass.lpszClassName = TRAY_WINDOW_CLASS; wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1); RegisterClass(&wndClass); diff --git a/src/main.cpp b/src/main.cpp index 3e18cd2..858ef7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,5 @@ #include "main.h" #include "FolderWindow.h" -#include "ThumbnailWindow.h" #include "PreviewWindow.h" #include "TextWindow.h" #include "TrayWindow.h" @@ -110,7 +109,6 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int showCommand) { initDPI(); ItemWindow::init(); FolderWindow::init(); - ThumbnailWindow::init(); PreviewWindow::init(); TextWindow::init(); TrayWindow::init();