![]() |
TX Library Help – Version: 00173a, Revision: 174
|
00001 //{=========================================================================== 00011 // $Copyright: (C) Ded (Ilya Dedinsky, http://txlib.ru) <mail@txlib.ru> $ 00012 //}=========================================================================== 00013 00014 #include "TXLib.h" 00015 00016 #if !defined (_TX_VER) || (_TX_VER < 0x173a0165) 00017 #error Must use TXLib.h version >= 1.73 and revision >= 165 to compile this. -- Ded 00018 #endif 00019 00020 //============================================================================ 00021 00022 HWND txCreateAR (POINT pos, HDC image, bool visible = true, int round = 10); 00023 void txDeleteAR (HWND wnd); 00024 void txMoveAR (HWND wnd, int x = INT_MIN, int y = INT_MIN); 00025 void txSetAR (HWND wnd, HDC image = NULL); 00026 00027 //============================================================================ 00028 00029 namespace { namespace TX { namespace Win32 { 00030 _TX_DLLIMPORT ("GDI32", HRGN, CreatePolygonRgn, (const POINT* points, int nPoints, int mode)); 00031 _TX_DLLIMPORT ("GDI32", HRGN, CreateRoundRectRgn, (int x1, int y1, int x2, int y2, int width, int height)); 00032 }}} 00033 00034 LRESULT CALLBACK _txAR_WndProc (HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar); 00035 00036 //---------------------------------------------------------------------------- 00037 00038 HWND txCreateAR (POINT pos, HDC image, bool visible /*= true*/, int round /*= 10*/) 00039 { 00040 POINT size = txGetExtent (image); 00041 00042 CREATESTRUCT createData = { NULL, NULL, NULL, txWindow(), size.y, size.x, pos.y, pos.x, WS_CHILD | WS_CLIPCHILDREN, "_txAR_Window", 00043 txRegisterClass ("_txAR_Class", _txAR_WndProc, CS_OWNDC, HOLLOW_BRUSH, 1) }; 00044 00045 HWND wnd = txCreateExtraWindow (createData); 00046 00047 int sz = MIN (size.x, size.y) / round; 00048 HRGN region = Win32::CreateRoundRectRgn (0, 0, size.x, size.y, sz, sz); 00049 SetWindowRgn (wnd, region, true); 00050 00051 txSetAR (wnd, image); 00052 00053 BringWindowToTop (wnd); 00054 if (visible) ShowWindow (wnd, SW_SHOW); 00055 00056 return wnd; 00057 } 00058 00059 //---------------------------------------------------------------------------- 00060 00061 void txDeleteAR (HWND wnd) 00062 { 00063 txSetAR (wnd, NULL); 00064 DestroyWindow (wnd); 00065 } 00066 00067 //---------------------------------------------------------------------------- 00068 00069 void txMoveAR (HWND wnd, int x /*= INT_MIN*/, int y /*= INT_MIN*/) 00070 { 00071 RECT rect = {}; GetClientRect (wnd, &rect); 00072 00073 if (x != INT_MIN && y != INT_MIN) 00074 MoveWindow (wnd, x, y, rect.right, rect.bottom, false); 00075 00076 InvalidateRect (wnd, NULL, false); 00077 } 00078 00079 //---------------------------------------------------------------------------- 00080 00081 void txSetAR (HWND wnd, HDC image /*= NULL*/) 00082 { 00083 SetWindowLongPtr (wnd, GWLP_USERDATA, (LONG_PTR) image); 00084 } 00085 00086 //---------------------------------------------------------------------------- 00087 00088 LRESULT CALLBACK _txAR_WndProc (HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar) 00089 { 00090 if (msg == WM_PAINT) 00091 { 00092 PAINTSTRUCT ps = {}; 00093 HDC dc = BeginPaint (wnd, &ps); 00094 00095 RECT rect = {}; GetClientRect (wnd, &rect); 00096 00097 HDC image = (HDC)(uintptr_t) GetWindowLongPtr (wnd, GWLP_USERDATA); 00098 if (image) Win32::BitBlt (dc, 0, 0, rect.right, rect.bottom, image, 0, 0, SRCCOPY); 00099 00100 EndPaint (wnd, &ps); 00101 return true; 00102 } 00103 00104 return DefWindowProc (wnd, msg, wpar, lpar); 00105 } 00106 00107 //============================================================================ 00108 00109 int main() 00110 { 00111 txCreateWindow (800, 600); 00112 txBegin(); 00113 00114 txPlayVideo ("\a" "http://ded32.net.ru/www.youtube.com-watch-z_AbfPXTKms"); 00115 00116 HDC info = txCreateCompatibleDC (200, 30); 00117 POINT infoSz = txGetExtent (info); 00118 POINT infoPos = {txGetExtentX()/2 - infoSz.x/2, txGetExtentY()/5*4}; 00119 HWND arInfo = txCreateAR (infoPos, info); 00120 00121 txSetTextAlign (TA_CENTER, info); 00122 txSetColor (TX_WHITE, 1, info); 00123 txTextOut (infoSz.x/2, 5, "[Move the mouse]", info); 00124 00125 HDC racket = txLoadImage ("Mouse.bmp"); 00126 POINT arSz = txGetExtent (racket); 00127 HWND ar = txCreateAR (txMousePos(), racket); 00128 00129 while (!txGetAsyncKeyState (VK_ESCAPE)) 00130 { 00131 POINT pos = txMousePos(); 00132 00133 pos.x -= arSz.x/2; 00134 pos.y -= arSz.y/2; 00135 00136 char str [100] = ""; 00137 _snprintf_s (str, sizeof (str), "[%03ld %03ld]", pos.x, pos.y); 00138 00139 txSetAR (ar); 00140 txSetColor (TX_BLACK, 1, racket); 00141 txSetFillColor (TX_BLACK, racket); 00142 txRectangle (0, arSz.y-25, 200, arSz.y, racket); 00143 txSetTextAlign (TA_CENTER, racket); 00144 txSetColor (TX_WHITE, 1, racket); 00145 txTextOut (arSz.x/2, arSz.y-23, str, racket); 00146 txSetAR (ar, racket); 00147 00148 txMoveAR (arInfo); 00149 txMoveAR (ar, pos.x, pos.y); 00150 00151 Sleep (0); 00152 } 00153 00154 txDeleteAR (ar); 00155 txDeleteAR (arInfo); 00156 00157 txDeleteDC (racket); 00158 txDeleteDC (info); 00159 } 00160