Smooth 2D Noise Viewer
Perlin and Value Noise
Functions
WindowsHelpers.cpp File Reference

Code for some helpful Windows-specific functions. More...

#include <shobjidl_core.h>
#include <atlbase.h>
#include "WindowsHelpers.h"
#include "Includes.h"

Go to the source code of this file.

Functions

ULONG_PTR InitGDIPlus ()
 Initialize GDI+. More...
 
HRESULT GetEncoderClsid (const WCHAR *format, CLSID *pClsid)
 
HRESULT SaveBitmap (HWND hwnd, const std::wstring &wstrName, Gdiplus::Bitmap *pBitmap)
 Save bitmap to file. More...
 
HMENU CreateFileMenu (HMENU hMenubar)
 Create File menu. More...
 
HMENU CreateGenerateMenu (HMENU hMenubar)
 Create Generate menu. More...
 
HMENU CreateViewMenu (HMENU hMenubar)
 Create View menu. More...
 
HMENU CreateDistributionMenu (HMENU hMenubar)
 Create Distribution menu. More...
 
HMENU CreateHashMenu (HMENU hMenubar)
 Create Hash menu. More...
 
HMENU CreateSplineMenu (HMENU hMenubar)
 Create Spline menu. More...
 
HMENU CreateSettingsMenu (HMENU hMenubar)
 Create Settings menu. More...
 
void CreateHelpMenu (HMENU hMenubar)
 Create Help menu. More...
 
void UpdateFileMenu (HMENU hMenu, eNoise noise)
 Update File menu. More...
 
void UpdateGenerateMenu (HMENU hMenu, eNoise noise)
 Update Generate menu. More...
 
void UpdateViewMenu (HMENU hMenu, eNoise noise)
 Update View menu. More...
 
void UpdateMenuItemGray (HMENU hMenu, UINT item, eNoise noise, bool bGray)
 Update menu item bool. More...
 
void UpdateMenuItemCheck (HMENU hMenu, UINT item, bool bCheck)
 Update menu item check. More...
 
void UpdateDistributionMenu (HMENU hMenu, eNoise noise, eDistribution distr)
 Update Distribution menu. More...
 
void UpdateHashMenu (HMENU hMenu, eNoise noise, eHash h)
 Update Hash menu. More...
 
void UpdateSplineMenu (HMENU hMenu, eNoise noise, eSpline spline)
 Update Spline menu. More...
 
void UpdateSettingsMenu (HMENU hMenu, eNoise noise)
 Update Settings menu. More...
 

Detailed Description

These platform-dependent functions are hidden away so that the faint-of-heart don't have to see them if they can't handle it.

Definition in file WindowsHelpers.cpp.

Function Documentation

◆ CreateDistributionMenu()

HMENU CreateDistributionMenu ( HMENU  hMenubar)

Create the Distribution menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Distribution menu.

Definition at line 192 of file WindowsHelpers.cpp.

◆ CreateFileMenu()

HMENU CreateFileMenu ( HMENU  hMenubar)

Create the File menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to File menu.

Definition at line 144 of file WindowsHelpers.cpp.

◆ CreateGenerateMenu()

HMENU CreateGenerateMenu ( HMENU  hMenubar)

Create the Generate menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Generate menu.

Definition at line 159 of file WindowsHelpers.cpp.

◆ CreateHashMenu()

HMENU CreateHashMenu ( HMENU  hMenubar)

Create the Hash menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Hash menu.

Definition at line 210 of file WindowsHelpers.cpp.

◆ CreateHelpMenu()

void CreateHelpMenu ( HMENU  hMenubar)

Create the Help menu.

Parameters
hMenubarHandle to menu bar.

Definition at line 263 of file WindowsHelpers.cpp.

◆ CreateSettingsMenu()

HMENU CreateSettingsMenu ( HMENU  hMenubar)

Create the Settings menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Settings menu.

Definition at line 240 of file WindowsHelpers.cpp.

◆ CreateSplineMenu()

HMENU CreateSplineMenu ( HMENU  hMenubar)

Create the Spline menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to Spline menu.

Definition at line 225 of file WindowsHelpers.cpp.

◆ CreateViewMenu()

HMENU CreateViewMenu ( HMENU  hMenubar)

Create the View menu.

