Animate: unicodification & cleanup

Dimitrie O. Paun dpaun at rogers.com
Wed Mar 2 09:29:34 CST 2005


ChangeLog
    Unicodification of the animate control.
    Indentation and style fixes. Cleanups.


Index: dlls/comctl32/animate.c
===================================================================
RCS file: /var/cvs/wine/dlls/comctl32/animate.c,v
retrieving revision 1.60
diff -u -r1.60 animate.c
--- dlls/comctl32/animate.c	23 Dec 2004 18:24:50 -0000	1.60
+++ dlls/comctl32/animate.c	2 Mar 2005 15:26:16 -0000
@@ -3,7 +3,8 @@
  * Animation control
  *
  * Copyright 1998, 1999 Eric Kohl
- * 		   1999 Eric Pouech
+ * Copyright 1999 Eric Pouech
+ * Copyright 2005 Dimitrie O. Paun
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -86,23 +87,23 @@
    HBITMAP  	    	hbmPrevFrame;
 } ANIMATE_INFO;
 
-#define ANIMATE_GetInfoPtr(hWnd) ((ANIMATE_INFO *)GetWindowLongPtrW(hWnd, 0))
 #define ANIMATE_COLOR_NONE  	0xffffffff
 
-static void ANIMATE_Notify(ANIMATE_INFO* infoPtr, UINT notif)
+static void ANIMATE_Notify(ANIMATE_INFO *infoPtr, UINT notif)
 {
-    SendMessageA(infoPtr->hwndNotify, WM_COMMAND,
+    SendMessageW(infoPtr->hwndNotify, WM_COMMAND,
 		 MAKEWPARAM(GetDlgCtrlID(infoPtr->hwndSelf), notif),
 		 (LPARAM)infoPtr->hwndSelf);
 }
 
-static BOOL ANIMATE_LoadResA(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPSTR lpName)
+static BOOL ANIMATE_LoadResW(ANIMATE_INFO *infoPtr, HINSTANCE hInst, LPWSTR lpName)
 {
+    static const WCHAR aviW[] = { 'A', 'V', 'I', 0 };
     HRSRC 	hrsrc;
     MMIOINFO	mminfo;
     LPVOID	lpAvi;
 
-    hrsrc = FindResourceA(hInst, lpName, "AVI");
+    hrsrc = FindResourceW(hInst, lpName, aviW);
     if (!hrsrc)
 	return FALSE;
 
@@ -118,8 +119,9 @@
     mminfo.fccIOProc = FOURCC_MEM;
     mminfo.pchBuffer = (LPSTR)lpAvi;
     mminfo.cchBuffer = SizeofResource(hInst, hrsrc);
-    infoPtr->hMMio = mmioOpenA(NULL, &mminfo, MMIO_READ);
-    if (!infoPtr->hMMio) {
+    infoPtr->hMMio = mmioOpenW(NULL, &mminfo, MMIO_READ);
+    if (!infoPtr->hMMio) 
+    {
 	FreeResource(infoPtr->hRes);
 	return FALSE;
     }
@@ -128,19 +130,15 @@
 }
 
 
-static BOOL ANIMATE_LoadFileA(ANIMATE_INFO *infoPtr, LPSTR lpName)
+static BOOL ANIMATE_LoadFileW(ANIMATE_INFO *infoPtr, LPWSTR lpName)
 {
-    infoPtr->hMMio = mmioOpenA((LPSTR)lpName, NULL,
-			       MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
-
-    if (!infoPtr->hMMio)
-	return FALSE;
+    infoPtr->hMMio = mmioOpenW(lpName, 0, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE);
 
-    return TRUE;
+    return (BOOL)infoPtr->hMMio;
 }
 
 
-static LRESULT ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
+static BOOL ANIMATE_DoStop(ANIMATE_INFO *infoPtr)
 {
     EnterCriticalSection(&infoPtr->cs);
 
@@ -165,7 +163,8 @@
         CloseHandle( infoPtr->hStopEvent );
         infoPtr->hStopEvent = 0;
     }
-    if (infoPtr->uTimer) {
+    if (infoPtr->uTimer) 
+    {
 	KillTimer(infoPtr->hwndSelf, infoPtr->uTimer);
 	infoPtr->uTimer = 0;
     }
@@ -180,16 +179,20 @@
 
 static void ANIMATE_Free(ANIMATE_INFO *infoPtr)
 {
-    if (infoPtr->hMMio) {
+    if (infoPtr->hMMio) 
+    {
 	ANIMATE_DoStop(infoPtr);
 	mmioClose(infoPtr->hMMio, 0);
-	if (infoPtr->hRes) {
+	infoPtr->hMMio = 0;
+	if (infoPtr->hRes) 
+        {
  	    FreeResource(infoPtr->hRes);
 	    infoPtr->hRes = 0;
 	}
         HeapFree(GetProcessHeap(), 0, infoPtr->lpIndex);
         infoPtr->lpIndex = NULL;
-	if (infoPtr->hic) {
+	if (infoPtr->hic) 
+        {
 	    fnIC.fnICClose(infoPtr->hic);
 	    infoPtr->hic = 0;
 	}
@@ -206,18 +209,16 @@
 	    DeleteObject(infoPtr->hbmPrevFrame);
             infoPtr->hbmPrevFrame = 0;
         }
-	infoPtr->indata = infoPtr->outdata = NULL;
-	infoPtr->hwndSelf = 0;
-	infoPtr->hMMio = 0;
 
 	memset(&infoPtr->mah, 0, sizeof(infoPtr->mah));
 	memset(&infoPtr->ash, 0, sizeof(infoPtr->ash));
-	infoPtr->nFromFrame = infoPtr->nToFrame = infoPtr->nLoop = infoPtr->currFrame = 0;
+	infoPtr->nFromFrame = infoPtr->nToFrame = 0;
+        infoPtr->nLoop = infoPtr->currFrame = 0;
     }
     infoPtr->transparentColor = ANIMATE_COLOR_NONE;
 }
 
-static void ANIMATE_TransparentBlt(ANIMATE_INFO* infoPtr, HDC hdcDest, HDC hdcSource)
+static void ANIMATE_TransparentBlt(ANIMATE_INFO *infoPtr, HDC hdcDest, HDC hdcSource)
 {
     HDC hdcMask;
     HBITMAP hbmMask;
@@ -225,31 +226,35 @@
 
     /* create a transparency mask */
     hdcMask = CreateCompatibleDC(hdcDest);
-    hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1,1,NULL);
+    hbmMask = CreateBitmap(infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 1, 1, NULL);
     hbmOld = SelectObject(hdcMask, hbmMask);
 
     SetBkColor(hdcSource,infoPtr->transparentColor);
-    BitBlt(hdcMask,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCCOPY);
+    BitBlt(hdcMask, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 
+           hdcSource, 0, 0, SRCCOPY);
 
     /* mask the source bitmap */
     SetBkColor(hdcSource, RGB(0,0,0));
     SetTextColor(hdcSource, RGB(255,255,255));
-    BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
+    BitBlt(hdcSource, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 
+           hdcMask, 0, 0, SRCAND);
 
     /* mask the destination bitmap */
     SetBkColor(hdcDest, RGB(255,255,255));
     SetTextColor(hdcDest, RGB(0,0,0));
-    BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, hdcMask, 0, 0, SRCAND);
+    BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight, 
+           hdcMask, 0, 0, SRCAND);
 
     /* combine source and destination */
-    BitBlt(hdcDest,0,0,infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,hdcSource,0,0,SRCPAINT);
+    BitBlt(hdcDest, 0, 0, infoPtr->inbih->biWidth, infoPtr->inbih->biHeight,
+           hdcSource, 0, 0, SRCPAINT);
 
     SelectObject(hdcMask, hbmOld);
     DeleteObject(hbmMask);
     DeleteDC(hdcMask);
 }
 
-static LRESULT ANIMATE_PaintFrame(ANIMATE_INFO* infoPtr, HDC hDC)
+static BOOL ANIMATE_PaintFrame(ANIMATE_INFO *infoPtr, HDC hDC)
 {
     void* pBitmapData = NULL;
     LPBITMAPINFO pBitmapInfo = NULL;
@@ -273,7 +278,8 @@
 
         nWidth = infoPtr->outbih->biWidth;
         nHeight = infoPtr->outbih->biHeight;
-    } else
+    } 
+    else
     {
         pBitmapData = infoPtr->indata;
         pBitmapInfo = (LPBITMAPINFO)infoPtr->inbih;
@@ -302,7 +308,7 @@
         infoPtr->transparentColor = GetPixel(hdcMem,0,0);
     }
 
-    if(GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
+    if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
     {
         HDC hdcFinal = CreateCompatibleDC(hDC);
         HBITMAP hbmFinal = CreateCompatibleBitmap(hDC,nWidth, nHeight);
@@ -327,7 +333,7 @@
         infoPtr->hbmPrevFrame = hbmFinal;
          }
 
-    if (GetWindowLongA(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER)
+    if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER)
     {
        RECT rect;
 
@@ -342,7 +348,7 @@
     return TRUE;
 }
 
-static LRESULT ANIMATE_DrawFrame(ANIMATE_INFO* infoPtr)
+static BOOL ANIMATE_DrawFrame(ANIMATE_INFO *infoPtr)
 {
     HDC		hDC;
 
@@ -355,23 +361,26 @@
 
     if (infoPtr->hic &&
 	fnIC.fnICDecompress(infoPtr->hic, 0, infoPtr->inbih, infoPtr->indata,
-		     infoPtr->outbih, infoPtr->outdata) != ICERR_OK) {
+		     infoPtr->outbih, infoPtr->outdata) != ICERR_OK) 
+    {
 	LeaveCriticalSection(&infoPtr->cs);
 	WARN("Decompression error\n");
 	return FALSE;
     }
 
-    if ((hDC = GetDC(infoPtr->hwndSelf)) != 0) {
+    if ((hDC = GetDC(infoPtr->hwndSelf)) != 0) 
+    {
 	ANIMATE_PaintFrame(infoPtr, hDC);
 	ReleaseDC(infoPtr->hwndSelf, hDC);
     }
 
-    if (infoPtr->currFrame++ >= infoPtr->nToFrame) {
+    if (infoPtr->currFrame++ >= infoPtr->nToFrame) 
+    {
 	infoPtr->currFrame = infoPtr->nFromFrame;
-	if (infoPtr->nLoop != -1) {
-	    if (--infoPtr->nLoop == 0) {
+	if (infoPtr->nLoop != -1) 
+        {
+	    if (--infoPtr->nLoop == 0) 
 		ANIMATE_DoStop(infoPtr);
-	    }
 	}
     }
     LeaveCriticalSection(&infoPtr->cs);
@@ -381,7 +390,7 @@
 
 static DWORD CALLBACK ANIMATE_AnimationThread(LPVOID ptr_)
 {
-    ANIMATE_INFO*	infoPtr = (ANIMATE_INFO*)ptr_;
+    ANIMATE_INFO *infoPtr = (ANIMATE_INFO *)ptr_;
     HANDLE event;
     DWORD timeout;
 
@@ -400,22 +409,21 @@
     return TRUE;
 }
 
-static LRESULT ANIMATE_Play(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static LRESULT ANIMATE_Play(ANIMATE_INFO *infoPtr, UINT cRepeat, WORD wFrom, WORD wTo)
 {
-    ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
-
     /* nothing opened */
     if (!infoPtr->hMMio)
 	return FALSE;
 
-    if (infoPtr->hThread || infoPtr->uTimer) {
+    if (infoPtr->hThread || infoPtr->uTimer) 
+    {
 	TRACE("Already playing\n");
 	return TRUE;
     }
 
-    infoPtr->nFromFrame = (INT)LOWORD(lParam);
-    infoPtr->nToFrame   = (INT)HIWORD(lParam);
-    infoPtr->nLoop      = (INT)wParam;
+    infoPtr->nFromFrame = wFrom;
+    infoPtr->nToFrame   = wTo;
+    infoPtr->nLoop      = cRepeat;
 
     if (infoPtr->nToFrame == 0xFFFF)
 	infoPtr->nToFrame = infoPtr->mah.dwTotalFrames - 1;
@@ -429,24 +437,30 @@
 
     infoPtr->currFrame = infoPtr->nFromFrame;
 
-    if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TIMER) {
+    if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_TIMER) 
+    {
 	TRACE("Using a timer\n");
 	/* create a timer to display AVI */
-	infoPtr->uTimer = SetTimer(hWnd, 1, infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
-    } else {
-        if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
+	infoPtr->uTimer = SetTimer(infoPtr->hwndSelf, 1, 
+                                   infoPtr->mah.dwMicroSecPerFrame / 1000, NULL);
+    } 
+    else 
+    {
+        if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
         {
-            infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
-                                                     WM_CTLCOLORSTATIC, 0, (LPARAM)hWnd);
+            infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
+                                                     WM_CTLCOLORSTATIC, 0, 
+                                                     (LPARAM)infoPtr->hwndSelf);
         }
 
 	TRACE("Using an animation thread\n");
         infoPtr->hStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
-        infoPtr->hThread = CreateThread(0,0,ANIMATE_AnimationThread,(LPVOID)infoPtr, 0, &infoPtr->threadId);
+        infoPtr->hThread = CreateThread(0, 0, ANIMATE_AnimationThread,
+                                        (LPVOID)infoPtr, 0, &infoPtr->threadId);
         if(!infoPtr->hThread)
         {
-           ERR("Could not create animation thread!\n");
-           return FALSE;
+            ERR("Could not create animation thread!\n");
+            return FALSE;
         }
 
     }
@@ -466,25 +480,29 @@
     DWORD		numFrame;
     DWORD		insize;
 
-    if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &ckMainRIFF, NULL, 0) != 0) 
+    {
 	WARN("Can't find 'RIFF' chunk\n");
 	return FALSE;
     }
 
     if ((ckMainRIFF.ckid != FOURCC_RIFF) ||
-	(ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) {
+	(ckMainRIFF.fccType != mmioFOURCC('A', 'V', 'I', ' '))) 
+    {
 	WARN("Can't find 'AVI ' chunk\n");
 	return FALSE;
     }
 
     mmckHead.fccType = mmioFOURCC('h', 'd', 'r', 'l');
-    if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &mmckHead, &ckMainRIFF, MMIO_FINDLIST) != 0) 
+    {
 	WARN("Can't find 'hdrl' list\n");
 	return FALSE;
     }
 
     mmckInfo.ckid = mmioFOURCC('a', 'v', 'i', 'h');
-    if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckHead, MMIO_FINDCHUNK) != 0) 
+    {
 	WARN("Can't find 'avih' chunk\n");
 	return FALSE;
     }
@@ -505,13 +523,15 @@
     mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
 
     mmckList.fccType = mmioFOURCC('s', 't', 'r', 'l');
-    if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &mmckList, &mmckHead, MMIO_FINDLIST) != 0) 
+    {
 	WARN("Can't find 'strl' list\n");
 	return FALSE;
     }
 
     mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'h');
