Skip to content

Commit

Permalink
HexCtrl is now completely MFC free, only Win32 API is used.
Browse files Browse the repository at this point in the history
All MFC dependencies have been removed. The HEXCTRL_MANUAL_MFC_INIT compiler option is removed.
The "Use of MFC" option in the "HexCtrl DLL" and "Win32 App" projects set to "Use Standard Windows Libraries".
  • Loading branch information
jovibor committed Dec 30, 2024
1 parent 460ee4f commit 7e86f1f
Show file tree
Hide file tree
Showing 26 changed files with 458 additions and 495 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:
PATH_PROJ_HEXCTRLDLL: '"./VS Projects/HexCtrl DLL/HexCtrl DLL.vcxproj"'
PATH_PROJ_HEXCTRLTEST: '"./VS Projects/HexCtrl Test/HexCtrl Test.vcxproj"'
PATH_VSTESTCONSOLE_EXE: '"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"'
PATH_TESTDLL: '"C:\HexCtrlTEMP\HexCtrl Test.dll"'
PATH_TESTDLL: '"C:\HexCtrlTEMP\HexCtrlTest.dll"'
PATH_TEMPDIR: '"C:\HexCtrlTEMP\"'
BUILD_CONFIG: Debug
BUILD_PLATFORM_x64: x64
Expand Down
4 changes: 2 additions & 2 deletions HexCtrl/HexCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This software is available under "The HexCtrl License", see the LICENSE file. *
****************************************************************************************/
#pragma once
#include <afxwin.h>
#include <Windows.h>
#include <compare>
#include <cstdint>
#include <memory>
Expand Down Expand Up @@ -501,6 +501,6 @@ namespace HEXCTRL {

constexpr auto HEXCTRL_FLAG_DLG_NOESC { 0x01ULL };

//Setting a manifest for the ComCtl32.dll version 6.
//Setting a manifest for the Comctl32.dll version 6.
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
}
32 changes: 18 additions & 14 deletions HexCtrl/dep/ListEx/ListEx.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module;
#include <vector>
export module ListEx;

#pragma comment(lib, "Comctl32.lib")
#pragma comment(lib, "Shlwapi.lib") //StrToInt64ExW().
#pragma comment(lib, "UxTheme.lib") //SetWindowTheme().

export namespace HEXCTRL::LISTEX {
/****************************************************************
* EListExSortMode - Sorting mode. *
Expand Down Expand Up @@ -1129,10 +1133,10 @@ namespace HEXCTRL::LISTEX {
[[nodiscard]] long GetFontSize()const;
[[nodiscard]] auto GetHeader() -> CListExHdr& { return m_Hdr; }
void FontSizeIncDec(bool fInc);
[[nodiscard]] bool IsWindow()const;
[[nodiscard]] auto GetCustomColor(int iItem, int iSubItem)const->std::optional<LISTEXCOLOR>;
[[nodiscard]] int GetIcon(int iItem, int iSubItem)const; //Does cell have an icon associated.
[[nodiscard]] auto GetTooltip(int iItem, int iSubItem)const->std::optional<LISTEXTTDATA>;
[[nodiscard]] bool IsWindow()const;
auto OnCommand(const MSG& msg) -> LRESULT;
auto OnDestroy() -> LRESULT;
void OnEditInPlaceEnterPressed();
Expand Down Expand Up @@ -1448,6 +1452,19 @@ auto CListEx::GetFont()const->LOGFONTW
return lf;
}

long CListEx::GetFontSize()const
{
assert(IsCreated());
if (!IsCreated()) {
return { };
}

LOGFONTW lf { };
::GetObjectW(m_hFntList, sizeof(lf), &lf);

return lf.lfHeight;
}

auto CListEx::GetHWND()const->HWND
{
if (!IsCreated()) {
Expand Down Expand Up @@ -1546,19 +1563,6 @@ int CListEx::GetSelectionMark()const
return static_cast<int>(::SendMessageW(m_hWnd, LVM_GETSELECTIONMARK, 0, 0));
}

long CListEx::GetFontSize()const
{
assert(IsCreated());
if (!IsCreated()) {
return { };
}

LOGFONTW lf { };
::GetObjectW(m_hFntList, sizeof(lf), &lf);

return lf.lfHeight;
}

int CListEx::GetSortColumn()const
{
assert(IsCreated());
Expand Down
38 changes: 1 addition & 37 deletions HexCtrl/res/HexCtrl.rc
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Data Interpreter"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_HEXCTRL_DATAINTERP_GRID,"MfcPropertyGrid",0x100,0,0,275,300
CONTROL "Hex numbers",IDC_HEXCTRL_DATAINTERP_CHK_HEX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,306,55,8
CONTROL "Big-endian",IDC_HEXCTRL_DATAINTERP_CHK_BE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,306,47,8
CONTROL "",IDC_HEXCTRL_DATAINTERP_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_TABSTOP,0,0,275,300
END

IDD_HEXCTRL_PROGRESS DIALOGEX 0, 0, 203, 74
Expand Down Expand Up @@ -308,42 +308,6 @@ IDB_HEXCTRL_GROUP BITMAP "IDB_HEXCTRL_GROUP.bmp"
IDB_HEXCTRL_FONTCHOOSE BITMAP "IDB_HEXCTRL_FONTCHOOSE.bmp"


/////////////////////////////////////////////////////////////////////////////
//
// Dialog Info
//

IDD_HEXCTRL_DATAINTERP DLGINIT
BEGIN
IDC_HEXCTRL_DATAINTERP_GRID, 0x37c, 414, 0
0x4d3c, 0x4346, 0x7250, 0x706f, 0x7265, 0x7974, 0x7247, 0x6469, 0x485f,
0x6165, 0x6564, 0x4372, 0x7274, 0x3e6c, 0x5254, 0x4555, 0x2f3c, 0x464d,
0x5043, 0x6f72, 0x6570, 0x7472, 0x4779, 0x6972, 0x5f64, 0x6548, 0x6461,
0x7265, 0x7443, 0x6c72, 0x3c3e, 0x464d, 0x5043, 0x6f72, 0x6570, 0x7472,
0x4779, 0x6972, 0x5f64, 0x6544, 0x6373, 0x6972, 0x7470, 0x6f69, 0x416e,
0x6572, 0x3e61, 0x4146, 0x534c, 0x3c45, 0x4d2f, 0x4346, 0x7250, 0x706f,
0x7265, 0x7974, 0x7247, 0x6469, 0x445f, 0x7365, 0x7263, 0x7069, 0x6974,
0x6e6f, 0x7241, 0x6165, 0x3c3e, 0x464d, 0x5043, 0x6f72, 0x6570, 0x7472,
0x4779, 0x6972, 0x5f64, 0x6c41, 0x6870, 0x6261, 0x7465, 0x6369, 0x6f4d,
0x6564, 0x463e, 0x4c41, 0x4553, 0x2f3c, 0x464d, 0x5043, 0x6f72, 0x6570,
0x7472, 0x4779, 0x6972, 0x5f64, 0x6c41, 0x6870, 0x6261, 0x7465, 0x6369,
0x6f4d, 0x6564, 0x3c3e, 0x464d, 0x5043, 0x6f72, 0x6570, 0x7472, 0x4779,
0x6972, 0x5f64, 0x6f4d, 0x6964, 0x6966, 0x6465, 0x7250, 0x706f, 0x7265,
0x6974, 0x7365, 0x463e, 0x4c41, 0x4553, 0x2f3c, 0x464d, 0x5043, 0x6f72,
0x6570, 0x7472, 0x4779, 0x6972, 0x5f64, 0x6f4d, 0x6964, 0x6966, 0x6465,
0x7250, 0x706f, 0x7265, 0x6974, 0x7365, 0x3c3e, 0x464d, 0x5043, 0x6f72,
0x6570, 0x7472, 0x4779, 0x6972, 0x5f64, 0x5356, 0x6f44, 0x4e74, 0x7465,
0x6f4c, 0x6b6f, 0x543e, 0x5552, 0x3c45, 0x4d2f, 0x4346, 0x7250, 0x706f,
0x7265, 0x7974, 0x7247, 0x6469, 0x565f, 0x4453, 0x746f, 0x654e, 0x4c74,
0x6f6f, 0x3e6b, 0x4d3c, 0x4346, 0x7250, 0x706f, 0x7265, 0x7974, 0x7247,
0x6469, 0x445f, 0x7365, 0x7263, 0x7069, 0x6974, 0x6e6f, 0x6f52, 0x7377,
0x303e, 0x2f3c, 0x464d, 0x5043, 0x6f72, 0x6570, 0x7472, 0x4779, 0x6972,
0x5f64, 0x6544, 0x6373, 0x6972, 0x7470, 0x6f69, 0x526e, 0x776f, 0x3e73,

0
END


/////////////////////////////////////////////////////////////////////////////
//
// Menu
Expand Down
4 changes: 2 additions & 2 deletions HexCtrl/res/HexCtrlRes.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
#define IDC_HEXCTRL_FILLDATA_RAD_SEL 9060
#define IDC_HEXCTRL_BKMMGR_LIST 9061
#define IDC_HEXCTRL_BKMMGR_CHK_HEX 9062
#define IDC_HEXCTRL_DATAINTERP_GRID 9063
#define IDC_HEXCTRL_DATAINTERP_LIST 9063
#define IDC_HEXCTRL_DATAINTERP_CHK_HEX 9064
#define IDC_HEXCTRL_DATAINTERP_CHK_BE 9065
#define IDC_HEXCTRL_CODEPAGE_LIST 9066
Expand Down Expand Up @@ -157,7 +157,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 9092
#define _APS_NEXT_COMMAND_VALUE 33058
#define _APS_NEXT_CONTROL_VALUE 9092
#define _APS_NEXT_CONTROL_VALUE 9093
#define _APS_NEXT_SYMED_VALUE 9092
#endif
#endif
48 changes: 20 additions & 28 deletions HexCtrl/src/CHexCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <numeric>
#include <random>
#include <thread>
#pragma comment(lib, "Comctl32.lib")

import HEXCTRL.CHexScroll;
import HEXCTRL.CHexSelection;
Expand All @@ -33,19 +34,9 @@ import HEXCTRL.CHexDlgProgress;
using namespace HEXCTRL::INTERNAL;

HEXCTRLAPI HEXCTRL::IHexCtrlPtr HEXCTRL::CreateHexCtrl() {
#if defined(HEXCTRL_MANUAL_MFC_INIT)
//MFC initialization, if HexCtrl is used in non MFC project with the "Shared MFC" linking.
if (!AfxGetModuleState()->m_lpszCurrentAppName) {
AfxWinInit(::GetModuleHandleW(nullptr), nullptr, ::GetCommandLineW(), 0);
}
#endif
return IHexCtrlPtr { new HEXCTRL::INTERNAL::CHexCtrl() };
}

#if defined(HEXCTRL_DYNAMIC_LIB) || defined(HEXCTRL_MANUAL_MFC_INIT)
CWinApp theApp; //CWinApp object is vital for manual MFC, and for in-DLL work.
#endif

namespace HEXCTRL::INTERNAL {
class CHexDlgAbout final {
public:
Expand Down Expand Up @@ -470,7 +461,6 @@ bool CHexCtrl::CreateDialogCtrl(UINT uCtrlID, HWND hWndParent)

void CHexCtrl::Destroy()
{
DestroyWindow();
delete this;
}

Expand Down Expand Up @@ -2067,21 +2057,22 @@ void CHexCtrl::SetGroupSize(DWORD dwSize)

//Getting the "Group Data" menu pointer independent of position.
const auto menuMain = m_MenuMain.GetSubMenu(0);
wnd::CMenu* pMenuGroupData { };
HMENU hMenuGroupData { };
for (auto i = 0; i < menuMain.GetMenuItemCount(); ++i) {
//Searching through all submenus whose first menuID is IDM_HEXCTRL_GROUPDATA_BYTE.
if (auto menuSub = menuMain.GetSubMenu(i); menuSub.IsMenu()) {
if (menuSub.GetMenuItemID(0) == IDM_HEXCTRL_GROUPDATA_BYTE) {
pMenuGroupData = &menuSub;
hMenuGroupData = menuSub.GetHMENU();
break;
}
}
}

if (pMenuGroupData != nullptr) {
if (hMenuGroupData != nullptr) {
//Unchecking all menus and checking only the currently selected.
for (auto i = 0; i < pMenuGroupData->GetMenuItemCount(); ++i) {
pMenuGroupData->CheckMenuItem(i, false, false);
wnd::CMenu menuGroup(hMenuGroupData);
for (auto iIDGroupData = 0; iIDGroupData < menuGroup.GetMenuItemCount(); ++iIDGroupData) {
menuGroup.CheckMenuItem(iIDGroupData, false, false);
}

UINT uIDToCheck { 0 };
Expand All @@ -2103,7 +2094,7 @@ void CHexCtrl::SetGroupSize(DWORD dwSize)
}

if (uIDToCheck != 0) {
pMenuGroupData->CheckMenuItem(uIDToCheck, true);
menuGroup.CheckMenuItem(uIDToCheck, true);
}
}

Expand Down Expand Up @@ -2955,9 +2946,9 @@ void CHexCtrl::DrawInfoBar(HDC hDC)const
vecInfoData.reserve(4);

const auto iScrollH = static_cast<int>(m_pScrollH->GetScrollPos());
CRect rcInfoBar(m_iFirstVertLinePx + 1 - iScrollH, m_iThirdHorzLinePx + 1,
wnd::CRect rcInfoBar(m_iFirstVertLinePx + 1 - iScrollH, m_iThirdHorzLinePx + 1,
m_iFourthVertLinePx, m_iFourthHorzLinePx); //Info bar rc until m_iFourthHorizLine.
CRect rcText = rcInfoBar;
wnd::CRect rcText = rcInfoBar;
rcText.left = m_iFirstVertLinePx + 5; //Draw the text beginning with little indent.
rcText.right = m_iFirstVertLinePx + m_iWidthClientAreaPx; //Draw text to the end of the client area, even if it passes iFourthHorizLine.

Expand Down Expand Up @@ -4167,8 +4158,9 @@ void CHexCtrl::Print()

constexpr auto iMarginX = 150;
constexpr auto iMarginY = 150;
const CRect rcPrint(CPoint(0, 0), CSize(::GetDeviceCaps(dcPrint, HORZRES) - (iMarginX * 2), ::GetDeviceCaps(dcPrint, VERTRES) - (iMarginY * 2)));
const CSize sizePrintDpi = { ::GetDeviceCaps(dcPrint, LOGPIXELSX), ::GetDeviceCaps(dcPrint, LOGPIXELSY) };
const wnd::CRect rcPrint(POINT(0, 0), SIZE(::GetDeviceCaps(dcPrint, HORZRES) - (iMarginX * 2),
::GetDeviceCaps(dcPrint, VERTRES) - (iMarginY * 2)));
const SIZE sizePrintDpi = { ::GetDeviceCaps(dcPrint, LOGPIXELSX), ::GetDeviceCaps(dcPrint, LOGPIXELSY) };
const auto iRatio = sizePrintDpi.cy / m_iLOGPIXELSY;

/***Changing Main and Info Bar fonts***/
Expand Down Expand Up @@ -4806,9 +4798,9 @@ void CHexCtrl::TTMainShow(bool fShow, bool fTimer)
{
if (fShow) {
m_tmTT = std::chrono::high_resolution_clock::now();
POINT pt;
GetCursorPos(&pt);
m_wndTTMain.SendMsg(TTM_TRACKPOSITION, 0, static_cast<LPARAM>(MAKELONG(pt.x + 3, pt.y - 20)));
POINT ptCur;
::GetCursorPos(&ptCur);
m_wndTTMain.SendMsg(TTM_TRACKPOSITION, 0, static_cast<LPARAM>(MAKELONG(ptCur.x + 3, ptCur.y - 20)));
m_wndTTMain.SendMsg(TTM_UPDATETIPTEXTW, 0, reinterpret_cast<LPARAM>(&m_ttiMain));
m_wndTTMain.SendMsg(TTM_TRACKACTIVATE, static_cast<WPARAM>(TRUE), reinterpret_cast<LPARAM>(&m_ttiMain));
m_Wnd.SetTimer(m_uIDTTTMain, 300, nullptr);
Expand All @@ -4831,11 +4823,11 @@ void CHexCtrl::TTMainShow(bool fShow, bool fTimer)
void CHexCtrl::TTOffsetShow(bool fShow)
{
if (fShow) {
CPoint ptScreen;
GetCursorPos(&ptScreen);
POINT ptCur;
::GetCursorPos(&ptCur);
auto wstrOffset = (IsOffsetAsHex() ? L"Offset: 0x" : L"Offset: ") + OffsetToWstr(GetTopLine() * GetCapacity());
m_ttiOffset.lpszText = wstrOffset.data();
m_wndTTOffset.SendMsg(TTM_TRACKPOSITION, 0, static_cast<LPARAM>(MAKELONG(ptScreen.x - 5, ptScreen.y - 20)));
m_wndTTOffset.SendMsg(TTM_TRACKPOSITION, 0, static_cast<LPARAM>(MAKELONG(ptCur.x - 5, ptCur.y - 20)));
m_wndTTOffset.SendMsg(TTM_UPDATETIPTEXTW, 0, reinterpret_cast<LPARAM>(&m_ttiOffset));
m_ttiOffset.lpszText = nullptr;
}
Expand Down Expand Up @@ -6834,7 +6826,7 @@ void CHexCtrl::ModifyOperVec256(std::byte* pData, const HEXMODIFY& hms, [[maybe_
}
#endif //^^^ _M_IX86 || _M_X64

//CHexCtrl MFC message handlers.
//CHexCtrl message handlers.

auto CHexCtrl::OnChar(const MSG& msg)->LRESULT
{
Expand Down
2 changes: 1 addition & 1 deletion HexCtrl/src/CHexCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
****************************************************************************************/
#pragma once
#include "../HexCtrl.h"
#include <afxwin.h>
#include <algorithm>
#include <commctrl.h>
#include <chrono>
#include <optional>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions HexCtrl/src/Dialogs/CHexDlgBkmMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "CHexDlgBkmMgr.h"
#include <algorithm>
#include <cassert>
#include <commctrl.h>
#include <format>
#include <numeric>

Expand Down
1 change: 1 addition & 0 deletions HexCtrl/src/Dialogs/CHexDlgBkmMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
****************************************************************************************/
#pragma once
#include "../../HexCtrl.h"
#include <commctrl.h>
#include <vector>

import HEXCTRL.HexUtility;
Expand Down
1 change: 1 addition & 0 deletions HexCtrl/src/Dialogs/CHexDlgCodepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "CHexDlgCodepage.h"
#include <algorithm>
#include <cassert>
#include <commctrl.h>
#include <format>

using namespace HEXCTRL::INTERNAL;
Expand Down
1 change: 1 addition & 0 deletions HexCtrl/src/Dialogs/CHexDlgCodepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
****************************************************************************************/
#pragma once
#include "../../HexCtrl.h"
#include <commctrl.h>

import HEXCTRL.HexUtility;

Expand Down
Loading

0 comments on commit 7e86f1f

Please sign in to comment.