Skip to content

Commit

Permalink
CHexDlgCallback renamed to CHexDlgProgress and is used now as a module.
Browse files Browse the repository at this point in the history
CHexDlgProgress is now MFC free. wnd::CWndProgBar class added.

Intermediate commit

Intermediate commit
  • Loading branch information
jovibor committed Dec 20, 2024
1 parent 541e742 commit 93db506
Show file tree
Hide file tree
Showing 17 changed files with 390 additions and 350 deletions.
6 changes: 3 additions & 3 deletions HexCtrl/res/HexCtrl.rc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ BEGIN
CONTROL "Big-endian",IDC_HEXCTRL_DATAINTERP_CHK_BE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,306,47,8
END

IDD_HEXCTRL_CALLBACK DIALOGEX 0, 0, 203, 74
IDD_HEXCTRL_PROGRESS DIALOGEX 0, 0, 203, 74
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Callback dialog"
Expand Down Expand Up @@ -257,7 +257,7 @@ BEGIN
BEGIN
END

IDD_HEXCTRL_CALLBACK, DIALOG
IDD_HEXCTRL_PROGRESS, DIALOG
BEGIN
END

Expand Down Expand Up @@ -516,7 +516,7 @@ BEGIN
0
END

IDD_HEXCTRL_CALLBACK AFX_DIALOG_LAYOUT
IDD_HEXCTRL_PROGRESS AFX_DIALOG_LAYOUT
BEGIN
0
END
Expand Down
2 changes: 1 addition & 1 deletion HexCtrl/res/HexCtrlRes.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define IDB_HEXCTRL_DATAINTERP 9009
#define IDB_HEXCTRL_GROUP 9010
#define IDB_HEXCTRL_FONTCHOOSE 9011
#define IDD_HEXCTRL_CALLBACK 9012
#define IDD_HEXCTRL_PROGRESS 9012
#define IDD_HEXCTRL_SEARCH 9013
#define IDD_HEXCTRL_GOTO 9014
#define IDD_HEXCTRL_BKMMGR 9015
Expand Down
38 changes: 19 additions & 19 deletions HexCtrl/src/CHexCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "../res/HexCtrlRes.h"
#include "CHexCtrl.h"
#include "Dialogs/CHexDlgBkmMgr.h"
#include "Dialogs/CHexDlgCallback.h"
#include "Dialogs/CHexDlgCodepage.h"
#include "Dialogs/CHexDlgDataInterp.h"
#include "Dialogs/CHexDlgGoTo.h"
Expand All @@ -30,6 +29,7 @@
import HEXCTRL.CHexScroll;
import HEXCTRL.CHexSelection;
import HEXCTRL.HexUtility;
import HEXCTRL.CHexDlgProgress;

using namespace HEXCTRL::INTERNAL;

