Import
This commit is contained in:
@@ -0,0 +1,381 @@
|
||||
#include "c_WinGUI.h"
|
||||
#include "c_WinGuiUtil.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <c_WinApp.h>
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
#define MAIN_WINDOW_CLASSNAME "KeyMouse"
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
#define DIRECTION_SIZE 100
|
||||
|
||||
static char Directions[DIRECTION_SIZE];
|
||||
static int xVal = 10;
|
||||
static int yVal = 30;
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_CREATE, KeyMouse_OnCreate){
|
||||
c_WinGuiUtil_MoveWindowToScreenCenter(hwnd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_DESTROY, KeyMouse_OnDestroy){
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_PAINT, KeyMouse_OnPaint){
|
||||
PAINTSTRUCT PaintStruct;
|
||||
RECT Rect;
|
||||
HDC hdc = BeginPaint(hwnd, &PaintStruct);
|
||||
static char* Message[]={
|
||||
"WM_CHAR",
|
||||
"WM_KEY",
|
||||
"WM_SYSKEY",
|
||||
"WM_MOUSEMOVE",
|
||||
"WM_MOUSEDOWN",
|
||||
"WM_MOUSEUP",
|
||||
};
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
HFONT OldFont = SelectFont(hdc, GetStockObject(OEM_FIXED_FONT));
|
||||
GetClientRect(hwnd, &Rect);
|
||||
DrawText(hdc, "MOUSE AND KEYBOARD DEMONSTRATION", -1, &Rect, DT_CENTER);
|
||||
Rect.top = 20;
|
||||
Rect.bottom = 40;
|
||||
DrawText(hdc, "(Try experimenting with mouse and keyboard)", -1, &Rect, DT_CENTER);
|
||||
SelectFont(hdc, OldFont);
|
||||
for(int i=0; i<sizeof(Message)/sizeof(Message[0]); i++){
|
||||
TextOut(hdc, xVal, yVal + (20 * (i+1)), Message[i], strlen(Message[i]));
|
||||
}
|
||||
EndPaint(hwnd, &PaintStruct);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_CHAR, KeyMouse_OnChar){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size = snprintf(s, sizeof(s)/sizeof(s[0]), "WM_CHAR ==> Ch = %c, cRepeat = %d "
|
||||
, ch
|
||||
, cRepeat);
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 20, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_KEYDOWN, KeyMouse_OnKey){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
if(fBool){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_KEYDOWN ==> vk = %c, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags
|
||||
);
|
||||
}else{
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_KEYUP ==> vk = %c, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags
|
||||
);
|
||||
}
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 40, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_SYSKEYDOWN, KeyMouse_OnSysKey){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size = 0;
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
if(fBool){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_SYSKEYDOWN ==> vk = %d, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags);
|
||||
|
||||
TextOut(hdc, xVal, yVal + 60, s, size);
|
||||
FORWARD_WM_SYSKEYDOWN(hwnd, vk, cRepeat, flags, DefWindowProc);
|
||||
}else{
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_SYSKEYUP ==> vk = %d, fDown = %d, cRepeat = %d, flags = %d "
|
||||
, vk
|
||||
, fBool
|
||||
, cRepeat
|
||||
, flags);
|
||||
|
||||
TextOut(hdc, xVal, yVal + 60, s, size);
|
||||
FORWARD_WM_SYSKEYUP(hwnd, vk, cRepeat, flags, DefWindowProc);
|
||||
}
|
||||
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_LBUTTONDOWN, KeyMouse_OnLButtonDown){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
if(fDoubleClick){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_LBUTTONDBLCLK ==> Db = %d, x = %d, y = %d, flags = %d "
|
||||
, fDoubleClick
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
}else{
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_LBUTTONDOWN ==> Db = %d, x = %d, y = %d, flags = %d "
|
||||
, fDoubleClick
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
}
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 100, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_LBUTTONUP, KeyMouse_OnLButtonUp){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_LBUTTONUP ==> x = %d, y = %d, flags = %d "
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 120, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_MOUSEMOVE, KeyMouse_OnMouseMove){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_MOUSEMOVE ==> x = %d, y = %d, flags = %d "
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
|
||||
if((keyFlags & MK_CONTROL) == MK_CONTROL){
|
||||
SetTextColor(hdc, RGB(0, 0, 255));
|
||||
}
|
||||
if((keyFlags & MK_LBUTTON) == MK_LBUTTON){
|
||||
SetTextColor(hdc, RGB(0, 255, 0));
|
||||
}
|
||||
if((keyFlags & MK_RBUTTON) == MK_RBUTTON){
|
||||
SetTextColor(hdc, RGB(255, 0, 0));
|
||||
}
|
||||
if((keyFlags & MK_SHIFT) == MK_SHIFT){
|
||||
SetTextColor(hdc, RGB(255, 0, 255));
|
||||
}
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 80, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_RBUTTONDOWN, KeyMouse_OnRButtonDown)
|
||||
{
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
if(fDoubleClick){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_RBUTTONDBLCLK ==> Db = %d, x = %d, y = %d, flags = %d "
|
||||
, fDoubleClick
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
c_WinGuiUtil_MoveWindowToScreenCenter(hwnd);
|
||||
}else{
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_RBUTTONDOWN ==> Db = %d, x = %d, y = %d, flags = %d "
|
||||
, fDoubleClick
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
}
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 140, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_RBUTTONUP, KeyMouse_OnRButtonUp){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_RBUTTONUP ==> x = %d, y = %d, flags = %d "
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 160, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_MBUTTONDOWN, KeyMouse_OnMButtonDown) {
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
if(fDoubleClick){
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_MBUTTONDBLCLK ==> Db = %d, x = %d, y = %d, flags = %d "
|
||||
, fDoubleClick
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
}else{
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_MBUTTONDOWN ==> Db = %d, x = %d, y = %d, flags = %d "
|
||||
, fDoubleClick
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
}
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 180, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
c_WinGUI_EventHandlerDef(WM_MBUTTONUP, KeyMouse_OnMButtonUp){
|
||||
char s[100];
|
||||
HDC hdc = GetDC(hwnd);
|
||||
int size =0;
|
||||
|
||||
size = snprintf(s, sizeof(s)/sizeof(s[0])
|
||||
, "WM_MBUTTONUP ==> x = %d, y = %d, flags = %d "
|
||||
, x
|
||||
, y
|
||||
, keyFlags
|
||||
);
|
||||
|
||||
|
||||
SetBkColor(hdc, GetSysColor(COLOR_WINDOW));
|
||||
TextOut(hdc, xVal, yVal + 160, s, size);
|
||||
ReleaseDC(hwnd, hdc);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
c_WinGUI_EventMapBegin(WndProc)
|
||||
c_WinGUI_EventMap(WM_CREATE, KeyMouse_OnCreate);
|
||||
c_WinGUI_EventMap(WM_CHAR, KeyMouse_OnChar);
|
||||
c_WinGUI_EventMap(WM_KEYDOWN, KeyMouse_OnKey);
|
||||
c_WinGUI_EventMap(WM_KEYUP, KeyMouse_OnKey);
|
||||
c_WinGUI_EventMap(WM_SYSKEYDOWN, KeyMouse_OnSysKey);
|
||||
c_WinGUI_EventMap(WM_SYSKEYUP, KeyMouse_OnSysKey);
|
||||
c_WinGUI_EventMap(WM_MOUSEMOVE, KeyMouse_OnMouseMove);
|
||||
c_WinGUI_EventMap(WM_LBUTTONDBLCLK, KeyMouse_OnLButtonDown);
|
||||
c_WinGUI_EventMap(WM_LBUTTONDOWN, KeyMouse_OnLButtonDown);
|
||||
c_WinGUI_EventMap(WM_LBUTTONUP, KeyMouse_OnLButtonUp);
|
||||
c_WinGUI_EventMap(WM_DESTROY, KeyMouse_OnDestroy);
|
||||
c_WinGUI_EventMap(WM_PAINT, KeyMouse_OnPaint);
|
||||
c_WinGUI_EventMap(WM_RBUTTONDBLCLK, KeyMouse_OnRButtonDown);
|
||||
c_WinGUI_EventMap(WM_RBUTTONDOWN, KeyMouse_OnRButtonDown);
|
||||
c_WinGUI_EventMap(WM_RBUTTONUP, KeyMouse_OnRButtonUp);
|
||||
c_WinGUI_EventMap(WM_MBUTTONDOWN, KeyMouse_OnMButtonDown);
|
||||
c_WinGUI_EventMap(WM_MBUTTONDBLCLK, KeyMouse_OnMButtonDown);
|
||||
c_WinGUI_EventMap(WM_MBUTTONUP, KeyMouse_OnMButtonUp);
|
||||
c_WinGUI_EventMapEnd()
|
||||
|
||||
/* -------------------------------------------------------------------------------------------------------------- */
|
||||
/* */
|
||||
|
||||
|
||||
|
||||
static bool Register(HINSTANCE hInstance){
|
||||
WNDCLASS WndClass;
|
||||
WndClass.lpszClassName = MAIN_WINDOW_CLASSNAME;
|
||||
WndClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
|
||||
WndClass.cbWndExtra = 0;
|
||||
WndClass.cbClsExtra = 0;
|
||||
WndClass.hInstance = hInstance;
|
||||
WndClass.lpfnWndProc = WndProc;
|
||||
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
WndClass.lpszMenuName = NULL;
|
||||
return (RegisterClass(&WndClass)!=0);
|
||||
}
|
||||
|
||||
|
||||
static HWND Create(HINSTANCE hInstance, int nCmdShow){
|
||||
HWND hWindow = CreateWindowEx(0, MAIN_WINDOW_CLASSNAME, MAIN_WINDOW_CLASSNAME,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
800, 600,
|
||||
800, 300,
|
||||
// CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
if(!hWindow) return NULL;
|
||||
ShowWindow(hWindow, nCmdShow);
|
||||
UpdateWindow(hWindow);
|
||||
return hWindow;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
|
||||
c_WinGUI_Main() {
|
||||
MSG msg;
|
||||
|
||||
if (!hPrevInstance) {
|
||||
if (!Register(hInstance)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
HWND MainHwnd = Create(hInstance, nShowCmd);
|
||||
if (!MainHwnd) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
c_WinApp_Init(hInstance, MainHwnd);
|
||||
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
Reference in New Issue
Block a user