2424namespace Bitmap
2525{
2626
27- HBITMAP getResource (unsigned int id)
27+ BitmapHandleWrapper getResource (unsigned int id)
2828{
2929 HINSTANCE hinstance = (HINSTANCE)GetModuleHandle (nullptr );
30- HBITMAP bitmap = ( HBITMAP)LoadImageA (hinstance, MAKEINTRESOURCEA (id), IMAGE_BITMAP, 0 , 0 , 0 );
30+ BitmapHandleWrapper bitmap (( HBITMAP)LoadImageA (hinstance, MAKEINTRESOURCEA (id), IMAGE_BITMAP, 0 , 0 , 0 ) );
3131 if (!bitmap) {
3232 WARNING_PRINTF (
3333 " failed to load resources bitmap %u, LoadImage() failed: %s\n " ,
@@ -38,31 +38,31 @@ HBITMAP getResource(unsigned int id)
3838 return bitmap;
3939}
4040
41- bool replaceColor (HBITMAP hbitmap , COLORREF oldColor, COLORREF newColor)
41+ bool replaceColor (const BitmapHandleWrapper & bitmap , COLORREF oldColor, COLORREF newColor)
4242{
43- if (!hbitmap ) {
43+ if (!bitmap ) {
4444 return false ;
4545 }
4646
47- DeviceContextHandleWrapper hdc (GetDC (HWND_DESKTOP), DeviceContextHandleWrapper::Referenced);
47+ DeviceContextHandleWrapper desktopDC (GetDC (HWND_DESKTOP), DeviceContextHandleWrapper::Referenced);
4848
49- BITMAP bitmap ;
50- memset (&bitmap , 0 , sizeof (bitmap ));
51- if (!GetObject (hbitmap , sizeof (bitmap ), &bitmap )) {
52- WARNING_PRINTF (" failed to get bitmap object, GetObject() failed: %s\n " , StringUtility::lastErrorString ().c_str ());
49+ BITMAP bm ;
50+ memset (&bm , 0 , sizeof (bm ));
51+ if (!GetObject (bitmap , sizeof (bm ), &bm )) {
52+ WARNING_PRINTF (" failed to get bm object, GetObject() failed: %s\n " , StringUtility::lastErrorString ().c_str ());
5353 return false ;
5454 }
5555
5656 BITMAPINFO bitmapInfo;
5757 memset (&bitmapInfo, 0 , sizeof (bitmapInfo));
5858 bitmapInfo.bmiHeader .biSize = sizeof (BITMAPINFOHEADER);
59- bitmapInfo.bmiHeader .biWidth = bitmap .bmWidth ;
60- bitmapInfo.bmiHeader .biHeight = bitmap .bmHeight ;
59+ bitmapInfo.bmiHeader .biWidth = bm .bmWidth ;
60+ bitmapInfo.bmiHeader .biHeight = bm .bmHeight ;
6161 bitmapInfo.bmiHeader .biPlanes = 1 ;
6262 bitmapInfo.bmiHeader .biBitCount = 32 ;
6363
64- std::vector<COLORREF> pixels (bitmap .bmWidth * bitmap .bmHeight );
65- if (!GetDIBits (hdc, hbitmap , 0 , bitmap .bmHeight , &pixels[0 ], &bitmapInfo, DIB_RGB_COLORS)) {
64+ std::vector<COLORREF> pixels (bm .bmWidth * bm .bmHeight );
65+ if (!GetDIBits (desktopDC, bitmap , 0 , bm .bmHeight , &pixels[0 ], &bitmapInfo, DIB_RGB_COLORS)) {
6666 WARNING_PRINTF (" failed to get bitmap bits, GetDIBits() failed: %s\n " , StringUtility::lastErrorString ().c_str ());
6767 return false ;
6868 }
@@ -74,7 +74,7 @@ bool replaceColor(HBITMAP hbitmap, COLORREF oldColor, COLORREF newColor)
7474 }
7575 }
7676
77- if (!SetDIBits (hdc, hbitmap , 0 , bitmap .bmHeight , &pixels[0 ], &bitmapInfo, DIB_RGB_COLORS)) {
77+ if (!SetDIBits (desktopDC, bitmap , 0 , bm .bmHeight , &pixels[0 ], &bitmapInfo, DIB_RGB_COLORS)) {
7878 WARNING_PRINTF (" failed to set bitmap bits, SetDIBits() failed: %s\n " , StringUtility::lastErrorString ().c_str ());
7979 }
8080
0 commit comments