Lindenmayer System
A Simple L-system Image Generator Featuring Turtle Graphics
Functions
WindowsHelpers.cpp File Reference

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

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

Go to the source code of this file.

Functions

void InitWindow (HINSTANCE hInst, INT nShow, WNDPROC WndProc)
 Initialize window. More...
 
ULONG_PTR InitGDIPlus ()
 Initialize GDI+. More...
 
void AddPointToRect (RECT &r, Gdiplus::PointF point)
 Add point to rectangle. More...
 
Gdiplus::RectF GetClientRectF (HWND hwnd)
 Get client rectangle as a RectF. More...
 
void MinDragRect (HWND hwnd, WPARAM wParam, RECT *pRect, int n)
 Enforce minimum drag rectangle. More...
 
HRESULT GetEncoderClsid (const WCHAR *format, CLSID *pClsid)
 
HRESULT SaveBitmap (HWND hwnd, Gdiplus::Bitmap *pBitmap)
 Save bitmap to file. More...
 

Detailed Description

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

Definition in file WindowsHelpers.cpp.

Function Documentation

◆ AddPointToRect()

void AddPointToRect ( RECT &  r,
Gdiplus::PointF  point 
)

Add a point to a rectangle, that is, extend the rectangle to enclose the point. Note that the rectangle has integer coefficients whereas the point has floating-point coefficients, and therefore we must apply floor and ceil judiciously.

Parameters
r[IN, OUT] Reference to a RECT structure.
pointA point.

Definition at line 110 of file WindowsHelpers.cpp.

◆ GetClientRectF()

Gdiplus::RectF GetClientRectF ( HWND  hwnd)

Get client rectangle in Gdiplus::RectF format.

Parameters
hwndWindow handle.
Returns
Client rectangle of that window.

Definition at line 122 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 207 of file WindowsHelpers.cpp.

◆ InitGDIPlus()

ULONG_PTR InitGDIPlus ( )

Initialize GDI+ and get a GDI+ token.

Returns
A GDI+ token.

Definition at line 89 of file WindowsHelpers.cpp.

◆ InitWindow()

void InitWindow ( HINSTANCE  hInst,
INT  nShow,
WNDPROC  WndProc 
)

Create and initialize a window.

Parameters
hInstInstance handle.
nShow1 to show window, 0 to hide.
WndProcWindow procedure.

Definition at line 47 of file WindowsHelpers.cpp.

◆ MinDragRect()

void MinDragRect ( HWND  hwnd,
WPARAM  wParam,
RECT *  pRect,
int  n 
)

Resize the drag rectangle provided by a WM_SIZING message to ensure a minimum client area width and height.

Parameters
hwndWindow handle.
wParamWMSZ message telling us which edge is being dragged on.
pRect[IN, OUT] Pointer to drag rectangle.
nMinimum width and height of client area.

Definition at line 137 of file WindowsHelpers.cpp.

◆ SaveBitmap()

HRESULT SaveBitmap ( HWND  hwnd,
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.
pBitmapPointer to a bitmap.
Returns
S_OK for success, E_FAIL for failure.

Definition at line 241 of file WindowsHelpers.cpp.