/// // ESWindowProc() // // Main window procedure // LRESULT WINAPI ESWindowProc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { LRESULT lRet = 1; switch (uMsg) { case WM_CREATE: break; case WM_PAINT: { ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); if ( esContext && esContext->drawFunc ) esContext->drawFunc ( esContext ); ValidateRect( esContext->hWnd, NULL ); } break; case WM_DESTROY: PostQuitMessage(0); break; /* case WM_CHAR: { POINT point; ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); GetCursorPos( &point ); if ( esContext && esContext->keyFunc ) esContext->keyFunc ( esContext, (unsigned char) wParam, (int) point.x, (int) point.y ); } break; */ case WM_KEYDOWN: { ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); if(esContext && esContext->keyFunc) { int state = ES_KEY_DOWN; esContext->keyFunc(esContext, state, wParam); } } break; case WM_KEYUP: { ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); if(esContext && esContext->keyFunc) { int state = ES_KEY_UP; esContext->keyFunc(esContext, state, wParam); } } break; case WM_LBUTTONDOWN: { POINT point; int x, y; RECT winRect; ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); GetCursorPos(&point); GetWindowRect(esContext->hWnd, &winRect); if(PtInRect(&winRect, point)) { x = (int)point.x - winRect.left; y = (int)point.y - winRect.top; left_pressed = 1; if(esContext->mouseFunc != NULL) { esContext->mouseFunc(ES_MOUSE_DOWN, x, y); } } } break; case WM_MOUSEMOVE: { if (MK_LBUTTON == wParam && left_pressed) { POINT point; int x, y; RECT winRect; ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); GetCursorPos(&point); GetWindowRect(esContext->hWnd, &winRect); if(PtInRect(&winRect, point)) { x = (int)point.x - winRect.left; y = (int)point.y - winRect.top; if(esContext->mouseFunc != NULL) { esContext->mouseFunc(ES_MOUSE_MOVE, x, y); } } } } break; case WM_LBUTTONUP: if(left_pressed) { POINT point; int x, y; RECT winRect; ESContext *esContext = (ESContext*)(LONG_PTR) GetWindowLongPtr ( hWnd, GWL_USERDATA ); GetCursorPos(&point); GetWindowRect(esContext->hWnd, &winRect); if(PtInRect(&winRect, point)) { x = (int)point.x - winRect.left; y = (int)point.y - winRect.top; if(esContext->mouseFunc != NULL) { esContext->mouseFunc(ES_MOUSE_UP, x, y); } } left_pressed = 0; } break; default: lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); break; } return lRet; }