HandmadeHero/project/platform/win32.h

242 lines
5.3 KiB
C
Raw Normal View History

2023-09-08 14:50:22 -07:00
/*
Alternative header for windows.h
*/
// #include <windows.h>
2023-09-08 14:50:22 -07:00
#include "windows/windows_base.h"
2023-09-08 15:54:16 -07:00
#include "windows/window.h"
2023-09-08 14:50:22 -07:00
#include "windows/file.h"
#include "windows/io.h"
2023-09-08 18:08:57 -07:00
// #ifdef Build_Debug
# include "windows/dbghelp.h"
// #endif
#if Build_DLL
2023-09-08 21:01:53 -07:00
# define WIN_LIBRARY_API_START extern "C" __declspec(dllexport)
# define WIN_LIBRARY_API_END
2023-09-08 18:08:57 -07:00
#else
2023-09-08 21:01:53 -07:00
# define WIN_LIBRARY_API_START extern "C" {
# define WIN_LIBRARY_API_END }
2023-09-08 18:08:57 -07:00
#endif
#ifndef CONST
# define CONST const
#endif
2023-09-08 21:01:53 -07:00
#define NS_WIN32_BEGIN namespace win32 {
#define NS_WIN32_END }
NS_WIN32_BEGIN
WIN_LIBRARY_API_START
#pragma region Gdi32
#define _SAL_nop_impl_ X
#define _Deref_post2_impl_(p1,p2)
#define _SAL2_Source_(Name, args, annotes) _SA_annotes3(SAL_name, #Name, "", "2") _Group_(annotes _SAL_nop_impl_)
#define _Outptr_result_bytebuffer_(size) _SAL2_Source_(_Outptr_result_bytebuffer_, (size), _Out_impl_ _Deref_post2_impl_(__notnull_impl_notref, __bytecap_impl(size)))
DECLARE_HANDLE(HBITMAP);
typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, *LPBITMAPINFOHEADER, *PBITMAPINFOHEADER;
typedef struct tagRGBQUAD {
BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *LPBITMAPINFO, *PBITMAPINFO;
#define GDI_DIBSIZE(bi) ((bi).biHeight < 0 ? (-1)*(GDI__DIBSIZE(bi)) : GDI__DIBSIZE(bi))
HDC WINAPI CreateCompatibleDC( HDC hdc);
HBITMAP WINAPI
CreateDIBSection(
HDC hdc,
CONST BITMAPINFO *pbmi,
UINT usage,
_When_((pbmi->bmiHeader.biBitCount != 0), _Outptr_result_bytebuffer_(_Inexpressible_(GDI_DIBSIZE((pbmi->bmiHeader)))))
_When_((pbmi->bmiHeader.biBitCount == 0), _Outptr_result_bytebuffer_((pbmi->bmiHeader).biSizeImage))
VOID **ppvBits,
HANDLE hSection,
DWORD offset
);
typedef HANDLE HGDIOBJ;
BOOL WINAPI DeleteObject( HGDIOBJ ho);
int WINAPI StretchDIBits( HDC hdc
, int xDest, int yDest, int DestWidth, int DestHeight
, int xSrc, int ySrc, int SrcWidth, int SrcHeight,
CONST VOID* lpBits, CONST BITMAPINFO* lpbmi
, UINT iUsage, DWORD rop );
2023-09-08 18:08:57 -07:00
2023-09-08 21:01:53 -07:00
typedef struct tagPAINTSTRUCT {
HDC hdc;
BOOL fErase;
RECT rcPaint;
BOOL fRestore;
BOOL fIncUpdate;
BYTE rgbReserved[32];
} PAINTSTRUCT, *PPAINTSTRUCT, *NPPAINTSTRUCT, *LPPAINTSTRUCT;
2023-09-08 18:08:57 -07:00
2023-09-08 21:01:53 -07:00
HDC WINAPI
BeginPaint( HWND hWnd, LPPAINTSTRUCT lpPaint );
BOOL WINAPI
EndPaint( HWND hWnd, CONST PAINTSTRUCT *lpPaint );
BOOL WINAPI
PatBlt( HDC hdc
, int x, int y
, int w, int h
, DWORD rop );
#pragma endregion Gdi32
2023-09-08 18:08:57 -07:00
#ifdef UNICODE
constexpr auto CreateWindowEx = CreateWindowExW;
#else
constexpr auto CreateWindowEx = CreateWindowExA;
#endif // !UNICODE
#ifdef UNICODE
constexpr auto DefWindowProc = DefWindowProcW;
#else
constexpr auto DefWindowProc = DefWindowProcA;
#endif // !UNICODE
#ifdef UNICODE
constexpr auto DispatchMessage = DispatchMessageW;
#else
constexpr auto DispatchMessage = DispatchMessageA;
#endif // !UNICODE
#pragma region WinUser
HDC WINAPI GetDC( HWND hWnd );
2023-09-08 18:08:57 -07:00
2023-09-08 21:01:53 -07:00
BOOL WINAPI
GetMessageA(
2023-09-08 18:08:57 -07:00
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax);
2023-09-08 21:01:53 -07:00
BOOL WINAPI
GetMessageW(
2023-09-08 18:08:57 -07:00
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax);
#ifdef UNICODE
constexpr auto GetMessage = GetMessageW;
#else
constexpr auto GetMessage = GetMessageA;
#endif // !UNICODE
2023-09-08 15:54:16 -07:00
#ifdef UNICODE
2023-09-08 18:08:57 -07:00
constexpr auto MessageBox = MessageBoxW;
2023-09-08 15:54:16 -07:00
#else
2023-09-08 18:08:57 -07:00
constexpr auto MessageBox = MessageBoxA;
2023-09-08 15:54:16 -07:00
#endif // !UNICODE
2023-09-08 18:08:57 -07:00
#ifdef UNICODE
constexpr auto RegisterClass = RegisterClassW;
#else
constexpr auto RegisterClass = RegisterClassA;
#endif // !UNICODE
#pragma endregion WinUser
2023-09-08 18:08:57 -07:00
// Class Style Constants
// https://learn.microsoft.com/en-us/windows/win32/winmsg/about-window-classes
// https://learn.microsoft.com/en-us/windows/win32/winmsg/window-class-styles
2023-09-08 21:01:53 -07:00
enum BI : DWORD
{
BI_RGB_Uncompressed = 0L,
BI_RunLength_Encoded_8bpp = 1L,
BI_RunLength_Encoded_4bpp = 2L,
};
2023-09-08 18:08:57 -07:00
enum CS : UINT
{
CS_Own_Device_Context = CS_OWNDC,
CS_Horizontal_Redraw = CS_HREDRAW,
CS_Vertical_Redraw = CS_VREDRAW,
};
2023-09-08 21:01:53 -07:00
enum DIB : UINT
{
DIB_ColorTable_RGB = 0,
DIB_ColorTable_Palette = 1
};
2023-09-08 18:08:57 -07:00
enum MB : UINT
{
MB_Ok_Btn = MB_OK,
MB_Icon_Information = MB_ICONINFORMATION,
};
enum Mem : DWORD
{
Mem_Commit_Zeroed = 0x00001000,
Mem_Reserve = 0x00002000,
Mem_Release = 0x00008000,
};
2023-09-08 21:01:53 -07:00
enum Page : DWORD
2023-09-08 18:08:57 -07:00
{
Page_Read_Write = 0x04,
};
enum PM : UINT
{
PM_Remove_Messages_From_Queue = PM_REMOVE,
2023-09-08 18:08:57 -07:00
};
enum RasterOps : DWORD
{
2023-09-08 21:01:53 -07:00
RO_Source_To_Dest = (DWORD)0x00CC0020,
RO_Blackness = (DWORD)0x00000042,
RO_Whiteness = (DWORD)0x00FF0062,
2023-09-08 18:08:57 -07:00
};
#define WM_ACTIVATEAPP 0x001C
enum WS : UINT
{
WS_Overlapped_Window = WS_OVERLAPPEDWINDOW,
WS_Initially_Visible = WS_VISIBLE,
};
2023-09-08 21:01:53 -07:00
WIN_LIBRARY_API_END
NS_WIN32_END
#undef _SAL_nop_impl_
#undef _SAL2_Source_
#undef _Deref_post2_impl_
#undef _Outptr_result_bytebuffer_
#undef _At_
#undef _When_
#undef GDI_DIBSIZE