Parameters
hMenubarHandle to menu bar.
Returns
Handle to View menu.

Definition at line 178 of file WindowsHelpers.cpp.

◆ GetEncoderClsid()

HRESULT GetEncoderClsid ( const WCHAR *  format,
CLSID *  pClsid 
)

Get an encoder clsid for an image file format.

Parameters
formatFile format using wide characters.
pClsid[OUT] Pointer to clsid.
Returns
S_OK for success, E_FAIL for failure.

Definition at line 62 of file WindowsHelpers.cpp.

◆ InitGDIPlus()

ULONG_PTR InitGDIPlus ( )

Initialize GDI+ and get a GDI+ token.

Returns
A GDI+ token.

Definition at line 43 of file WindowsHelpers.cpp.

◆ SaveBitmap()

HRESULT SaveBitmap ( HWND  hwnd,
const std::wstring &  wstrName,
Gdiplus::Bitmap *  pBitmap 
)

Display a Save dialog box for png files and save a bitmap to the file name that the user selects. Only files with a .png extension are allowed. The default file name is "ImageN.png", where N is the number of images saved so far in the current instance of this program. This prevents any collisions with files already saved by this instance. If there is a collision with a file from a previous instance, then the user is prompted to overwrite or rename it in the normal fashion.

Parameters
hwndWindow handle.
wstrNameFile name without extension.
pBitmapPointer to a bitmap.
Returns
S_OK for success, E_FAIL for failure.

Definition at line 97 of file WindowsHelpers.cpp.

◆ UpdateDistributionMenu()

void UpdateDistributionMenu ( HMENU  hMenu,
eNoise  noise,
eDistribution  distr 
)

Gray out and set the checkmarks in the Distribution menu according to the current noise and distribution types.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.
distrDistribution enumerated type.

Definition at line 356 of file WindowsHelpers.cpp.

◆ UpdateFileMenu()

void UpdateFileMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out the Properties and Save menu entries in the File menu if there is no noise present, and ungray them otherwise.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 283 of file WindowsHelpers.cpp.

◆ UpdateGenerateMenu()

void UpdateGenerateMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out and set the checkmarks in the Generate menu according to the current noise properties. Check or uncheck the menu entries for pixel, Perlin, and Value noise depending on the current noise type. Gray out the Randomize menu entry if there is no noise generated, and ungray it otherwise.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 303 of file WindowsHelpers.cpp.

◆ UpdateHashMenu()

void UpdateHashMenu ( HMENU  hMenu,
eNoise  noise,
eHash  h 
)

Gray out and set the checkmarks in the Hash menu according to the current noise and hash function types.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.
hHash function enumerated type.

Definition at line 395 of file WindowsHelpers.cpp.

◆ UpdateMenuItemCheck()

void UpdateMenuItemCheck ( HMENU  hMenu,
UINT  item,
bool  bCheck 
)

Update the check mark on a menu item.

Parameters
hMenuMenu handle.
itemMenu item id.
bCheckTrue if entry is to be checked.

Definition at line 346 of file WindowsHelpers.cpp.

◆ UpdateMenuItemGray()

void UpdateMenuItemGray ( HMENU  hMenu,
UINT  item,
eNoise  noise,
bool  bGray 
)

Gray or ungray a menu item depending on noise type and a boolean value.

Parameters
hMenuMenu handle.
itemMenu item id.
noiseNoise enumerated type.
bGrayTrue if entry is to be grayed out.

Definition at line 336 of file WindowsHelpers.cpp.

◆ UpdateSettingsMenu()

void UpdateSettingsMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out entries in the Settings menu if they are not appropriate for the current noise type and parameters.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 454 of file WindowsHelpers.cpp.

◆ UpdateSplineMenu()

void UpdateSplineMenu ( HMENU  hMenu,
eNoise  noise,
eSpline  spline 
)

Gray out and set the checkmarks in the Spline menu according to the current noise and spline types.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.
splineSpline enumerated type.

Definition at line 425 of file WindowsHelpers.cpp.

◆ UpdateViewMenu()

void UpdateViewMenu ( HMENU  hMenu,
eNoise  noise 
)

Gray out entries in the View menu according to the current noise properties.

Parameters
hMenuMenu handle.
noiseNoise enumerated type.

Definition at line 323 of file WindowsHelpers.cpp.