-    if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) 
+    {
 	WARN("Can't find 'strh' chunk\n");
 	return FALSE;
     }
@@ -543,13 +563,15 @@
     mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
 
     mmckInfo.ckid = mmioFOURCC('s', 't', 'r', 'f');
-    if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, MMIO_FINDCHUNK) != 0) 
+    {
 	WARN("Can't find 'strh' chunk\n");
 	return FALSE;
     }
 
     infoPtr->inbih = HeapAlloc(GetProcessHeap(), 0, mmckInfo.cksize);
-    if (!infoPtr->inbih) {
+    if (!infoPtr->inbih) 
+    {
 	WARN("Can't alloc input BIH\n");
 	return FALSE;
     }
@@ -588,7 +610,8 @@
     /* no need to read optional JUNK chunk */
 
     mmckList.fccType = mmioFOURCC('m', 'o', 'v', 'i');
-    if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) {
+    if (mmioDescend(infoPtr->hMMio, &mmckList, &ckMainRIFF, MMIO_FINDLIST) != 0) 
+    {
 	WARN("Can't find 'movi' list\n");
 	return FALSE;
     }
@@ -597,40 +620,39 @@
 
     infoPtr->lpIndex = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 				 infoPtr->mah.dwTotalFrames * sizeof(DWORD));
