Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I'M TOO TIED TO DO SEPARATE SOURCE FILES THIS WEEK,
- SO I'LL BE SHOWING MOST OF THEM IN ONE BIG PASTE!!!! */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\_kit_globals.hpp */
- #ifndef __KIT_GLOBALS_HPP
- #define __KIT_GLOBALS_HPP
- #include <Windows.h>
- #if defined(_DEBUG)
- #include <stdio.h>
- #define loghere printf("line %4i: (%s)\n",__LINE__,__FILE__);
- #else
- #define loghere ; /* do {} while(0); */
- #endif /* _DEBUG */
- //used for Window and Bitmap
- #define KIT_INITIAL_STRETCH_MODE COLORONCOLOR
- //class type ID numbers
- #define KIT_CONTAINS_OPAQUE (0x80000000)
- #define KIT_CLASSTYPE_NULL (0)
- #define KIT_CLASSTYPE_MUTEXSIMPLE (1 | KIT_CONTAINS_OPAQUE)
- #define KIT_CLASSTYPE_WINDOW (2 | KIT_CONTAINS_OPAQUE)
- #define KIT_CLASSTYPE_BITMAP (3 | KIT_CONTAINS_OPAQUE)
- namespace kit {
- /*++++++++++*/
- /*+kit_main+*/
- /*++++++++++*/
- namespace w32 {
- extern HINSTANCE hThisInst;
- extern HINSTANCE hPrevInst;
- extern LPSTR lpszArg;
- extern int nCmdShow;
- extern LARGE_INTEGER ticksPerSecond; //used in time::getTicksPerSecond()
- };
- /*++++++++++*/
- /*+kit_main+*/
- /*++++++++++*/
- };
- #endif /* __KIT_GLOBALS_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\_kit_globals.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Window\_kit_Window.hpp */
- #ifndef _KIT_WINDOW__KIT_WINDOW_HPP
- #define _KIT_WINDOW__KIT_WINDOW_HPP
- #include "../_kit_globals.hpp"
- #define KIT_LOCK_SPINCOUNT (2048)
- namespace kit {
- static inline shape::rect ConvertToKitRect(RECT& rectIn){
- shape::rect rectOut;
- rectOut.x = rectIn.left;
- rectOut.y = rectIn.top;
- rectOut.w = rectIn.right - rectIn.left;
- rectOut.h = rectIn.bottom - rectIn.top;
- return rectOut;
- }
- static inline RECT ConvertFromKitRect(shape::rect& rectIn){
- RECT rectOut;
- rectOut.left = rectIn.x;
- rectOut.top = rectIn.y;
- rectOut.right = rectIn.x + rectIn.w;
- rectOut.bottom = rectIn.y + rectIn.h;
- return rectOut;
- }
- //assumes window is without a menu
- static inline shape::point CalculateWindowSize(u32 innerWidth, u32 innerHeight,
- u32 flags, u32 flagsEx)
- {
- RECT winSize;
- winSize.left = 0;
- winSize.top = 0;
- winSize.right = innerWidth;
- winSize.bottom = innerHeight;
- AdjustWindowRectEx(&winSize, flags, false, flagsEx);
- shape::point winSizeAdjusted;
- winSizeAdjusted.x = winSize.right - winSize.left;
- winSizeAdjusted.y = winSize.bottom - winSize.top;
- return winSizeAdjusted;
- }
- /*++++++++++++*/
- /*+kit_Window+*/
- /*++++++++++++*/
- namespace w32 {
- extern size_t winCount; //number of existing kit::Window instances
- extern const char winClassName[];
- extern WNDCLASSEXA winClass;
- extern ATOM winClassAtom;
- };
- struct _WindowOpaque { //intentionally excluded from w32 namespace
- CRITICAL_SECTION lock;
- HWND winHandle;
- shape::rect winRect; //contains both window position, and window size
- u32 winIndex;
- bool winResizable;
- bool winDestroyed;
- BITMAPINFO canvasInfo;
- HBITMAP canvas;
- color::ARGB* canvasPixels;
- shape::point canvasSize;
- HDC canvasDevCtx;
- s32 canvasStretchMode;
- bool canvasStretch; //if false, canvas is resized alongside window
- };
- /*------------*/
- /*-kit_Window-*/
- /*------------*/
- /*++++++++++++++++*/
- /*+kit_WindowProc+*/
- /*++++++++++++++++*/
- namespace w32 {
- extern LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
- };
- /*----------------*/
- /*-kit_WindowProc-*/
- /*----------------*/
- };
- #endif /* _KIT_WINDOW__KIT_WINDOW_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Window\_kit_Window.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Bitmap\_kit_Bitmap.hpp */
- #ifndef _KIT_BITMAP__KIT_BITMAP_HPP
- #define _KIT_BITMAP__KIT_BITMAP_HPP
- #include "../_kit_globals.hpp"
- namespace kit {
- /*++++++++++++*/
- /*+kit_Bitmap+*/
- /*++++++++++++*/
- struct _BitmapOpaque {
- BITMAPINFO bmpInfo;
- HBITMAP bmp;
- color::ARGB* bmpPixels;
- shape::point bmpSize;
- HDC bmpDevCtx;
- s32 bmpStretchMode;
- bool bmpDirectAccess; //false for
- };
- /*------------*/
- /*-kit_Bitmap-*/
- /*------------*/
- };
- #endif /* _KIT_BITMAP__KIT_BITMAP_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Bitmap\_kit_Bitmap.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\video.hpp */
- #ifndef _KIT_VIDEO_HPP
- #define _KIT_VIDEO_HPP
- #include "commondef.hpp"
- #include "_video/misc.hpp"
- #include "_video/Window.hpp"
- #include "_video/Bitmap.hpp"
- #endif /* _KIT_VIDEO_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\video.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\misc.hpp */
- #ifndef _KIT_MISC_HPP
- #define _KIT_MISC_HPP
- #include "commondef.hpp"
- #include "_misc/Mutex.hpp"
- #include "_misc/time.hpp"
- #endif /* _KIT_MISC_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\misc.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\commondef.hpp */
- #ifndef _KIT_COMMONDEF_HPP
- #define _KIT_COMMONDEF_HPP
- namespace kit {
- #ifndef MIN
- #define MIN(a,b) ( ((a)<(b)) ? (a) : (b) )
- #endif /* MIN(a,b) */
- #ifndef MAX
- #define MAX(a,b) ( ((a)>(b)) ? (a) : (b) )
- #endif /* MAX(a,b) */
- #ifndef CLAMP
- #define CLAMP(n, mn, mx) MIN(MAX(n,mn),mx)
- #endif /* CLAMP(n, mn, mx) */
- // integer bounds
- #define KIT_U8_MAX (0xff)
- #define KIT_U16_MAX (0xffff)
- #define KIT_U32_MAX (0xffffffff)
- #define KIT_U64_MAX (0xffffffffffffffff)
- //
- #define KIT_S8_MIN (-0x80)
- #define KIT_S8_MAX ( 0x7f)
- #define KIT_S16_MIN (-0x8000)
- #define KIT_S16_MAX ( 0x7fff)
- #define KIT_S32_MIN (-0x80000000)
- #define KIT_S32_MAX ( 0x7fffffff)
- #define KIT_S64_MIN (-0x8000000000000000)
- #define KIT_S64_MAX ( 0x7fffffffffffffff)
- // most significant bits/Bytes
- #define KIT_MSb_8 (0x80)
- #define KIT_MSb_16 (0x8000)
- #define KIT_MSb_32 (0x80000000)
- #define KIT_MSb_64 (0x8000000000000000)
- //
- #define KIT_MSB_8 (0xff)
- #define KIT_MSB_16 (0xff00)
- #define KIT_MSB_32 (0xff000000)
- #define KIT_MSB_64 (0xff00000000000000)
- #if defined(SDL_h_)
- typedef Uint8 u8 ;
- typedef Uint16 u16;
- typedef Uint32 u32;
- typedef Uint64 u64;
- typedef Sint8 s8 ;
- typedef Sint16 s16;
- typedef Sint32 s32;
- typedef Sint64 s64;
- #elif defined(_STDINT) || defined(_CSTDINT_)
- typedef uint8_t u8 ;
- typedef uint16_t u16;
- typedef uint32_t u32;
- typedef uint64_t u64;
- typedef int8_t s8 ;
- typedef int16_t s16;
- typedef int32_t s32;
- typedef int64_t s64;
- #else
- typedef unsigned char u8 ;
- typedef unsigned short u16;
- typedef unsigned int u32;
- typedef unsigned long long u64;
- typedef signed char s8 ;
- typedef signed short s16;
- typedef signed int s32;
- typedef signed long long s64;
- #endif
- // for consistency
- typedef float f32;
- typedef double f64;
- typedef void* _GenericOpaquePtr;
- };
- #endif /* _KIT_COMMONDEF_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\commondef.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\all.hpp */
- #ifndef _KIT_ALL_HPP
- #define _KIT_ALL_HPP
- #include "commondef.hpp"
- #include "misc.hpp"
- #include "video.hpp"
- #endif /* _KIT_ALL_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\all.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\WindowEvent.hpp */
- #ifndef _KIT__VIDEO_WINDOWEVENT_HPP
- #define _KIT__VIDEO_WINDOWEVENT_HPP
- #include "../commondef.hpp"
- namespace kit {
- enum WindowEventEnum {
- WINEVENT_NULL = 0,
- WINEVENT_COMMON = 1,
- };
- struct WindowEvent_Common {
- u32 type;
- u32 winIndex;
- u64 timestamp;
- };
- union WindowEvent {
- u32 type;
- WindowEvent_Common common;
- };
- };
- #endif /* _KIT__VIDEO_WINDOWEVENT_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\WindowEvent.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\Window.hpp */
- #ifndef _KIT__VIDEO_WINDOW_HPP
- #define _KIT__VIDEO_WINDOW_HPP
- #include "../commondef.hpp"
- #include "misc.hpp"
- #include "WindowEvent.hpp"
- namespace kit {
- enum WindowPositionEnum {
- WINPOS_UNDEFINED = 0xC0000000,
- WINPOS_CENTERED = 0xC0000001,
- };
- enum WindowFlagEnum {
- WINFLAG_HIDDEN = 0x01, // window is not visible
- WINFLAG_BORDERLESS = 0x02, // window lacks any decoration
- WINFLAG_RESIZABLE = 0x04, // window can be resized
- WINFLAG_MINIMIZED = 0x08, // window is minimized
- WINFLAG_MAXIMIZED = 0x10, // window is maximized
- WINFLAG_FOCUS = 0x20, // window has grabbed input focus
- WINFLAG_FULLSCREEN = 0x40, // window is in fullscreen mode (non-exclusive)
- //WINFLAG_CAPTURE_DESTROY = 0x80,
- };
- class Bitmap;
- struct _WindowOpaque;
- class Window {
- u32 _type;
- u32 _padding32;
- _WindowOpaque* _opaque = nullptr;
- bool _constructing = true;
- bool _valid = false;
- char _title[256];
- public:
- _WindowOpaque* _accessOpaque(){ return _opaque; }; //don't touch this, seriously
- Window(const char* windowTitle,
- u32 windowWidth, u32 windowHeight,
- u32 windowFlags = 0,
- s32 windowX = WINPOS_UNDEFINED,
- s32 windowY = WINPOS_UNDEFINED,
- u32 canvasWidth = 0, u32 canvasHeight = 0);
- ~Window();
- bool isConstructing(){ return _constructing; }
- bool isValid(){ return _valid; }
- bool isDestroyed();
- const char* getTitle(){ return _title; }
- shape::rect getWindowRect();
- shape::point getCanvasSize();
- color::ARGB* getPixels();
- bool pollEvent(WindowEvent* event_p);
- void lock(bool locked = true);
- void unlock(){ lock(false); }
- void present();
- void clear(color::ARGB color = 0x00000000);
- void tblitns(Bitmap* bmp, s32 x, s32 y, color::ARGB transparency);
- };
- };
- #endif /* _KIT__VIDEO_WINDOW_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\Window.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\misc.hpp */
- #ifndef _KIT__VIDEO_MISC_HPP
- #define _KIT__VIDEO_MISC_HPP
- #include "../commondef.hpp"
- namespace kit {
- namespace color {
- //what GDI uses (save for the alpha channel)
- union ARGB { //4B; 0xAARRGGBB
- u32 v; //entire color [v]alue
- struct {
- u8 b;
- u8 g;
- u8 r;
- u8 a;
- };
- ARGB() : v(0) {}
- ARGB(u32 _v) : v(_v) {}
- ARGB(u8 _r, u8 _g,
- u8 _b, u8 _a) : r(_r), g(_g), b(_b), a(_a) {}
- };
- union ABGR { //4B; 0xAABBGGRR
- u32 v; //entire color [v]alue
- struct {
- u8 r;
- u8 g;
- u8 b;
- u8 a;
- };
- ABGR() : v(0) {}
- ABGR(u32 _v) : v(_v) {}
- ABGR(u8 _r, u8 _g,
- u8 _b, u8 _a) : r(_r), g(_g), b(_b), a(_a) {}
- };
- };
- namespace shape {
- struct point { //8B
- s32 x, y;
- point() : x(0), y(0) {}
- point(s32 _x, s32 _y) : x(_x), y(_y) {}
- };
- struct rect { //16B
- s32 x, y; //x & y position of the rectangle's top-left corner
- s32 w, h; //the rectangle's width & height
- rect() : x(0), y(0), w(0), h(0) {}
- rect(s32 _x, s32 _y) : x(_x), y(_y) {}
- rect(s32 _x, s32 _y,
- s32 _w, s32 _h) : x(_x), y(_y), w(_w), h(_h) {}
- };
- struct line { //16B
- s32 x0, y0;
- s32 x1, y1;
- line() : x0(0), y0(0), x1(0), y1(0) {}
- line(s32 _x0, s32 _y0,
- s32 _x1, s32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- };
- struct fpoint { //8B
- f32 x, y;
- fpoint() : x(0.0f), y(0.0f) {}
- fpoint(f32 _x, f32 _y) : x(_x), y(_y) {}
- };
- struct frect { //16B
- f32 x, y; //x & y position of rectangle's top-left corner
- f32 w, h; //the rectangle's width & height
- frect() : x(0.0f), y(0.0f), w(0.0f), h(0.0f) {}
- frect(f32 _x, f32 _y) : x(_x), y(_y) {}
- frect(f32 _x, f32 _y,
- f32 _w, f32 _h) : x(_x), y(_y), w(_w), h(_h) {}
- };
- struct fline { //16B
- f32 x0, y0;
- f32 x1, y1;
- fline() : x0(0.0f), y0(0.0f), x1(0.0f), y1(0.0f) {}
- fline(f32 _x0, f32 _y0,
- f32 _x1, f32 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- };
- struct dpoint { //16B
- f64 x, y;
- dpoint() : x(0.0), y(0.0) {}
- dpoint(f64 _x, f64 _y) : x(_x), y(_y) {}
- };
- struct drect { //32B
- f64 x, y; //x & y position of rectangle's top-left corner
- f64 w, h; //the rectangle's width & height
- drect() : x(0.0), y(0.0), w(0.0), h(0.0) {}
- drect(f64 _x, f64 _y) : x(_x), y(_y) {}
- drect(f64 _x, f64 _y,
- f64 _w, f64 _h) : x(_x), y(_y), w(_w), h(_h) {}
- };
- struct dline { //32B
- f64 x0, y0;
- f64 x1, y1;
- dline() : x0(0.0), y0(0.0), x1(0.0), y1(0.0) {}
- dline(f64 _x0, f64 _y0,
- f64 _x1, f64 _y1) : x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
- };
- };
- };
- #endif /* _KIT__VIDEO_MISC_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\misc.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\Bitmap.hpp */
- #ifndef _KIT__VIDEO_BITMAP_HPP
- #define _KIT__VIDEO_BITMAP_HPP
- #include "../commondef.hpp"
- #include "misc.hpp"
- namespace kit {
- class Window; //from Window.hpp
- struct _BitmapOpaque;
- class Bitmap {
- u32 _type;
- u32 _padding32;
- _BitmapOpaque* _opaque = nullptr;
- bool _valid = false;
- public:
- _BitmapOpaque* _accessOpaque(){ return _opaque; }
- u32 getType(){ return _type; }
- //loads from memory
- Bitmap(const color::ARGB* pixelData,
- u32 width, u32 height,
- bool directAccess = false);
- //loads from file
- Bitmap(const char* fileName,
- u32 width, u32 height,
- bool directAccess = false);
- ~Bitmap();
- };
- };
- #endif /* _KIT__VIDEO_BITMAP_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_video\Bitmap.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_misc\time.hpp */
- #ifndef _KIT__MISC_TIME_HPP
- #define _KIT__MISC_TIME_HPP
- #include "../commondef.hpp"
- namespace kit {
- namespace time {
- u64 getTicks();
- u64 getTicksPerSecond();
- f64 getUptime();
- void sleep(u32 milliseconds);
- };
- };
- #endif /* _KIT__MISC_TIME_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_misc\time.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_misc\Mutex.hpp */
- #ifndef _KIT__MISC_MUTEX_HPP
- #define _KIT__MISC_MUTEX_HPP
- #include "../commondef.hpp"
- namespace kit {
- //this mutex is non-blocking within the same thread!
- //(that means you can lock multiple times in one thread
- // as long as you unlock it the same number of times)
- class MutexSimple {
- u32 _type;
- u32 _spinCount;
- _GenericOpaquePtr _mutex_ptr = nullptr;
- public:
- MutexSimple(u32 spinCount = -1);
- ~MutexSimple();
- void setSpinCount(u32 spinCount);
- u32 getSpinCount(){ return _spinCount; }
- void lock(bool locked = true);
- void unlock(){ lock(false); }
- bool tryLock(); //returns true if locked successfully
- };
- };
- #endif /* _KIT__MISC_MUTEX_HPP */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\include\kit\_misc\Mutex.hpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\kit_time.cpp */
- #include <kit/_misc/time.hpp>
- #include "_kit_globals.hpp"
- #include <Windows.h>
- namespace kit {
- u64 time::getTicks(){
- LARGE_INTEGER ticks;
- QueryPerformanceCounter(&ticks);
- return ticks.QuadPart;
- }
- u64 time::getTicksPerSecond(){
- return w32::ticksPerSecond.QuadPart;
- }
- f64 time::getUptime(){
- return (f64)time::getTicks()/w32::ticksPerSecond.QuadPart;
- }
- void time::sleep(u32 milliseconds){
- Sleep(milliseconds);
- }
- }; /* namespace kit */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\kit_time.cpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\kit_main.cpp */
- #include "_kit_globals.hpp"
- using namespace kit;
- HINSTANCE w32::hThisInst = nullptr;
- HINSTANCE w32::hPrevInst = nullptr;
- LPSTR w32::lpszArg = nullptr;
- int w32::nCmdShow = SW_HIDE;
- LARGE_INTEGER w32::ticksPerSecond;
- //get first and last char of string, excluding leading or trailing whitespace
- //(whitespace as in ' '; i'm not going to bother with '\t', '\n', etc.)
- static inline char* _getFirstCharPtr(char* start){
- if(*start == 0) return start;
- while(*start == ' ') ++start;
- return start;
- }
- static inline char* _getLastCharPtr(char* start){
- if(*start == 0) return start;
- char* end = start;
- while(*(end+1) != 0 ) ++end; //go to null terminator
- while(*end == ' ') --end; //go back until a non-whitespace char is found
- return end;
- }
- //provided by the user
- extern int main(int argc, char** argv);
- //converts lpszArg to how argv normally behaves,
- //before calling a user-defined main() function
- int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
- LPSTR lpszArg, int nCmdShow)
- {
- //assign some global values
- w32::hThisInst = hThisInst;
- w32::hPrevInst = hPrevInst;
- w32::lpszArg = lpszArg;
- w32::nCmdShow = nCmdShow;
- QueryPerformanceFrequency(&w32::ticksPerSecond);
- char* p = (char*)lpszArg;
- int _argc = 1; //should always contain path to executable
- char** _argv = nullptr;
- //parse for the number of arguments (assuming space as delimiter)
- char* first = _getFirstCharPtr(p);
- char* last = _getLastCharPtr(p);
- int Arg_len = (int)(last-first) + ((*first!=0) ? 1 : 0);
- if(Arg_len > 0) ++_argc;
- for(p=first; p<=last; ++p){
- if(*p == ' ') ++_argc;
- }
- //create and fill in _argv
- _argv = (char**)CoTaskMemAlloc( sizeof(char*) * _argc );
- if(_argv == nullptr) return ERROR_NOT_ENOUGH_MEMORY;
- char filepath[MAX_PATH]; //path to current process
- if(GetModuleFileNameA(NULL, filepath, MAX_PATH) == 0)
- return ERROR_INSUFFICIENT_BUFFER;
- _argv[0] = filepath;
- if(Arg_len > 0){
- int i = 1;
- _argv[i++] = first;
- for(p=first; p<=last; ++p){
- if(*p == ' '){
- *p = 0; //set delimiter to null
- _argv[i++] = p+1; //+1 as in +sizeof(char*)
- }
- }
- *p = 0; //make sure last arg has null terminator
- }
- int returnCode = main(_argc,_argv);
- CoTaskMemFree(_argv);
- return returnCode;
- }
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\kit_main.cpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\kit_Mutex.cpp */
- #include <kit/_misc/Mutex.hpp>
- #include "_kit_globals.hpp"
- #include <Windows.h>
- #define KIT_MUTEX_NULLPTR _kit_mutex_nullptr
- using namespace kit;
- static const char _kit_mutex_nullptr[] = "internal mutex = nullptr";
- MutexSimple::MutexSimple(u32 spinCount){
- _type = KIT_CLASSTYPE_MUTEXSIMPLE;
- _mutex_ptr = new CRITICAL_SECTION;
- if(spinCount == -1){
- InitializeCriticalSection((CRITICAL_SECTION*)_mutex_ptr);
- //to my knowledge, there is no GetCriticalSectionSpinCount,
- //so i need to probe for it with a "Set" before setting it back
- //(also, i tried to grab the SpinCount member of the critical section
- // directly, but that seemed to result in undefined behavior for some reason!!!)
- _spinCount = SetCriticalSectionSpinCount((CRITICAL_SECTION*)_mutex_ptr, 0);
- SetCriticalSectionSpinCount((CRITICAL_SECTION*)_mutex_ptr, _spinCount);
- } else {
- InitializeCriticalSectionAndSpinCount((CRITICAL_SECTION*)_mutex_ptr, spinCount);
- _spinCount = spinCount;
- }
- }
- MutexSimple::~MutexSimple(){
- if(_mutex_ptr == nullptr) return;
- DeleteCriticalSection((CRITICAL_SECTION*)_mutex_ptr);
- delete _mutex_ptr;
- _mutex_ptr = nullptr;
- }
- void MutexSimple::setSpinCount(u32 spinCount){
- if(_mutex_ptr == nullptr) throw KIT_MUTEX_NULLPTR;
- SetCriticalSectionSpinCount((CRITICAL_SECTION*)_mutex_ptr, spinCount);
- _spinCount = spinCount;
- }
- void MutexSimple::lock(bool locked){
- if(_mutex_ptr == nullptr) throw KIT_MUTEX_NULLPTR;
- if(locked) EnterCriticalSection((CRITICAL_SECTION*)_mutex_ptr);
- else LeaveCriticalSection((CRITICAL_SECTION*)_mutex_ptr);
- }
- bool MutexSimple::tryLock(){
- if(_mutex_ptr == nullptr) throw KIT_MUTEX_NULLPTR;
- return TryEnterCriticalSection((CRITICAL_SECTION*)_mutex_ptr);
- }
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\kit_Mutex.cpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Window\kit_WindowProc.cpp */
- #include <kit/_video/Window.hpp>
- #include "_kit_Window.hpp"
- #include <stdio.h>
- using namespace kit;
- #if defined(_DEBUG)
- static void printMessage(HWND, UINT, WPARAM, LPARAM);
- #endif /* _DEBUG */
- LRESULT CALLBACK w32::WindowProc(HWND winHandle, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- #if defined(_DEBUG)
- //printMessage(winHandle, message, wParam, lParam);
- #endif /* _DEBUG */
- Window* window = (Window*)GetWindowLongPtrA(winHandle, GWLP_USERDATA);
- if(window == nullptr){
- if(message == WM_CREATE){
- //set userdata to a pointer to the associated kit::Window
- CREATESTRUCT* cs = (CREATESTRUCT*)lParam;
- SetWindowLongPtrA(winHandle, GWLP_USERDATA, (LONG_PTR)cs->lpCreateParams);
- return 0;
- } else {
- goto _dwp; //lol
- }
- } else if(!window->isValid() && !window->isConstructing()){
- _dwp: return DefWindowProcA(winHandle, message, wParam, lParam);
- }
- _WindowOpaque* opaque = window->_accessOpaque();
- EnterCriticalSection(&opaque->lock);
- LRESULT returnResult = 0;
- switch(message){
- case WM_QUIT:
- case WM_DESTROY:
- {
- //delete canvas and and any of its allocated memory
- if(opaque->canvas != nullptr){
- DeleteObject(opaque->canvas);
- opaque->canvas = nullptr;
- }
- opaque->winDestroyed = true;
- } break;
- case WM_PAINT:
- {
- if(opaque->canvas == nullptr) break; //just in case
- static PAINTSTRUCT paint;
- static HDC winDevCtx; //window device context
- static RECT rectO; //[O]riginal
- static shape::rect rectW; //[W]indow
- static shape::point sizeF; //[F]rame
- //prepare window for painting
- winDevCtx = BeginPaint(winHandle, &paint);
- rectO = paint.rcPaint;
- rectW = ConvertToKitRect(rectO);
- sizeF = opaque->canvasSize;
- //copy canvas bitmap to window
- SetStretchBltMode(winDevCtx, opaque->canvasStretchMode);
- StretchBlt(winDevCtx, rectW.x,rectW.y, rectW.w,rectW.h,
- opaque->canvasDevCtx, 0,0, sizeF.x,sizeF.y, SRCCOPY);
- EndPaint(winHandle, &paint);
- } break;
- case WM_SIZE:
- {
- //window resized; adjust canvas size accordingly
- opaque->winRect.w = LOWORD(lParam);
- opaque->winRect.h = HIWORD(lParam);
- if(opaque->canvasStretch){
- //create initial canvas bitmap, before binding the canvas device context to it
- if(opaque->canvas == nullptr){
- opaque->canvas = CreateDIBSection(nullptr, &opaque->canvasInfo, DIB_RGB_COLORS,
- (void**)&opaque->canvasPixels, nullptr, 0);
- SelectObject(opaque->canvasDevCtx, opaque->canvas);
- }
- } else {
- //calculate new canvas size
- opaque->canvasSize.x = LOWORD(lParam);
- opaque->canvasSize.y = HIWORD(lParam);
- opaque->canvasInfo.bmiHeader.biWidth = LOWORD(lParam);
- opaque->canvasInfo.bmiHeader.biHeight = HIWORD(lParam);
- //create new canvas bitmap, before binding the canvas device context to it
- if(opaque->canvas != nullptr) DeleteObject(opaque->canvas);
- opaque->canvas = CreateDIBSection(nullptr, &opaque->canvasInfo, DIB_RGB_COLORS,
- (void**)&opaque->canvasPixels, nullptr, 0);
- SelectObject(opaque->canvasDevCtx, opaque->canvas);
- }
- window->present(); //blit canvas to the window to reflect its new size
- } break;
- case WM_GETMINMAXINFO:
- {
- //enforce minimum window size if canvas does not scale with the window
- if(opaque->canvasStretch){
- u32 winStyleCurrent = GetWindowLongA(winHandle, GWL_STYLE );
- u32 winStyleExCurrent = GetWindowLongA(winHandle, GWL_EXSTYLE);
- shape::point winSizeAdjusted = CalculateWindowSize(opaque->canvasSize.x,
- opaque->canvasSize.y,
- winStyleCurrent,
- winStyleExCurrent);
- MINMAXINFO* mmi = (MINMAXINFO*)lParam;
- mmi->ptMinTrackSize.x = winSizeAdjusted.x;
- mmi->ptMinTrackSize.y = winSizeAdjusted.y;
- }
- } break;
- default: returnResult = DefWindowProcA(winHandle, message, wParam, lParam);
- }
- LeaveCriticalSection(&opaque->lock);
- return returnResult;
- }
- //these are for enabling and disabling what messages are printed
- //simply comment these out to disable them
- #define KIT_PM_WM_NULL //0x0000
- #define KIT_PM_WM_CREATE //0x0001
- #define KIT_PM_WM_DESTROY //0x0002
- #define KIT_PM_WM_MOVE //0x0003
- #define KIT_PM_WM_SIZE //0x0005
- #define KIT_PM_WM_ACTIVATE //0x0006
- #define KIT_PM_WM_SETFOCUS //0x0007
- #define KIT_PM_WM_KILLFOCUS //0x0008
- #define KIT_PM_WM_ENABLE //0x000A
- #define KIT_PM_WM_SETREDRAW //0x000B
- #define KIT_PM_WM_SETTEXT //0x000C
- //#define KIT_PM_WM_GETTEXT //0x000D
- //#define KIT_PM_WM_GETTEXTLENGTH //0x000E
- #define KIT_PM_WM_PAINT //0x000F
- #define KIT_PM_WM_CLOSE //0x0010
- #define KIT_PM_WM_QUERYENDSESSION //0x0011
- #define KIT_PM_WM_QUIT //0x0012
- #define KIT_PM_WM_QUERYOPEN //0x0013
- #define KIT_PM_WM_ERASEBKGND //0x0014
- #define KIT_PM_WM_SYSCOLORCHANGE //0x0015
- #define KIT_PM_WM_ENDSESSION //0x0016
- #define KIT_PM_WM_SHOWWINDOW //0x0018
- #define KIT_PM_WM_SETTINGCHANGE //0x001A
- #define KIT_PM_WM_DEVMODECHANGE //0x001B
- #define KIT_PM_WM_ACTIVATEAPP //0x001C
- #define KIT_PM_WM_FONTCHANGE //0x001D
- #define KIT_PM_WM_TIMECHANGE //0x001E
- #define KIT_PM_WM_CANCELMODE //0x001F
- //#define KIT_PM_WM_SETCURSOR //0x0020
- #define KIT_PM_WM_MOUSEACTIVATE //0x0021
- #define KIT_PM_WM_CHILDACTIVATE //0x0022
- #define KIT_PM_WM_QUEUESYNC //0x0023
- #define KIT_PM_WM_GETMINMAXINFO //0x0024
- #define KIT_PM_WM_PAINTICON //0x0026
- #define KIT_PM_WM_ICONERASEBKGND //0x0027
- #define KIT_PM_WM_NEXTDLGCTL //0x0028
- #define KIT_PM_WM_SPOOLERSTATUS //0x002A
- #define KIT_PM_WM_DRAWITEM //0x002B
- #define KIT_PM_WM_MEASUREITEM //0x002C
- #define KIT_PM_WM_DELETEITEM //0x002D
- #define KIT_PM_WM_VKEYTOITEM //0x002E
- #define KIT_PM_WM_CHARTOITEM //0x002F
- #define KIT_PM_WM_SETFONT //0x0030
- #define KIT_PM_WM_GETFONT //0x0031
- #define KIT_PM_WM_SETHOTKEY //0x0032
- #define KIT_PM_WM_GETHOTKEY //0x0033
- #define KIT_PM_WM_QUERYDRAGICON //0x0037
- #define KIT_PM_WM_COMPAREITEM //0x0039
- #define KIT_PM_WM_GETOBJECT //0x003D
- #define KIT_PM_WM_COMPACTING //0x0041
- #define KIT_PM_WM_COMMNOTIFY //0x0044
- #define KIT_PM_WM_WINDOWPOSCHANGING //0x0046
- #define KIT_PM_WM_WINDOWPOSCHANGED //0x0047
- #define KIT_PM_WM_POWER //0x0048
- #define KIT_PM_WM_COPYDATA //0x004A
- #define KIT_PM_WM_CANCELJOURNAL //0x004B
- #define KIT_PM_WM_NOTIFY //0x004E
- #define KIT_PM_WM_INPUTLANGCHANGEREQUEST //0x0050
- #define KIT_PM_WM_INPUTLANGCHANGE //0x0051
- #define KIT_PM_WM_TCARD //0x0052
- #define KIT_PM_WM_HELP //0x0053
- #define KIT_PM_WM_USERCHANGED //0x0054
- #define KIT_PM_WM_NOTIFYFORMAT //0x0055
- #define KIT_PM_WM_CONTEXTMENU //0x007B
- #define KIT_PM_WM_STYLECHANGING //0x007C
- #define KIT_PM_WM_STYLECHANGED //0x007D
- #define KIT_PM_WM_DISPLAYCHANGE //0x007E
- #define KIT_PM_WM_GETICON //0x007F
- #define KIT_PM_WM_SETICON //0x0080
- #define KIT_PM_WM_NCCREATE //0x0081
- #define KIT_PM_WM_NCDESTROY //0x0082
- #define KIT_PM_WM_NCCALCSIZE //0x0083
- //#define KIT_PM_WM_NCHITTEST //0x0084
- #define KIT_PM_WM_NCPAINT //0x0085
- #define KIT_PM_WM_NCACTIVATE //0x0086
- #define KIT_PM_WM_GETDLGCODE //0x0087
- #define KIT_PM_WM_SYNCPAINT //0x0088
- //#define KIT_PM_WM_NCMOUSEMOVE //0x00A0
- #define KIT_PM_WM_NCLBUTTONDOWN //0x00A1
- #define KIT_PM_WM_NCLBUTTONUP //0x00A2
- #define KIT_PM_WM_NCLBUTTONDBLCLK //0x00A3
- #define KIT_PM_WM_NCRBUTTONDOWN //0x00A4
- #define KIT_PM_WM_NCRBUTTONUP //0x00A5
- #define KIT_PM_WM_NCRBUTTONDBLCLK //0x00A6
- #define KIT_PM_WM_NCMBUTTONDOWN //0x00A7
- #define KIT_PM_WM_NCMBUTTONUP //0x00A8
- #define KIT_PM_WM_NCMBUTTONDBLCLK //0x00A9
- #define KIT_PM_WM_NCXBUTTONDOWN //0x00AB
- #define KIT_PM_WM_NCXBUTTONUP //0x00AC
- #define KIT_PM_WM_NCXBUTTONDBLCLK //0x00AD
- #define KIT_PM_WM_INPUT_DEVICE_CHANGE //0x00FE
- #define KIT_PM_WM_INPUT //0x00FF
- #define KIT_PM_WM_KEYDOWN //0x0100
- #define KIT_PM_WM_KEYUP //0x0101
- #define KIT_PM_WM_CHAR //0x0102
- #define KIT_PM_WM_DEADCHAR //0x0103
- #define KIT_PM_WM_SYSKEYDOWN //0x0104
- #define KIT_PM_WM_SYSKEYUP //0x0105
- #define KIT_PM_WM_SYSCHAR //0x0106
- #define KIT_PM_WM_SYSDEADCHAR //0x0107
- #define KIT_PM_WM_UNICHAR //0x0109
- #define KIT_PM_WM_IME_STARTCOMPOSITION //0x010D
- #define KIT_PM_WM_IME_ENDCOMPOSITION //0x010E
- #define KIT_PM_WM_IME_COMPOSITION //0x010F
- #define KIT_PM_WM_INITDIALOG //0x0110
- #define KIT_PM_WM_COMMAND //0x0111
- #define KIT_PM_WM_SYSCOMMAND //0x0112
- #define KIT_PM_WM_TIMER //0x0113
- #define KIT_PM_WM_HSCROLL //0x0114
- #define KIT_PM_WM_VSCROLL //0x0115
- #define KIT_PM_WM_INITMENU //0x0116
- #define KIT_PM_WM_INITMENUPOPUP //0x0117
- #define KIT_PM_WM_GESTURE //0x0119
- #define KIT_PM_WM_GESTURENOTIFY //0x011A
- #define KIT_PM_WM_MENUSELECT //0x011F
- #define KIT_PM_WM_MENUCHAR //0x0120
- #define KIT_PM_WM_ENTERIDLE //0x0121
- #define KIT_PM_WM_MENURBUTTONUP //0x0122
- #define KIT_PM_WM_MENUDRAG //0x0123
- #define KIT_PM_WM_MENUGETOBJECT //0x0124
- #define KIT_PM_WM_UNINITMENUPOPUP //0x0125
- #define KIT_PM_WM_MENUCOMMAND //0x0126
- #define KIT_PM_WM_CHANGEUISTATE //0x0127
- #define KIT_PM_WM_UPDATEUISTATE //0x0128
- #define KIT_PM_WM_QUERYUISTATE //0x0129
- #define KIT_PM_WM_CTLCOLORMSGBOX //0x0132
- #define KIT_PM_WM_CTLCOLOREDIT //0x0133
- #define KIT_PM_WM_CTLCOLORLISTBOX //0x0134
- #define KIT_PM_WM_CTLCOLORBTN //0x0135
- #define KIT_PM_WM_CTLCOLORDLG //0x0136
- #define KIT_PM_WM_CTLCOLORSCROLLBAR //0x0137
- #define KIT_PM_WM_CTLCOLORSTATIC //0x0138
- #define KIT_PM_MN_GETHMENU //0x01E1
- //#define KIT_PM_WM_MOUSEMOVE //0x0200
- #define KIT_PM_WM_LBUTTONDOWN //0x0201
- #define KIT_PM_WM_LBUTTONUP //0x0202
- #define KIT_PM_WM_LBUTTONDBLCLK //0x0203
- #define KIT_PM_WM_RBUTTONDOWN //0x0204
- #define KIT_PM_WM_RBUTTONUP //0x0205
- #define KIT_PM_WM_RBUTTONDBLCLK //0x0206
- #define KIT_PM_WM_MBUTTONDOWN //0x0207
- #define KIT_PM_WM_MBUTTONUP //0x0208
- #define KIT_PM_WM_MBUTTONDBLCLK //0x0209
- #define KIT_PM_WM_MOUSEWHEEL //0x020A
- #define KIT_PM_WM_XBUTTONDOWN //0x020B
- #define KIT_PM_WM_XBUTTONUP //0x020C
- #define KIT_PM_WM_XBUTTONDBLCLK //0x020D
- #define KIT_PM_WM_PARENTNOTIFY //0x0210
- #define KIT_PM_WM_ENTERMENULOOP //0x0211
- #define KIT_PM_WM_EXITMENULOOP //0x0212
- #define KIT_PM_WM_NEXTMENU //0x0213
- #define KIT_PM_WM_SIZING //0x0214
- #define KIT_PM_WM_CAPTURECHANGED //0x0215
- #define KIT_PM_WM_MOVING //0x0216
- #define KIT_PM_WM_POWERBROADCAST //0x0218
- #define KIT_PM_WM_DEVICECHANGE //0x0219
- #define KIT_PM_WM_MDICREATE //0x0220
- #define KIT_PM_WM_MDIDESTROY //0x0221
- #define KIT_PM_WM_MDIACTIVATE //0x0222
- #define KIT_PM_WM_MDIRESTORE //0x0223
- #define KIT_PM_WM_MDINEXT //0x0224
- #define KIT_PM_WM_MDIMAXIMIZE //0x0225
- #define KIT_PM_WM_MDITILE //0x0226
- #define KIT_PM_WM_MDICASCADE //0x0227
- #define KIT_PM_WM_MDIICONARRANGE //0x0228
- #define KIT_PM_WM_MDIGETACTIVE //0x0229
- #define KIT_PM_WM_MDISETMENU //0x0230
- #define KIT_PM_WM_ENTERSIZEMOVE //0x0231
- #define KIT_PM_WM_EXITSIZEMOVE //0x0232
- #define KIT_PM_WM_DROPFILES //0x0233
- #define KIT_PM_WM_MDIREFRESHMENU //0x0234
- #define KIT_PM_WM_POINTERDEVICECHANGE //0x0238
- #define KIT_PM_WM_POINTERDEVICEINRANGE //0x0239
- #define KIT_PM_WM_POINTERDEVICEOUTOFRANGE //0x023A
- #define KIT_PM_WM_TOUCH //0x0240
- #define KIT_PM_WM_NCPOINTERUPDATE //0x0241
- #define KIT_PM_WM_NCPOINTERDOWN //0x0242
- #define KIT_PM_WM_NCPOINTERUP //0x0243
- #define KIT_PM_WM_POINTERUPDATE //0x0245
- #define KIT_PM_WM_POINTERDOWN //0x0246
- #define KIT_PM_WM_POINTERUP //0x0247
- #define KIT_PM_WM_POINTERENTER //0x0249
- #define KIT_PM_WM_POINTERLEAVE //0x024A
- #define KIT_PM_WM_POINTERACTIVATE //0x024B
- #define KIT_PM_WM_POINTERCAPTURECHANGED //0x024C
- #define KIT_PM_WM_TOUCHHITTESTING //0x024D
- #define KIT_PM_WM_POINTERWHEEL //0x024E
- #define KIT_PM_WM_POINTERHWHEEL //0x024F
- #define KIT_PM_DM_POINTERHITTEST //0x0250
- #define KIT_PM_WM_POINTERROUTEDTO //0x0251
- #define KIT_PM_WM_POINTERROUTEDAWAY //0x0252
- #define KIT_PM_WM_POINTERROUTEDRELEASED //0x0253
- #define KIT_PM_WM_IME_SETCONTEXT //0x0281
- #define KIT_PM_WM_IME_NOTIFY //0x0282
- #define KIT_PM_WM_IME_CONTROL //0x0283
- #define KIT_PM_WM_IME_COMPOSITIONFULL //0x0284
- #define KIT_PM_WM_IME_SELECT //0x0285
- #define KIT_PM_WM_IME_CHAR //0x0286
- #define KIT_PM_WM_IME_REQUEST //0x0288
- #define KIT_PM_WM_IME_KEYDOWN //0x0290
- #define KIT_PM_WM_IME_KEYUP //0x0291
- #define KIT_PM_WM_MOUSEHOVER //0x02A1
- #define KIT_PM_WM_MOUSELEAVE //0x02A3
- #define KIT_PM_WM_NCMOUSEHOVER //0x02A0
- #define KIT_PM_WM_NCMOUSELEAVE //0x02A2
- #define KIT_PM_WM_WTSSESSION_CHANGE //0x02B1
- #define KIT_PM_WM_DPICHANGED //0x02E0
- #define KIT_PM_WM_DPICHANGED_BEFOREPARENT //0x02E2
- #define KIT_PM_WM_DPICHANGED_AFTERPARENT //0x02E3
- #define KIT_PM_WM_GETDPISCALEDSIZE //0x02E4
- #define KIT_PM_WM_CUT //0x0300
- #define KIT_PM_WM_COPY //0x0301
- #define KIT_PM_WM_PASTE //0x0302
- #define KIT_PM_WM_CLEAR //0x0303
- #define KIT_PM_WM_UNDO //0x0304
- #define KIT_PM_WM_RENDERFORMAT //0x0305
- #define KIT_PM_WM_RENDERALLFORMATS //0x0306
- #define KIT_PM_WM_DESTROYCLIPBOARD //0x0307
- #define KIT_PM_WM_DRAWCLIPBOARD //0x0308
- #define KIT_PM_WM_PAINTCLIPBOARD //0x0309
- #define KIT_PM_WM_VSCROLLCLIPBOARD //0x030A
- #define KIT_PM_WM_SIZECLIPBOARD //0x030B
- #define KIT_PM_WM_ASKCBFORMATNAME //0x030C
- #define KIT_PM_WM_CHANGECBCHAIN //0x030D
- #define KIT_PM_WM_HSCROLLCLIPBOARD //0x030E
- #define KIT_PM_WM_QUERYNEWPALETTE //0x030F
- #define KIT_PM_WM_PALETTEISCHANGING //0x0310
- #define KIT_PM_WM_PALETTECHANGED //0x0311
- #define KIT_PM_WM_HOTKEY //0x0312
- #define KIT_PM_WM_PRINT //0x0317
- #define KIT_PM_WM_PRINTCLIENT //0x0318
- #define KIT_PM_WM_APPCOMMAND //0x0319
- #define KIT_PM_WM_THEMECHANGED //0x031A
- #define KIT_PM_WM_CLIPBOARDUPDATE //0x031D
- #define KIT_PM_WM_DWMCOMPOSITIONCHANGED //0x031E
- #define KIT_PM_WM_DWMNCRENDERINGCHANGED //0x031F
- #define KIT_PM_WM_DWMCOLORIZATIONCOLORCHANGED //0x0320
- #define KIT_PM_WM_DWMWINDOWMAXIMIZEDCHANGE //0x0321
- #define KIT_PM_WM_DWMSENDICONICTHUMBNAIL //0x0323
- #define KIT_PM_WM_DWMSENDICONICLIVEPREVIEWBITMAP //0x0326
- #define KIT_PM_WM_GETTITLEBARINFOEX //0x033F
- //#define KIT_PM_WM_UNKNOWN //0x????
- #if defined(_DEBUG) //this function will do nothing otherwise
- static void printMessage(HWND hwnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- char* messageName = nullptr;
- switch(message){
- # ifdef KIT_PM_WM_NULL
- case WM_NULL : messageName = "WM_NULL"; break; //0x0000
- # endif
- # ifdef KIT_PM_WM_CREATE
- case WM_CREATE : messageName = "WM_CREATE"; break; //0x0001
- # endif
- # ifdef KIT_PM_WM_DESTROY
- case WM_DESTROY : messageName = "WM_DESTROY"; break; //0x0002
- # endif
- # ifdef KIT_PM_WM_MOVE
- case WM_MOVE : messageName = "WM_MOVE"; break; //0x0003
- # endif
- # ifdef KIT_PM_WM_SIZE
- case WM_SIZE : messageName = "WM_SIZE"; break; //0x0005
- # endif
- # ifdef KIT_PM_WM_ACTIVATE
- case WM_ACTIVATE : messageName = "WM_ACTIVATE"; break; //0x0006
- # endif
- # ifdef KIT_PM_WM_SETFOCUS
- case WM_SETFOCUS : messageName = "WM_SETFOCUS"; break; //0x0007
- # endif
- # ifdef KIT_PM_WM_KILLFOCUS
- case WM_KILLFOCUS : messageName = "WM_KILLFOCUS"; break; //0x0008
- # endif
- # ifdef KIT_PM_WM_ENABLE
- case WM_ENABLE : messageName = "WM_ENABLE"; break; //0x000A
- # endif
- # ifdef KIT_PM_WM_SETREDRAW
- case WM_SETREDRAW : messageName = "WM_SETREDRAW"; break; //0x000B
- # endif
- # ifdef KIT_PM_WM_SETTEXT
- case WM_SETTEXT : messageName = "WM_SETTEXT"; break; //0x000C
- # endif
- # ifdef KIT_PM_WM_GETTEXT
- case WM_GETTEXT : messageName = "WM_GETTEXT"; break; //0x000D
- # endif
- # ifdef KIT_PM_WM_GETTEXTLENGTH
- case WM_GETTEXTLENGTH : messageName = "WM_GETTEXTLENGTH"; break; //0x000E
- # endif
- # ifdef KIT_PM_WM_PAINT
- case WM_PAINT : messageName = "WM_PAINT"; break; //0x000F
- # endif
- # ifdef KIT_PM_WM_CLOSE
- case WM_CLOSE : messageName = "WM_CLOSE"; break; //0x0010
- # endif
- # ifdef KIT_PM_WM_QUERYENDSESSION
- case WM_QUERYENDSESSION : messageName = "WM_QUERYENDSESSION"; break; //0x0011
- # endif
- # ifdef KIT_PM_WM_QUIT
- case WM_QUIT : messageName = "WM_QUIT"; break; //0x0012
- # endif
- # ifdef KIT_PM_WM_QUERYOPEN
- case WM_QUERYOPEN : messageName = "WM_QUERYOPEN"; break; //0x0013
- # endif
- # ifdef KIT_PM_WM_ERASEBKGND
- case WM_ERASEBKGND : messageName = "WM_ERASEBKGND"; break; //0x0014
- # endif
- # ifdef KIT_PM_WM_SYSCOLORCHANGE
- case WM_SYSCOLORCHANGE : messageName = "WM_SYSCOLORCHANGE"; break; //0x0015
- # endif
- # ifdef KIT_PM_WM_ENDSESSION
- case WM_ENDSESSION : messageName = "WM_ENDSESSION"; break; //0x0016
- # endif
- # ifdef KIT_PM_WM_SHOWWINDOW
- case WM_SHOWWINDOW : messageName = "WM_SHOWWINDOW"; break; //0x0018
- # endif
- # ifdef KIT_PM_WM_SETTINGCHANGE
- case WM_SETTINGCHANGE : messageName = "WM_SETTINGCHANGE"; break; //0x001A
- # endif
- # ifdef KIT_PM_WM_DEVMODECHANGE
- case WM_DEVMODECHANGE : messageName = "WM_DEVMODECHANGE"; break; //0x001B
- # endif
- # ifdef KIT_PM_WM_ACTIVATEAPP
- case WM_ACTIVATEAPP : messageName = "WM_ACTIVATEAPP"; break; //0x001C
- # endif
- # ifdef KIT_PM_WM_FONTCHANGE
- case WM_FONTCHANGE : messageName = "WM_FONTCHANGE"; break; //0x001D
- # endif
- # ifdef KIT_PM_WM_TIMECHANGE
- case WM_TIMECHANGE : messageName = "WM_TIMECHANGE"; break; //0x001E
- # endif
- # ifdef KIT_PM_WM_CANCELMODE
- case WM_CANCELMODE : messageName = "WM_CANCELMODE"; break; //0x001F
- # endif
- # ifdef KIT_PM_WM_SETCURSOR
- case WM_SETCURSOR : messageName = "WM_SETCURSOR"; break; //0x0020
- # endif
- # ifdef KIT_PM_WM_MOUSEACTIVATE
- case WM_MOUSEACTIVATE : messageName = "WM_MOUSEACTIVATE"; break; //0x0021
- # endif
- # ifdef KIT_PM_WM_CHILDACTIVATE
- case WM_CHILDACTIVATE : messageName = "WM_CHILDACTIVATE"; break; //0x0022
- # endif
- # ifdef KIT_PM_WM_QUEUESYNC
- case WM_QUEUESYNC : messageName = "WM_QUEUESYNC"; break; //0x0023
- # endif
- # ifdef KIT_PM_WM_GETMINMAXINFO
- case WM_GETMINMAXINFO : messageName = "WM_GETMINMAXINFO"; break; //0x0024
- # endif
- # ifdef KIT_PM_WM_PAINTICON
- case WM_PAINTICON : messageName = "WM_PAINTICON"; break; //0x0026
- # endif
- # ifdef KIT_PM_WM_ICONERASEBKGND
- case WM_ICONERASEBKGND : messageName = "WM_ICONERASEBKGND"; break; //0x0027
- # endif
- # ifdef KIT_PM_WM_NEXTDLGCTL
- case WM_NEXTDLGCTL : messageName = "WM_NEXTDLGCTL"; break; //0x0028
- # endif
- # ifdef KIT_PM_WM_SPOOLERSTATUS
- case WM_SPOOLERSTATUS : messageName = "WM_SPOOLERSTATUS"; break; //0x002A
- # endif
- # ifdef KIT_PM_WM_DRAWITEM
- case WM_DRAWITEM : messageName = "WM_DRAWITEM"; break; //0x002B
- # endif
- # ifdef KIT_PM_WM_MEASUREITEM
- case WM_MEASUREITEM : messageName = "WM_MEASUREITEM"; break; //0x002C
- # endif
- # ifdef KIT_PM_WM_DELETEITEM
- case WM_DELETEITEM : messageName = "WM_DELETEITEM"; break; //0x002D
- # endif
- # ifdef KIT_PM_WM_VKEYTOITEM
- case WM_VKEYTOITEM : messageName = "WM_VKEYTOITEM"; break; //0x002E
- # endif
- # ifdef KIT_PM_WM_CHARTOITEM
- case WM_CHARTOITEM : messageName = "WM_CHARTOITEM"; break; //0x002F
- # endif
- # ifdef KIT_PM_WM_SETFONT
- case WM_SETFONT : messageName = "WM_SETFONT"; break; //0x0030
- # endif
- # ifdef KIT_PM_WM_GETFONT
- case WM_GETFONT : messageName = "WM_GETFONT"; break; //0x0031
- # endif
- # ifdef KIT_PM_WM_SETHOTKEY
- case WM_SETHOTKEY : messageName = "WM_SETHOTKEY"; break; //0x0032
- # endif
- # ifdef KIT_PM_WM_GETHOTKEY
- case WM_GETHOTKEY : messageName = "WM_GETHOTKEY"; break; //0x0033
- # endif
- # ifdef KIT_PM_WM_QUERYDRAGICON
- case WM_QUERYDRAGICON : messageName = "WM_QUERYDRAGICON"; break; //0x0037
- # endif
- # ifdef KIT_PM_WM_COMPAREITEM
- case WM_COMPAREITEM : messageName = "WM_COMPAREITEM"; break; //0x0039
- # endif
- #if(WINVER >= 0x0500)
- #ifndef _WIN32_WCE
- # ifdef KIT_PM_WM_GETOBJECT
- case WM_GETOBJECT : messageName = "WM_GETOBJECT"; break; //0x003D
- # endif
- #endif
- #endif /* WINVER >= 0x0500 */
- # ifdef KIT_PM_WM_COMPACTING
- case WM_COMPACTING : messageName = "WM_COMPACTING"; break; //0x0041
- # endif
- # ifdef KIT_PM_WM_COMMNOTIFY
- case WM_COMMNOTIFY : messageName = "WM_COMMNOTIFY"; break; //0x0044
- # endif
- # ifdef KIT_PM_WM_WINDOWPOSCHANGING
- case WM_WINDOWPOSCHANGING : messageName = "WM_WINDOWPOSCHANGING"; break; //0x0046
- # endif
- # ifdef KIT_PM_WM_WINDOWPOSCHANGED
- case WM_WINDOWPOSCHANGED : messageName = "WM_WINDOWPOSCHANGED"; break; //0x0047
- # endif
- # ifdef KIT_PM_WM_POWER
- case WM_POWER : messageName = "WM_POWER"; break; //0x0048
- # endif
- # ifdef KIT_PM_WM_COPYDATA
- case WM_COPYDATA : messageName = "WM_COPYDATA"; break; //0x004A
- # endif
- # ifdef KIT_PM_WM_CANCELJOURNAL
- case WM_CANCELJOURNAL : messageName = "WM_CANCELJOURNAL"; break; //0x004B
- # endif
- #if(WINVER >= 0x0400)
- # ifdef KIT_PM_WM_NOTIFY
- case WM_NOTIFY : messageName = "WM_NOTIFY"; break; //0x004E
- # endif
- # ifdef KIT_PM_WM_INPUTLANGCHANGEREQUEST
- case WM_INPUTLANGCHANGEREQUEST : messageName = "WM_INPUTLANGCHANGEREQUEST"; break; //0x0050
- # endif
- # ifdef KIT_PM_WM_INPUTLANGCHANGE
- case WM_INPUTLANGCHANGE : messageName = "WM_INPUTLANGCHANGE"; break; //0x0051
- # endif
- # ifdef KIT_PM_WM_TCARD
- case WM_TCARD : messageName = "WM_TCARD"; break; //0x0052
- # endif
- # ifdef KIT_PM_WM_HELP
- case WM_HELP : messageName = "WM_HELP"; break; //0x0053
- # endif
- # ifdef KIT_PM_WM_USERCHANGED
- case WM_USERCHANGED : messageName = "WM_USERCHANGED"; break; //0x0054
- # endif
- # ifdef KIT_PM_WM_NOTIFYFORMAT
- case WM_NOTIFYFORMAT : messageName = "WM_NOTIFYFORMAT"; break; //0x0055
- # endif
- # ifdef KIT_PM_WM_CONTEXTMENU
- case WM_CONTEXTMENU : messageName = "WM_CONTEXTMENU"; break; //0x007B
- # endif
- # ifdef KIT_PM_WM_STYLECHANGING
- case WM_STYLECHANGING : messageName = "WM_STYLECHANGING"; break; //0x007C
- # endif
- # ifdef KIT_PM_WM_STYLECHANGED
- case WM_STYLECHANGED : messageName = "WM_STYLECHANGED"; break; //0x007D
- # endif
- # ifdef KIT_PM_WM_DISPLAYCHANGE
- case WM_DISPLAYCHANGE : messageName = "WM_DISPLAYCHANGE"; break; //0x007E
- # endif
- # ifdef KIT_PM_WM_GETICON
- case WM_GETICON : messageName = "WM_GETICON"; break; //0x007F
- # endif
- # ifdef KIT_PM_WM_SETICON
- case WM_SETICON : messageName = "WM_SETICON"; break; //0x0080
- # endif
- #endif /* WINVER >= 0x0400 */
- # ifdef KIT_PM_WM_NCCREATE
- case WM_NCCREATE : messageName = "WM_NCCREATE"; break; //0x0081
- # endif
- # ifdef KIT_PM_WM_NCDESTROY
- case WM_NCDESTROY : messageName = "WM_NCDESTROY"; break; //0x0082
- # endif
- # ifdef KIT_PM_WM_NCCALCSIZE
- case WM_NCCALCSIZE : messageName = "WM_NCCALCSIZE"; break; //0x0083
- # endif
- # ifdef KIT_PM_WM_NCHITTEST
- case WM_NCHITTEST : messageName = "WM_NCHITTEST"; break; //0x0084
- # endif
- # ifdef KIT_PM_WM_NCPAINT
- case WM_NCPAINT : messageName = "WM_NCPAINT"; break; //0x0085
- # endif
- # ifdef KIT_PM_WM_NCACTIVATE
- case WM_NCACTIVATE : messageName = "WM_NCACTIVATE"; break; //0x0086
- # endif
- # ifdef KIT_PM_WM_GETDLGCODE
- case WM_GETDLGCODE : messageName = "WM_GETDLGCODE"; break; //0x0087
- # endif
- #ifndef _WIN32_WCE
- # ifdef KIT_PM_WM_SYNCPAINT
- case WM_SYNCPAINT : messageName = "WM_SYNCPAINT"; break; //0x0088
- # endif
- #endif
- # ifdef KIT_PM_WM_NCMOUSEMOVE
- case WM_NCMOUSEMOVE : messageName = "WM_NCMOUSEMOVE"; break; //0x00A0
- # endif
- # ifdef KIT_PM_WM_NCLBUTTONDOWN
- case WM_NCLBUTTONDOWN : messageName = "WM_NCLBUTTONDOWN"; break; //0x00A1
- # endif
- # ifdef KIT_PM_WM_NCLBUTTONUP
- case WM_NCLBUTTONUP : messageName = "WM_NCLBUTTONUP"; break; //0x00A2
- # endif
- # ifdef KIT_PM_WM_NCLBUTTONDBLCLK
- case WM_NCLBUTTONDBLCLK : messageName = "WM_NCLBUTTONDBLCLK"; break; //0x00A3
- # endif
- # ifdef KIT_PM_WM_NCRBUTTONDOWN
- case WM_NCRBUTTONDOWN : messageName = "WM_NCRBUTTONDOWN"; break; //0x00A4
- # endif
- # ifdef KIT_PM_WM_NCRBUTTONUP
- case WM_NCRBUTTONUP : messageName = "WM_NCRBUTTONUP"; break; //0x00A5
- # endif
- # ifdef KIT_PM_WM_NCRBUTTONDBLCLK
- case WM_NCRBUTTONDBLCLK : messageName = "WM_NCRBUTTONDBLCLK"; break; //0x00A6
- # endif
- # ifdef KIT_PM_WM_NCMBUTTONDOWN
- case WM_NCMBUTTONDOWN : messageName = "WM_NCMBUTTONDOWN"; break; //0x00A7
- # endif
- # ifdef KIT_PM_WM_NCMBUTTONUP
- case WM_NCMBUTTONUP : messageName = "WM_NCMBUTTONUP"; break; //0x00A8
- # endif
- # ifdef KIT_PM_WM_NCMBUTTONDBLCLK
- case WM_NCMBUTTONDBLCLK : messageName = "WM_NCMBUTTONDBLCLK"; break; //0x00A9
- # endif
- #if(_WIN32_WINNT >= 0x0500)
- # ifdef KIT_PM_WM_NCXBUTTONDOWN
- case WM_NCXBUTTONDOWN : messageName = "WM_NCXBUTTONDOWN"; break; //0x00AB
- # endif
- # ifdef KIT_PM_WM_NCXBUTTONUP
- case WM_NCXBUTTONUP : messageName = "WM_NCXBUTTONUP"; break; //0x00AC
- # endif
- # ifdef KIT_PM_WM_NCXBUTTONDBLCLK
- case WM_NCXBUTTONDBLCLK : messageName = "WM_NCXBUTTONDBLCLK"; break; //0x00AD
- # endif
- #endif /* _WIN32_WINNT >= 0x0500 */
- #if(_WIN32_WINNT >= 0x0501)
- # ifdef KIT_PM_WM_INPUT_DEVICE_CHANGE
- case WM_INPUT_DEVICE_CHANGE : messageName = "WM_INPUT_DEVICE_CHANGE"; break; //0x00FE
- # endif
- # ifdef KIT_PM_WM_INPUT
- case WM_INPUT : messageName = "WM_INPUT"; break; //0x00FF
- # endif
- #endif /* _WIN32_WINNT >= 0x0501 */
- # ifdef KIT_PM_WM_KEYDOWN
- case WM_KEYDOWN : messageName = "WM_KEYDOWN"; break; //0x0100
- # endif
- # ifdef KIT_PM_WM_KEYUP
- case WM_KEYUP : messageName = "WM_KEYUP"; break; //0x0101
- # endif
- # ifdef KIT_PM_WM_CHAR
- case WM_CHAR : messageName = "WM_CHAR"; break; //0x0102
- # endif
- # ifdef KIT_PM_WM_DEADCHAR
- case WM_DEADCHAR : messageName = "WM_DEADCHAR"; break; //0x0103
- # endif
- # ifdef KIT_PM_WM_SYSKEYDOWN
- case WM_SYSKEYDOWN : messageName = "WM_SYSKEYDOWN"; break; //0x0104
- # endif
- # ifdef KIT_PM_WM_SYSKEYUP
- case WM_SYSKEYUP : messageName = "WM_SYSKEYUP"; break; //0x0105
- # endif
- # ifdef KIT_PM_WM_SYSCHAR
- case WM_SYSCHAR : messageName = "WM_SYSCHAR"; break; //0x0106
- # endif
- # ifdef KIT_PM_WM_SYSDEADCHAR
- case WM_SYSDEADCHAR : messageName = "WM_SYSDEADCHAR"; break; //0x0107
- # endif
- #if(_WIN32_WINNT >= 0x0501)
- # ifdef KIT_PM_WM_UNICHAR
- case WM_UNICHAR : messageName = "WM_UNICHAR"; break; //0x0109
- # endif
- #endif /* _WIN32_WINNT >= 0x0501 */
- #if(WINVER >= 0x0400)
- # ifdef KIT_PM_WM_IME_STARTCOMPOSITION
- case WM_IME_STARTCOMPOSITION : messageName = "WM_IME_STARTCOMPOSITION"; break; //0x010D
- # endif
- # ifdef KIT_PM_WM_IME_ENDCOMPOSITION
- case WM_IME_ENDCOMPOSITION : messageName = "WM_IME_ENDCOMPOSITION"; break; //0x010E
- # endif
- # ifdef KIT_PM_WM_IME_COMPOSITION
- case WM_IME_COMPOSITION : messageName = "WM_IME_COMPOSITION"; break; //0x010F
- # endif
- #endif /* WINVER >= 0x0400 */
- # ifdef KIT_PM_WM_INITDIALOG
- case WM_INITDIALOG : messageName = "WM_INITDIALOG"; break; //0x0110
- # endif
- # ifdef KIT_PM_WM_COMMAND
- case WM_COMMAND : messageName = "WM_COMMAND"; break; //0x0111
- # endif
- # ifdef KIT_PM_WM_SYSCOMMAND
- case WM_SYSCOMMAND : messageName = "WM_SYSCOMMAND"; break; //0x0112
- # endif
- # ifdef KIT_PM_WM_TIMER
- case WM_TIMER : messageName = "WM_TIMER"; break; //0x0113
- # endif
- # ifdef KIT_PM_WM_HSCROLL
- case WM_HSCROLL : messageName = "WM_HSCROLL"; break; //0x0114
- # endif
- # ifdef KIT_PM_WM_VSCROLL
- case WM_VSCROLL : messageName = "WM_VSCROLL"; break; //0x0115
- # endif
- # ifdef KIT_PM_WM_INITMENU
- case WM_INITMENU : messageName = "WM_INITMENU"; break; //0x0116
- # endif
- # ifdef KIT_PM_WM_INITMENUPOPUP
- case WM_INITMENUPOPUP : messageName = "WM_INITMENUPOPUP"; break; //0x0117
- # endif
- #if(WINVER >= 0x0601)
- # ifdef KIT_PM_WM_GESTURE
- case WM_GESTURE : messageName = "WM_GESTURE"; break; //0x0119
- # endif
- # ifdef KIT_PM_WM_GESTURENOTIFY
- case WM_GESTURENOTIFY : messageName = "WM_GESTURENOTIFY"; break; //0x011A
- # endif
- #endif /* WINVER >= 0x0601 */
- # ifdef KIT_PM_WM_MENUSELECT
- case WM_MENUSELECT : messageName = "WM_MENUSELECT"; break; //0x011F
- # endif
- # ifdef KIT_PM_WM_MENUCHAR
- case WM_MENUCHAR : messageName = "WM_MENUCHAR"; break; //0x0120
- # endif
- # ifdef KIT_PM_WM_ENTERIDLE
- case WM_ENTERIDLE : messageName = "WM_ENTERIDLE"; break; //0x0121
- # endif
- /* WHY IS THIS SET UP THIS WAY! */
- #if(WINVER >= 0x0500)
- #ifndef _WIN32_WCE
- # ifdef KIT_PM_WM_MENURBUTTONUP
- case WM_MENURBUTTONUP : messageName = "WM_MENURBUTTONUP"; break; //0x0122
- # endif
- # ifdef KIT_PM_WM_MENUDRAG
- case WM_MENUDRAG : messageName = "WM_MENUDRAG"; break; //0x0123
- # endif
- # ifdef KIT_PM_WM_MENUGETOBJECT
- case WM_MENUGETOBJECT : messageName = "WM_MENUGETOBJECT"; break; //0x0124
- # endif
- # ifdef KIT_PM_WM_UNINITMENUPOPUP
- case WM_UNINITMENUPOPUP : messageName = "WM_UNINITMENUPOPUP"; break; //0x0125
- # endif
- # ifdef KIT_PM_WM_MENUCOMMAND
- case WM_MENUCOMMAND : messageName = "WM_MENUCOMMAND"; break; //0x0126
- # endif
- #ifndef _WIN32_WCE
- #if(_WIN32_WINNT >= 0x0500)
- # ifdef KIT_PM_WM_CHANGEUISTATE
- case WM_CHANGEUISTATE : messageName = "WM_CHANGEUISTATE"; break; //0x0127
- # endif
- # ifdef KIT_PM_WM_UPDATEUISTATE
- case WM_UPDATEUISTATE : messageName = "WM_UPDATEUISTATE"; break; //0x0128
- # endif
- # ifdef KIT_PM_WM_QUERYUISTATE
- case WM_QUERYUISTATE : messageName = "WM_QUERYUISTATE"; break; //0x0129
- # endif
- #endif /* _WIN32_WINNT >= 0x0500 */
- #endif
- #endif
- #endif /* WINVER >= 0x0500 */
- /* WHY IS THIS SET UP THIS WAY! */
- # ifdef KIT_PM_WM_CTLCOLORMSGBOX
- case WM_CTLCOLORMSGBOX : messageName = "WM_CTLCOLORMSGBOX"; break; //0x0132
- # endif
- # ifdef KIT_PM_WM_CTLCOLOREDIT
- case WM_CTLCOLOREDIT : messageName = "WM_CTLCOLOREDIT"; break; //0x0133
- # endif
- # ifdef KIT_PM_WM_CTLCOLORLISTBOX
- case WM_CTLCOLORLISTBOX : messageName = "WM_CTLCOLORLISTBOX"; break; //0x0134
- # endif
- # ifdef KIT_PM_WM_CTLCOLORBTN
- case WM_CTLCOLORBTN : messageName = "WM_CTLCOLORBTN"; break; //0x0135
- # endif
- # ifdef KIT_PM_WM_CTLCOLORDLG
- case WM_CTLCOLORDLG : messageName = "WM_CTLCOLORDLG"; break; //0x0136
- # endif
- # ifdef KIT_PM_WM_CTLCOLORSCROLLBAR
- case WM_CTLCOLORSCROLLBAR : messageName = "WM_CTLCOLORSCROLLBAR"; break; //0x0137
- # endif
- # ifdef KIT_PM_WM_CTLCOLORSTATIC
- case WM_CTLCOLORSTATIC : messageName = "WM_CTLCOLORSTATIC"; break; //0x0138
- # endif
- # ifdef KIT_PM_MN_GETHMENU
- case MN_GETHMENU : messageName = "MN_GETHMENU"; break; //0x01E1
- # endif
- # ifdef KIT_PM_WM_MOUSEMOVE
- case WM_MOUSEMOVE : messageName = "WM_MOUSEMOVE"; break; //0x0200
- # endif
- # ifdef KIT_PM_WM_LBUTTONDOWN
- case WM_LBUTTONDOWN : messageName = "WM_LBUTTONDOWN"; break; //0x0201
- # endif
- # ifdef KIT_PM_WM_LBUTTONUP
- case WM_LBUTTONUP : messageName = "WM_LBUTTONUP"; break; //0x0202
- # endif
- # ifdef KIT_PM_WM_LBUTTONDBLCLK
- case WM_LBUTTONDBLCLK : messageName = "WM_LBUTTONDBLCLK"; break; //0x0203
- # endif
- # ifdef KIT_PM_WM_RBUTTONDOWN
- case WM_RBUTTONDOWN : messageName = "WM_RBUTTONDOWN"; break; //0x0204
- # endif
- # ifdef KIT_PM_WM_RBUTTONUP
- case WM_RBUTTONUP : messageName = "WM_RBUTTONUP"; break; //0x0205
- # endif
- # ifdef KIT_PM_WM_RBUTTONDBLCLK
- case WM_RBUTTONDBLCLK : messageName = "WM_RBUTTONDBLCLK"; break; //0x0206
- # endif
- # ifdef KIT_PM_WM_MBUTTONDOWN
- case WM_MBUTTONDOWN : messageName = "WM_MBUTTONDOWN"; break; //0x0207
- # endif
- # ifdef KIT_PM_WM_MBUTTONUP
- case WM_MBUTTONUP : messageName = "WM_MBUTTONUP"; break; //0x0208
- # endif
- # ifdef KIT_PM_WM_MBUTTONDBLCLK
- case WM_MBUTTONDBLCLK : messageName = "WM_MBUTTONDBLCLK"; break; //0x0209
- # endif
- #if (_WIN32_WINNT >= 0x0400) || (_WIN32_WINDOWS > 0x0400)
- # ifdef KIT_PM_WM_MOUSEWHEEL
- case WM_MOUSEWHEEL : messageName = "WM_MOUSEWHEEL"; break; //0x020A
- # endif
- #endif
- #if (_WIN32_WINNT >= 0x0500)
- # ifdef KIT_PM_WM_XBUTTONDOWN
- case WM_XBUTTONDOWN : messageName = "WM_XBUTTONDOWN"; break; //0x020B
- # endif
- # ifdef KIT_PM_WM_XBUTTONUP
- case WM_XBUTTONUP : messageName = "WM_XBUTTONUP"; break; //0x020C
- # endif
- # ifdef KIT_PM_WM_XBUTTONDBLCLK
- case WM_XBUTTONDBLCLK : messageName = "WM_XBUTTONDBLCLK"; break; //0x020D
- # endif
- #endif
- # ifdef KIT_PM_WM_PARENTNOTIFY
- case WM_PARENTNOTIFY : messageName = "WM_PARENTNOTIFY"; break; //0x0210
- # endif
- # ifdef KIT_PM_WM_ENTERMENULOOP
- case WM_ENTERMENULOOP : messageName = "WM_ENTERMENULOOP"; break; //0x0211
- # endif
- # ifdef KIT_PM_WM_EXITMENULOOP
- case WM_EXITMENULOOP : messageName = "WM_EXITMENULOOP"; break; //0x0212
- # endif
- #if(WINVER >= 0x0400)
- # ifdef KIT_PM_WM_NEXTMENU
- case WM_NEXTMENU : messageName = "WM_NEXTMENU"; break; //0x0213
- # endif
- # ifdef KIT_PM_WM_SIZING
- case WM_SIZING : messageName = "WM_SIZING"; break; //0x0214
- # endif
- # ifdef KIT_PM_WM_CAPTURECHANGED
- case WM_CAPTURECHANGED : messageName = "WM_CAPTURECHANGED"; break; //0x0215
- # endif
- # ifdef KIT_PM_WM_MOVING
- case WM_MOVING : messageName = "WM_MOVING"; break; //0x0216
- # endif
- # ifdef KIT_PM_WM_POWERBROADCAST
- case WM_POWERBROADCAST : messageName = "WM_POWERBROADCAST"; break; //0x0218
- # endif
- # ifdef KIT_PM_WM_DEVICECHANGE
- case WM_DEVICECHANGE : messageName = "WM_DEVICECHANGE"; break; //0x0219
- # endif
- #endif /* WINVER >= 0x0400 */
- # ifdef KIT_PM_WM_MDICREATE
- case WM_MDICREATE : messageName = "WM_MDICREATE"; break; //0x0220
- # endif
- # ifdef KIT_PM_WM_MDIDESTROY
- case WM_MDIDESTROY : messageName = "WM_MDIDESTROY"; break; //0x0221
- # endif
- # ifdef KIT_PM_WM_MDIACTIVATE
- case WM_MDIACTIVATE : messageName = "WM_MDIACTIVATE"; break; //0x0222
- # endif
- # ifdef KIT_PM_WM_MDIRESTORE
- case WM_MDIRESTORE : messageName = "WM_MDIRESTORE"; break; //0x0223
- # endif
- # ifdef KIT_PM_WM_MDINEXT
- case WM_MDINEXT : messageName = "WM_MDINEXT"; break; //0x0224
- # endif
- # ifdef KIT_PM_WM_MDIMAXIMIZE
- case WM_MDIMAXIMIZE : messageName = "WM_MDIMAXIMIZE"; break; //0x0225
- # endif
- # ifdef KIT_PM_WM_MDITILE
- case WM_MDITILE : messageName = "WM_MDITILE"; break; //0x0226
- # endif
- # ifdef KIT_PM_WM_MDICASCADE
- case WM_MDICASCADE : messageName = "WM_MDICASCADE"; break; //0x0227
- # endif
- # ifdef KIT_PM_WM_MDIICONARRANGE
- case WM_MDIICONARRANGE : messageName = "WM_MDIICONARRANGE"; break; //0x0228
- # endif
- # ifdef KIT_PM_WM_MDIGETACTIVE
- case WM_MDIGETACTIVE : messageName = "WM_MDIGETACTIVE"; break; //0x0229
- # endif
- # ifdef KIT_PM_WM_MDISETMENU
- case WM_MDISETMENU : messageName = "WM_MDISETMENU"; break; //0x0230
- # endif
- # ifdef KIT_PM_WM_ENTERSIZEMOVE
- case WM_ENTERSIZEMOVE : messageName = "WM_ENTERSIZEMOVE"; break; //0x0231
- # endif
- # ifdef KIT_PM_WM_EXITSIZEMOVE
- case WM_EXITSIZEMOVE : messageName = "WM_EXITSIZEMOVE"; break; //0x0232
- # endif
- # ifdef KIT_PM_WM_DROPFILES
- case WM_DROPFILES : messageName = "WM_DROPFILES"; break; //0x0233
- # endif
- # ifdef KIT_PM_WM_MDIREFRESHMENU
- case WM_MDIREFRESHMENU : messageName = "WM_MDIREFRESHMENU"; break; //0x0234
- # endif
- #if(WINVER >= 0x0602)
- # ifdef KIT_PM_WM_POINTERDEVICECHANGE
- case WM_POINTERDEVICECHANGE : messageName = "WM_POINTERDEVICECHANGE"; break; //0x0238
- # endif
- # ifdef KIT_PM_WM_POINTERDEVICEINRANGE
- case WM_POINTERDEVICEINRANGE : messageName = "WM_POINTERDEVICEINRANGE"; break; //0x0239
- # endif
- # ifdef KIT_PM_WM_POINTERDEVICEOUTOFRANGE
- case WM_POINTERDEVICEOUTOFRANGE : messageName = "WM_POINTERDEVICEOUTOFRANGE"; break; //0x023A
- # endif
- #endif /* WINVER >= 0x0602 */
- #if(WINVER >= 0x0601)
- # ifdef KIT_PM_WM_TOUCH
- case WM_TOUCH : messageName = "WM_TOUCH"; break; //0x0240
- # endif
- #endif /* WINVER >= 0x0601 */
- #if(WINVER >= 0x0602)
- # ifdef KIT_PM_WM_NCPOINTERUPDATE
- case WM_NCPOINTERUPDATE : messageName = "WM_NCPOINTERUPDATE"; break; //0x0241
- # endif
- # ifdef KIT_PM_WM_NCPOINTERDOWN
- case WM_NCPOINTERDOWN : messageName = "WM_NCPOINTERDOWN"; break; //0x0242
- # endif
- # ifdef KIT_PM_WM_NCPOINTERUP
- case WM_NCPOINTERUP : messageName = "WM_NCPOINTERUP"; break; //0x0243
- # endif
- # ifdef KIT_PM_WM_POINTERUPDATE
- case WM_POINTERUPDATE : messageName = "WM_POINTERUPDATE"; break; //0x0245
- # endif
- # ifdef KIT_PM_WM_POINTERDOWN
- case WM_POINTERDOWN : messageName = "WM_POINTERDOWN"; break; //0x0246
- # endif
- # ifdef KIT_PM_WM_POINTERUP
- case WM_POINTERUP : messageName = "WM_POINTERUP"; break; //0x0247
- # endif
- # ifdef KIT_PM_WM_POINTERENTER
- case WM_POINTERENTER : messageName = "WM_POINTERENTER"; break; //0x0249
- # endif
- # ifdef KIT_PM_WM_POINTERLEAVE
- case WM_POINTERLEAVE : messageName = "WM_POINTERLEAVE"; break; //0x024A
- # endif
- # ifdef KIT_PM_WM_POINTERACTIVATE
- case WM_POINTERACTIVATE : messageName = "WM_POINTERACTIVATE"; break; //0x024B
- # endif
- # ifdef KIT_PM_WM_POINTERCAPTURECHANGED
- case WM_POINTERCAPTURECHANGED : messageName = "WM_POINTERCAPTURECHANGED"; break; //0x024C
- # endif
- # ifdef KIT_PM_WM_TOUCHHITTESTING
- case WM_TOUCHHITTESTING : messageName = "WM_TOUCHHITTESTING"; break; //0x024D
- # endif
- # ifdef KIT_PM_WM_POINTERWHEEL
- case WM_POINTERWHEEL : messageName = "WM_POINTERWHEEL"; break; //0x024E
- # endif
- # ifdef KIT_PM_WM_POINTERHWHEEL
- case WM_POINTERHWHEEL : messageName = "WM_POINTERHWHEEL"; break; //0x024F
- # endif
- # ifdef KIT_PM_DM_POINTERHITTEST
- case DM_POINTERHITTEST : messageName = "DM_POINTERHITTEST"; break; //0x0250
- # endif
- # ifdef KIT_PM_WM_POINTERROUTEDTO
- case WM_POINTERROUTEDTO : messageName = "WM_POINTERROUTEDTO"; break; //0x0251
- # endif
- # ifdef KIT_PM_WM_POINTERROUTEDAWAY
- case WM_POINTERROUTEDAWAY : messageName = "WM_POINTERROUTEDAWAY"; break; //0x0252
- # endif
- # ifdef KIT_PM_WM_POINTERROUTEDRELEASED2
- case WM_POINTERROUTEDRELEASED : messageName = "WM_POINTERROUTEDRELEASED"; break; //0x0253
- # endif
- #endif /* WINVER >= 0x0602 */
- #if(WINVER >= 0x0400)
- # ifdef KIT_PM_WM_IME_SETCONTEXT
- case WM_IME_SETCONTEXT : messageName = "WM_IME_SETCONTEXT"; break; //0x0281
- # endif
- # ifdef KIT_PM_WM_IME_NOTIFY
- case WM_IME_NOTIFY : messageName = "WM_IME_NOTIFY"; break; //0x0282
- # endif
- # ifdef KIT_PM_WM_IME_CONTROL
- case WM_IME_CONTROL : messageName = "WM_IME_CONTROL"; break; //0x0283
- # endif
- # ifdef KIT_PM_WM_IME_COMPOSITIONFULL
- case WM_IME_COMPOSITIONFULL : messageName = "WM_IME_COMPOSITIONFULL"; break; //0x0284
- # endif
- # ifdef KIT_PM_WM_IME_SELECT
- case WM_IME_SELECT : messageName = "WM_IME_SELECT"; break; //0x0285
- # endif
- # ifdef KIT_PM_WM_IME_CHAR
- case WM_IME_CHAR : messageName = "WM_IME_CHAR"; break; //0x0286
- # endif
- #endif /* WINVER >= 0x0400 */
- #if(WINVER >= 0x0500)
- # ifdef KIT_PM_WM_IME_REQUEST
- case WM_IME_REQUEST : messageName = "WM_IME_REQUEST"; break; //0x0288
- # endif
- #endif /* WINVER >= 0x0500 */
- #if(WINVER >= 0x0400)
- # ifdef KIT_PM_WM_IME_KEYDOWN
- case WM_IME_KEYDOWN : messageName = "WM_IME_KEYDOWN"; break; //0x0290
- # endif
- # ifdef KIT_PM_WM_IME_KEYUP
- case WM_IME_KEYUP : messageName = "WM_IME_KEYUP"; break; //0x0291
- # endif
- #endif /* WINVER >= 0x0400 */
- #if((_WIN32_WINNT >= 0x0400) || (WINVER >= 0x0500))
- # ifdef KIT_PM_WM_MOUSEHOVER
- case WM_MOUSEHOVER : messageName = "WM_MOUSEHOVER"; break; //0x02A1
- # endif
- # ifdef KIT_PM_WM_MOUSELEAVE
- case WM_MOUSELEAVE : messageName = "WM_MOUSELEAVE"; break; //0x02A3
- # endif
- #endif
- #if(WINVER >= 0x0500)
- # ifdef KIT_PM_WM_NCMOUSEHOVER
- case WM_NCMOUSEHOVER : messageName = "WM_NCMOUSEHOVER"; break; //0x02A0
- # endif
- # ifdef KIT_PM_WM_NCMOUSELEAVE
- case WM_NCMOUSELEAVE : messageName = "WM_NCMOUSELEAVE"; break; //0x02A2
- # endif
- #endif /* WINVER >= 0x0500 */
- #if(_WIN32_WINNT >= 0x0501)
- # ifdef KIT_PM_WM_WTSSESSION_CHANGE
- case WM_WTSSESSION_CHANGE : messageName = "WM_WTSSESSION_CHANGE"; break; //0x02B1
- # endif
- #endif /* _WIN32_WINNT >= 0x0501 */
- #if(WINVER >= 0x0601)
- # ifdef KIT_PM_WM_DPICHANGED
- case WM_DPICHANGED : messageName = "WM_DPICHANGED"; break; //0x02E0
- # endif
- #endif /* WINVER >= 0x0601 */
- #if(WINVER >= 0x0605)
- # ifdef KIT_PM_WM_DPICHANGED_BEFOREPARENT
- case WM_DPICHANGED_BEFOREPARENT : messageName = "WM_DPICHANGED_BEFOREPARENT"; break; //0x02E2
- # endif
- # ifdef KIT_PM_WM_DPICHANGED_AFTERPARENT
- case WM_DPICHANGED_AFTERPARENT : messageName = "WM_DPICHANGED_AFTERPARENT"; break; //0x02E3
- # endif
- # ifdef KIT_PM_WM_GETDPISCALEDSIZE
- case WM_GETDPISCALEDSIZE : messageName = "WM_GETDPISCALEDSIZE"; break; //0x02E4
- # endif
- #endif /* WINVER >= 0x0605 */
- # ifdef KIT_PM_WM_CUT
- case WM_CUT : messageName = "WM_CUT"; break; //0x0300
- # endif
- # ifdef KIT_PM_WM_COPY
- case WM_COPY : messageName = "WM_COPY"; break; //0x0301
- # endif
- # ifdef KIT_PM_WM_PASTE
- case WM_PASTE : messageName = "WM_PASTE"; break; //0x0302
- # endif
- # ifdef KIT_PM_WM_CLEAR
- case WM_CLEAR : messageName = "WM_CLEAR"; break; //0x0303
- # endif
- # ifdef KIT_PM_WM_UNDO
- case WM_UNDO : messageName = "WM_UNDO"; break; //0x0304
- # endif
- # ifdef KIT_PM_WM_RENDERFORMAT
- case WM_RENDERFORMAT : messageName = "WM_RENDERFORMAT"; break; //0x0305
- # endif
- # ifdef KIT_PM_WM_RENDERALLFORMATS
- case WM_RENDERALLFORMATS : messageName = "WM_RENDERALLFORMATS"; break; //0x0306
- # endif
- # ifdef KIT_PM_WM_DESTROYCLIPBOARD
- case WM_DESTROYCLIPBOARD : messageName = "WM_DESTROYCLIPBOARD"; break; //0x0307
- # endif
- # ifdef KIT_PM_WM_DRAWCLIPBOARD
- case WM_DRAWCLIPBOARD : messageName = "WM_DRAWCLIPBOARD"; break; //0x0308
- # endif
- # ifdef KIT_PM_WM_PAINTCLIPBOARD
- case WM_PAINTCLIPBOARD : messageName = "WM_PAINTCLIPBOARD"; break; //0x0309
- # endif
- # ifdef KIT_PM_WM_VSCROLLCLIPBOARD
- case WM_VSCROLLCLIPBOARD : messageName = "WM_VSCROLLCLIPBOARD"; break; //0x030A
- # endif
- # ifdef KIT_PM_WM_SIZECLIPBOARD
- case WM_SIZECLIPBOARD : messageName = "WM_SIZECLIPBOARD"; break; //0x030B
- # endif
- # ifdef KIT_PM_WM_ASKCBFORMATNAME
- case WM_ASKCBFORMATNAME : messageName = "WM_ASKCBFORMATNAME"; break; //0x030C
- # endif
- # ifdef KIT_PM_WM_CHANGECBCHAIN
- case WM_CHANGECBCHAIN : messageName = "WM_CHANGECBCHAIN"; break; //0x030D
- # endif
- # ifdef KIT_PM_WM_HSCROLLCLIPBOARD
- case WM_HSCROLLCLIPBOARD : messageName = "WM_HSCROLLCLIPBOARD"; break; //0x030E
- # endif
- # ifdef KIT_PM_WM_QUERYNEWPALETTE
- case WM_QUERYNEWPALETTE : messageName = "WM_QUERYNEWPALETTE"; break; //0x030F
- # endif
- # ifdef KIT_PM_WM_PALETTEISCHANGING
- case WM_PALETTEISCHANGING : messageName = "WM_PALETTEISCHANGING"; break; //0x0310
- # endif
- # ifdef KIT_PM_WM_PALETTECHANGED
- case WM_PALETTECHANGED : messageName = "WM_PALETTECHANGED"; break; //0x0311
- # endif
- # ifdef KIT_PM_WM_HOTKEY
- case WM_HOTKEY : messageName = "WM_HOTKEY"; break; //0x0312
- # endif
- #if(WINVER >= 0x0400)
- # ifdef KIT_PM_WM_PRINT
- case WM_PRINT : messageName = "WM_PRINT"; break; //0x0317
- # endif
- # ifdef KIT_PM_WM_PRINTCLIENT
- case WM_PRINTCLIENT : messageName = "WM_PRINTCLIENT"; break; //0x0318
- # endif
- #endif /* WINVER >= 0x0400 */
- #if(_WIN32_WINNT >= 0x0500)
- # ifdef KIT_PM_WM_APPCOMMAND
- case WM_APPCOMMAND : messageName = "WM_APPCOMMAND"; break; //0x0319
- # endif
- #endif /* _WIN32_WINNT >= 0x0500 */
- #if(_WIN32_WINNT >= 0x0501)
- # ifdef KIT_PM_WM_THEMECHANGED
- case WM_THEMECHANGED : messageName = "WM_THEMECHANGED"; break; //0x031A
- # endif
- #endif /* _WIN32_WINNT >= 0x0501 */
- #if(_WIN32_WINNT >= 0x0501)
- # ifdef KIT_PM_WM_CLIPBOARDUPDATE
- case WM_CLIPBOARDUPDATE : messageName = "WM_CLIPBOARDUPDATE"; break; //0x031D
- # endif
- #endif /* _WIN32_WINNT >= 0x0501 */
- #if(_WIN32_WINNT >= 0x0600)
- # ifdef KIT_PM_WM_DWMCOMPOSITIONCHANGED
- case WM_DWMCOMPOSITIONCHANGED : messageName = "WM_DWMCOMPOSITIONCHANGED"; break; //0x031E
- # endif
- # ifdef KIT_PM_WM_DWMNCRENDERINGCHANGED
- case WM_DWMNCRENDERINGCHANGED : messageName = "WM_DWMNCRENDERINGCHANGED"; break; //0x031F
- # endif
- # ifdef KIT_PM_WM_DWMCOLORIZATIONCOLORCHANGED
- case WM_DWMCOLORIZATIONCOLORCHANGED : messageName = "WM_DWMCOLORIZATIONCOLORCHANGED"; break; //0x0320
- # endif
- # ifdef KIT_PM_WM_DWMWINDOWMAXIMIZEDCHANGE
- case WM_DWMWINDOWMAXIMIZEDCHANGE : messageName = "WM_DWMWINDOWMAXIMIZEDCHANGE"; break; //0x0321
- # endif
- #endif /* _WIN32_WINNT >= 0x0600 */
- #if(_WIN32_WINNT >= 0x0601)
- # ifdef KIT_PM_WM_DWMSENDICONICTHUMBNAIL
- case WM_DWMSENDICONICTHUMBNAIL : messageName = "WM_DWMSENDICONICTHUMBNAIL"; break; //0x0323
- # endif
- # ifdef KIT_PM_WM_DWMSENDICONICLIVEPREVIEWBITMAP
- case WM_DWMSENDICONICLIVEPREVIEWBITMAP: messageName = "WM_DWMSENDICONICLIVEPREVIEWBITMAP"; break; //0x0326
- # endif
- #endif /* _WIN32_WINNT >= 0x0601 */
- #if(WINVER >= 0x0600)
- # ifdef KIT_PM_WM_GETTITLEBARINFOEX
- case WM_GETTITLEBARINFOEX : messageName = "WM_GETTITLEBARINFOEX"; break; //0x033F
- # endif
- #endif /* WINVER >= 0x0600 */
- default:;
- # ifdef KIT_PM_WM_UNKNOWN
- messageName = "(unknown)";
- # endif
- }
- if(messageName != nullptr){
- printf("hwnd=%p, wParam=0x%08X, lParam=%p, msg={ 0x%04X \"%s\" }\n",
- hwnd, (u32)wParam, (void*)lParam, message, messageName);
- }
- }
- #endif /* _DEBUG */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Window\kit_WindowProc.cpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Window\kit_Window.cpp */
- #include <kit/_video/Window.hpp>
- #include "_kit_Window.hpp"
- #include <kit/_video/Bitmap.hpp>
- #include "../Bitmap/_kit_Bitmap.hpp"
- #include <string.h> //for strncpy_s
- #define KIT_INVALID_WINDOW _kit_invalid_window
- namespace kit {
- static const char _kit_invalid_window[] = "invalid window";
- namespace w32 {
- size_t winCount = 0; //number of existing kit::Window instances
- const char winClassName[] = "kit::Window Class";
- WNDCLASSEXA winClass;
- ATOM winClassAtom;
- };
- Window::Window(const char* windowTitle,
- u32 windowWidth, u32 windowHeight,
- u32 windowFlags,
- s32 windowX, s32 windowY,
- u32 canvasWidth, u32 canvasHeight)
- {
- _type = KIT_CLASSTYPE_WINDOW;
- _opaque = new _WindowOpaque;
- char* errorText = nullptr;
- if(0){ //this code block is only entered via goto in the event of an exception
- //_DestroyWindow : DestroyWindow(_opaque->winHandle);
- _DeleteDC : DeleteDC(_opaque->canvasDevCtx);
- _UnregisterClass: if(w32::winCount == 0) UnregisterClassA(w32::winClassName, w32::hThisInst);
- _DelCritSection : DeleteCriticalSection(&_opaque->lock);
- throw (const char*)errorText;
- }
- //window title
- if(windowTitle != nullptr){
- if( strncpy_s(_title, 256, windowTitle, 255) )
- throw "windowTitle failed to copy";
- _title[255] = 0; //just in case
- } else {
- _title[0] = 0;
- }
- //window size
- s32 screenWidth = GetSystemMetrics(SM_CXSCREEN);
- s32 screenHeight = GetSystemMetrics(SM_CYSCREEN);
- if(!windowWidth ) windowWidth = screenWidth;
- if(!windowHeight) windowHeight = screenHeight;
- //canvas size
- if(canvasWidth > windowWidth ) throw "canvasWidth > windowWidth";
- if(canvasHeight > windowHeight) throw "canvasHeight > windowHeight";
- if(!canvasWidth ) canvasWidth = windowWidth;
- if(!canvasHeight) canvasHeight = windowHeight;
- _opaque->canvasSize.x = canvasWidth;
- _opaque->canvasSize.y = canvasHeight;
- _opaque->canvasStretchMode = KIT_INITIAL_STRETCH_MODE;
- _opaque->canvasStretch = (canvasWidth<windowWidth || canvasHeight<windowHeight);
- //initialize mutex
- InitializeCriticalSectionAndSpinCount(&_opaque->lock, KIT_LOCK_SPINCOUNT);
- //create and register window class (only if no other windows are present)
- if(w32::winCount == 0){
- w32::winClass.cbSize = sizeof(WNDCLASSEX);
- w32::winClass.style = 0;
- w32::winClass.lpfnWndProc = w32::WindowProc;
- w32::winClass.cbClsExtra = 0;
- w32::winClass.cbWndExtra = 0;
- w32::winClass.hInstance = w32::hThisInst;
- w32::winClass.hIcon = nullptr;
- w32::winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- w32::winClass.hbrBackground = nullptr;
- w32::winClass.lpszMenuName = nullptr;
- w32::winClass.lpszClassName = w32::winClassName;
- w32::winClass.hIconSm = nullptr; //(the window's small icon)
- w32::winClassAtom = RegisterClassExA(&w32::winClass);
- if(!w32::winClassAtom){
- errorText = "RegisterClassA() failed";
- goto _DelCritSection;
- }
- }
- //create canvas info
- _opaque->canvasInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- _opaque->canvasInfo.bmiHeader.biWidth = canvasWidth;
- _opaque->canvasInfo.bmiHeader.biHeight = canvasHeight;
- _opaque->canvasInfo.bmiHeader.biPlanes = 1; //should always be 1
- _opaque->canvasInfo.bmiHeader.biBitCount = 32; //for 0x--RRGGBB
- _opaque->canvasInfo.bmiHeader.biCompression = BI_RGB; //uncompressed rgb
- _opaque->canvas = nullptr;
- _opaque->canvasDevCtx = CreateCompatibleDC(nullptr);
- if(_opaque->canvasDevCtx == nullptr){
- errorText = "CreateCompatibleDC() failed";
- goto _UnregisterClass;
- }
- //pre-creation window flag handling
- DWORD _windowFlags = WS_OVERLAPPEDWINDOW; //will be hidden initially
- DWORD _windowFlagsEx = 0;
- //if(windowFlags & KIT_WINFLAG_FULLSCREEN); //tbd
- if(windowFlags & WINFLAG_BORDERLESS){
- windowFlags &= ~WINFLAG_RESIZABLE;
- //_windowFlags |= WS_POPUP;
- //_windowFlags &= ~WS_CAPTION;
- //_windowFlags &= ~WS_SYSMENU;
- }
- if(!(windowFlags & WINFLAG_RESIZABLE)){
- _windowFlags &= ~WS_THICKFRAME;
- }
- if(windowFlags & WINFLAG_MINIMIZED) _windowFlags |= WS_MINIMIZE;
- if(windowFlags & WINFLAG_MAXIMIZED) _windowFlags |= WS_MAXIMIZE;
- //create window
- shape::point winSize = CalculateWindowSize(windowWidth, windowHeight,
- _windowFlags, _windowFlagsEx);
- _opaque->winHandle = CreateWindowExA(_windowFlagsEx, w32::winClassName, _title,
- _windowFlags, windowX, windowY, winSize.x, winSize.y,
- nullptr, nullptr, w32::hThisInst, (LPVOID)this);
- if(_opaque->winHandle == nullptr){
- errorText = "CreateWindowA() failed";
- goto _DeleteDC;
- }
- //window position
- RECT winRectTmp;
- GetWindowRect(_opaque->winHandle, &winRectTmp); //get window's bounding box
- _opaque->winRect = ConvertToKitRect(winRectTmp);
- shape::point centerPos;
- centerPos.x = screenWidth /2 - _opaque->winRect.w/2;
- centerPos.y = screenHeight/2 - _opaque->winRect.h/2;
- if( windowX == WINPOS_UNDEFINED) windowX = CW_USEDEFAULT;
- else if(windowX == WINPOS_CENTERED ) windowX = centerPos.x;
- if( windowY == WINPOS_UNDEFINED) windowY = CW_USEDEFAULT;
- else if(windowY == WINPOS_CENTERED ) windowY = centerPos.y;
- SetWindowPos(_opaque->winHandle, nullptr, windowX,windowY,
- 0,0, SWP_NOZORDER | SWP_NOSIZE);
- GetWindowRect(_opaque->winHandle, &winRectTmp); //get window's bounding box
- _opaque->winRect = ConvertToKitRect(winRectTmp);
- //post-creation window flag handling
- //SetWindowLong(_opaque->winHandle, GWL_STYLE, WS_POPUP);
- if(!(windowFlags & WINFLAG_HIDDEN)) ShowWindow(_opaque->winHandle, SW_SHOW);
- if( windowFlags & WINFLAG_FOCUS ) SetFocus(_opaque->winHandle);
- _opaque->winDestroyed = false;
- ++w32::winCount; //add window to total count
- _valid = true;
- _constructing = false;
- }
- Window::~Window(){
- if(!_valid) return;
- _valid = false;
- --w32::winCount; //remove window from total count
- if(_opaque != nullptr){
- DestroyWindow(_opaque->winHandle);
- DeleteDC(_opaque->canvasDevCtx);
- if(w32::winCount == 0) UnregisterClassA(w32::winClassName, w32::hThisInst);
- DeleteCriticalSection(&_opaque->lock);
- delete _opaque;
- _opaque = nullptr;
- }
- }
- bool Window::isDestroyed(){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- return _opaque->winDestroyed; //set by w32::WindowProc, rather than destructor
- }
- shape::rect Window::getWindowRect(){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- return _opaque->winRect;
- }
- shape::point Window::getCanvasSize(){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- return _opaque->canvasSize;
- }
- color::ARGB* Window::getPixels(){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- return _opaque->canvasPixels;
- }
- bool Window::pollEvent(WindowEvent* event_p){
- MSG message;
- if(PeekMessage(&message, NULL, 0, 0, PM_REMOVE)){
- TranslateMessage(&message);
- DispatchMessage(&message);
- return true;
- } else {
- return false;
- }
- }
- void Window::lock(bool locked){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- if(locked) EnterCriticalSection(&_opaque->lock);
- else LeaveCriticalSection(&_opaque->lock);
- }
- void Window::present(){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- InvalidateRect(_opaque->winHandle, nullptr, false);
- UpdateWindow(_opaque->winHandle);
- }
- void Window::clear(color::ARGB color){
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- HBRUSH brushHandle = CreateSolidBrush(color.v);
- if(brushHandle != nullptr){
- SelectObject(_opaque->canvasDevCtx, brushHandle);
- RECT rectF;
- rectF.left = 0;
- rectF.top = 0;
- rectF.right = _opaque->canvasSize.x;
- rectF.bottom = _opaque->canvasSize.y;
- FillRect(_opaque->canvasDevCtx, &rectF, brushHandle);
- DeleteObject(brushHandle);
- }
- }
- void Window::tblitns(Bitmap* bmp, s32 x, s32 y,
- color::ARGB transparency)
- {
- if(!_valid && !_constructing) throw KIT_INVALID_WINDOW;
- if(bmp->getType() != KIT_CLASSTYPE_BITMAP) throw "bmp is not a Bitmap";
- _BitmapOpaque* bmpOpaque = bmp->_accessOpaque();
- TransparentBlt(_opaque->canvasDevCtx, x, y,
- bmpOpaque->bmpSize.x,
- bmpOpaque->bmpSize.y,
- bmpOpaque->bmpDevCtx, 0, 0,
- bmpOpaque->bmpSize.x,
- bmpOpaque->bmpSize.y,
- transparency.v);
- }
- }; /* namespace kit */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Window\kit_Window.cpp */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Bitmap\kit_Bitmap.cpp */
- #include <kit/_video/Bitmap.hpp>
- #include "_kit_Bitmap.hpp"
- #include <string.h> //for memcpy
- #define KIT_INVALID_BITMAP _kit_invalid_bitmap
- namespace kit {
- static const char _kit_invalid_bitmap[] = "invalid bitmap";
- //loads from memory
- Bitmap::Bitmap(const color::ARGB* pixelData,
- u32 width, u32 height,
- bool directAccess)
- {
- _type = KIT_CLASSTYPE_BITMAP;
- _opaque = new _BitmapOpaque;
- char* errorText = nullptr;
- if(0){ //this code block is only entered via goto in the event of an exception
- _DeleteDC: DeleteDC(_opaque->bmpDevCtx);
- throw (const char*)errorText;
- }
- //verify parameters
- if(!width ) throw "width = 0";
- if(!height) throw "height = 0";
- _opaque->bmpSize.x = width;
- _opaque->bmpSize.y = height;
- _opaque->bmpDirectAccess = directAccess;
- //create the bitmap's device context (for rendering directly to the bitmap)
- _opaque->bmpDevCtx = CreateCompatibleDC(nullptr);
- if(_opaque->bmpDevCtx == nullptr) throw "CreateCompatibleDC() failed";
- //fill in bitmap info
- _opaque->bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- _opaque->bmpInfo.bmiHeader.biWidth = width;
- _opaque->bmpInfo.bmiHeader.biHeight = height;
- _opaque->bmpInfo.bmiHeader.biPlanes = 1; //should always be 1
- _opaque->bmpInfo.bmiHeader.biBitCount = 32; //for 0x--RRGGBB
- _opaque->bmpInfo.bmiHeader.biCompression = BI_RGB; //uncompressed rgb
- //create the actual bitmap object
- if(directAccess){
- _opaque->bmp = CreateDIBSection(nullptr, &_opaque->bmpInfo, DIB_RGB_COLORS,
- (void**)&_opaque->bmpPixels, nullptr, 0);
- if(pixelData != nullptr){ //copy pixel data if not null
- memcpy(_opaque->bmpPixels, pixelData, sizeof(color::ARGB)*width*height);
- }
- } else {
- //tbd
- }
- if(_opaque->bmp != nullptr){
- SelectObject(_opaque->bmpDevCtx, _opaque->bmp);
- SetStretchBltMode(_opaque->bmpDevCtx, KIT_INITIAL_STRETCH_MODE);
- _opaque->bmpStretchMode = KIT_INITIAL_STRETCH_MODE;
- } else {
- errorText = "failed to create bitmap object";
- goto _DeleteDC;
- }
- _valid = true;
- }
- Bitmap::~Bitmap(){
- if(!_valid) return;
- _valid = false;
- if(_opaque != nullptr){
- DeleteObject(_opaque->bmp);
- DeleteDC(_opaque->bmpDevCtx);
- delete _opaque;
- _opaque = nullptr;
- }
- }
- }; /* namespace kit */
- /* D:\Media\ToolProj\_C++\projects\win32_2\w32_2\src\kit_win32\Bitmap\kit_Bitmap.cpp */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement