commit facf9ec28875f089598bbb0674a893b89c21efa5 Author: Chen Peng Date: Thu Aug 6 14:17:11 2026 +0800 import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..822dd55 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +cmake-build-*/ +.idea/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..95d29d7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.15) +project(HardFaultAnalysis C) + +set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +file(GLOB SOURCES ${SOURCE_DIR}/*.c) +list(FILTER SOURCES EXCLUDE REGEX \\.t\\.c) +foreach (item IN LISTS SOURCES) + message(STATUS "[${PROJECT_NAME}] SOURCE: ${item}") +endforeach () + +add_library(${PROJECT_NAME} "") +target_sources(${PROJECT_NAME} PUBLIC ${SOURCES}) +target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +file(GLOB TEST_SOURCES ${SOURCE_DIR}/*.t.c) +foreach (item IN LISTS TEST_SOURCES) + get_filename_component(TestUnit ${item} NAME_WLE) + message(STATUS "[${PROJECT_NAME}] TEST UNIT: ${TestUnit} - ${item}") + add_executable(${TestUnit} ${item}) + target_link_libraries(${TestUnit} PRIVATE ${PROJECT_NAME}) +endforeach () + + + + + diff --git a/Data/crash_dump.txt.sample b/Data/crash_dump.txt.sample new file mode 100644 index 0000000..379aa6d --- /dev/null +++ b/Data/crash_dump.txt.sample @@ -0,0 +1,16 @@ +# PyOCD 抓取的寄存器离线数据文件 +r0 = 0x00000000 +r1 = 0x20001000 +r2 = 0x00000005 +r3 = 0x080015B4 +r12 = 0x00000000 +sp = 0x20004FB0 +lr = 0x080012CE +pc = 0x080011A4 +xpsr = 0x20000000 + +# SCB 核心故障寄存器组 +hfsr = 0x40000000 +cfsr = 0x00008200 +bfar = 0x40002004 +mmfar = 0x00000000 \ No newline at end of file diff --git a/HardFaultAnalysis.c b/HardFaultAnalysis.c new file mode 100644 index 0000000..b977d35 --- /dev/null +++ b/HardFaultAnalysis.c @@ -0,0 +1,201 @@ +#include +#include +#include + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +// 定义常见 Cortex-M 芯片的内存映射边界 +#define FLASH_START 0x08000000 +#define FLASH_END 0x0C000000 +#define SRAM_START 0x20000000 +#define SRAM_END 0x30000000 +#define PERIPH_START 0x40000000 +#define PERIPH_END 0x60000000 +#define FMC_START 0x60000000 +#define FMC_END 0xA0000000 + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +// 深度分析崩溃的物理地址 +static void analyze_fault_address(const char* fault_type, uint32_t addr) { + printf("\n🔍 [%s Address Analysis] ----------------\n", fault_type); + printf("Target Address: 0x%08X\n", addr); + + // 1. 经典空指针或极其接近0的地址(如结构体成员偏移) + if (addr < 0x00000400) { + printf("🚨 诊断结论: 空指针 (NULL Pointer) 解引用!\n"); + if (addr == 0) { + printf(" -> 代码尝试直接读取或写入 NULL。\n"); + } else { + printf(" -> 代码操作了 NULL 结构体指针,该地址是成员偏移量 (Offset: %d bytes)。\n", addr); + } + return; + } + + // 2. 检查是否在代码区 (Flash) + if (addr >= FLASH_START && addr < FLASH_END) { + printf("🚨 诊断结论: 尝试写入只读的 Flash 区域,或者读取了未初始化的非法 Flash 地址!\n"); + printf(" -> 请检查代码是否在尝试修改常量(const)或直接通过指针对0x08xxxxxx地址写数据。\n"); + return; + } + + // 3. 检查是否在运行内存区 (SRAM) + if (addr >= SRAM_START && addr < SRAM_END) { + printf("🚨 诊断结论: 访问 SRAM 时崩溃。\n"); + printf(" -> 极大可能是 数组越界 或 堆栈溢出 (Stack Overflow) 破坏了相邻的数据边界。\n"); + printf(" -> 请在 .map 文件中查找哪个全局/静态变量的地址最接近 0x%08X。\n", addr); + return; + } + + // 4. 检查是否在外设寄存器区 (Peripheral) + if (addr >= PERIPH_START && addr < PERIPH_END) { + printf("🚨 诊断结论: 访问外设寄存器时总线报错。\n"); + printf(" -> 原因 1: 该外设的时钟 (RCC) 没有开启,就去读写它的寄存器!(最常见)\n"); + printf(" -> 原因 2: 尝试访问当前芯片型号根本不存在的外设。\n"); + return; + } + + // 5. 检查是否在外部扩展内存 (FMC/FSMC, 如外部 SDRAM/LCD) + if (addr >= FMC_START && addr < FMC_END) { + printf("🚨 诊断结论: 访问外部存储器(FMC/FSMC)报错。\n"); + printf(" -> 请检查外部 SDRAM/NAND/LCD 的初始化代码是否未执行,或者硬件引脚接触不良。\n"); + return; + } + + // 6. 处于完全未定义的无人区 (野指针) + printf("🚨 诊断结论: 绝对的野指针 (Wild Pointer) 访问!\n"); + printf(" -> 0x%08X 是一个完全不合法的未映射地址空间。\n", addr); + printf(" -> 通常是因为指针变量未初始化、指针转义、或者堆栈被破坏导致恢复出的指针变成了垃圾值。\n"); +} + +static void decode_xpsr(uint32_t xpsr) { + printf("\n------ [ xPSR Detail Analysis ] ------\n"); + printf("xPSR: 0x%08X\n", xpsr); + + // 检查第 24 位 (1 << 24 = 0x01000000) + if ((xpsr & (1 << 24)) == 0) { + printf("🚨 [CRITICAL ERROR] xPSR T-bit (Bit 24) is 0!\n"); + printf(" Cortex-M processors ONLY support Thumb state.\n"); + printf(" Switching to ARM state (T=0) is illegal and caused this crash.\n"); + printf("💡 [SUGGESTION] This usually happens because:\n"); + printf(" 1. A function pointer lacked the LSB set to 1 (e.g., calling an even address).\n"); + printf(" 2. Destructed stack frame or corrupted LR/PC during pop/return.\n"); + } else { + printf(" -> T-bit (Bit 24) = 1 (Correct: Processor is in Thumb state).\n"); + } + + // 顺便打印当前处于哪个中断/异常中 (IPSR 位: Bit 0-8) + uint8_t exception_number = (xpsr & 0x1FF); + if (exception_number == 0) { + printf(" -> Mode: Thread Mode (Application code).\n"); + } else { + printf(" -> Mode: Handler Mode (Interrupt/Exception Handler #%d).\n", exception_number); + } +} + +// 解析 CFSR 寄存器 (Cortex-M3/M4/M7/M33 适用) +static void decode_cfsr(uint32_t cfsr, uint32_t bfar, uint32_t mmfar) { + uint8_t mmfsr = (cfsr & 0x000000FF); + uint8_t bfsr = ((cfsr & 0x0000FF00) >> 8); + uint16_t ufsr = ((cfsr & 0xFFFF0000) >> 16); + + printf("\n------ [ CFSR Detail Analysis ] ------\n"); + + if (ufsr) { + printf("[UsageFault] Detected (0x%04X):\n", ufsr); + if (ufsr & (1 << 9)) printf(" -> DIVBYZERO: Try to divide by zero.\n"); + if (ufsr & (1 << 8)) printf(" -> UNALIGNED: Unaligned memory access alignment fault.\n"); + if (ufsr & (1 << 3)) printf(" -> NOCP: Access to an unenabled coprocessor (e.g. FPU).\n"); + if (ufsr & (1 << 2)) printf(" -> INVPC: Invalid PC load caused by EXC_RETURN.\n"); + if (ufsr & (1 << 1)) printf(" -> INVSTATE: Invalid execution state (Thumb bit issue).\n"); + if (ufsr & (1 << 0)) printf(" -> UNDEFINSTR: Executed an undefined instruction.\n"); + } + + if (bfsr) { + printf("[BusFault] Detected (0x%02X):\n", bfsr); + if (bfsr & (1 << 7)) { + printf(" -> BFARVALID: Address in BFAR is valid.\n"); + analyze_fault_address("BusFault (BFAR)", bfar); + } else { + printf(" -> Note: BFAR address is NOT valid (Imprecise fault).\n"); + } + if (bfsr & (1 << 1)) printf(" -> PRECISERR: Precise data bus error.\n"); + if (bfsr & (1 << 0)) printf(" -> IBUSERR: Instruction bus error.\n"); + } + + if (mmfsr) { + printf("[MemManage Fault] Detected (0x%02X):\n", mmfsr); + if (mmfsr & (1 << 7)) { + printf(" -> MMFARVALID: Address in MMFAR is valid.\n"); + analyze_fault_address("MemManage (MMFAR)", mmfar); + } + if (mmfsr & (1 << 1)) printf(" -> DACCVIOL: Data access violation.\n"); + } +} + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +void HardFaultAnalysis(HardFaultDump_t *dump) { + printf("==================================================\n"); + printf(" Cortex-M Offline HardFault Decoder \n"); + printf("==================================================\n"); + + printf("\n------ [ Core Registers Snapshot ] ------\n"); + printf("PC : 0x%08X (崩溃发生在此指令附近)\n", dump->pc); + printf("LR : 0x%08X (父级函数返回地址)\n", dump->lr); + printf("SP : 0x%08X R0 : 0x%08X\n", dump->sp, dump->r0); + printf("R1 : 0x%08X R2 : 0x%08X\n", dump->r1, dump->r2); + printf("R3 : 0x%08X R12 : 0x%08X\n", dump->r3, dump->r12); + + decode_xpsr(dump->xpsr); + + printf("\n------ [ HFSR High Level Summary ] ------\n"); + printf("HFSR : 0x%08X\n", dump->hfsr); + if (dump->hfsr & (1 << 30)) { + printf(" -> FORCED: 强制硬件故障。由于其他特定异常升级导致,详情见下方 CFSR。\n"); + } + + decode_cfsr(dump->cfsr, dump->bfar, dump->mmfar); + printf("==================================================\n"); +} + +int HardFaultAnalysis_Load(const char* filename, HardFaultDump_t* dump ) { + FILE *file = fopen(filename, "r"); + if (!file) { + printf("Error: Cannot open file %s\n", filename); + return 0; + } + + char line[256]; + while (fgets(line, sizeof(line), file)) { + // 忽略注释和空行 + if (line[0] == '#' || line[0] == '/' || line[0] == '\n' || line[0] == '\r') { + continue; + } + + char key[32]; + uint32_t val; + // 解析 "key = 0xValue" 格式 + if (sscanf(line, "%s = %i", key, &val) == 2) { + if (strcasecmp(key, "r0") == 0) dump->r0 = val; + else if (strcasecmp(key, "r1") == 0) dump->r1 = val; + else if (strcasecmp(key, "r2") == 0) dump->r2 = val; + else if (strcasecmp(key, "r3") == 0) dump->r3 = val; + else if (strcasecmp(key, "r12") == 0) dump->r12 = val; + else if (strcasecmp(key, "sp") == 0) dump->sp = val; + else if (strcasecmp(key, "lr") == 0) dump->lr = val; + else if (strcasecmp(key, "pc") == 0) dump->pc = val; + else if (strcasecmp(key, "xpsr") == 0) dump->xpsr = val; + else if (strcasecmp(key, "hfsr") == 0) dump->hfsr = val; + else if (strcasecmp(key, "cfsr") == 0) dump->cfsr = val; + else if (strcasecmp(key, "bfar") == 0) dump->bfar = val; + else if (strcasecmp(key, "mmfar") == 0) dump->mmfar = val; + } + } + + fclose(file); + return 1; +} diff --git a/HardFaultAnalysis.h b/HardFaultAnalysis.h new file mode 100644 index 0000000..6ef205d --- /dev/null +++ b/HardFaultAnalysis.h @@ -0,0 +1,32 @@ +#ifndef INCLUDED_HARDFAULTANALYSIS_H +#define INCLUDED_HARDFAULTANALYSIS_H + +#ifndef INCLUDED_STDINT_H +#define INCLUDED_STDINT_H +#include +#endif /*INCLUDED_STDINT_H*/ + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +typedef struct { + uint32_t r0; + uint32_t r1; + uint32_t r2; + uint32_t r3; + uint32_t r12; + uint32_t sp; + uint32_t lr; + uint32_t pc; + uint32_t xpsr; + uint32_t hfsr; // HardFault Status + uint32_t cfsr; // Configurable Fault Status MMFSR/BFSR/UFSR + uint32_t bfar; // BusFault Address + uint32_t mmfar; // MemManage Fault Address +}HardFaultDump_t; + +void HardFaultAnalysis(HardFaultDump_t *dump); + +int HardFaultAnalysis_Load(const char* filename, HardFaultDump_t* dump ); + +#endif /*INCLUDED_HARDFAULTANALYSIS_H*/ diff --git a/HardFaultAnalysis.t.c b/HardFaultAnalysis.t.c new file mode 100644 index 0000000..4747024 --- /dev/null +++ b/HardFaultAnalysis.t.c @@ -0,0 +1,35 @@ +#include "HardFaultAnalysis.h" +#include +#include + +int main(int argc, char** argv){ + // HardFaultDump_t pyocd_data = { + // .r0 = 0x00000000, // 比如 R0 是 0,引发空指针 + // .r1 = 0x20001000, + // .r2 = 0x00000005, + // .r3 = 0x080015B4, + // .r12 = 0x00000000, + // .sp = 0x20004FB0, + // .lr = 0x080012CE, // 调用发生崩溃函数的上级函数地址 + // .pc = 0x080011A4, // 死机代码行对应的指令地址 + // .xpsr = 0x21000000, + // + // // 以下是通过 PyOCD 读取的 SCB 寄存器物理地址数据 + // .hfsr = 0x40000000, // FORCED = 1 + // .cfsr = 0x00008200, // BFARVALID = 1, PRECISERR = 1 (精确总线错误) + // .bfar = 0x00000004, // 芯片在尝试访问 0x00000004 地址时崩溃 + // .mmfar= 0x00000000 + // }; + + if (argc < 2) { + printf("Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + + HardFaultDump_t pyocd_data={0}; + + HardFaultAnalysis_Load(argv[1], &pyocd_data); + HardFaultAnalysis(&pyocd_data); + + return 0; +} diff --git a/c_WinApp.c b/c_WinApp.c new file mode 100644 index 0000000..23bb509 --- /dev/null +++ b/c_WinApp.c @@ -0,0 +1,3 @@ +#include + +c_WinApp_t WinApp={0}; diff --git a/c_WinApp.h b/c_WinApp.h new file mode 100644 index 0000000..0a3aaa5 --- /dev/null +++ b/c_WinApp.h @@ -0,0 +1,30 @@ +#ifndef INCLUDED_C_WINAPP_H +#define INCLUDED_C_WINAPP_H + +#ifndef INCLUDED_C_WINGUI_H +#include +#endif /*INCLUDED_C_WINGUI_H*/ + + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +typedef struct { + HINSTANCE hInstance; + HWND hwnd; +}c_WinApp_t; + +extern c_WinApp_t WinApp; + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +static void c_WinApp_Init(HINSTANCE hInstance, HWND hwnd) { + WinApp.hInstance = hInstance; + WinApp.hwnd = hwnd; +} + + + + +#endif /*INCLUDED_C_WINAPP_H*/ diff --git a/c_WinGUI.c b/c_WinGUI.c new file mode 100644 index 0000000..bb6193a --- /dev/null +++ b/c_WinGUI.c @@ -0,0 +1 @@ +#include diff --git a/c_WinGUI.h b/c_WinGUI.h new file mode 100644 index 0000000..6e76120 --- /dev/null +++ b/c_WinGUI.h @@ -0,0 +1,459 @@ +#ifndef INCLUDED_C_WINGUI_H +#define INCLUDED_C_WINGUI_H + +#ifndef INCLUDED_WINDOWS_H +#define INCLUDED_WINDOWS_H +#include +#endif /*INCLUDED_WINDOWS_H*/ + +#ifndef INCLUDED_WINDOWSX_H +#define INCLUDED_WINDOWSX_H +#include +#endif /*INCLUDED_WINDOWSX_H*/ + +#ifndef INCLUDED_C_WINAPP_H +#include +#endif /*INCLUDED_C_WINAPP_H*/ + + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +#define c_WinGUI_EventFn_WM_COMPACTING(fn) \ + void fn(HWND hwnd, UINT compactRatio) + +#define c_WinGUI_EventFn_WM_WININICHANGE(fn) \ + void fn(HWND hwnd, LPCTSTR lpszSectionName) + +#define c_WinGUI_EventFn_WM_SYSCOLORCHANGE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_QUERYNEWPALETTE(fn) \ + WINBOOL fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_PALETTEISCHANGING(fn) \ + void fn(HWND hwnd, HWND hwndPaletteChange) + +#define c_WinGUI_EventFn_WM_PALETTECHANGED(fn) \ + void fn(HWND hwnd, HWND hwndPaletteChange) + +#define c_WinGUI_EventFn_WM_FONTCHANGE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_SPOOLERSTATUS(fn) \ + void fn(HWND hwnd, UINT status, int cJobInQueue) + +#define c_WinGUI_EventFn_WM_DEVMODECHANGE(fn) \ + void fn(HWND hwnd, LPCTSTR lpszDeviceName) + +#define c_WinGUI_EventFn_WM_TIMECHANGE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_POWER(fn) \ + void fn(HWND hwnd, int code) + +#define c_WinGUI_EventFn_WM_QUERYENDSESSION(fn) \ + WINBOOL fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_ENDSESSION(fn) \ + void fn(HWND hwnd, WINBOOL fEnding) + +#define c_WinGUI_EventFn_WM_QUIT(fn) \ + void fn(HWND hwnd, int exitCode) + +#define c_WinGUI_EventFn_WM_SYSTEMERROR(fn) \ + void fn() + +#define c_WinGUI_EventFn_WM_CREATE(fn) \ + WINBOOL fn(HWND hwnd, LPCREATESTRUCT lpCreateStruct) + +#define c_WinGUI_EventFn_WM_NCCREATE(fn) \ + WINBOOL fn(HWND hwnd, LPCREATESTRUCT lpCreateStruct) + +#define c_WinGUI_EventFn_WM_DESTROY(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_NCDESTROY(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_SHOWWINDOW(fn) \ + void fn(HWND hwnd, WINBOOL fShow, UINT status) + +#define c_WinGUI_EventFn_WM_SETREDRAW(fn) \ + void fn(HWND hwnd, WINBOOL fRedraw) + +#define c_WinGUI_EventFn_WM_ENABLE(fn) \ + void fn(HWND hwnd, WINBOOL fEnable) + +#define c_WinGUI_EventFn_WM_SETTEXT(fn) \ + void fn(HWND hwnd, LPCTSTR lpszText) + +#define c_WinGUI_EventFn_WM_GETTEXT(fn) \ + int fn(HWND hwnd, int cchTextMax, LPTSTR lpszText) + +#define c_WinGUI_EventFn_WM_GETTEXTLENGTH(fn) \ + int fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_WINDOWPOSCHANGING(fn) \ + WINBOOL fn(HWND hwnd, LPWINDOWPOS lpwpos) + +#define c_WinGUI_EventFn_WM_WINDOWPOSCHANGED(fn) \ + void fn(HWND hwnd, const LPWINDOWPOS lpwpos) + +#define c_WinGUI_EventFn_WM_MOVE(fn) \ + void fn(HWND hwnd, int x, int y) + +#define c_WinGUI_EventFn_WM_SIZE(fn) \ + void fn(HWND hwnd, UINT state, int cx, int cy) + +#define c_WinGUI_EventFn_WM_CLOSE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_QUERYOPEN(fn) \ + WINBOOL fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_GETMINMAXINFO(fn) \ + void fn(HWND hwnd, LPMINMAXINFO lpMinMaxInfo) + +#define c_WinGUI_EventFn_WM_PAINT(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_ERASEBKGND(fn) \ + WINBOOL fn(HWND hwnd, HDC hdc) + +#define c_WinGUI_EventFn_WM_ICONERASEBKGND(fn) \ + WINBOOL fn(HWND hwnd, HDC hdc) + +#define c_WinGUI_EventFn_WM_NCPAINT(fn) \ + void fn(HWND hwnd, HRGN hrgn) + +#define c_WinGUI_EventFn_WM_NCCALCSIZE(fn) \ + UINT fn(HWND hwnd, WINBOOL fCalcValidRects, NCCALCSIZE_PARAMS * lpcsp) + +#define c_WinGUI_EventFn_WM_NCHITTEST(fn) \ + UINT fn(HWND hwnd, int x, int y) + +#define c_WinGUI_EventFn_WM_QUERYDRAGICON(fn) \ + HICON fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_DROPFILES(fn) \ + void fn(HWND hwnd, HDROP hdrop) + +#define c_WinGUI_EventFn_WM_ACTIVATE(fn) \ + void fn(HWND hwnd, UINT state, HWND hwndActDeact, WINBOOL fMinimized) + +#define c_WinGUI_EventFn_WM_ACTIVATEAPP(fn) \ + void fn(HWND hwnd, WINBOOL fActivate, DWORD dwThreadId) + +#define c_WinGUI_EventFn_WM_NCACTIVATE(fn) \ + WINBOOL fn(HWND hwnd, WINBOOL fActive, WPARAM hwndActDeact, LPARAM fMinimized) + +#define c_WinGUI_EventFn_WM_SETFOCUS(fn) \ + void fn(HWND hwnd, HWND hwndOldFocus) + +#define c_WinGUI_EventFn_WM_KILLFOCUS(fn) \ + void fn(HWND hwnd, HWND hwndNewFocus) + +#define c_WinGUI_EventFn_WM_KEYDOWN(fn) \ + void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags) + +#define c_WinGUI_EventFn_WM_KEYUP(fn) \ + void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags) + +#define c_WinGUI_EventFn_WM_CHAR(fn) \ + void fn(HWND hwnd, TCHAR ch, int cRepeat) + +#define c_WinGUI_EventFn_WM_DEADCHAR(fn) \ + void fn(HWND hwnd, TCHAR ch, int cRepeat) + +#define c_WinGUI_EventFn_WM_SYSKEYDOWN(fn) \ + void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags) + +#define c_WinGUI_EventFn_WM_SYSKEYUP(fn) \ + void fn(HWND hwnd, UINT vk, WINBOOL fBool, int cRepeat, UINT flags) + +#define c_WinGUI_EventFn_WM_SYSCHAR(fn) \ + void fn(HWND hwnd, TCHAR ch, int cRepeat) + +#define c_WinGUI_EventFn_WM_SYSDEADCHAR(fn) \ + void fn(HWND hwnd, TCHAR ch, int cRepeat) + +#define c_WinGUI_EventFn_WM_MOUSEMOVE(fn) \ + void fn(HWND hwnd, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_LBUTTONDOWN(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_LBUTTONDBLCLK(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_LBUTTONUP(fn) \ + void fn(HWND hwnd, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_RBUTTONDOWN(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_RBUTTONDBLCLK(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_RBUTTONUP(fn) \ + void fn(HWND hwnd, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_MBUTTONDOWN(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_MBUTTONUP(fn) \ + void fn(HWND hwnd, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_MOUSEWHEEL(fn) \ + void fn(HWND hwnd, int xPos, int yPos, int zDelta, UINT fwKeys) + +#define c_WinGUI_EventFn_WM_NCMOUSEMOVE(fn) \ + void fn(HWND hwnd, int x, int y, UINT codeHitTest) + +#define c_WinGUI_EventFn_WM_NCLBUTTONDOWN(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_NCLBUTTONUP(fn) \ + void fn(HWND hwnd, int x, int y, UINT codeHitTest) + +#define c_WinGUI_EventFn_WM_NCRBUTTONDOWN(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_NCRBUTTONUP(fn) \ + void fn(HWND hwnd, int x, int y, UINT codeHitTest) + +#define c_WinGUI_EventFn_WM_NCMBUTTONDOWN(fn) \ + void fn(HWND hwnd, WINBOOL fDoubleClick, int x, int y, UINT keyFlags) + +#define c_WinGUI_EventFn_WM_NCMBUTTONUP(fn) \ + void fn(HWND hwnd, int x, int y, UINT codeHitTest) + +#define c_WinGUI_EventFn_WM_MOUSEACTIVATE(fn) \ + int fn(HWND hwnd, HWND hwndTopLevel, UINT codeHitTest, UINT msg) + +#define c_WinGUI_EventFn_WM_CANCELMODE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_TIMER(fn) \ + void fn(HWND hwnd, UINT id) + +#define c_WinGUI_EventFn_WM_INITMENU(fn) \ + void fn(HWND hwnd, HMENU hMenu) + +#define c_WinGUI_EventFn_WM_INITMENUPOPUP(fn) \ + void fn(HWND hwnd, HMENU hMenu, UINT item, WINBOOL fSystemMenu) + +#define c_WinGUI_EventFn_WM_MENUSELECT(fn) \ + void fn(HWND hwnd, HMENU hmenu, UINT item, HMENU hmenuPopup, UINT flags) + +#define c_WinGUI_EventFn_WM_MENUCHAR(fn) \ + DWORD fn(HWND hwnd, UINT ch, UINT flags, HMENU hmenu) + +#define c_WinGUI_EventFn_WM_COMMAND(fn) \ + void fn(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) + +#define c_WinGUI_EventFn_WM_HSCROLL(fn) \ + void fn(HWND hwnd, HWND hwndCtl, UINT code, int pos) + +#define c_WinGUI_EventFn_WM_VSCROLL(fn) \ + void fn(HWND hwnd, HWND hwndCtl, UINT code, int pos) + +#define c_WinGUI_EventFn_WM_CUT(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_COPY(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_PASTE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_CLEAR(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_UNDO(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_RENDERFORMAT(fn) \ + HANDLE fn(HWND hwnd, UINT fmt) + +#define c_WinGUI_EventFn_WM_RENDERALLFORMATS(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_DESTROYCLIPBOARD(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_DRAWCLIPBOARD(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_PAINTCLIPBOARD(fn) \ + void fn(HWND hwnd, HWND hwndCBViewer, const LPPAINTSTRUCT lpPaintStruct) + +#define c_WinGUI_EventFn_WM_SIZECLIPBOARD(fn) \ + void fn(HWND hwnd, HWND hwndCBViewer, const LPRECT lprc) + +#define c_WinGUI_EventFn_WM_VSCROLLCLIPBOARD(fn) \ + void fn(HWND hwnd, HWND hwndCBViewer, UINT code, int pos) + +#define c_WinGUI_EventFn_WM_HSCROLLCLIPBOARD(fn) \ + void fn(HWND hwnd, HWND hwndCBViewer, UINT code, int pos) + +#define c_WinGUI_EventFn_WM_ASKCBFORMATNAME(fn) \ + void fn(HWND hwnd, int cchMax, LPTSTR rgchName) + +#define c_WinGUI_EventFn_WM_CHANGECBCHAIN(fn) \ + void fn(HWND hwnd, HWND hwndRemove, HWND hwndNext) + +#define c_WinGUI_EventFn_WM_SETCURSOR(fn) \ + WINBOOL fn(HWND hwnd, HWND hwndCursor, UINT codeHitTest, UINT msg) + +#define c_WinGUI_EventFn_WM_SYSCOMMAND(fn) \ + void fn(HWND hwnd, UINT cmd, int x, int y) + +#define c_WinGUI_EventFn_WM_MDICREATE(fn) \ + HWND fn(HWND hwnd, LPMDICREATESTRUCT lpmcs) + +#define c_WinGUI_EventFn_WM_MDIDESTROY(fn) \ + void fn(HWND hwnd, HWND hwndDestroy) + +#define c_WinGUI_EventFn_WM_MDIACTIVATE(fn) \ + void fn(HWND hwnd, WINBOOL fActive, HWND hwndActivate, HWND hwndDeactivate) + +#define c_WinGUI_EventFn_WM_MDIRESTORE(fn) \ + void fn(HWND hwnd, HWND hwndRestore) + +#define c_WinGUI_EventFn_WM_MDINEXT(fn) \ + HWND fn(HWND hwnd, HWND hwndCur, WINBOOL fPrev) + +#define c_WinGUI_EventFn_WM_MDIMAXIMIZE(fn) \ + void fn(HWND hwnd, HWND hwndMaximize) + +#define c_WinGUI_EventFn_WM_MDITILE(fn) \ + WINBOOL fn(HWND hwnd, UINT cmd) + +#define c_WinGUI_EventFn_WM_MDICASCADE(fn) \ + WINBOOL fn(HWND hwnd, UINT cmd) + +#define c_WinGUI_EventFn_WM_MDIICONARRANGE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_MDIGETACTIVE(fn) \ + HWND fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_MDISETMENU(fn) \ + HMENU fn(HWND hwnd, WINBOOL fRefresh, HMENU hmenuFrame, HMENU hmenuWindow) + +#define c_WinGUI_EventFn_WM_CHILDACTIVATE(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_INITDIALOG(fn) \ + WINBOOL fn(HWND hwnd, HWND hwndFocus, LPARAM lParam) + +#define c_WinGUI_EventFn_WM_NEXTDLGCTL(fn) \ + HWND fn(HWND hwnd, HWND hwndSetFocus, WINBOOL fNext) + +#define c_WinGUI_EventFn_WM_PARENTNOTIFY(fn) \ + void fn(HWND hwnd, UINT msg, HWND hwndChild, UINT idChild) + +#define c_WinGUI_EventFn_WM_ENTERIDLE(fn) \ + void fn(HWND hwnd, UINT source, HWND hwndSource) + +#define c_WinGUI_EventFn_WM_GETDLGCODE(fn) \ + UINT fn(HWND hwnd, LPMSG lpmsg) + +#define c_WinGUI_EventFn_WM_CTLCOLORMSGBOX(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_CTLCOLOREDIT(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_CTLCOLORLISTBOX(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_CTLCOLORBTN(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_CTLCOLORDLG(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_CTLCOLORSCROLLBAR(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_CTLCOLORSTATIC(fn) \ + HBRUSH fn(HWND hwnd, HDC hdc, HWND hwndChild) + +#define c_WinGUI_EventFn_WM_SETFONT(fn) \ + void fn(HWND hwnd, HFONT hfont, WINBOOL fRedraw) + +#define c_WinGUI_EventFn_WM_GETFONT(fn) \ + HFONT fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_DRAWITEM(fn) \ + void fn(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem) + +#define c_WinGUI_EventFn_WM_MEASUREITEM(fn) \ + void fn(HWND hwnd, MEASUREITEMSTRUCT * lpMeasureItem) + +#define c_WinGUI_EventFn_WM_DELETEITEM(fn) \ + void fn(HWND hwnd, const DELETEITEMSTRUCT * lpDeleteItem) + +#define c_WinGUI_EventFn_WM_COMPAREITEM(fn) \ + int fn(HWND hwnd, const COMPAREITEMSTRUCT * lpCompareItem) + +#define c_WinGUI_EventFn_WM_VKEYTOITEM(fn) \ + int fn(HWND hwnd, UINT vk, HWND hwndListBox, int iCaret) + +#define c_WinGUI_EventFn_WM_CHARTOITEM(fn) \ + int fn(HWND hwnd, UINT ch, HWND hwndListBox, int iCaret) + +#define c_WinGUI_EventFn_WM_QUEUESYNC(fn) \ + void fn(HWND hwnd) + +#define c_WinGUI_EventFn_WM_COMMNOTIFY(fn) \ + void fn(HWND hwnd, int cid, UINT flags) + +#define c_WinGUI_EventFn_WM_DISPLAYCHANGE(fn) \ + void fn(HWND hwnd, UINT bitsPerPixel, UINT cxScreen, UINT cyScreen) + +#define c_WinGUI_EventFn_WM_DEVICECHANGE(fn) \ + WINBOOL fn(HWND hwnd, UINT uEvent, DWORD dwEventData) + +#define c_WinGUI_EventFn_WM_CONTEXTMENU(fn) \ + void fn(HWND hwnd, HWND hwndContext, UINT xPos, UINT yPos) + +#define c_WinGUI_EventFn_WM_COPYDATA(fn) \ + WINBOOL fn(HWND hwnd, HWND hwndFrom, PCOPYDATASTRUCT pcds) + +#define c_WinGUI_EventFn_WM_HOTKEY(fn) \ + void fn(HWND hwnd, int idHotKey, UINT fuModifiers, UINT vk) + +#define c_WinGUI_EventFn_WM_USERDEFINED(fn) \ + LRESULT fn(HWND hwnd, WPARAM wParam, LPARAM lParam) + +/* ------------------------------------------------------------------------------------------------------------------ */ +/* */ + +#define c_WinGUI_EventMapBegin(fn) \ +static LRESULT CALLBACK fn(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ \ + switch (msg){ + +#define c_WinGUI_EventMap(message, fn) \ + case message: return HANDLE_##message(hwnd, wParam, lParam, fn) + +#define c_WinGUI_UDEventMap(message, fn) \ + case message: return fn(hwnd, wParam, lParam) + +#define c_WinGUI_EventMapEnd() \ + default: return DefWindowProc(hwnd, msg, wParam, lParam); \ + } \ +} + +#define c_WinGUI_EventHandlerDef(message, fn) \ +static c_WinGUI_EventFn_##message(fn) + +#define c_WinGUI_Main() \ +int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) + + + +#endif /*INCLUDED_C_WINGUI_H*/