-    if (!infoPtr->lpIndex) {
-	WARN("Can't alloc index array\n");
+    if (!infoPtr->lpIndex) 
 	return FALSE;
-    }
 
     numFrame = insize = 0;
     while (mmioDescend(infoPtr->hMMio, &mmckInfo, &mmckList, 0) == 0 &&
-	   numFrame < infoPtr->mah.dwTotalFrames) {
+	   numFrame < infoPtr->mah.dwTotalFrames) 
+    {
 	infoPtr->lpIndex[numFrame] = mmckInfo.dwDataOffset;
 	if (insize < mmckInfo.cksize)
 	    insize = mmckInfo.cksize;
 	numFrame++;
 	mmioAscend(infoPtr->hMMio, &mmckInfo, 0);
     }
-    if (numFrame != infoPtr->mah.dwTotalFrames) {
+    if (numFrame != infoPtr->mah.dwTotalFrames) 
+    {
 	WARN("Found %ld frames (/%ld)\n", numFrame, infoPtr->mah.dwTotalFrames);
 	return FALSE;
     }
-    if (insize > infoPtr->ash.dwSuggestedBufferSize) {
+    if (insize > infoPtr->ash.dwSuggestedBufferSize) 
+    {
 	WARN("insize=%ld suggestedSize=%ld\n", insize, infoPtr->ash.dwSuggestedBufferSize);
 	infoPtr->ash.dwSuggestedBufferSize = insize;
     }
 
     infoPtr->indata = HeapAlloc(GetProcessHeap(), 0, infoPtr->ash.dwSuggestedBufferSize);
-    if (!infoPtr->indata) {
-	WARN("Can't alloc input buffer\n");
+    if (!infoPtr->indata) 
 	return FALSE;
-    }
 
     return TRUE;
 }
 
 
-static BOOL    ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
+static BOOL ANIMATE_GetAviCodec(ANIMATE_INFO *infoPtr)
 {
     DWORD	outSize;
 
@@ -645,7 +667,8 @@
 
     /* try to get a decompressor for that type */
     infoPtr->hic = fnIC.fnICOpen(ICTYPE_VIDEO, infoPtr->ash.fccHandler, ICMODE_DECOMPRESS);
-    if (!infoPtr->hic) {
+    if (!infoPtr->hic) 
+    {
 	WARN("Can't load codec for the file\n");
 	return FALSE;
     }
@@ -654,25 +677,23 @@
 			    (DWORD)infoPtr->inbih, 0L);
 
     infoPtr->outbih = HeapAlloc(GetProcessHeap(), 0, outSize);
-    if (!infoPtr->outbih) {
-	WARN("Can't alloc output BIH\n");
+    if (!infoPtr->outbih)
 	return FALSE;
-    }
 
     if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_GET_FORMAT,
-		      (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) {
+		      (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != outSize) 
+    {
 	WARN("Can't get output BIH\n");
 	return FALSE;
     }
 
     infoPtr->outdata = HeapAlloc(GetProcessHeap(), 0, infoPtr->outbih->biSizeImage);
-    if (!infoPtr->outdata) {
-	WARN("Can't alloc output buffer\n");
+    if (!infoPtr->outdata) 
 	return FALSE;
-    }
 
     if (fnIC.fnICSendMessage(infoPtr->hic, ICM_DECOMPRESS_BEGIN,
-		      (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) {
+		      (DWORD)infoPtr->inbih, (DWORD)infoPtr->outbih) != ICERR_OK) 
+    {
 	WARN("Can't begin decompression\n");
 	return FALSE;
     }
@@ -680,74 +701,92 @@
     return TRUE;
 }
 
-static LRESULT ANIMATE_OpenA(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static BOOL ANIMATE_OpenW(ANIMATE_INFO *infoPtr, HINSTANCE hInstance, LPWSTR lpszName)
 {
-    ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
-    HINSTANCE hInstance = (HINSTANCE)wParam;
-
     ANIMATE_Free(infoPtr);
-    infoPtr->hwndSelf = hWnd;
 
-    if (!lParam) {
+    if (!lpszName) 
+    {
 	TRACE("Closing avi!\n");
         /* installer of thebat! v1.62 requires FALSE here */
 	return (infoPtr->hMMio != 0);
     }
 
     if (!hInstance)
-       hInstance = (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE);
+        hInstance = (HINSTANCE)GetWindowLongPtrW(infoPtr->hwndSelf, GWLP_HINSTANCE);
 
-    if (HIWORD(lParam)) {
-	TRACE("(\"%s\");\n", (LPSTR)lParam);
+    if (HIWORD(lpszName)) 
+    {
+	TRACE("(\"%s\");\n", debugstr_w(lpszName));
 
-	if (!ANIMATE_LoadResA(infoPtr, hInstance, (LPSTR)lParam)) {
+	if (!ANIMATE_LoadResW(infoPtr, hInstance, lpszName)) 
+        {
 	    TRACE("No AVI resource found!\n");
-	    if (!ANIMATE_LoadFileA(infoPtr, (LPSTR)lParam)) {
+	    if (!ANIMATE_LoadFileW(infoPtr, lpszName)) 
+            {
 		WARN("No AVI file found!\n");
 		return FALSE;
 	    }
 	}
-    } else {
-	TRACE("(%u);\n", (WORD)LOWORD(lParam));
+    } 
+    else 
+    {
+	TRACE("(%u);\n", (WORD)(DWORD)lpszName);
 
-	if (!ANIMATE_LoadResA(infoPtr, hInstance,
-			      MAKEINTRESOURCEA((INT)lParam))) {
+	if (!ANIMATE_LoadResW(infoPtr, hInstance, MAKEINTRESOURCEW((INT)lpszName))) 
+        {
 	    WARN("No AVI resource found!\n");
 	    return FALSE;
 	}
     }
 
-    if (!ANIMATE_GetAviInfo(infoPtr)) {
+    if (!ANIMATE_GetAviInfo(infoPtr)) 
+    {
 	WARN("Can't get AVI information\n");
 	ANIMATE_Free(infoPtr);
 	return FALSE;
     }
 
-    if (!ANIMATE_GetAviCodec(infoPtr)) {
+    if (!ANIMATE_GetAviCodec(infoPtr)) 
+    {
 	WARN("Can't get AVI Codec\n");
 	ANIMATE_Free(infoPtr);
 	return FALSE;
     }
 
-    if (!GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
-	SetWindowPos(hWnd, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
+    if (!GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER) 
+	SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, infoPtr->mah.dwWidth, infoPtr->mah.dwHeight,
 		     SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER);
-    }
 
-    if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_AUTOPLAY) {
-	return ANIMATE_Play(hWnd, -1, (LPARAM)MAKELONG(0, infoPtr->mah.dwTotalFrames-1));
-    }
+    if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_AUTOPLAY) 
+	return ANIMATE_Play(infoPtr, -1, 0, infoPtr->mah.dwTotalFrames - 1);
 
     return TRUE;
 }
 
 
-/* << ANIMATE_Open32W >> */
-
-static LRESULT ANIMATE_Stop(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static BOOL ANIMATE_OpenA(ANIMATE_INFO *infoPtr, HINSTANCE hInstance, LPSTR lpszName)
 {
-    ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
+    LPWSTR lpwszName;
+    LRESULT result;
+    INT len;
+
+    if (!HIWORD(lpszName))
+        return ANIMATE_OpenW(infoPtr, hInstance, (LPWSTR)lpszName);
+
+    len = MultiByteToWideChar(CP_ACP, 0, lpszName, -1, NULL, 0);
+    lpwszName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
+    if (!lpwszName) return FALSE;
+    MultiByteToWideChar(CP_ACP, 0, lpszName, -1, lpwszName, len);
+
+    result = ANIMATE_OpenW(infoPtr, hInstance, lpwszName);
+    HeapFree(GetProcessHeap(), 0, lpwszName);
+    return result;
+}
 
+
+static BOOL ANIMATE_Stop(ANIMATE_INFO *infoPtr)
+{
     /* nothing opened */
     if (!infoPtr->hMMio)
 	return FALSE;
@@ -757,9 +796,10 @@
 }
 
 
-static LRESULT ANIMATE_Create(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static BOOL ANIMATE_Create(HWND hWnd, LPCREATESTRUCTW lpcs)
 {
-    ANIMATE_INFO*	infoPtr;
+    static const WCHAR msvfw32W[] = { 'm', 's', 'v', 'f', 'w', '3', '2', '.', 'd', 'l', 'l', 0 };
+    ANIMATE_INFO *infoPtr;
 
     if (!fnIC.hModule) /* FIXME: not thread safe */
     {
@@ -768,7 +808,7 @@
 	 * - handle it by hand
 	 * AJ wants the latter :-(
 	 */
-	fnIC.hModule = LoadLibraryA("msvfw32.dll");
+	fnIC.hModule = LoadLibraryW(msvfw32W);
 	if (!fnIC.hModule) return FALSE;
 
 	fnIC.fnICOpen        = (void*)GetProcAddress(fnIC.hModule, "ICOpen");
@@ -779,19 +819,16 @@
 
     /* allocate memory for info structure */
     infoPtr = (ANIMATE_INFO *)Alloc(sizeof(ANIMATE_INFO));
-    if (!infoPtr) {
-	ERR("could not allocate info memory!\n");
-	return 0;
-    }
+    if (!infoPtr) return FALSE;
 
     /* store crossref hWnd <-> info structure */
     SetWindowLongPtrW(hWnd, 0, (DWORD_PTR)infoPtr);
     infoPtr->hwndSelf = hWnd;
-    infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
+    infoPtr->hwndNotify = lpcs->hwndParent;
     infoPtr->transparentColor = ANIMATE_COLOR_NONE;
     infoPtr->hbmPrevFrame = 0;
 
-    TRACE("Animate style=0x%08lx, parent=%p\n", GetWindowLongA(hWnd, GWL_STYLE), infoPtr->hwndNotify);
+    TRACE("Animate style=0x%08lx, parent=%p\n", GetWindowLongW(hWnd, GWL_STYLE), infoPtr->hwndNotify);
 
     InitializeCriticalSection(&infoPtr->cs);
 
@@ -799,97 +836,91 @@
 }
 
 
-static LRESULT ANIMATE_Destroy(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static LRESULT ANIMATE_Destroy(ANIMATE_INFO *infoPtr)
 {
-    ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
-
-
     /* free avi data */
     ANIMATE_Free(infoPtr);
 
     /* free animate info data */
+    SetWindowLongPtrW(infoPtr->hwndSelf, 0, 0);
     Free(infoPtr);
-    SetWindowLongPtrW(hWnd, 0, 0);
 
     return 0;
 }
 
 
-static LRESULT ANIMATE_EraseBackground(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static BOOL ANIMATE_EraseBackground(ANIMATE_INFO *infoPtr, HDC hdc)
 {
-    ANIMATE_INFO *infoPtr = ANIMATE_GetInfoPtr(hWnd);
     RECT rect;
     HBRUSH hBrush = 0;
 
-    if(GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
+    if(GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
     {
-        hBrush = (HBRUSH)SendMessageA(infoPtr->hwndNotify,WM_CTLCOLORSTATIC,
-				      wParam, (LPARAM)hWnd);
+        hBrush = (HBRUSH)SendMessageW(infoPtr->hwndNotify, WM_CTLCOLORSTATIC,
+				      (WPARAM)hdc, (LPARAM)infoPtr->hwndSelf);
     }
 
-    GetClientRect(hWnd, &rect);
-    FillRect((HDC)wParam, &rect, hBrush ? hBrush : GetCurrentObject((HDC)wParam, OBJ_BRUSH));
+    GetClientRect(infoPtr->hwndSelf, &rect);
+    FillRect(hdc, &rect, hBrush ? hBrush : GetCurrentObject(hdc, OBJ_BRUSH));
 
     return TRUE;
 }
 
-static LRESULT WINAPI ANIMATE_Size(HWND hWnd, WPARAM wParam, LPARAM lParam)
+static LRESULT WINAPI ANIMATE_Size(ANIMATE_INFO *infoPtr, INT flags, WORD width, WORD height)
 {
-    if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_CENTER) {
-	InvalidateRect(hWnd, NULL, TRUE);
+    if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_CENTER) 
+    {
+	InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
     }
     return TRUE;
 }
 
 static LRESULT WINAPI ANIMATE_WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
+    ANIMATE_INFO *infoPtr = (ANIMATE_INFO *)GetWindowLongPtrW(hWnd, 0);
+
     TRACE("hwnd=%p msg=%x wparam=%x lparam=%lx\n", hWnd, uMsg, wParam, lParam);
-    if (!ANIMATE_GetInfoPtr(hWnd) && (uMsg != WM_NCCREATE))
-	return DefWindowProcA(hWnd, uMsg, wParam, lParam);
+    if (!infoPtr && (uMsg != WM_NCCREATE))
+	return DefWindowProcW(hWnd, uMsg, wParam, lParam);
     switch (uMsg)
     {
     case ACM_OPENA:
-	return ANIMATE_OpenA(hWnd, wParam, lParam);
+	return ANIMATE_OpenA(infoPtr, (HINSTANCE)wParam, (LPSTR)lParam);
 
     case ACM_OPENW:
-	FIXME("ACM_OPENW: stub!\n");
-	/* return ANIMATE_Open32W(hWnd, wParam, lParam); */
-	return 0;
+	return ANIMATE_OpenW(infoPtr, (HINSTANCE)wParam, (LPWSTR)lParam);
 
     case ACM_PLAY:
-	return ANIMATE_Play(hWnd, wParam, lParam);
+	return ANIMATE_Play(infoPtr, (INT)wParam, LOWORD(lParam), HIWORD(lParam));
 
     case ACM_STOP:
-	return ANIMATE_Stop(hWnd, wParam, lParam);
+	return ANIMATE_Stop(infoPtr);
 
     case WM_NCCREATE:
-	return ANIMATE_Create(hWnd, wParam, lParam);
+	return ANIMATE_Create(hWnd, (LPCREATESTRUCTW)lParam);
 
     case WM_NCHITTEST:
 	return HTTRANSPARENT;
 
     case WM_DESTROY:
-	return ANIMATE_Destroy(hWnd, wParam, lParam);
+	return ANIMATE_Destroy(infoPtr);
 
     case WM_ERASEBKGND:
-	return ANIMATE_EraseBackground(hWnd, wParam, lParam);
+	return ANIMATE_EraseBackground(infoPtr, (HDC)wParam);
 
     /*	case WM_STYLECHANGED: FIXME shall we do something ?? */
 
     case WM_TIMER:
-    	if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
+    	if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
         {
-            ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
-            infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
+            infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
 						     WM_CTLCOLORSTATIC,
-						     wParam, (LPARAM)hWnd);
+						     wParam, (LPARAM)infoPtr->hwndSelf);
         }
-	return ANIMATE_DrawFrame(ANIMATE_GetInfoPtr(hWnd));
+	return ANIMATE_DrawFrame(infoPtr);
 
     case WM_PAINT:
         {
-            ANIMATE_INFO* infoPtr = ANIMATE_GetInfoPtr(hWnd);
-
             /* the animation isn't playing, or has not decompressed
              * (and displayed) the first frame yet, don't paint
              */
@@ -897,13 +928,13 @@
                 !infoPtr->hbmPrevFrame)
             {
                 /* default paint handling */
-                return DefWindowProcA(hWnd, uMsg, wParam, lParam);
+                return DefWindowProcW(hWnd, uMsg, wParam, lParam);
             }
 
-            if (GetWindowLongA(hWnd, GWL_STYLE) & ACS_TRANSPARENT)
-                infoPtr->hbrushBG = (HBRUSH)SendMessageA(infoPtr->hwndNotify,
+            if (GetWindowLongW(infoPtr->hwndSelf, GWL_STYLE) & ACS_TRANSPARENT)
+                infoPtr->hbrushBG = (HBRUSH)SendMessageW(infoPtr->hwndNotify,
 							 WM_CTLCOLORSTATIC,
-							 wParam, (LPARAM)hWnd);
+							 wParam, (LPARAM)infoPtr->hwndSelf);
 
             if (wParam)
             {
@@ -914,47 +945,47 @@
             else
             {
 	        PAINTSTRUCT ps;
- 	        HDC hDC = BeginPaint(hWnd, &ps);
+ 	        HDC hDC = BeginPaint(infoPtr->hwndSelf, &ps);
 
                 EnterCriticalSection(&infoPtr->cs);
                 ANIMATE_PaintFrame(infoPtr, hDC);
                 LeaveCriticalSection(&infoPtr->cs);
 
-	        EndPaint(hWnd, &ps);
+	        EndPaint(infoPtr->hwndSelf, &ps);
 	    }
         }
 	break;
 
     case WM_SIZE:
-	return ANIMATE_Size(hWnd, wParam, lParam);
+	return ANIMATE_Size(infoPtr, (INT)wParam, LOWORD(lParam), HIWORD(lParam));
 
     default:
 	if ((uMsg >= WM_USER) && (uMsg < WM_APP))
 	    ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
 
-	return DefWindowProcA(hWnd, uMsg, wParam, lParam);
+	return DefWindowProcW(hWnd, uMsg, wParam, lParam);
     }
     return 0;
 }
 
 void ANIMATE_Register(void)
 {
-    WNDCLASSA wndClass;
+    WNDCLASSW wndClass;
 
-    ZeroMemory(&wndClass, sizeof(WNDCLASSA));
+    ZeroMemory(&wndClass, sizeof(WNDCLASSW));
     wndClass.style         = CS_GLOBALCLASS | CS_DBLCLKS;
     wndClass.lpfnWndProc   = ANIMATE_WindowProc;
     wndClass.cbClsExtra    = 0;
     wndClass.cbWndExtra    = sizeof(ANIMATE_INFO *);
-    wndClass.hCursor       = LoadCursorA(0, (LPSTR)IDC_ARROW);
+    wndClass.hCursor       = LoadCursorW(0, (LPCWSTR)IDC_ARROW);
     wndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
-    wndClass.lpszClassName = ANIMATE_CLASSA;
+    wndClass.lpszClassName = ANIMATE_CLASSW;
 
-    RegisterClassA(&wndClass);
+    RegisterClassW(&wndClass);
 }
 
 
 void ANIMATE_Unregister(void)
 {
-    UnregisterClassA(ANIMATE_CLASSA, NULL);
+    UnregisterClassW(ANIMATE_CLASSW, NULL);
 }

-- 
Dimi.



More information about the wine-patches mailing list