Expand Down Expand Up @@ -62,7 +62,7 @@ namespace HEXCTRL::INTERNAL {
auto OnMouseMove(const MSG& stMsg) -> INT_PTR;
private:
wnd::CWnd m_Wnd; //Main window.
wnd::CWnd m_wndLink; //Static link control
wnd::CWnd m_WndLink; //Static link control
HBITMAP m_hBmpLogo { }; //Logo bitmap.
HFONT m_hFontDef { };
HFONT m_hFontUnderline { };
Expand Down Expand Up @@ -106,7 +106,7 @@ auto CHexDlgAbout::OnCommand(const MSG& stMsg)->INT_PTR {
auto CHexDlgAbout::OnCtlClrStatic(const MSG& stMsg)->INT_PTR
{
const auto hWndFrom = reinterpret_cast<HWND>(stMsg.lParam);
if (hWndFrom == m_wndLink) {
if (hWndFrom == m_WndLink) {
const auto hDC = reinterpret_cast<HDC>(stMsg.wParam);
::SetTextColor(hDC, RGB(0, 50, 250));
::SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
Expand All @@ -129,11 +129,11 @@ auto CHexDlgAbout::OnInitDialog(const MSG& stMsg)->INT_PTR
{
m_Wnd.Attach(stMsg.hwnd);
m_Wnd.SetWndClassLong(GCLP_HCURSOR, 0); //To prevent cursor blinking.
m_wndLink.Attach(m_Wnd.GetDlgItem(IDC_HEXCTRL_ABOUT_STAT_LINKGH));
m_WndLink.Attach(m_Wnd.GetDlgItem(IDC_HEXCTRL_ABOUT_STAT_LINKGH));

if (const auto hFont = m_wndLink.GetHFont(); hFont != nullptr) {
if (const auto hFont = m_WndLink.GetHFont(); hFont != nullptr) {
m_hFontDef = hFont;
auto lf = m_wndLink.GetLogFont().value();
auto lf = m_WndLink.GetLogFont().value();
lf.lfUnderline = TRUE;
m_hFontUnderline = ::CreateFontIndirectW(&lf);
}
Expand Down Expand Up @@ -167,7 +167,7 @@ auto CHexDlgAbout::OnLButtonDown(const MSG& stMsg)->INT_PTR
{
const POINT pt { .x { GET_X_LPARAM(stMsg.lParam) }, .y { GET_Y_LPARAM(stMsg.lParam) } };
const auto hWnd = m_Wnd.ChildWindowFromPoint(pt);
if (hWnd != m_wndLink) {
if (hWnd != m_WndLink) {
m_fLBDownLink = false;
return FALSE;
}
Expand All @@ -181,13 +181,13 @@ auto CHexDlgAbout::OnLButtonUp(const MSG& stMsg) -> INT_PTR
{
const POINT pt { .x { GET_X_LPARAM(stMsg.lParam) }, .y { GET_Y_LPARAM(stMsg.lParam) } };
const auto hWnd = m_Wnd.ChildWindowFromPoint(pt);
if (hWnd != m_wndLink) {
if (hWnd != m_WndLink) {
m_fLBDownLink = false;
return FALSE;
}

if (m_fLBDownLink) {
::ShellExecuteW(nullptr, L"open", m_wndLink.GetWndText().data(), nullptr, nullptr, 0);
::ShellExecuteW(nullptr, L"open", m_WndLink.GetWndText().data(), nullptr, nullptr, 0);
}

return TRUE;
Expand All @@ -203,9 +203,9 @@ auto CHexDlgAbout::OnMouseMove(const MSG& stMsg)->INT_PTR
const auto curHand = reinterpret_cast<HCURSOR>(::LoadImageW(nullptr, IDC_HAND, IMAGE_CURSOR, 0, 0, LR_SHARED));
const auto curArrow = reinterpret_cast<HCURSOR>(::LoadImageW(nullptr, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED));

if (m_fLinkUnderline != (m_wndLink == hWnd)) {
m_fLinkUnderline = m_wndLink == hWnd;
m_wndLink.Invalidate(false);
if (m_fLinkUnderline != (m_WndLink == hWnd)) {
m_fLinkUnderline = m_WndLink == hWnd;
m_WndLink.Invalidate(false);
::SetCursor(m_fLinkUnderline ? curHand : curArrow);
}

Expand Down Expand Up @@ -3940,7 +3940,7 @@ void CHexCtrl::ModifyWorker(const HEXCTRL::HEXMODIFY& hms, const auto& FuncWorke
[](ULONGLONG ullSumm, const HEXSPAN& ref) { return ullSumm + ref.ullSize; });
assert(ullTotalSize <= GetDataSize());

CHexDlgCallback dlgClbk(L"Modifying...", L"", vecSpanRef.back().ullOffset, vecSpanRef.back().ullOffset + ullTotalSize, this);
CHexDlgProgress dlgProg(L"Modifying...", L"", vecSpanRef.back().ullOffset, vecSpanRef.back().ullOffset + ullTotalSize);
const auto lmbModify = [&]() {
for (const auto& iterSpan : vecSpanRef) { //Span-vector's size times.
const auto ullOffsetToModify { iterSpan.ullOffset };
Expand Down Expand Up @@ -3997,11 +3997,11 @@ void CHexCtrl::ModifyWorker(const HEXCTRL::HEXMODIFY& hms, const auto& FuncWorke
assert(!spnData.empty());
for (auto ullIndex { 0ULL }; ullIndex <= (ullSizeCache - ullSizeDataOper); ullIndex += ullSizeDataOper) {
FuncWorker(spnData.data() + ullIndex, hms, spnOper);
if (dlgClbk.IsCanceled()) {
if (dlgProg.IsCanceled()) {
SetDataVirtual(spnData, { ullOffsetCurr, ullSizeCache });
goto exit;
}
dlgClbk.SetCurrent(ullOffsetCurr + ullIndex);
dlgProg.SetCurrent(ullOffsetCurr + ullIndex);
}
SetDataVirtual(spnData, { ullOffsetCurr, ullSizeCache });
}
Expand Down Expand Up @@ -4033,12 +4033,12 @@ void CHexCtrl::ModifyWorker(const HEXCTRL::HEXMODIFY& hms, const auto& FuncWorke
FuncWorker(spnData.data(), hms, spnOper.subspan(static_cast<std::size_t>(ullOffsetSubSpan),
static_cast<std::size_t>(ullSizeCacheCurr)));

if (dlgClbk.IsCanceled()) {
if (dlgProg.IsCanceled()) {
SetDataVirtual(spnData, { ullOffsetCurr, ullSizeCacheCurr });
goto exit;
}

dlgClbk.SetCurrent(ullOffsetCurr + ullSizeCacheCurr);
dlgProg.SetCurrent(ullOffsetCurr + ullSizeCacheCurr);
SetDataVirtual(spnData, { ullOffsetCurr, ullSizeCacheCurr });

if (++ullSmallChunkCur == ullSmallChunks) {
Expand All @@ -4049,13 +4049,13 @@ void CHexCtrl::ModifyWorker(const HEXCTRL::HEXMODIFY& hms, const auto& FuncWorke
}
}
exit:
dlgClbk.OnCancel();
dlgProg.OnCancel();
};

static constexpr auto uSizeToRunThread { 1024U * 1024U * 50U }; //50MB.
if (ullTotalSize > uSizeToRunThread) { //Spawning new thread only if data size is big enough.
std::thread thrd(lmbModify);
dlgClbk.DoModal();
dlgProg.DoModal(m_hWnd);
thrd.join();
}
else {
Expand Down
136 changes: 0 additions & 136 deletions HexCtrl/src/Dialogs/CHexDlgCallback.cpp

This file was deleted.

41 changes: 0 additions & 41 deletions HexCtrl/src/Dialogs/CHexDlgCallback.h

This file was deleted.

Loading

0 comments on commit 93db506

Please sign in to comment.