Changeset 10097 for trunk/src/comctl32/animate.c
- Timestamp:
- May 15, 2003, 4:25:14 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/animate.c
r8382 r10097 29 29 */ 30 30 31 #define COM_NO_WINDOWS_H 31 32 #include <string.h> 32 33 #include "winbase.h" … … 79 80 int currFrame; 80 81 /* tranparency info*/ 81 COLORREF transparentColor; 82 COLORREF transparentColor; 82 83 HBRUSH hbrushBG; 83 84 HBITMAP hbmPrevFrame; … … 89 90 static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif) 90 91 { 91 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND, 92 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif), 92 SendMessageA(GetParent(infoPtr->hWnd), WM_COMMAND, 93 MAKEWPARAM(GetDlgCtrlID(infoPtr->hWnd), notif), 93 94 (LPARAM)infoPtr->hWnd); 94 95 } … … 99 100 MMIOINFO mminfo; 100 101 LPVOID lpAvi; 101 102 102 103 hrsrc = FindResourceA(hInst, lpName, "AVI"); 103 104 if (!hrsrc) 104 105 return FALSE; 105 106 106 107 infoPtr->hRes = LoadResource(hInst, hrsrc); 107 108 if (!infoPtr->hRes) 108 109 return FALSE; 109 110 110 111 lpAvi = LockResource(infoPtr->hRes); 111 112 if (!lpAvi) 112 113 return FALSE; 113 114 114 115 memset(&mminfo, 0, sizeof(mminfo)); 115 116 mminfo.fccIOProc = FOURCC_MEM; … … 130 131 infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL, 131 132 MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); 132 133 133 134 if (!infoPtr->hMMio) 134 135 return FALSE; 135 136 136 137 return TRUE; 137 138 } … … 143 144 144 145 /* should stop playing */ 145 if (infoPtr->hThread) 146 if (infoPtr->hThread) 146 147 { 147 148 if (!TerminateThread(infoPtr->hThread,0)) … … 205 206 infoPtr->hWnd = 0; 206 207 infoPtr->hMMio = 0; 207 208 208 209 memset(&infoPtr->mah, 0, sizeof(infoPtr->mah)); 209 210 memset(&infoPtr->ash, 0, sizeof(infoPtr->ash)); 210 211 infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0; 211 212 } 212 infoPtr->transparentColor = ANIMATE_COLOR_NONE; 213 infoPtr->transparentColor = ANIMATE_COLOR_NONE; 213 214 } 214 215 215 216 static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource) 216 { 217 { 217 218 HDC hdcMask; 218 219 HBITMAP hbmMask; 219 HBITMAP hbmOld; 220 220 HBITMAP hbmOld; 221 221 222 /* create a transparency mask */ 222 223 hdcMask = CreateCompatibleDC(hdcDest); 223 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL); 224 hbmOld = SelectObject(hdcMask, hbmMask); 224 hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL); 225 hbmOld = SelectObject(hdcMask, hbmMask); 225 226 226 227 SetBkColor(hdcSource,infoPtr->transparentColor); 227 228 BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY); 228 229 229 230 /* mask the source bitmap */ 230 SetBkColor(hdcSource, RGB(0,0,0)); 231 SetTextColor(hdcSource, RGB(255,255,255)); 231 SetBkColor(hdcSource, RGB(0,0,0)); 232 SetTextColor(hdcSource, RGB(255,255,255)); 232 233 BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND); 233 234 234 235 /* mask the destination bitmap */ 235 SetBkColor(hdcDest, RGB(255,255,255)); 236 SetTextColor(hdcDest, RGB(0,0,0)); 236 SetBkColor(hdcDest, RGB(255,255,255)); 237 SetTextColor(hdcDest, RGB(0,0,0)); 237 238 BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND); 238 239 … … 268 269 269 270 nWidth = infoPtr->outbih->biWidth; 270 nHeight = infoPtr->outbih->biHeight; 271 nHeight = infoPtr->outbih->biHeight; 271 272 } else 272 { 273 { 273 274 pBitmapData = infoPtr->indata; 274 275 pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih; 275 276 276 277 nWidth = infoPtr->inbih->biWidth; 277 nHeight = infoPtr->inbih->biHeight; 278 } 278 nHeight = infoPtr->inbih->biHeight; 279 } 279 280 280 281 if(!infoPtr->hbmPrevFrame) … … 283 284 } 284 285 285 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS); 286 286 SetDIBits(hDC, infoPtr->hbmPrevFrame, 0, nHeight, pBitmapData, (LPBITMAPINFO)pBitmapInfo, DIB_RGB_COLORS); 287 287 288 hdcMem = CreateCompatibleDC(hDC); 288 289 hbmOld = SelectObject(hdcMem, infoPtr->hbmPrevFrame); 289 290 290 /* 291 * we need to get the transparent color even without ACS_TRANSPARENT, 291 /* 292 * we need to get the transparent color even without ACS_TRANSPARENT, 292 293 * because the style can be changed later on and the color should always 293 * be obtained in the first frame 294 * be obtained in the first frame 294 295 */ 295 296 if(infoPtr->transparentColor == ANIMATE_COLOR_NONE) 296 297 { 297 298 infoPtr->transparentColor = GetPixel(hdcMem,0,0); 298 } 299 300 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT) 301 { 299 } 300 301 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT) 302 { 302 303 HDC hdcFinal = CreateCompatibleDC(hDC); 303 304 HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight); 304 305 HBITMAP hbmOld2 = SelectObject(hdcFinal, hbmFinal); 305 306 RECT rect; 306 307 307 308 rect.left = 0; 308 309 rect.top = 0; 309 310 rect.right = nWidth; 310 311 rect.bottom = nHeight; 311 312 312 313 if(!infoPtr->hbrushBG) 313 314 infoPtr->hbrushBG = GetCurrentObject(hDC, OBJ_BRUSH); … … 322 323 infoPtr->hbmPrevFrame = hbmFinal; 323 324 } 324 325 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER) 326 { 327 RECT rect; 325 326 if (GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_CENTER) 327 { 328 RECT rect; 328 329 329 330 GetWindowRect(infoPtr->hWnd, &rect); 330 nOffsetX = ((rect.right - rect.left) - nWidth)/2; 331 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2; 332 } 333 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY); 331 nOffsetX = ((rect.right - rect.left) - nWidth)/2; 332 nOffsetY = ((rect.bottom - rect.top) - nHeight)/2; 333 } 334 BitBlt(hDC, nOffsetX, nOffsetY, nWidth, nHeight, hdcMem, 0, 0, SRCCOPY); 334 335 335 336 SelectObject(hdcMem, hbmOld); … … 348 349 mmioSeek(infoPtr->hMMio, infoPtr->lpIndex[infoPtr->currFrame], SEEK_SET); 349 350 mmioRead(infoPtr->hMMio, infoPtr->indata, infoPtr->ash.dwSuggestedBufferSize); 350 351 351 352 if (infoPtr->hic && 352 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata, 353 fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata, 353 354 infoPtr->outbih, infoPtr->outdata) != ICERR_OK) { 354 355 LeaveCriticalSection(&infoPtr->cs); … … 379 380 ANIMATE_INFO* infoPtr = (ANIMATE_INFO*)ptr_; 380 381 HDC hDC; 381 382 382 383 if(!infoPtr) 383 384 { … … 387 388 388 389 while(1) 389 { 390 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT) 390 { 391 if(GetWindowLongA(infoPtr->hWnd, GWL_STYLE) & ACS_TRANSPARENT) 391 392 { 392 393 hDC = GetDC(infoPtr->hWnd); 393 394 /* sometimes the animation window will be destroyed in between 394 395 * by the main program, so a ReleaseDC() error msg is possible */ 395 infoPtr->hbrushBG = SendMessageA(GetParent(infoPtr->hWnd),WM_CTLCOLORSTATIC,hDC, infoPtr->hWnd); 396 infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(infoPtr->hWnd), 397 WM_CTLCOLORSTATIC, (WPARAM)hDC, 398 (LPARAM)infoPtr->hWnd); 396 399 ReleaseDC(infoPtr->hWnd,hDC); 397 400 } 398 401 399 402 EnterCriticalSection(&infoPtr->cs); 400 403 ANIMATE_DrawFrame(infoPtr); 401 404 LeaveCriticalSection(&infoPtr->cs); 402 405 403 406 /* time is in microseconds, we should convert it to milliseconds */ 404 407 Sleep((infoPtr->mah.dwMicroSecPerFrame+500)/1000); … … 427 430 infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1; 428 431 429 TRACE("(repeat=%d from=%d to=%d);\n", 432 TRACE("(repeat=%d from=%d to=%d);\n", 430 433 infoPtr->nLoop, infoPtr->nFromFrame, infoPtr->nToFrame); 431 434 … … 444 447 445 448 TRACE("Using an animation thread\n"); 446 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0,0&threadID);449 infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &threadID); 447 450 if(!infoPtr->hThread) 448 451 { … … 450 453 return FALSE; 451 454 } 452 453 } 454 455 456 } 457 455 458 ANIMATE_Notify(infoPtr, ACN_START); 456 459 … … 520 523 mmioRead(infoPtr->hMMio, (LPSTR)&infoPtr->ash, sizeof(infoPtr->ash)); 521 524 522 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)), 523 HIBYTE(LOWORD(infoPtr->ash.fccType)), 524 LOBYTE(HIWORD(infoPtr->ash.fccType)), 525 TRACE("ash.fccType='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccType)), 526 HIBYTE(LOWORD(infoPtr->ash.fccType)), 527 LOBYTE(HIWORD(infoPtr->ash.fccType)), 525 528 HIBYTE(HIWORD(infoPtr->ash.fccType))); 526 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)), 527 HIBYTE(LOWORD(infoPtr->ash.fccHandler)), 528 LOBYTE(HIWORD(infoPtr->ash.fccHandler)), 529 TRACE("ash.fccHandler='%c%c%c%c'\n", LOBYTE(LOWORD(infoPtr->ash.fccHandler)), 530 HIBYTE(LOWORD(infoPtr->ash.fccHandler)), 531 LOBYTE(HIWORD(infoPtr->ash.fccHandler)), 529 532 HIBYTE(HIWORD(infoPtr->ash.fccHandler))); 530 533 TRACE("ash.dwFlags=%ld\n", infoPtr->ash.dwFlags); … … 539 542 TRACE("ash.dwQuality=%ld\n", infoPtr->ash.dwQuality); 540 543 TRACE("ash.dwSampleSize=%ld\n", infoPtr->ash.dwSampleSize); 541 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left, 544 TRACE("ash.rcFrame=(%d,%d,%d,%d)\n", infoPtr->ash.rcFrame.top, infoPtr->ash.rcFrame.left, 542 545 infoPtr->ash.rcFrame.bottom, infoPtr->ash.rcFrame.right); 543 546 … … 573 576 574 577 mmioAscend(infoPtr->hMMio, &mmckList, 0); 575 578 576 579 #if 0 577 580 /* an AVI has 0 or 1 video stream, and to be animated should not contain 578 * an audio stream, so only one strl is allowed 581 * an audio stream, so only one strl is allowed 579 582 */ 580 583 mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l'); … … 597 600 /* FIXME: should handle the 'rec ' LIST when present */ 598 601 599 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 602 infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 600 603 infoPtr->mah.dwTotalFrames * sizeof(DWORD)); 601 604 if (!infoPtr->lpIndex) { … … 605 608 606 609 numFrame = insize = 0; 607 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 && 610 while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 && 608 611 numFrame < infoPtr->mah.dwTotalFrames) { 609 612 infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset; … … 641 644 (infoPtr->ash.fccHandler == mmioFOURCC(0, 0, 0, 0))) 642 645 { 643 infoPtr->hic = 0; 646 infoPtr->hic = 0; 644 647 return TRUE; 645 648 } … … 651 654 return FALSE; 652 655 } 653 654 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT, 656 657 outSize = fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT, 655 658 (DWORD)infoPtr->inbih, 0L); 656 659 … … 661 664 } 662 665 663 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT, 664 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {666 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT, 667 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) { 665 668 WARN("Can't get output BIH\n"); 666 669 return FALSE; … … 673 676 } 674 677 675 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN, 678 if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN, 676 679 (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) { 677 680 WARN("Can't begin decompression\n"); … … 692 695 if (!lParam) { 693 696 TRACE("Closing avi!\n"); 694 return TRUE; 695 } 696 697 /* installer of thebat! v1.62 requires FALSE here */ 698 return (infoPtr->hMMio != 0); 699 } 700 697 701 if (!hInstance) 698 hInstance = GetWindowLongA(hWnd, GWL_HINSTANCE);702 hInstance = (HINSTANCE)GetWindowLongA(hWnd, GWL_HINSTANCE); 699 703 700 704 if (HIWORD(lParam)) { … … 794 798 795 799 InitializeCriticalSection(&infoPtr->cs); 796 800 797 801 return 0; 798 802 } … … 818 822 { 819 823 RECT rect; 820 HBRUSH hBrush = 0; 821 822 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT) 823 { 824 hBrush = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd); 824 HBRUSH hBrush = 0; 825 826 if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT) 827 { 828 hBrush = (HBRUSH)SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC, 829 wParam, (LPARAM)hWnd); 825 830 } 826 831 … … 841 846 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 842 847 { 843 TRACE("hwnd=% xmsg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);848 TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam); 844 849 if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE)) 845 850 return DefWindowProcA(hWnd, uMsg, wParam, lParam); … … 848 853 case ACM_OPENA: 849 854 return ANIMATE_OpenA(hWnd, wParam, lParam); 850 855 851 856 /* case ACM_OPEN32W: FIXME!! */ 852 857 /* return ANIMATE_Open32W(hWnd, wParam, lParam); */ 853 858 854 859 case ACM_PLAY: 855 860 return ANIMATE_Play(hWnd, wParam, lParam); 856 861 857 862 case ACM_STOP: 858 863 return ANIMATE_Stop(hWnd, wParam, lParam); 859 864 860 865 case WM_NCCREATE: 861 866 ANIMATE_Create(hWnd, wParam, lParam); 862 867 return DefWindowProcA(hWnd, uMsg, wParam, lParam); 863 868 864 869 case WM_NCHITTEST: 865 870 return HTTRANSPARENT; … … 868 873 ANIMATE_Destroy(hWnd, wParam, lParam); 869 874 return DefWindowProcA(hWnd, uMsg, wParam, lParam); 870 875 871 876 case WM_ERASEBKGND: 872 877 ANIMATE_EraseBackground(hWnd, wParam, lParam); … … 879 884 { 880 885 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd); 881 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd),WM_CTLCOLORSTATIC,(HDC)wParam, hWnd); 886 infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(hWnd), 887 WM_CTLCOLORSTATIC, 888 wParam, (LPARAM)hWnd); 882 889 } 883 890 return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd)); 884 891 885 892 case WM_CLOSE: 886 893 ANIMATE_Free(ANIMATE_GetInfoPtr(hWnd)); … … 890 897 { 891 898 ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd); 892 899 893 900 /* the animation isn't playing, don't paint */ 894 901 if(!infoPtr->uTimer && !infoPtr->hThread) 895 902 /* default paint handling */ 896 903 return DefWindowProcA(hWnd, uMsg, wParam, lParam); 897 904 898 905 if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT) 899 infoPtr->hbrushBG = SendMessageA(GetParent(hWnd), WM_CTLCOLORSTATIC, 900 (HDC)wParam, hWnd); 901 906 infoPtr->hbrushBG = (HBRUSH)SendMessageA(GetParent(hWnd), 907 WM_CTLCOLORSTATIC, 908 wParam, (LPARAM)hWnd); 909 902 910 if (wParam) 903 911 { … … 914 922 ANIMATE_PaintFrame(infoPtr, hDC); 915 923 LeaveCriticalSection(&infoPtr->cs); 916 924 917 925 EndPaint(hWnd, &ps); 918 926 } … … 925 933 926 934 default: 927 if ( uMsg >= WM_USER)935 if ((uMsg >= WM_USER) && (uMsg < WM_APP)) 928 936 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam); 929 937 930 938 return DefWindowProcA(hWnd, uMsg, wParam, lParam); 931 939 } … … 945 953 wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); 946 954 wndClass.lpszClassName = ANIMATE_CLASSA; 947 955 948 956 RegisterClassA(&wndClass); 949 957 } … … 952 960 void ANIMATE_Unregister(void) 953 961 { 954 UnregisterClassA(ANIMATE_CLASSA, (HINSTANCE)NULL); 955 } 956 962 UnregisterClassA(ANIMATE_CLASSA, NULL); 963 }
Note:
See TracChangeset
for help on using the changeset viewer.