Files
Open-Shell-Menu/ClassicStartSrc/ClassicStartLib/TrackResources.cpp
Xenhat 0adcd693e4 Some branding and licensing work (#22)
* Fix stdafx include

* Fix basic handling of "Games" folder on Windows10 RS4 (#10)
This does the following:
- Sets the default state to hidden
- Skips the Games folder when searching

This does not:
- Hide the dead menu entry.

I do not currently know how to actively change the user preference setting to forcefully hide it.

* Add basic Visual Studio gitignore

* Add specific entries to gitignore

* Do not set default menu to Win7 on RS4 (#10)

* Rename "PC Settings" to "Settings" (#12)

* Create distinction between modern and legacy settings in search results

* Add more build artifacts to gitignore

* Add default paths for toolset and build all languages

* Fix several memsize, memtype and nullpointer issues

* create trunk branch containing all changes

* set fallback and next version to 4.3.2, set resource fallback value to allow loading in IDE

* add generated en-US.dll to gitignore

* Don't echo script contents, add disabled "git clean -dfx" to build fresh

* Initial re-branding work (#21)

* Create copy of __MakeFinal to build all languages (Use this file when releasing new versions)

* Move the registry key IvoSoft->Passionate-Coder (#21)

* Change company/mfg name IvoSoft->Passionate-Coder (#21)

* Update some leftover copyright dates (#21)

* Fix accidental copy-paste breaking MakeFinal scripts

* Fix invalid company name for Wix and change registry keys to match the new string (#21)

* Update more copyright and legal text (#21)

* Update RTF files format (Wordpad generated those) (#21)

* update license text in RTF files (#21)
We lost the blue link text in the installer page. Will have to manually re-color all the links later.
2018-06-25 01:42:52 -04:00

228 lines
5.5 KiB
C++

#include <stdafx.h>
#include <map>
#include <vector>
#include "StringUtils.h"
#include "ResourceHelper.h"
#include "Assert.h"
typedef std::pair<const char*,int> TrackedResource;
typedef std::map<HGDIOBJ,TrackedResource> TrackedResourceMap;
static TrackedResourceMap g_TrackedGdiResources;
static TrackedResourceMap g_TrackedUserResources;
HDC TrackCreateCompatibleDC( HDC hdc, const char *file, int line )
{
HDC res=CreateCompatibleDC(hdc);
if (res)
g_TrackedGdiResources[res]=TrackedResource(file,line);
return res;
}
HFONT TrackCreateFont( int cHeight, int cWidth, int cEscapement, int cOrientation, int cWeight, DWORD bItalic, DWORD bUnderline, DWORD bStrikeOut, DWORD iCharSet, DWORD iOutPrecision, DWORD iClipPrecision, DWORD iQuality, DWORD iPitchAndFamily, LPCWSTR pszFaceName, const char *file, int line )
{
HFONT res=CreateFont(cHeight,cWidth,cEscapement,cOrientation,cWeight,bItalic,bUnderline,bStrikeOut,iCharSet,iOutPrecision,iClipPrecision,iQuality,iPitchAndFamily,pszFaceName);
if (res)
g_TrackedGdiResources[res]=TrackedResource(file,line);
return res;
}
HFONT TrackCreateFontIndirect( const LOGFONT *lplf, const char *file, int line )
{
HFONT res=CreateFontIndirect(lplf);
if (res)
g_TrackedGdiResources[res]=TrackedResource(file,line);
return res;
}
HANDLE TrackLoadImage( HINSTANCE hInst, LPCWSTR name, UINT type, int cx, int cy, UINT fuLoad, const char *file, int line )
{
HANDLE res=LoadImage(hInst,name,type,cx,cy,fuLoad);
if (type==IMAGE_BITMAP)
g_TrackedGdiResources[res]=TrackedResource(file,line);
else
g_TrackedUserResources[res]=TrackedResource(file,line);
return res;
}
HBITMAP TrackCreateDIBSection( HDC hdc, CONST BITMAPINFO *lpbmi, UINT usage, VOID **ppvBits, HANDLE hSection, DWORD offset, const char *file, int line )
{
HBITMAP res=CreateDIBSection(hdc,lpbmi,usage,ppvBits,hSection,offset);
if (res)
g_TrackedGdiResources[res]=TrackedResource(file,line);
return res;
}
HBITMAP TrackCreateBitmap( int nWidth, int nHeight, UINT nPlanes, UINT nBitCount, CONST VOID *lpBits, const char *file, int line )
{
HBITMAP res=CreateBitmap(nWidth,nHeight,nPlanes,nBitCount,lpBits);
if (res)
g_TrackedGdiResources[res]=TrackedResource(file,line);
return res;
}
HBITMAP TrackCreateCompatibleBitmap( HDC hdc, int cx, int cy, const char *file, int line )
{
HBITMAP res=CreateCompatibleBitmap(hdc,cx,cy);
if (res)
g_TrackedGdiResources[res]=TrackedResource(file,line);
return res;
}
void TrackAddTrackedObject( HGDIOBJ obj, const char *file, int line )
{
if (obj)
g_TrackedGdiResources[obj]=TrackedResource(file,line);
}
void TrackAddTrackedIcon( HICON hIcon, const char *file, int line )
{
if (hIcon)
g_TrackedUserResources[hIcon]=TrackedResource(file,line);
}
BOOL TrackDeleteDC( HDC hdc )
{
Assert(hdc);
if (g_TrackedGdiResources.find(hdc)!=g_TrackedGdiResources.end())
g_TrackedGdiResources.erase(hdc);
else
Assert(0);
return DeleteDC(hdc);
}
BOOL TrackDeleteObject( HGDIOBJ obj )
{
Assert(obj);
if (g_TrackedGdiResources.find(obj)!=g_TrackedGdiResources.end())
g_TrackedGdiResources.erase(obj);
else
Assert(0);
return DeleteObject(obj);
}
BOOL TrackDestroyIcon( HICON hIcon )
{
Assert(hIcon);
if (g_TrackedUserResources.find(hIcon)!=g_TrackedUserResources.end())
g_TrackedUserResources.erase(hIcon);
else
Assert(0);
return DestroyIcon(hIcon);
}
static void DumpBitmapLeaks( const std::vector<HBITMAP> &bitmaps )
{
int index=0;
for (std::vector<HBITMAP>::const_iterator it=bitmaps.begin();it!=bitmaps.end();++it)
{
BITMAP info;
GetObject(*it,sizeof(info),&info);
// ...
}
}
struct GdiTableCell
{
void *pKernel;
unsigned short nProcess;
unsigned short nCount;
unsigned short nUpper;
unsigned short nType;
void *pUser;
};
static const GdiTableCell *GetGdiTable( void )
{
HMODULE gdi32=GetModuleHandle(L"gdi32.dll");
FARPROC GdiQueryTable=GetProcAddress(gdi32,"GdiQueryTable");
if (GdiQueryTable)
{
// GdiQueryTable();
if (GetWinVersion()>=WIN_VER_WIN8)
return *(GdiTableCell**)((char*)GdiQueryTable+0x6b1b0);
else
return *(GdiTableCell**)((char*)GdiQueryTable+0x29db0);
}
return NULL;
}
void DumpResourceLeaks( void )
{
GdiFlush();
Trace("GDI objects %d",GetGuiResources(GetCurrentProcess(),GR_GDIOBJECTS));
Trace("USER objects %d",GetGuiResources(GetCurrentProcess(),GR_USEROBJECTS));
const GdiTableCell *cells=GetGdiTable();
if (!cells) return;
int counts[16]={0};
unsigned short pid=(unsigned short)GetCurrentProcessId();
int n=65536;
std::vector<HBITMAP> bitmaps;
for (int i=0;i<n;i++)
{
if (cells[i].pKernel && cells[i].nProcess==pid)
{
HGDIOBJ handle=(HGDIOBJ)(intptr_t)((cells[i].nUpper<<16)|i);
const TrackedResource *res=NULL;
TrackedResourceMap::const_iterator it=g_TrackedGdiResources.find(handle);
if (it!=g_TrackedGdiResources.end())
res=&it->second;
DWORD type=GetObjectType(handle);
if (!(type&~15))
counts[type]++;
switch (type)
{
case OBJ_BITMAP:
{
BITMAP info;
GetObject(handle,sizeof(info),&info);
bitmaps.push_back((HBITMAP)handle);
}
break;
case OBJ_BRUSH:
{
LOGBRUSH info;
GetObject(handle,sizeof(info),&info);
int q=0;
}
break;
case OBJ_DC:
{
int q=0;
}
break;
case OBJ_FONT:
{
LOGFONT info;
GetObject(handle,sizeof(info),&info);
int q=0;
}
break;
case OBJ_PEN:
{
LOGPEN info;
GetObject(handle,sizeof(info),&info);
int q=0;
}
break;
case OBJ_REGION:
{
int q=0;
}
break;
case OBJ_MEMDC:
{
int q=0;
}
break;
}
}
}
DumpBitmapLeaks(bitmaps);
}