Skip to content

Commit

Permalink
Replace some deprecated calls and cleanup the code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
neatdecisions committed May 25, 2020
1 parent 97a10dc commit bad421e
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 244 deletions.
14 changes: 7 additions & 7 deletions NeatMouseWtl/AboutDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "stdafx.h"
#include "resource.h"

#include "AboutDlg.h"

#include "logic/MainSingleton.h"
Expand All @@ -18,7 +17,9 @@

namespace neatmouse {

constexpr TCHAR * kRegistryStartupValueName = _T("NeatMouse");
namespace {
constexpr TCHAR * kRegistryStartupValueName = _T("NeatMouse");
}


//=====================================================================================================================
Expand Down Expand Up @@ -89,19 +90,18 @@ CAboutDlg::OnInitDialog(HWND, LRESULT)
programVersion.Attach(GetDlgItem(IDC_STATIC_VERSION));
programVersion.SetWindowText(s);


ykLink.SetHyperLinkExtendedStyle(HLINK_UNDERLINEHOVER);
ykLink.SubclassWindow(GetDlgItem(IDC_STATIC_YK));
ykLink.SetHyperLink(_T("http://p.yusukekamiyamane.com"));
ykLink.SetHyperLink(L"https://p.yusukekamiyamane.com");

visitLink.SetHyperLinkExtendedStyle(HLINK_UNDERLINEHOVER);
visitLink.SubclassWindow(GetDlgItem(IDC_STATIC_VISIT));
visitLink.SetHyperLink(CString(LINK_SITE));
visitLink.SetHyperLink(L"https://neatdecisions.com");

link.SetHyperLinkExtendedStyle(HLINK_UNDERLINEHOVER);
link.SubclassWindow(GetDlgItem(IDC_STATIC_UPDATE));

link.SetHyperLink(CString(LINK_GITHUB));
link.SetHyperLink(L"https://github.com/neatdecisions/neatmouse");
link.SetLabel(_("about.github"));

someIcons.Attach(GetDlgItem(IDC_STATIC_SOMEICONS));
Expand Down Expand Up @@ -137,7 +137,7 @@ CAboutDlg::OnRunAtStartup(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/,
LRESULT
CAboutDlg::OnSetCursor(CWindow /*wndTopLevel*/, UINT /*nHitTest*/, UINT /*message*/)
{
SetCursor(::LoadCursor(NULL, IDC_ARROW));
SetCursor(AtlLoadSysCursorImage(OCR_NORMAL, LR_SHARED | LR_DEFAULTSIZE));
SetMsgHandled(TRUE);
return TRUE;
}
Expand Down
6 changes: 3 additions & 3 deletions NeatMouseWtl/CursorOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void InitOverlay(HINSTANCE hinst)
{
overlayInstance = hinst;

WNDCLASSEX wcex;
WNDCLASSEX wcex{};

wcex.cbSize = sizeof(WNDCLASSEX);

Expand All @@ -123,8 +123,8 @@ void InitOverlay(HINSTANCE hinst)
wcex.cbWndExtra = 0;
wcex.hInstance = overlayInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.hCursor = AtlLoadSysCursorImage(OCR_NORMAL, LR_SHARED | LR_DEFAULTSIZE);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = OVERLAY_WINDOW_NAME;
wcex.hIconSm = NULL;
Expand Down
31 changes: 15 additions & 16 deletions NeatMouseWtl/EmulationNotifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,22 @@ EmulationNotifier::EmulationNotifier(HWND mainWindow) : hwndMainWindow(mainWindo
//---------------------------------------------------------------------------------------------------------------------
void EmulationNotifier::Notify(bool enabled)
{
NOTIFYICONDATA nd;
memset(&nd, '\0', sizeof(nd));
nd.cbSize = sizeof(NOTIFYICONDATA);
nd.hWnd = hwndMainWindow;
nd.uID = 10;
nd.uFlags = NIF_INFO;
nd.dwInfoFlags = NIIF_INFO;
if (enabled)
{
wcscpy_s(nd.szInfo, 255, _("notify.balloon-enabled"));
} else
{
wcscpy_s(nd.szInfo, 255, _("notify.balloon-disabled"));
}
wcscpy_s(nd.szInfoTitle, 63, L"NeatMouse");
NOTIFYICONDATA nd{};
nd.cbSize = sizeof(NOTIFYICONDATA);
nd.hWnd = hwndMainWindow;
nd.uID = 10;
nd.uFlags = NIF_INFO;
nd.dwInfoFlags = NIIF_INFO;
if (enabled)
{
wcscpy_s(nd.szInfo, 255, _("notify.balloon-enabled"));
} else
{
wcscpy_s(nd.szInfo, 255, _("notify.balloon-disabled"));
}
wcscpy_s(nd.szInfoTitle, 63, L"NeatMouse");

Shell_NotifyIcon(NIM_MODIFY, &nd);
Shell_NotifyIcon(NIM_MODIFY, &nd);
}


Expand Down
21 changes: 8 additions & 13 deletions NeatMouseWtl/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,14 @@

namespace neatmouse {

//---------------------------------------------------------------------------------------------------------------------
CMainFrame::CMainFrame() : cbPresetsSelectionIndex(0), isVisible(true)
{}


//---------------------------------------------------------------------------------------------------------------------
BOOL
CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
return TRUE;

return m_view.PreTranslateMessage(pMsg);
return (CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
? TRUE
: m_view.PreTranslateMessage(pMsg);
}


Expand Down Expand Up @@ -286,28 +281,28 @@ CMainFrame::ToggleVisible()
void
CMainFrame::TrackTrayMenu()
{
POINT pt;
POINT pt{};
GetCursorPos(&pt);

CMenuHandle menu = tb.GetMenus().GetSubMenu(1);

MENUITEMINFO iii;
MENUITEMINFO iii{};

iii.cbSize = sizeof(MENUITEMINFO);
iii.fMask = MIIM_STRING;

iii.dwTypeData = const_cast<LPWSTR>(_("notify.restore"));
iii.cch = (UINT)wcslen( iii.dwTypeData );
iii.cch = static_cast<UINT>(wcslen(iii.dwTypeData));
SetMenuItemInfo(menu, 0, TRUE, &iii);

iii.dwTypeData = logic::MainSingleton::Instance().GetMouseActioner().isEmulationActivated()
? const_cast<LPWSTR>(_("notify.disable"))
: const_cast<LPWSTR>(_("notify.enable"));
iii.cch = (UINT)wcslen( iii.dwTypeData );
iii.cch = static_cast<UINT>(wcslen(iii.dwTypeData));
SetMenuItemInfo(menu, 1, TRUE, &iii);

iii.dwTypeData = const_cast<LPWSTR>(_("notify.exit"));
iii.cch = (UINT)wcslen( iii.dwTypeData );
iii.cch = static_cast<UINT>(wcslen(iii.dwTypeData));
SetMenuItemInfo(menu, 2, TRUE, &iii);

TrackPopupMenu(menu, 0, pt.x, pt.y, 0, m_hWnd, 0);
Expand Down
70 changes: 33 additions & 37 deletions NeatMouseWtl/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,6 @@ namespace neatmouse {
class CMainFrame : public CFrameWindowImpl<CMainFrame>,
public CMessageFilter
{
protected:
neatcommon::ui::CMenuBitmapsManager menuBitmapsManager;
CNeatMouseWtlView m_view;
CNeatToolbar tb;

int cbPresetsSelectionIndex;
bool isVisible;

void OnClose();
void OnSysCommand(UINT nID, CPoint point);
void OnLanguageMenuItem(UINT uCode, int nID, HWND hwndCtrl);
void OnComboPresetsSelChange(UINT uCode, int nID, HWND hwndCtrl);
void OnDrawItem(UINT id, LPDRAWITEMSTRUCT lpdis);
void OnMeasureItem(UINT id, LPMEASUREITEMSTRUCT lpmis);

LRESULT OnCreate(LPCREATESTRUCT lpcs);
LRESULT OnBnClickedButtonPresetSave(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnBnClickedButtonPresetAdd(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnBnClickedButtonPresetDelete(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnBnClickedButtonAdvancedView(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnAppAbout(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);

LRESULT OnTrayBtnClick(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled);

LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnTrayShow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnTrayToggleEmulation(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

void RedrawToolbar();
void localize();
void TrackTrayMenu();

BEGIN_MSG_MAP(CMainFrame)
MSG_WM_CREATE(OnCreate)
MSG_WM_CLOSE(OnClose)
Expand Down Expand Up @@ -78,8 +45,7 @@ class CMainFrame : public CFrameWindowImpl<CMainFrame>,
SetMsgHandled(TRUE);
OnLanguageMenuItem((UINT)HIWORD(wParam), (int)LOWORD(wParam), (HWND)lParam);
lResult = 0;
if(IsMsgHandled())
return TRUE;
if(IsMsgHandled()) return TRUE;
}

CHAIN_MSG_MAP_MEMBER(tb)
Expand All @@ -91,12 +57,42 @@ class CMainFrame : public CFrameWindowImpl<CMainFrame>,
DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)
virtual BOOL PreTranslateMessage(MSG* pMsg);

CMainFrame();

void ToggleVisible();

private:
void OnClose();
void OnSysCommand(UINT nID, CPoint point);
void OnLanguageMenuItem(UINT uCode, int nID, HWND hwndCtrl);
void OnComboPresetsSelChange(UINT uCode, int nID, HWND hwndCtrl);
void OnDrawItem(UINT id, LPDRAWITEMSTRUCT lpdis);
void OnMeasureItem(UINT id, LPMEASUREITEMSTRUCT lpmis);

LRESULT OnCreate(LPCREATESTRUCT lpcs);
LRESULT OnBnClickedButtonPresetSave(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnBnClickedButtonPresetAdd(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnBnClickedButtonPresetDelete(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnBnClickedButtonAdvancedView(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);
LRESULT OnAppAbout(UINT /*wNotifyCode*/, int /*wID*/, HWND /*hWndCtl*/);

LRESULT OnTrayBtnClick(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled);

LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnTrayShow(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnTrayToggleEmulation(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

void RedrawToolbar();
void localize();
void TrackTrayMenu();

void resizeByContent();

neatcommon::ui::CMenuBitmapsManager menuBitmapsManager;
CNeatMouseWtlView m_view;
CNeatToolbar tb;

int cbPresetsSelectionIndex = 0;
bool isVisible = true;
};

} // namespace neatmouse
8 changes: 4 additions & 4 deletions NeatMouseWtl/NeatMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ int Run(LPTSTR /*lpstrCmdLine*/ = NULL, int nCmdShow = SW_SHOWDEFAULT)
}
neatmouse::logic::MainSingleton::Instance().SetEmulationNotifier(std::make_shared<neatmouse::EmulationNotifier>(wndMain));
neatmouse::logic::MainSingleton::Instance().TriggerOverlay();
const CIcon icon = AtlLoadIconImage(IDI_MAUSEMUL);

wndMain.SetIcon(LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDI_MAUSEMUL)));
wndMain.SetIcon(icon);

WCHAR a[64] = L"NeatMouse";
NOTIFYICONDATA nd;
ZeroMemory(&nd, sizeof(nd));
NOTIFYICONDATA nd{};
nd.cbSize = sizeof(NOTIFYICONDATA);
nd.hWnd = wndMain;
wcscpy_s(nd.szTip, wcslen(a) + 1, a);
nd.uCallbackMessage = NEAT_TRAY_CALLBACK;
nd.uID = 10;
nd.hIcon = LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDI_MAUSEMUL));
nd.hIcon = icon;
nd.uFlags = NIF_TIP | NIF_ICON | NIF_MESSAGE;

if (neatmouse::logic::MainSingleton::Instance().GetMouseParams().minimizeOnStartup)
Expand Down
Loading

0 comments on commit bad421e

Please sign in to comment.