Skip to content

Commit

Permalink
Optimized text highlighting.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuerp committed Jun 15, 2023
1 parent 0714571 commit 852c659
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions Console.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class Console
void IncreaseIndent() const noexcept;
void DecreaseIndent() const noexcept;

void Select(int from, int to) const noexcept { ::SendMessageW(_hRichEdit, EM_SETSEL, (WPARAM) from, to); }
void ScrollToTop() const noexcept { ::SendMessageW(_hRichEdit, WM_VSCROLL, SB_TOP, 0L); }

private:
Expand Down
11 changes: 2 additions & 9 deletions ShowSID.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/** ShowSID.cpp (2023.06.14) P. Stuer **/
/** ShowSID.cpp (2023.06.15) P. Stuer **/

#include "pch.h"

Expand Down Expand Up @@ -40,14 +40,7 @@ HRESULT ShowSID(const PSID sid)
_Console.SetBullet(true);

_Console.Write(L"SID: \"");
_Console.SetTextForeColor(GetSysColor(COLOR_HIGHLIGHT));

if (DomainName[0])
_Console.Write(L"%s\\%s", DomainName, AccountName);
else
_Console.Write(L"%s", AccountName);

_Console.ResetTextColor();
_Console.Write((DomainName[0] ? L"%s\\%s" : L"%s"), DomainName, AccountName);
_Console.Write(L"\", %s, %s\n", AccountSidString, GetSidNameUseDescription(SidNameUse));

_Console.SetBullet(false);
Expand Down
32 changes: 27 additions & 5 deletions dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ int __stdcall ListNotificationReceived(HWND hWnd, int msg, WPARAM wParam, LPARAM
return 0;

if (HIWORD(wParam) != EN_UPDATE)
return 9;
return 0;

int LineCount = (int) ::SendMessageW(hWnd, EM_GETLINECOUNT, 0, 0);

Expand Down Expand Up @@ -398,10 +398,7 @@ static void ProcessItem(const wstring & pathName)
ObjectType ObjectType = ((FileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(FileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) ? DirectoryObject : FileObject;

_Console.SetBold(true);
_Console.Write(L"Item: \"");
_Console.SetTextForeColor(GetSysColor(COLOR_HIGHLIGHT));
_Console.Write(pathName.c_str());
_Console.Write(L"\"\n", pathName.c_str());
_Console.Write(L"Item: \"%s\"\n", pathName.c_str());

// Low-level Security Descriptor Functions, https://msdn.microsoft.com/en-us/library/aa379204(v=vs.85).aspx
const SECURITY_INFORMATION RequestedInformation = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION;
Expand Down Expand Up @@ -479,5 +476,30 @@ static void ProcessItem(const wstring & pathName)
if (sd)
::LocalFree(sd);

// Highlight any quoted text.
{
FINDTEXTW ft = { { 0, (LONG) ::SendMessageW(_Console.Handle(), WM_GETTEXTLENGTH, 0, 0) }, L"\"" };

int OpeningQuote = (int) ::SendMessageW(_Console.Handle(), EM_FINDTEXT, (WPARAM) FR_DOWN, (LPARAM) &ft);

while (OpeningQuote != -1)
{
ft.chrg.cpMin = ++OpeningQuote;

int ClosingQuote = (int) ::SendMessageW(_Console.Handle(), EM_FINDTEXT, (WPARAM) FR_DOWN, (LPARAM) &ft);

if (ClosingQuote == -1)
break;

_Console.Select(OpeningQuote, ClosingQuote);
_Console.SetTextForeColor(::GetSysColor(COLOR_HIGHLIGHT));

ft.chrg.cpMin = ClosingQuote + 1;

OpeningQuote = (int) ::SendMessageW(_Console.Handle(), EM_FINDTEXT, (WPARAM) FR_DOWN, (LPARAM) &ft);
}
}

_Console.ScrollToTop();
_Console.Select(0, 0);
}

0 comments on commit 852c659

Please sign in to comment.