MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / LoadPicture

Function LoadPicture

source/util.cpp:2032–2517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2030
2031
2032HBITMAP LoadPicture(LPTSTR aFilespec, int aWidth, int aHeight, int &aImageType, int aIconNumber
2033 , bool aUseGDIPlusIfAvailable, bool *apNoDelete, HMODULE *apModule)
2034// Returns NULL on failure.
2035// If aIconNumber > 0, an HICON or HCURSOR is returned (both should be interchangeable), never an HBITMAP.
2036// However, aIconNumber==1 is treated as a special icon upon which LoadImage is given preference over ExtractIcon
2037// for .ico/.cur/.ani files.
2038// Otherwise, .ico/.cur/.ani files are normally loaded as HICON (unless aUseGDIPlusIfAvailable is true or
2039// something else unusual happened such as file contents not matching file's extension). This is done to preserve
2040// any properties that HICONs have but HBITMAPs lack, namely the ability to be animated and perhaps other things.
2041//
2042// Loads a JPG/GIF/BMP/ICO/etc. and returns an HBITMAP or HICON to the caller (which it may call
2043// DeleteObject()/DestroyIcon() upon, though upon program termination all such handles are freed
2044// automatically). The image is scaled to the specified width and height. If zero is specified
2045// for either, the image's actual size will be used for that dimension. If -1 is specified for one,
2046// that dimension will be kept proportional to the other dimension's size so that the original aspect
2047// ratio is retained.
2048{
2049 HBITMAP hbitmap = NULL;
2050 aImageType = -1; // The type of image currently inside hbitmap. Set default value for output parameter as "unknown".
2051 if (apNoDelete)
2052 *apNoDelete = false; // Set default.
2053
2054 if (!*aFilespec) // Allow blank filename to yield NULL bitmap (and currently, some callers do call it this way).
2055 return NULL;
2056 // Lexikos: Negative values now indicate an icon's integer resource ID.
2057 //if (aIconNumber < 0) // Allowed to be called this way by GUI and others (to avoid need for validation of user input there).
2058 // aIconNumber = 0; // Use the default behavior, which is "load icon or bitmap, whichever is most appropriate".
2059
2060 bool script_passed_handle = false, script_owns_handle = false;
2061 if ( !_tcsnicmp(aFilespec, _T("hicon:"), 6)
2062 || !_tcsnicmp(aFilespec, _T("hbitmap:"), 8) )
2063 {
2064 if (aFilespec[5] == ':') // hicon:
2065 {
2066 aImageType = IMAGE_ICON;
2067 aFilespec += 6;
2068 }
2069 else
2070 {
2071 aImageType = IMAGE_BITMAP;
2072 aFilespec += 8;
2073 }
2074 script_passed_handle = true;
2075 script_owns_handle = (*aFilespec == '*'); // The "don't delete my icon/bitmap" flag.
2076 if (script_owns_handle)
2077 {
2078 ++aFilespec;
2079 if (apNoDelete) // Caller supports conditional delete.
2080 *apNoDelete = true; // May be overridden if a resized copy is created below.
2081 }
2082 hbitmap = (HBITMAP)(UINT_PTR)ATOI64(aFilespec);
2083 if (!hbitmap)
2084 return NULL;
2085 }
2086
2087 LPTSTR file_ext = _tcsrchr(aFilespec, '.');
2088 if (file_ext)
2089 ++file_ext;

Callers 5

ControlLoadPictureMethod · 0.85
SetTrayIconMethod · 0.85
SetItemIconMethod · 0.85
BIF_DECLFunction · 0.85
StatusBarMethod · 0.85

Calls 3

ATOI64Function · 0.85
ReleaseMethod · 0.45

Tested by

no test coverage detected