summaryrefslogtreecommitdiff
path: root/plugins/NewStory/src/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/NewStory/src/utils.cpp')
-rw-r--r--plugins/NewStory/src/utils.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/plugins/NewStory/src/utils.cpp b/plugins/NewStory/src/utils.cpp
index a02d6aa393..5f990fa337 100644
--- a/plugins/NewStory/src/utils.cpp
+++ b/plugins/NewStory/src/utils.cpp
@@ -18,6 +18,37 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdafx.h"
+#include <msapi/comptr.h>
+
+Bitmap* LoadImageFromResource(HINSTANCE hInst, int resourceId, const wchar_t *pwszType)
+{
+ if (HRSRC hrsrc = FindResourceW(hInst, MAKEINTRESOURCE(resourceId), pwszType)) {
+ if (DWORD dwSize = SizeofResource(hInst, hrsrc)) {
+ if (HGLOBAL hRes = LoadResource(hInst, hrsrc)) {
+ void *pImage = LockResource(hRes);
+
+ if (HGLOBAL hGlobal = ::GlobalAlloc(GHND, dwSize)) {
+ void *pBuffer = ::GlobalLock(hGlobal);
+ if (pBuffer) {
+ memcpy(pBuffer, pImage, dwSize);
+
+ CComPtr<IStream> pStream;
+ HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pStream);
+ if (SUCCEEDED(hr))
+ return new Gdiplus::Bitmap(pStream);
+ }
+
+ GlobalFree(hGlobal); // free memory only if the function fails
+ }
+ }
+ }
+ }
+
+ return nullptr;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
uint32_t toggleBit(uint32_t dw, uint32_t bit)
{
if (dw & bit)