Skip to content

Commit

Permalink
Remove legacy code for Windows 2000 and before.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Dec 7, 2018
1 parent f677546 commit 626becd
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 103 deletions.
8 changes: 2 additions & 6 deletions metapath/src/Dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,14 +1079,10 @@ INT_PTR OptionsPropSheet(HWND hwnd, HINSTANCE hInstance) {

if (bFullRowSelect) {
ListView_SetExtendedListViewStyleEx(hwndDirList, LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);
if (IsVistaAndAbove()) {
SetTheme(hwndDirList, L"Explorer");
}
SetExplorerTheme(hwndDirList);
} else {
ListView_SetExtendedListViewStyleEx(hwndDirList, LVS_EX_FULLROWSELECT, 0);
if (IsVistaAndAbove()) {
SetTheme(hwndDirList, L"Listview");
}
SetListViewTheme(hwndDirList);
}

if (!StrEqual(tchFilter, L"*.*") || bNegFilter) {
Expand Down
10 changes: 3 additions & 7 deletions metapath/src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,11 +626,9 @@ void DeleteBitmapButton(HWND hwnd, int nCtlId) {
void SetWindowTransparentMode(HWND hwnd, BOOL bTransparentMode, int iOpacityLevel) {
const LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
if (bTransparentMode) {
if (IsWin2KAndAbove()) {
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
const BYTE bAlpha = (BYTE)(iOpacityLevel * 255 / 100);
SetLayeredWindowAttributes(hwnd, 0, bAlpha, LWA_ALPHA);
}
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
const BYTE bAlpha = (BYTE)(iOpacityLevel * 255 / 100);
SetLayeredWindowAttributes(hwnd, 0, bAlpha, LWA_ALPHA);
} else {
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_LAYERED);
}
Expand Down Expand Up @@ -1770,13 +1768,11 @@ DLGTEMPLATE *LoadThemedDialogTemplate(LPCWSTR lpDialogTemplateID, HINSTANCE hIns

DLGTEMPLATE *pTemplate = dwTemplateSize ? (DLGTEMPLATE *)NP2HeapAlloc(dwTemplateSize + LF_FACESIZE * 2) : NULL;
if (pTemplate == NULL) {
UnlockResource(hRsrcMem);
FreeResource(hRsrcMem);
return NULL;
}

CopyMemory((BYTE *)pTemplate, pRsrcMem, (size_t)dwTemplateSize);
UnlockResource(hRsrcMem);
FreeResource(hRsrcMem);

WCHAR wchFaceName[LF_FACESIZE];
Expand Down
19 changes: 3 additions & 16 deletions metapath/src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ int ParseCommaList(LPCWSTR str, int result[], int count);

extern HINSTANCE g_hInstance;
extern HANDLE g_hDefaultHeap;
extern UINT16 g_uWinVer;

// https://docs.microsoft.com/en-us/windows/desktop/Memory/comparing-memory-allocation-methods
// https://blogs.msdn.microsoft.com/oldnewthing/20120316-00/?p=8083/
Expand Down Expand Up @@ -233,28 +232,16 @@ NP2_inline void EndWaitCursor(void) {
DestroyCursor(SetCursor(LoadCursor(NULL, IDC_ARROW)));
}

#if 0
#define IsWin2KAndAbove() (g_uWinVer >= 0x0500)
#define IsWinXPAndAbove() (g_uWinVer >= 0x0501)
#else
#define IsWin2KAndAbove() TRUE
#define IsWinXPAndAbove() TRUE
#endif
#define IsVistaAndAbove() (g_uWinVer >= 0x0600)
#define IsWin7AndAbove() (g_uWinVer >= 0x0601)
#define IsWin8AndAbove() (g_uWinVer >= 0x0602)

#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
#endif

BOOL ExeNameFromWnd(HWND hwnd, LPWSTR szExeName, int cchExeName);
//BOOL Is32bitExe(LPCWSTR lpszExeName);
BOOL PrivateIsAppThemed(void);
BOOL SetTheme(HWND hwnd, LPCWSTR lpszTheme);
NP2_inline BOOL SetExplorerTheme(HWND hwnd) {
return SetTheme(hwnd, L"Explorer");
}
NP2_inline BOOL SetListViewTheme(HWND hwnd) {
return SetTheme(hwnd, L"Listview");
}

HBITMAP LoadBitmapFile(LPCWSTR path);
BOOL BitmapMergeAlpha(HBITMAP hbmp, COLORREF crDest);
Expand Down
28 changes: 8 additions & 20 deletions metapath/src/metapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ WCHAR szDDETopic[256] = L"";

HINSTANCE g_hInstance;
HANDLE g_hDefaultHeap;
UINT16 g_uWinVer;

//=============================================================================
//
Expand Down Expand Up @@ -205,9 +204,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi

// Set global variable g_hInstance
g_hInstance = hInstance;
// Set the Windows version global variable
g_uWinVer = LOWORD(GetVersion());
g_uWinVer = MAKEWORD(HIBYTE(g_uWinVer), LOBYTE(g_uWinVer));
g_hDefaultHeap = GetProcessHeap();

SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
Expand Down Expand Up @@ -714,7 +710,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) {
hInstance,
NULL);

if (IsVistaAndAbove() && IsAppThemed()) {
if (IsAppThemed()) {
SetWindowLongPtr(hwndDirList, GWL_EXSTYLE, GetWindowLongPtr(hwndDirList, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
SetWindowPos(hwndDirList, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
}
Expand Down Expand Up @@ -753,9 +749,7 @@ LRESULT MsgCreate(HWND hwnd, WPARAM wParam, LPARAM lParam) {
ListView_SetExtendedListViewStyleEx(hwndDirList,
LVS_EX_FULLROWSELECT,
LVS_EX_FULLROWSELECT);
if (IsVistaAndAbove()) {
SetExplorerTheme(hwndDirList);
}
SetExplorerTheme(hwndDirList);
}

ListView_SetHoverTime(hwndDirList, 10);
Expand Down Expand Up @@ -825,9 +819,6 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) {

BITMAP bmp;
GetObject(hbmp, sizeof(BITMAP), &bmp);
if (!IsWinXPAndAbove()) {
BitmapMergeAlpha(hbmp, GetSysColor(COLOR_3DFACE));
}

HIMAGELIST himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
Expand Down Expand Up @@ -863,12 +854,9 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) {
BOOL fProcessed = FALSE;
if (flagToolbarLook == 1) {
fProcessed = BitmapAlphaBlend(hbmpCopy, GetSysColor(COLOR_3DFACE), 0x60);
} else if (flagToolbarLook == 2 || (!IsWinXPAndAbove() && flagToolbarLook == 0)) {
} else if (flagToolbarLook == 2) {
fProcessed = BitmapGrayScale(hbmpCopy);
}
if (fProcessed && !IsWinXPAndAbove()) {
BitmapMergeAlpha(hbmpCopy, GetSysColor(COLOR_3DFACE));
}
if (fProcessed) {
himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmpCopy, CLR_DEFAULT);
Expand Down Expand Up @@ -958,7 +946,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) {
cyReBar = rc.bottom - rc.top;

cyReBarFrame = bIsAppThemed ? 0 : 2;
cyDriveBoxFrame = (bIsAppThemed && IsVistaAndAbove()) ? 0 : 2;
cyDriveBoxFrame = bIsAppThemed ? 0 : 2;
}

//=============================================================================
Expand All @@ -973,19 +961,19 @@ void MsgThemeChanged(HWND hwnd, WPARAM wParam, LPARAM lParam) {
HINSTANCE hInstance = (HINSTANCE)(INT_PTR)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
const BOOL bIsAppThemed = IsAppThemed();

if (IsVistaAndAbove() && bIsAppThemed) {
if (bIsAppThemed) {
SetWindowLongPtr(hwndDirList, GWL_EXSTYLE, GetWindowLongPtr(hwndDirList, GWL_EXSTYLE) & ~WS_EX_CLIENTEDGE);
SetWindowPos(hwndDirList, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE);
if (bFullRowSelect) {
SetExplorerTheme(hwndDirList);
} else {
SetTheme(hwndDirList, L"Listview");
SetListViewTheme(hwndDirList);
}
} else {
SetWindowLongPtr(hwndDirList, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongPtr(hwndDirList, GWL_EXSTYLE));
SetWindowPos(hwndDirList, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
if (bIsAppThemed) {
SetTheme(hwndDirList, L"Listview");
SetListViewTheme(hwndDirList);
}
}

Expand Down Expand Up @@ -2864,7 +2852,7 @@ void LoadFlags(void) {
iValue = IniSectionGetInt(pIniSection, L"OpacityLevel", 75);
iOpacityLevel = validate_i(iValue, 0, 100, 75);

iValue = IniSectionGetInt(pIniSection, L"ToolbarLook", IsWinXPAndAbove() ? 1 : 2);
iValue = IniSectionGetInt(pIniSection, L"ToolbarLook", 1);
flagToolbarLook = clamp_i(iValue, 0, 2);

IniSectionFree(pIniSection);
Expand Down
18 changes: 5 additions & 13 deletions src/Edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3884,7 +3884,7 @@ void EditSortLines(HWND hwnd, int iSortFlags) {
}

if (iSortFlags & SORT_DESCENDING) {
if ((iSortFlags & SORT_LOGICAL) && IsWinXPAndAbove()) {
if ((iSortFlags & SORT_LOGICAL)) {
qsort(pLines, iLineCount, sizeof(SORTLINE), CmpLogicalRev);
} else {
qsort(pLines, iLineCount, sizeof(SORTLINE), CmpStdRev);
Expand All @@ -3898,7 +3898,7 @@ void EditSortLines(HWND hwnd, int iSortFlags) {
pLines[j] = sLine;
}
} else {
if ((iSortFlags & SORT_LOGICAL) && IsWinXPAndAbove()) {
if ((iSortFlags & SORT_LOGICAL)) {
qsort(pLines, iLineCount, sizeof(SORTLINE), CmpLogical);
} else {
qsort(pLines, iLineCount, sizeof(SORTLINE), CmpStd);
Expand Down Expand Up @@ -5985,8 +5985,6 @@ void EditShowUnicodeControlCharacter(HWND hwnd, BOOL bShow) {
//
//
static INT_PTR CALLBACK EditSortDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) {
static BOOL bEnableLogicalSort;

switch (umsg) {
case WM_INITDIALOG: {
SetWindowLongPtr(hwnd, DWLP_USER, lParam);
Expand Down Expand Up @@ -6023,14 +6021,8 @@ static INT_PTR CALLBACK EditSortDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPA
CheckDlgButton(hwnd, IDC_SORT_IGNORE_CASE, BST_CHECKED);
}

if (IsWinXPAndAbove()) {
if (iSortFlags & SORT_LOGICAL) {
CheckDlgButton(hwnd, IDC_SORT_LOGICAL_NUMBER, BST_CHECKED);
}
bEnableLogicalSort = TRUE;
} else {
EnableWindow(GetDlgItem(hwnd, IDC_SORT_LOGICAL_NUMBER), FALSE);
bEnableLogicalSort = FALSE;
if (iSortFlags & SORT_LOGICAL) {
CheckDlgButton(hwnd, IDC_SORT_LOGICAL_NUMBER, BST_CHECKED);
}

if (SC_SEL_RECTANGLE != SendMessage(hwndEdit, SCI_GETSELECTIONMODE, 0, 0)) {
Expand Down Expand Up @@ -6088,7 +6080,7 @@ static INT_PTR CALLBACK EditSortDlgProc(HWND hwnd, UINT umsg, WPARAM wParam, LPA
EnableWindow(GetDlgItem(hwnd, IDC_SORT_REMOVE_DUP), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_SORT_REMOVE_UNIQUE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_SORT_IGNORE_CASE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_SORT_LOGICAL_NUMBER), bEnableLogicalSort);
EnableWindow(GetDlgItem(hwnd, IDC_SORT_LOGICAL_NUMBER), TRUE);
break;

case IDC_SORT_SHUFFLE:
Expand Down
10 changes: 3 additions & 7 deletions src/Helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,9 @@ BOOL SetWindowTitle(HWND hwnd, UINT uIDAppName, BOOL bIsElevated, UINT uIDUntitl
void SetWindowTransparentMode(HWND hwnd, BOOL bTransparentMode, int iOpacityLevel) {
const LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
if (bTransparentMode) {
if (IsWin2KAndAbove()) {
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
const BYTE bAlpha = (BYTE)(iOpacityLevel * 255 / 100);
SetLayeredWindowAttributes(hwnd, 0, bAlpha, LWA_ALPHA);
}
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
const BYTE bAlpha = (BYTE)(iOpacityLevel * 255 / 100);
SetLayeredWindowAttributes(hwnd, 0, bAlpha, LWA_ALPHA);
} else {
SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_LAYERED);
}
Expand Down Expand Up @@ -2146,13 +2144,11 @@ DLGTEMPLATE *LoadThemedDialogTemplate(LPCWSTR lpDialogTemplateID, HINSTANCE hIns

DLGTEMPLATE *pTemplate = dwTemplateSize ? (DLGTEMPLATE *)NP2HeapAlloc(dwTemplateSize + LF_FACESIZE * 2) : NULL;
if (pTemplate == NULL) {
UnlockResource(hRsrcMem);
FreeResource(hRsrcMem);
return NULL;
}

CopyMemory((BYTE *)pTemplate, pRsrcMem, (size_t)dwTemplateSize);
UnlockResource(hRsrcMem);
FreeResource(hRsrcMem);

WCHAR wchFaceName[LF_FACESIZE];
Expand Down
7 changes: 0 additions & 7 deletions src/Helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,6 @@ extern WCHAR szIniFile[MAX_PATH];
// Operating System Version
// https://docs.microsoft.com/en-us/windows/desktop/SysInfo/operating-system-version

#if 0
#define IsWin2KAndAbove() (g_uWinVer >= 0x0500)
#define IsWinXPAndAbove() (g_uWinVer >= 0x0501)
#else
#define IsWin2KAndAbove() TRUE
#define IsWinXPAndAbove() TRUE
#endif
#define IsVistaAndAbove() (g_uWinVer >= 0x0600)
#define IsWin7AndAbove() (g_uWinVer >= 0x0601)
#define IsWin8AndAbove() (g_uWinVer >= 0x0602)
Expand Down
32 changes: 5 additions & 27 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi
g_hDefaultHeap = GetProcessHeap();
// https://docs.microsoft.com/en-us/windows/desktop/Memory/low-fragmentation-heap
#if 0 // default enabled since Vista
if (IsWinXPAndAbove()) {
{
// Enable the low-fragmenation heap (LFH).
ULONG HeapInformation = 2;//HEAP_LFH;
HeapSetInformation(g_hDefaultHeap, HeapCompatibilityInformation, &HeapInformation, sizeof(HeapInformation));
Expand All @@ -501,22 +501,6 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLi

SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);

// check if running at least on Windows 2000
if (!IsWin2KAndAbove()) {
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ERROR_OLD_WIN_VERSION,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPWSTR)&lpMsgBuf,
0,
NULL);
MessageBox(NULL, (LPCWSTR)lpMsgBuf, L"Notepad2", MB_OK | MB_ICONEXCLAMATION);
LocalFree(lpMsgBuf);
return 0;
}

// Check if running with elevated privileges
fIsElevated = IsElevated();

Expand Down Expand Up @@ -1734,9 +1718,7 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) {
}
BITMAP bmp;
GetObject(hbmp, sizeof(BITMAP), &bmp);
if (!IsWinXPAndAbove()) {
BitmapMergeAlpha(hbmp, GetSysColor(COLOR_3DFACE));
}

HIMAGELIST himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
Expand Down Expand Up @@ -1773,12 +1755,9 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) {
BOOL fProcessed = FALSE;
if (flagToolbarLook == 1) {
fProcessed = BitmapAlphaBlend(hbmpCopy, GetSysColor(COLOR_3DFACE), 0x60);
} else if (flagToolbarLook == 2 || (!IsWinXPAndAbove() && flagToolbarLook == 0)) {
} else if (flagToolbarLook == 2) {
fProcessed = BitmapGrayScale(hbmpCopy);
}
if (fProcessed && !IsWinXPAndAbove()) {
BitmapMergeAlpha(hbmpCopy, GetSysColor(COLOR_3DFACE));
}
if (fProcessed) {
himl = ImageList_Create(bmp.bmWidth / NUMTOOLBITMAPS, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmpCopy, CLR_DEFAULT);
Expand Down Expand Up @@ -2370,8 +2349,7 @@ void MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) {
CheckCmd(hmenu, IDM_VIEW_STICKYWINPOS, bStickyWinPos);
CheckCmd(hmenu, IDM_VIEW_ALWAYSONTOP, ((bAlwaysOnTop || flagAlwaysOnTop == 2) && flagAlwaysOnTop != 1));
CheckCmd(hmenu, IDM_VIEW_MINTOTRAY, bMinimizeToTray);
i = IsWin2KAndAbove(); // bTransparentModeAvailable
CheckCmd(hmenu, IDM_VIEW_TRANSPARENT, bTransparentMode && i);
CheckCmd(hmenu, IDM_VIEW_TRANSPARENT, bTransparentMode);
EnableCmd(hmenu, IDM_VIEW_TRANSPARENT, i);

// Rendering Technology
Expand Down Expand Up @@ -6324,7 +6302,7 @@ void LoadFlags(void) {
iValue = IniSectionGetInt(pIniSection, L"FindReplaceOpacityLevel", 75);
iFindReplaceOpacityLevel = validate_i(iValue, 0, 100, 75);

iValue = IniSectionGetInt(pIniSection, L"ToolbarLook", IsWinXPAndAbove() ? 1 : 2);
iValue = IniSectionGetInt(pIniSection, L"ToolbarLook", 1);
flagToolbarLook = clamp_i(iValue, 0, 2);

flagSimpleIndentGuides = IniSectionGetBool(pIniSection, L"SimpleIndentGuides", 0);
Expand Down

0 comments on commit 626becd

Please sign in to comment.