Minesweeper2  V1.1.1 Game in C++ by Górka Mateusz
Func.cpp File Reference
#include "Func.hpp"
#include "Error.hpp"
#include <windows.h>

Functions

sf::Texture LoadTextureFromResource (const char *const name)
 Creates a new sf::Texture and loads it with Texture data from a resource (.rc) file https://github.com/SFML/SFML/wiki/Source:-Load-Image-From-Resource. More...
 
sf::Font LoadFontFromResource (const char *const name)
 Create a new sf::Font and load it from resoruces. More...
 

Function Documentation

◆ LoadTextureFromResource()

sf::Texture LoadTextureFromResource ( const char *const  name)

Creates a new sf::Texture and loads it with Texture data from a resource (.rc) file https://github.com/SFML/SFML/wiki/Source:-Load-Image-From-Resource.

Parameters
name- name of resoruce
Returns
sf::Texture -
6  {
7 
8  HRSRC rsrcData = FindResource(NULL, name, RT_RCDATA);
9  if (!rsrcData) throw ErrSys("RESORUCES find resoruce.");
10 
11  DWORD rsrcDataSize = SizeofResource(NULL, rsrcData);
12  if (rsrcDataSize <= 0) throw ErrSys("RESORUCES Size is 0.");
13 
14  HGLOBAL grsrcData = LoadResource(NULL, rsrcData);
15  if (!grsrcData) throw ErrSys("RESORUCES load resuroce.");
16 
17  LPVOID firstByte = LockResource(grsrcData);
18  if (!firstByte) throw ErrSys("RESORUCES lock resoruce.");
19 
20  sf::Texture texture;
21  if (!texture.loadFromMemory(firstByte, rsrcDataSize))
22  throw ErrSys("RESORUCES load texture form memory.");
23 
24  return texture;
25 }

◆ LoadFontFromResource()

sf::Font LoadFontFromResource ( const char *const  name)

Create a new sf::Font and load it from resoruces.

Parameters
name- name of resource
Returns
sf::Font -
28  {
29 
30  HRSRC rsrcData = FindResource(NULL, name, RT_RCDATA);
31  if (!rsrcData) throw ErrSys("RESORUCES find resoruce.");
32 
33  DWORD rsrcDataSize = SizeofResource(NULL, rsrcData);
34  if (rsrcDataSize <= 0) throw ErrSys("RESORUCES Size of is 0.");
35 
36  HGLOBAL grsrcData = LoadResource(NULL, rsrcData);
37  if (!grsrcData) throw ErrSys("RESORUCES load resuroce.");
38 
39  LPVOID firstByte = LockResource(grsrcData);
40  if (!firstByte) throw ErrSys("RESORUCES lock resoruce.");
41 
42  sf::Font font;
43  if (!font.loadFromMemory(firstByte, rsrcDataSize))
44  throw ErrSys("RESORUCES load font form memory.");
45 
46  return font;
47 }
ErrSys
Error.
Definition: Error.hpp:48