From e2199bbb83d1799a5a03e08bd07ff417bb31f972 Mon Sep 17 00:00:00 2001 From: zvon Date: Wed, 1 Apr 2020 13:51:53 +0200 Subject: [PATCH] windows/gui_functions: localization, nicer edit box, buttons have appropriate size --- windows/gui_functions.cpp | 28 +++++++++++++++++++++++----- windows/gui_functions.hpp | 3 ++- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/windows/gui_functions.cpp b/windows/gui_functions.cpp index 14ac630..3ae8371 100644 --- a/windows/gui_functions.cpp +++ b/windows/gui_functions.cpp @@ -1,4 +1,3 @@ -#define UNICODE #include "gui_functions.hpp" #include "databasewindow.hpp" #include "mainwindow.hpp" @@ -6,6 +5,8 @@ #include "progresswindow.hpp" #include "searchwindow.hpp" #include "seasonwindow.hpp" +#include "../resources_windows.h" +#include "../functions.hpp" #include @@ -75,8 +76,7 @@ HWND createLabel( const wchar_t *text, int x, int y, int width, int height, HWND createEditBox( int x, int y, int width, int height, long long id, HWND parent, HFONT hFont ) { return createWindow( L"Edit", NULL, x, y, width, height, id, parent, hFont, - WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | - ES_AUTOHSCROLL, + WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL, WS_EX_CLIENTEDGE ); } @@ -87,11 +87,21 @@ HWND createCombo( int x, int y, int width, int height, long long id, WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP, 0 ); } +void idealButton( HWND hwnd, int x, int y, int width, int height ) { + SIZE size; + SendMessage( hwnd, BCM_GETIDEALSIZE, 0, ( LPARAM )&size ); + auto ideal_width = size.cx + 10; + if ( ideal_width > width ) + SetWindowPos( hwnd, HWND_TOP, x, y, ideal_width, height, 0 ); +} + HWND createButton( const wchar_t *text, int x, int y, int width, int height, long long id, HWND parent, HFONT hFont ) { - return createWindow( + HWND hwnd = createWindow( L"Button", text, x, y, width, height, id, parent, hFont, WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | WS_TABSTOP, 0 ); + idealButton( hwnd, x, y, width, height ); + return hwnd; } HWND createCheckbox( const wchar_t *text, int x, int y, int width, int height, @@ -170,7 +180,7 @@ void setListViewItemText( HWND list_view, int row, int column, std::wstring getDir() { wchar_t path[MAX_PATH]; BROWSEINFO bi{}; - bi.lpszTitle = L"Choose a folder"; + bi.lpszTitle = _( CHOOSE_DIR ); LPITEMIDLIST pidl = SHBrowseForFolder( &bi ); if ( pidl != 0 ) { SHGetPathFromIDList( pidl, path ); @@ -194,3 +204,11 @@ std::wstring getItemText( HWND hwnd, int row, int column ) { int getComboCurSel( HWND hwnd ) { return SendMessage( hwnd, CB_GETCURSEL, 0, 0 ); } + +void setIcons( HINSTANCE hInstance, HWND window ) { + auto hIcon = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_TV_RENAME_GUI ) ); + auto hIconSmall = LoadIcon( hInstance, MAKEINTRESOURCE( IDI_SMALL ) ); + SendMessage( window, WM_SETICON, ( WPARAM )ICON_BIG, ( LPARAM )hIcon ); + SendMessage( window, WM_SETICON, ( WPARAM )ICON_SMALL, + ( LPARAM )hIconSmall ); +} diff --git a/windows/gui_functions.hpp b/windows/gui_functions.hpp index 43e8fa6..f1942ce 100644 --- a/windows/gui_functions.hpp +++ b/windows/gui_functions.hpp @@ -1,6 +1,6 @@ -#include #include #include +#include void registerWindowClasses( HINSTANCE hInstance ); void centerWindow( HWND hwnd ); @@ -30,3 +30,4 @@ void setListViewItemText( HWND list_view, int row, int column, std::wstring getItemText( HWND hwnd, int row, int column ); int getComboCurSel( HWND hwnd ); std::wstring getDir(); +void setIcons( HINSTANCE hInstance, HWND window );