Example #1
0
void CSkinButton::OnPaint() 
{
	if ( !m_res || !m_res->m_bInited )
	{
		Default();
		return;
	}
	//Note:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	// to draw button, cliprgn is needed
	//
	CPaintDC dc(this); // device context for painting
	CRect r;
	CMyBitmap bmp;
	GetClientRect(r);
	DrawImage(bmp);
	SetWindowRgn(bmp.CreateRgnFromFile(RGB(255,0,255)), TRUE );

	
	HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
	GetWindowRgn(hRgn);				
	::SelectClipRgn(dc.GetSafeHdc(), hRgn);
	bmp.Draw( &dc, r );	
	dc.SelectClipRgn(NULL);
	DeleteObject(hRgn);
	
	//dc.BitBlt( 0, 0, r.Width(), r.Height(), &memDC, 0, 0, SRCCOPY);
	DrawText( &dc );

	// TODO: Add your message handler code here
	// Do not call CButton::OnPaint() for painting messages
}
	LRESULT OnMouseMove(HWND hWnd, UINT nFlags, CPoint point ) {
		HRGN hRgn = CreateRectRgn( 0, 0, 0, 0 );
		GetWindowRgn( hWnd,hRgn );
		BOOL ret = PtInRegion( hRgn, point.x, point.y );
		if( ret ) 
		{
			
			if( m_State == bsDown) 
				return TRUE;
			if( m_State != bsHot ) 
			{
				m_State = bsHot;
				InvalidateRect(hWnd,NULL,TRUE);
				UpdateWindow(hWnd);
				SetCapture(hWnd);
			}
		} 
		else 
		{
			m_State = bsNormal;
			InvalidateRect(hWnd,NULL,TRUE);	
			ReleaseCapture();
		}	
		DeleteObject( hRgn );
		return TRUE;
	}
Example #3
0
void CSkinButton::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
	GetWindowRgn(hRgn);		

	if ( PtInRegion( hRgn, point.x, point.y ))
	{
		if ( !m_bMouseIn)
		{
			m_bMouseIn = TRUE;
			//GetRegion();
			Invalidate();
			UpdateWindow();
			SetCapture();
		}
	}
	else
	{
		if ( m_bMouseIn)
		{
			m_bMouseIn = FALSE;
			//GetRegion();
			Invalidate();
			UpdateWindow();
			if ( !m_bDown )
				ReleaseCapture();
		}

	}
	DeleteObject(hRgn);
}
void CMyBalloon::OnPaint() 
{
	CPaintDC dc(this); 

	CRgn rgn; 
	rgn.CreateRectRgn (0,0,0,0);
	GetWindowRgn (rgn);
	
	CBrush brWnd; brWnd.CreateSolidBrush (m_pContent->getBkColor ());
	CBrush br1; br1.CreateSolidBrush (m_pContent->getTextColor ());
	dc.FillRgn (&rgn, &brWnd);
	dc.FrameRgn (&rgn, &br1, 1, 1);
}
Example #5
0
VOID StatUpdate()
{
    HDC hdc;
    HDC hdcSav;
	HRGN hrgn = { 0 };

    if(hwndStat == NULL)
        return;
	GetWindowRgn(hwndStat, hrgn);
    if (hdc = GetDC(hwndStat))
    {
        hdcSav = HdcSet(hdc, 0, 0);
        StatRender();
        HdcSet(hdcSav, 0, 0);
        ReleaseDC(hwndStat, hdc);
    }
}
Example #6
0
void SharedDesktopArea::DrawFrameAroundWindow(HWND hWnd)
{
	HDC hWindowDc=::GetWindowDC(hWnd);
	HBRUSH hBrush=CreateSolidBrush(RGB(0,0,0));
	HRGN Rgn=CreateRectRgn(0,0,1,1);
	int iRectResult=GetWindowRgn(hWnd,Rgn);
	if (iRectResult==ERROR || iRectResult==NULLREGION || Rgn==NULL)
	{
		RECT rect;
		GetWindowRect(hWnd,&rect);
		OffsetRect(&rect,-rect.left,-rect.top);
		Rgn=CreateRectRgn(rect.left,rect.top,rect.right,rect.bottom);
	}
	
	SetROP2(hWindowDc,R2_MERGEPENNOT);
	FrameRgn(hWindowDc,Rgn,hBrush,3,3);
	::DeleteObject(Rgn);
	::DeleteObject(hBrush);
    ::ReleaseDC(hWnd,hWindowDc);
}
Example #7
0
VOID StatStringSz(TCHAR *sz)
{
    HDC hdc, hdcSav;
    RC rc;
	HRGN hrgn = { 0 };

    if(hwndStat == NULL)
            return;
	GetWindowRgn(hwndStat, hrgn);
    hdc = GetDC(hwndStat);
    if(hdc == NULL)
            return;
    hdcSav =        HdcSet(hdc, 0, 0);
    GetClientRect(hwndStat, (LPRECT) &rc);
    PatBlt(hdcCur, rc.xLeft, rc.yTop, rc.xRight-rc.xLeft, rc.yBot-rc.yTop, PATCOPY);
    TextOut(hdcCur, dxStatMarg, 0, sz, lstrlen(sz));
    StatRender();
    HdcSet(hdcSav, 0, 0);
   ReleaseDC(hwndStat, hdc);
}
Example #8
0
//
//   FUNCTION: InitInstance(HINSTANCE, int)
//
//   PURPOSE: Saves instance handle and creates main window
//
//   COMMENTS:
//
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   config.init();
   hInst = hInstance; // Store instance handle in our global variable

   hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);

   if (!hWnd)
   {
      return FALSE;
   }

   GetWindowRgn(hWnd, oldRgn);

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);
   DialogBox(hInst, MAKEINTRESOURCE(IDD_SETTINGS), hWnd, Settings);

   return TRUE;
}
LRESULT ControlMediaPlayer::Evento_Mouse_Movimiento(const int cX, const int cY, const UINT wParam) {
	UltimoMovimiento = GetTickCount();
	if (EstaEnPantallaCompleta() == true) {
		DWL::SO::DWLMouse::Visible(TRUE);
		RECT  Recta;
		POINT MousePos;
		DWL::SO::DWLMouse::ObtenerPosicion(&MousePos);
		HRGN RMP = CreateRectRgn(0, 0, 0, 0);
		GetWindowRgn(Sistema.App.ControlesMP.hWnd(), RMP);
		
		GetWindowRect(_hWnd, &Recta);
		int x;
		if (Recta.left > 0) x = ((Recta.right - Recta.left) - CONTROLESMP_ANCHO) / 2;
		else				x = (((Recta.right + Recta.left) + CONTROLESMP_ANCHO) / 2) - CONTROLESMP_ANCHO;
		if (ControlesMP_Abajo == true) {
			int y = (Recta.bottom - Recta.top) - CONTROLESMP_ALTO;
			int r = OffsetRgn(RMP, x, y);
			if (PtInRegion(RMP, MousePos.x, MousePos.y) == TRUE) {
				Sistema.App.ControlesMP.Mostrar(_hWnd, ControlesMP_Abajo);
			}
			else {
				Sistema.App.ControlesMP.Ocultar(hWnd());
			}
		}
		else {
			OffsetRgn(RMP, x, 0);
			if (PtInRegion(RMP, MousePos.x, MousePos.y) == TRUE) {
				Sistema.App.ControlesMP.Mostrar(_hWnd, ControlesMP_Abajo);
			}
			else {
				Sistema.App.ControlesMP.Ocultar(hWnd());
			}
		}
		DeleteObject(RMP);
	}
	return 0;
}
void CDlgShowControl::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	HRGN hRgn = CreateRectRgn(0, 0, 0, 0);
	GetWindowRgn(hRgn);		

	if (PtInRegion( hRgn, point.x, point.y ))
	{
		::SetCursor(AfxGetApp()->LoadCursor(IDC_MY_HAND));
	
		if (!m_bMouseIn)
		{
			m_bMouseIn = TRUE;
			Invalidate();
			UpdateWindow();
			SetCapture();
		}
	}
	else
	{
		if (m_bMouseIn)
		{
			m_bMouseIn = FALSE;
			
			Invalidate();
			UpdateWindow();
			
			if (!m_bDown )
				ReleaseCapture();
		}
	}
	DeleteObject(hRgn);

	CDialog::OnMouseMove(nFlags, point);
}
Example #11
0
BOOL CALLBACK VBoxEnumFunc(HWND hwnd, LPARAM lParam)
{
    PVBOX_ENUM_PARAM    lpParam = (PVBOX_ENUM_PARAM)lParam;
    DWORD               dwStyle, dwExStyle;
    RECT                rectWindow, rectVisible;

    dwStyle   = GetWindowLong(hwnd, GWL_STYLE);
    dwExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
    if (   !(dwStyle & WS_VISIBLE)
        ||  (dwStyle & WS_CHILD))
        return TRUE;

    Log(("VBoxTray: VBoxEnumFunc %x\n", hwnd));
    /* Only visible windows that are present on the desktop are interesting here */
    if (GetWindowRect(hwnd, &rectWindow))
    {
        char szWindowText[256];
        szWindowText[0] = 0;
        OSVERSIONINFO OSinfo;
        HWND hStart = NULL;
        GetWindowText(hwnd, szWindowText, sizeof(szWindowText));
        OSinfo.dwOSVersionInfoSize = sizeof (OSinfo);
        GetVersionEx (&OSinfo);
        if (OSinfo.dwMajorVersion >= 6)
        {
            hStart = ::FindWindowEx(GetDesktopWindow(), NULL, "Button", "Start");
            if (  hwnd == hStart && szWindowText != NULL
                && !(strcmp(szWindowText, "Start"))
               )
            {
                /* for vista and above. To solve the issue of small bar above
                 * the Start button when mouse is hovered over the start button in seamless mode.
                 * Difference of 7 is observed in Win 7 platform between the dimensionsof rectangle with Start title and its shadow.
                 */
                rectWindow.top += 7;
                rectWindow.bottom -=7;
            }
        }
        rectVisible = rectWindow;

#ifdef LOG_ENABLED
        DWORD pid = 0;
        DWORD tid = GetWindowThreadProcessId(hwnd, &pid);
#endif

        /* Filter out Windows XP shadow windows */
        /** @todo still shows inside the guest */
        if (   szWindowText[0] == 0
            && (
                    (dwStyle == (WS_POPUP|WS_VISIBLE|WS_CLIPSIBLINGS)
                            && dwExStyle == (WS_EX_LAYERED|WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT|WS_EX_TOPMOST))
                 || (dwStyle == (WS_POPUP|WS_VISIBLE|WS_DISABLED|WS_CLIPSIBLINGS|WS_CLIPCHILDREN)
                            && dwExStyle == (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_LAYERED | WS_EX_NOACTIVATE))
                 || (dwStyle == (WS_POPUP|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN)
                                       && dwExStyle == (WS_EX_TOOLWINDOW))
                            ))
        {
            Log(("VBoxTray: Filter out shadow window style=%x exstyle=%x\n", dwStyle, dwExStyle));
            Log(("VBoxTray: Enum hwnd=%x rect (%d,%d) (%d,%d) (filtered)\n", hwnd, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
            Log(("VBoxTray: title=%s style=%x exStyle=%x\n", szWindowText, dwStyle, dwExStyle));
            Log(("VBoxTray: pid=%d tid=%d\n", pid, tid));
            return TRUE;
        }

        /** @todo will this suffice? The Program Manager window covers the whole screen */
        if (strcmp(szWindowText, "Program Manager"))
        {
            Log(("VBoxTray: Enum hwnd=%x rect (%d,%d) (%d,%d) (applying)\n", hwnd, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
            Log(("VBoxTray: title=%s style=%x exStyle=%x\n", szWindowText, dwStyle, dwExStyle));
            Log(("VBoxTray: pid=%d tid=%d\n", pid, tid));

            HRGN hrgn = CreateRectRgn(0,0,0,0);

            int ret = GetWindowRgn(hwnd, hrgn);

            if (ret == ERROR)
            {
                Log(("VBoxTray: GetWindowRgn failed with rc=%d\n", GetLastError()));
                SetRectRgn(hrgn, rectVisible.left, rectVisible.top, rectVisible.right, rectVisible.bottom);
            }
            else
            {
                /* this region is relative to the window origin instead of the desktop origin */
                OffsetRgn(hrgn, rectWindow.left, rectWindow.top);
            }
            if (lpParam->hrgn)
            {
                /* create a union of the current visible region and the visible rectangle of this window. */
                CombineRgn(lpParam->hrgn, lpParam->hrgn, hrgn, RGN_OR);
                DeleteObject(hrgn);
            }
            else
                lpParam->hrgn = hrgn;
        }
        else
        {
            Log(("VBoxTray: Enum hwnd=%x rect (%d,%d) (%d,%d) (ignored)\n", hwnd, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
            Log(("VBoxTray: title=%s style=%x\n", szWindowText, dwStyle));
            Log(("VBoxTray: pid=%d tid=%d\n", pid, tid));
        }
    }
    return TRUE; /* continue enumeration */
}
Example #12
0
LRESULT CALLBACK _export BalloonProc(HWND hwnd, UINT message, WPARAM wParam,
                                     LPARAM lParam)
{
static DWORD lasttime;  // ??? should be a property
static POINT ttpos;
  RECT rect;
  POINT point;
  int x, y, width, height;
  SIZE size;
  LPSTR ptr;
  char text[256];

  switch (message) {
  case WM_CREATE: {
    HFONT hfont = CreateFont(-11, 0, 0, 0, FW_NORMAL, FALSE, 0, 0, DEFAULT_CHARSET,
                             OUT_DEFAULT_PRECIS, CLIP_CHARACTER_PRECIS,
                             PROOF_QUALITY, FF_DONTCARE, "MS Sans Serif");
    SetProp(hwnd,MAKEINTRESOURCE(atomFont),hfont);
    break;
  } /* case */

  case WM_DESTROY: {
    HFONT hfont = (HFONT)GetProp(hwnd,MAKEINTRESOURCE(atomFont));
    if (hfont)
      DeleteObject(hfont);
    RemoveProp(hwnd,MAKEINTRESOURCE(atomAlignStyle));
    RemoveProp(hwnd,MAKEINTRESOURCE(atomTailSize));
    RemoveProp(hwnd,MAKEINTRESOURCE(atomTimeout));
    RemoveProp(hwnd,MAKEINTRESOURCE(atomFont));
    break;
  } /* case */

  case WM_ERASEBKGND:
    return 0L;

  case WM_LBUTTONDOWN:
  case WM_RBUTTONDOWN:
  case WM_LBUTTONUP:
  case WM_RBUTTONUP:
    ShowWindow(hwnd, SW_HIDE);
    if (IsWindow(GetParent(hwnd)))
      PostMessage(GetParent(hwnd), BAN_VISIBLE, (WPARAM)hwnd, 0L);
    break;

  case WM_WINDOWPOSCHANGING:
  case WM_WINDOWPOSCHANGED:
    return 0L;

  case WM_PAINT: {
    PAINTSTRUCT ps;
    COLORREF clrBackgr;
    HBRUSH hbrBackgr;
    HRGN hrgn;
    int AlignStyle=(int)GetProp(hwnd,MAKEINTRESOURCE(atomAlignStyle));
    HFONT hfont = (HFONT)GetProp(hwnd,MAKEINTRESOURCE(atomFont));

    HDC hdc = BeginPaint(hwnd, &ps);
    GetClientRect(hwnd, &rect);

    clrBackgr=GetNearestColor(hdc, RGB(255,255,192));
    hbrBackgr = CreateSolidBrush(clrBackgr);
    #if defined __WIN32__
      hrgn=CreateRectRgn(0,0,1,1);
      GetWindowRgn(hwnd,hrgn);      /* Win32-only */
    #else
      #if BM_RADIUS==0
        hrgn=CreateRectRgn(rect.left, rect.top, rect.right, rect.bottom);
      #else
        hrgn=CreateRoundRectRgn(rect.left, rect.top, rect.right, rect.bottom, BM_RADIUS, BM_RADIUS);
      #endif
    #endif
    FillRgn(hdc,hrgn,hbrBackgr);
    FrameRgn(hdc,hrgn,GetStockObject(BLACK_BRUSH),1,1);
    DeleteObject(hbrBackgr);

    hfont = SelectObject(hdc, hfont);
    GetWindowText(hwnd, text, sizeof text);
    GetTextExtentPoint(hdc, text, lstrlen(text), &size);
    SetBkMode(hdc, TRANSPARENT);
    y=BM_MARGINTOP;
    if (AlignStyle==BAA_TOP) {
      int TailSize=(int)GetProp(hwnd,MAKEINTRESOURCE(atomTailSize));
      y+=TailSize;
    } /* if */
    for (ptr=strtok(text,"\n"); ptr!=NULL; ptr=strtok(NULL,"\n"), y+=size.cy) {
      GetTextExtentPoint(hdc, ptr, lstrlen(ptr), &size);
      x = ((rect.right-rect.left) - size.cx) / 2;
      TextOut(hdc, x, y, ptr, lstrlen(ptr));
    } /* for */
    SelectObject(hdc, hfont);

    EndPaint(hwnd, &ps);
    break;
  } /* case */

  case WM_TIMER: {
    DWORD timeout=(DWORD)GetProp(hwnd,MAKEINTRESOURCE(atomTimeout));
    DWORD curtime=GetTickCount();
    GetCursorPos(&point);
    if (timeout==0)
      break;
    if (curtime >= lasttime+timeout)
      SendMessage(hwnd, BAM_SHOW, 0, 0L);
    break;
  } /* if */

  case BAM_SETPOS:
    ttpos=*(LPPOINT)lParam;
    break;

  case BAM_SHOW:
    if (wParam) {
      HDC hdc;
      HRGN hrgn;
      int AlignStyle=(int)GetProp(hwnd,MAKEINTRESOURCE(atomAlignStyle));
      int TailSize=(int)GetProp(hwnd,MAKEINTRESOURCE(atomTailSize));
      HFONT hfont=(HFONT)GetProp(hwnd,MAKEINTRESOURCE(atomFont));
      ASSERT(lParam!=0);
      lstrcpy(text, (LPSTR)lParam);
      SetWindowText(hwnd, text);
      InvalidateRect(hwnd, NULL, FALSE);
      hdc = GetDC(hwnd);
      hfont = SelectObject(hdc, hfont);
      for (ptr=strtok(text,"\n"), width=height=0; ptr!=NULL; ptr=strtok(NULL,"\n")) {
        GetTextExtentPoint(hdc, ptr, lstrlen(ptr), &size);
        width = max(width, size.cx);
        height += size.cy;
      } /* for */
      SelectObject(hdc, hfont);
      ReleaseDC(hwnd, hdc);
      width += 2*BM_MARGINX;
      height += BM_MARGINTOP + BM_MARGINBOTTOM;
      #if 0
        // round width up to multiple of 16 pixels and height up to a multiple
        // of 8 pixels
        width+=16-1;
        width=width - (width%16);
        height+=8-1;
        height=height - (height%8);
      #endif
      // also add the tail size to the height
      height+=TailSize;
      // check alignment
      switch (AlignStyle) {
      case BAA_TOP:
        x = ttpos.x - width/4;
        y = ttpos.y;
        break;
      case BAA_BOTTOM:
        x = ttpos.x - width/4;
        y = ttpos.y - height;
        break;
      } /* switch */
      // check screen position against the screen size (width)
      if (x < 0)
        x = 0;
      else if (x+width >= GetSystemMetrics(SM_CXSCREEN)-1)
        x = GetSystemMetrics(SM_CXSCREEN) - width - 1;
      if (y < 0)
        y = 0;
      else if (y+height >= GetSystemMetrics(SM_CYSCREEN)-1)
        y = GetSystemMetrics(SM_CYSCREEN) - height - 1;
      GetWindowRect(hwnd,&rect);  // get first, check later (for new region)
      SetWindowPos(hwnd, HWND_TOPMOST, x, y, width, height, SWP_SHOWWINDOW|SWP_NOACTIVATE);
      hrgn=MakeBalloonRegion(width+1,height+1,BM_RADIUS,AlignStyle,TailSize,ttpos.x-x,ttpos.y-y);
      ASSERT(hrgn!=NULL);
      SetWindowRgn(hwnd, hrgn, TRUE);
      UpdateWindow(hwnd);
      lasttime=GetTickCount();
    } else {
      ShowWindow(hwnd, SW_HIDE);
      lasttime=GetTickCount();
    } /* if */
    break;

  default:
    return DefWindowProc(hwnd, message, wParam, lParam);
  } /* switch */
  return 0L;
}
Example #13
0
FIBITMAP* CaptureScreen  (HDC hDC,SIZE size,HWND hCapture){
//HDC GetDC			(NULL)		entire desktp
//HDC GetDC			(HWND hWnd)	client area of the specified window. (may include artifacts)
//HDC GetWindowDC	(HWND hWnd)	entire window.
	FIBITMAP *dib = NULL;
	HBITMAP hBitmap;					// handles to device-dependent bitmaps
	HDC hScrDC, hMemDC;					// screen DC and memory DC

	// create a DC for the screen and create
	// a memory DC compatible to screen DC
	if(!(hScrDC=hDC)) hScrDC=GetDC(hCapture);
	hMemDC = CreateCompatibleDC(hScrDC);
	// create a bitmap compatible with the screen DC
	hBitmap = CreateCompatibleBitmap(hScrDC,size.cx,size.cy);
	// select new bitmap into memory DC
	SelectObject(hMemDC, hBitmap);

	if(hCapture && hDC){
		PrintWindow(hCapture,hMemDC,0);
	}else{// bitblt screen DC to memory DC
		BitBlt(hMemDC,0,0,size.cx,size.cy,hScrDC,0,0,CAPTUREBLT|SRCCOPY);
	}
	dib = FIP->FI_CreateDIBFromHBITMAP(hBitmap);

	//alpha channel from window is always wrong and sometimes even for desktop (Win7, no aero)
	//coz GDI do not draw all in alpha mode.
	//we have to create our own new alpha channel.
	bool bFixAlpha=true;
	bool bInvert=false;
	HBRUSH hBr=CreateSolidBrush(RGB(255,255,255));//Create a SolidBrush object for non transparent area
	HBITMAP hMask=CreateBitmap(size.cx,size.cy,1,1,NULL);// Create monochrome (1 bit) B+W mask bitmap.
	HDC hMaskDC=CreateCompatibleDC(0);
	SelectBitmap(hMaskDC,hMask);
	HRGN hRgn=CreateRectRgn(0,0,0,0);
	if(hCapture && GetWindowRgn(hCapture,hRgn)==ERROR){
		if((GetWindowLongPtr(hCapture,GWL_EXSTYLE)&WS_EX_LAYERED)){
			BYTE bAlpha=0;
			COLORREF crKey=0;//0x00bbggrr
			DWORD dwFlags=0;
			if(GetLayeredWindowAttributes(hCapture,&crKey,&bAlpha,&dwFlags)) {
				//per window transparency (like fading in a whole window).
				if((dwFlags&LWA_COLORKEY)){
					SetBkColor(hMemDC,crKey);
					BitBlt(hMaskDC,0,0,size.cx,size.cy,hMemDC,0,0,SRCCOPY);
					bInvert=true;
				}else if((dwFlags&LWA_ALPHA)){
					bFixAlpha=false;
				}
			}else{//per-pixel transparency (won't use the WM_PAINT)
				bFixAlpha=false;
			}
		}else{//not layered - fill the window region
			SetRectRgn(hRgn,0,0,size.cx,size.cy);
			FillRgn(hMaskDC,hRgn,hBr);
		}
	}else{
		if(!hCapture) SetRectRgn(hRgn,0,0,size.cx,size.cy);//client area only, no transparency
		FillRgn(hMaskDC,hRgn,hBr);
	}
	DeleteObject(hRgn);
	if(bFixAlpha){
		FIBITMAP* dibMask = FIP->FI_CreateDIBFromHBITMAP(hMask);
		if(bInvert) FIP->FI_Invert(dibMask);
		FIBITMAP* dib8 = FIP->FI_ConvertTo8Bits(dibMask);
		//copy the dib8 alpha mask to dib32 main bitmap
		FIP->FI_SetChannel(dib,dib8,FICC_ALPHA);
		FIP->FI_Unload(dibMask);
		FIP->FI_Unload(dib8);
	}
	DeleteDC(hMaskDC);
	DeleteObject(hMask);
	DeleteObject(hBr);
	//clean up
	DeleteDC(hMemDC);
	DeleteObject(hBitmap);
	if(!hDC) ReleaseDC(NULL, hScrDC);

	#ifdef _DEBUG
	switch (FIP->FI_GetImageType(dib)){
		case FIT_UNKNOWN:
			OutputDebugStringA("FIBITMAP Typ: FIT_UNKNOWN\r\n" );
			break;
		case FIT_BITMAP:
			OutputDebugStringA("FIBITMAP Typ: FIT_BITMAP\r\n" );
			break;
		case FIT_UINT16:
			OutputDebugStringA("FIBITMAP Typ: FIT_UINT16\r\n" );
			break;
		case FIT_INT16:
			OutputDebugStringA("FIBITMAP Typ: FIT_INT16\r\n" );
			break;
		case FIT_UINT32:
			OutputDebugStringA("FIBITMAP Typ: FIT_UINT32\r\n" );
			break;
		case FIT_INT32:
			OutputDebugStringA("FIBITMAP Typ: FIT_INT32\r\n" );
			break;
		case FIT_FLOAT:
			OutputDebugStringA("FIBITMAP Typ: FIT_FLOAT\r\n" );
			break;
		case FIT_DOUBLE:
			OutputDebugStringA("FIBITMAP Typ: FIT_DOUBLE\r\n" );
			break;
		case FIT_COMPLEX:
			OutputDebugStringA("FIBITMAP Typ: FIT_COMPLEX\r\n" );
			break;
		case FIT_RGB16:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGB16\r\n" );
			break;
		case FIT_RGBA16:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGBA16\r\n" );
			break;
		case FIT_RGBF:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGBF\r\n" );
			break;
		case FIT_RGBAF:
			OutputDebugStringA("FIBITMAP Typ: FIT_RGBAF\r\n" );
			break;
		default:
			OutputDebugStringA("FIBITMAP Typ: non detectable image type (error)\r\n" );
			break;
	}
	BOOL inf = FIP->FI_IsTransparent(dib);
	OutputDebugStringA(inf ? "FIBITMAP Transparent: true\r\n" : "FIBITMAP Transparent: false\r\n");
	#endif

	return dib;
}
Example #14
0
void CWndShadow::MakeShadow(UINT32 *pShadBits, HWND hParent, RECT *rcParent)
{
	// The shadow algorithm:
	// Get the region of parent window,
	// Apply morphologic erosion to shrink it into the size (ShadowWndSize - Sharpness)
	// Apply modified (with blur effect) morphologic dilation to make the blurred border
	// The algorithm is optimized by assuming parent window is just "one piece" and without "wholes" on it
	
	// Get the region of parent window,
	HRGN hParentRgn = CreateRectRgn(0, 0, 0, 0);
	GetWindowRgn(hParent, hParentRgn);
	
	// Determine the Start and end point of each horizontal scan line
	SIZE szParent = { rcParent->right - rcParent->left, rcParent->bottom - rcParent->top };
	SIZE szShadow = { szParent.cx + 2 * m_nSize, szParent.cy + 2 * m_nSize };
	// Extra 2 lines (set to be empty) in ptAnchors are used in dilation
	int nAnchors = max(szParent.cy, szShadow.cy);   // # of anchor points pares
	int(*ptAnchors)[2] = new int[nAnchors + 2][2];
	int(*ptAnchorsOri)[2] = new int[szParent.cy][2];   // anchor points, will not modify during erosion
	ptAnchors[0][0] = szParent.cx;
	ptAnchors[0][1] = 0;
	ptAnchors[nAnchors + 1][0] = szParent.cx;
	ptAnchors[nAnchors + 1][1] = 0;
	if (m_nSize > 0)
	{
		// Put the parent window anchors at the center
		for (int i = 0; i < m_nSize; i++)
		{
			ptAnchors[i + 1][0] = szParent.cx;
			ptAnchors[i + 1][1] = 0;
			ptAnchors[szShadow.cy - i][0] = szParent.cx;
			ptAnchors[szShadow.cy - i][1] = 0;
		}
		ptAnchors += m_nSize;
	}
	for (int i = 0; i < szParent.cy; i++)
	{
		// find start point
		int j;
		for (j = 0; j < szParent.cx; j++)
		{
			if (PtInRegion(hParentRgn, j, i))
			{
				ptAnchors[i + 1][0] = j + m_nSize;
				ptAnchorsOri[i][0] = j;
				break;
			}
		}
	
		if (j >= szParent.cx) // Start point not found
		{
			ptAnchors[i + 1][0] = szParent.cx;
			ptAnchorsOri[i][1] = 0;
			ptAnchors[i + 1][0] = szParent.cx;
			ptAnchorsOri[i][1] = 0;
		}
		else
		{
		// find end point
			for (j = szParent.cx - 1; j >= ptAnchors[i + 1][0]; j--)
			{
				if (PtInRegion(hParentRgn, j, i))
				{
					ptAnchors[i + 1][1] = j + 1 + m_nSize;
					ptAnchorsOri[i][1] = j + 1;
					break;
				}
			}
		}
	}

	if (m_nSize > 0)
		ptAnchors -= m_nSize;   // Restore pos of ptAnchors for erosion
	int(*ptAnchorsTmp)[2] = new int[nAnchors + 2][2];  // Store the result of erosion
	// First and last line should be empty
	ptAnchorsTmp[0][0] = szParent.cx;
	ptAnchorsTmp[0][1] = 0;
	ptAnchorsTmp[nAnchors + 1][0] = szParent.cx;
	ptAnchorsTmp[nAnchors + 1][1] = 0;
	int nEroTimes = 0;
	// morphologic erosion
	for (int i = 0; i < m_nSharpness - m_nSize; i++)
	{
		nEroTimes++;
		//ptAnchorsTmp[1][0] = szParent.cx;
		//ptAnchorsTmp[1][1] = 0;
		//ptAnchorsTmp[szParent.cy + 1][0] = szParent.cx;
		//ptAnchorsTmp[szParent.cy + 1][1] = 0;
		for (int j = 1; j < nAnchors + 1; j++)
		{
			ptAnchorsTmp[j][0] = max(ptAnchors[j - 1][0], max(ptAnchors[j][0], ptAnchors[j + 1][0])) + 1;
			ptAnchorsTmp[j][1] = min(ptAnchors[j - 1][1], min(ptAnchors[j][1], ptAnchors[j + 1][1])) - 1;
		}
		// Exchange ptAnchors and ptAnchorsTmp;
		int(*ptAnchorsXange)[2] = ptAnchorsTmp;
		ptAnchorsTmp = ptAnchors;
		ptAnchors = ptAnchorsXange;
	}
	
	// morphologic dilation
	ptAnchors += (m_nSize < 0 ? -m_nSize : 0) + 1;   // now coordinates in ptAnchors are same as in shadow window
	// Generate the kernel
	int nKernelSize = m_nSize > m_nSharpness ? m_nSize : m_nSharpness;
	int nCenterSize = m_nSize > m_nSharpness ? (m_nSize - m_nSharpness) : 0;
	UINT32 *pKernel = new UINT32[(2 * nKernelSize + 1) * (2 * nKernelSize + 1)];
	UINT32 *pKernelIter = pKernel;
	for (int i = 0; i <= 2 * nKernelSize; i++)
	{
		for (int j = 0; j <= 2 * nKernelSize; j++)
		{
			double dLength = sqrt((i - nKernelSize) * (i - nKernelSize) + (j - nKernelSize) * (double)(j - nKernelSize));
			if (dLength < nCenterSize)
				*pKernelIter = m_nDarkness << 24 | PreMultiply(m_Color, m_nDarkness);
			else if (dLength <= nKernelSize)
			{
				UINT32 nFactor = ((UINT32)((1 - (dLength - nCenterSize) / (m_nSharpness + 1)) * m_nDarkness));
				*pKernelIter = nFactor << 24 | PreMultiply(m_Color, nFactor);
			}
			else
				*pKernelIter = 0;
				//TRACE("%d ", *pKernelIter >> 24);
				pKernelIter++;
		}
		//TRACE("\n");
	}
	// Generate blurred border
	for (int i = nKernelSize; i < szShadow.cy - nKernelSize; i++)
	{
		int j;
		if (ptAnchors[i][0] < ptAnchors[i][1])
		{
	
			// Start of line
			for (j = ptAnchors[i][0];j < min(max(ptAnchors[i - 1][0], ptAnchors[i + 1][0]) + 1, ptAnchors[i][1]);j++)
			{
				for (int k = 0; k <= 2 * nKernelSize; k++)
				{
					UINT32 *pPixel = pShadBits +
									(szShadow.cy - i - 1 + nKernelSize - k) * szShadow.cx + j - nKernelSize;
					UINT32 *pKernelPixel = pKernel + k * (2 * nKernelSize + 1);
					for (int l = 0; l <= 2 * nKernelSize; l++)
					{
						if (*pPixel < *pKernelPixel)
							*pPixel = *pKernelPixel;
							
						pPixel++;
						pKernelPixel++;
					}
				 }
			}   // for() start of line
		
			// End of line
			for (j = max(j, min(ptAnchors[i - 1][1], ptAnchors[i + 1][1]) - 1);j < ptAnchors[i][1];j++)
			{
				for (int k = 0; k <= 2 * nKernelSize; k++)
				{
					UINT32 *pPixel = pShadBits +(szShadow.cy - i - 1 + nKernelSize - k) * szShadow.cx + j - nKernelSize;
					UINT32 *pKernelPixel = pKernel + k * (2 * nKernelSize + 1);
					for (int l = 0; l <= 2 * nKernelSize; l++)
					{
						if (*pPixel < *pKernelPixel)
							*pPixel = *pKernelPixel;

						pPixel++;
						pKernelPixel++;
					}
				}
			}   // for() end of line

		}
	}   // for() Generate blurred border
		
		// Erase unwanted parts and complement missing
	UINT32 clCenter = m_nDarkness << 24 | PreMultiply(m_Color, m_nDarkness);
	for (int i = min(nKernelSize, max(m_nSize - m_nyOffset, 0));i < max(szShadow.cy - nKernelSize, min(szParent.cy + m_nSize - m_nyOffset, szParent.cy + 2 * m_nSize));i++)
	{
		UINT32 *pLine = pShadBits + (szShadow.cy - i - 1) * szShadow.cx;
		if (i - m_nSize + m_nyOffset < 0 || i - m_nSize + m_nyOffset >= szParent.cy)   // Line is not covered by parent window
		{
			for (int j = ptAnchors[i][0]; j < ptAnchors[i][1]; j++)
			{
				*(pLine + j) = clCenter;
			}
		}
		else
		{
			for (int j = ptAnchors[i][0];j < min(ptAnchorsOri[i - m_nSize + m_nyOffset][0] + m_nSize - m_nxOffset, ptAnchors[i][1]);j++)
				*(pLine + j) = clCenter;
			for (int j = max(ptAnchorsOri[i - m_nSize + m_nyOffset][0] + m_nSize - m_nxOffset, 0);j < min(ptAnchorsOri[i - m_nSize + m_nyOffset][1] + m_nSize - m_nxOffset, szShadow.cx);j++)
				*(pLine + j) = 0;
			for (int j = max(ptAnchorsOri[i - m_nSize + m_nyOffset][1] + m_nSize - m_nxOffset, ptAnchors[i][0]);j < ptAnchors[i][1];j++)
				*(pLine + j) = clCenter;
		}
	}
	
	// Delete used resources
	delete[](ptAnchors - (m_nSize < 0 ? -m_nSize : 0) - 1);
	delete[] ptAnchorsTmp;
	delete[] ptAnchorsOri;
	delete[] pKernel;
	DeleteObject(hParentRgn);
}
Example #15
0
static void BoxPreview_OnPaint(HWND hwnd, HDC mydc, int mode)
{
	RECT rc;

	switch (mode) {
	case 0:
		{ // Avatar
			HDC hdcAvatar = CreateCompatibleDC(mydc);
			HBITMAP hbmSave = (HBITMAP)SelectObject(hdcAvatar, hbmNoAvatar);
			GetClientRect(hwnd, &rc);
			BITMAP bmp;
			GetObject(hbmNoAvatar, sizeof(bmp), &bmp);
			StretchBlt(mydc, 0, 0, rc.right, rc.bottom, hdcAvatar, 0, 0, abs(bmp.bmWidth), abs(bmp.bmHeight), SRCCOPY);
			SelectObject(hdcAvatar, hbmSave);
			DeleteDC(hdcAvatar);
			HRGN rgn = CreateRoundRectRgn(0, 0, rc.right, rc.bottom, 2 * PopupOptions.avatarRadius, 2 * PopupOptions.avatarRadius);
			FrameRgn(mydc, rgn, (HBRUSH)GetStockObject(BLACK_BRUSH), 1, 1);
			DeleteObject(rgn);
			break;
		}
	case 1:
		{ // Opacity
			HBRUSH hbr = CreateSolidBrush(fonts.clBack);
			HFONT hfnt = (HFONT)SelectObject(mydc, fonts.title);
			GetClientRect(hwnd, &rc);
			FillRect(mydc, &rc, hbr);
			DrawIconEx(mydc, 10, (rc.bottom-rc.top-16)/2, IcoLib_GetIcon(ICO_POPUP_ON,0), 16, 16, 0, hbr, DI_NORMAL);
			SetBkMode(mydc, TRANSPARENT);
			GetClientRect(hwnd, &rc);
			rc.left += 30; // 10+16+4 -- icon
			rc.right -= (rc.right-rc.left)/3;
			rc.bottom -= (rc.bottom-rc.top)/3;
			DrawText(mydc, _T(MODULNAME_LONG), lstrlen(_T(MODULNAME_LONG)), &rc, DT_CENTER|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);
			GetClientRect(hwnd, &rc);
			rc.left += 30; // 10+16+4 -- icon
			rc.left += (rc.right-rc.left)/3;
			rc.top += (rc.bottom-rc.top)/3;
			DrawText(mydc, _T(MODULNAME_LONG), lstrlen(_T(MODULNAME_LONG)), &rc, DT_CENTER|DT_NOPREFIX|DT_SINGLELINE|DT_VCENTER);
			GetClientRect(hwnd, &rc);
			FrameRect(mydc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
			SelectObject(mydc, hfnt);
			DeleteObject(hbr);
		}
		break;

	case 2:
		{ // Position
			HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
			GetClientRect(hwnd, &rc);
			FillRect(mydc, &rc, hbr);
			DeleteObject(hbr);

			hbr = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
			GetClientRect(hwnd, &rc);
			rc.right -= 100;
			rc.top += 100;
			FillRect(mydc, &rc, hbr);
			DeleteObject(hbr);

			HPEN hpen = (HPEN)SelectObject(mydc, CreatePen(PS_DOT, 1, RGB(0,0,0)));
			MoveToEx(mydc,   0, 100, NULL);
			LineTo  (mydc, 201, 100);
			MoveToEx(mydc, 100,   0, NULL);
			LineTo  (mydc, 100, 201);
			DeleteObject(SelectObject(mydc, hpen));

			HRGN hrgn = CreateRectRgn(0,0,0,0);
			GetWindowRgn(hwnd, hrgn);
			FrameRgn(mydc, hrgn, (HBRUSH)GetStockObject(BLACK_BRUSH), 1, 1);
			DeleteObject(hrgn);
		}
		break;
	}
}
Example #16
0
LRESULT OverlayWindow::onLeftButtonUp(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	POINT p;
	GetCursorPos(&p);
	if (((MainWindow *)_parent)->getCaptureMode() == 1) {
		ShowWindow(_handle, SW_HIDE);
		_selectedWindow = WindowFromPoint(p);
		ShowWindow(_handle, SW_SHOW);
		_selectedWindow = GetAncestor(_selectedWindow, GA_ROOT);
		if (_selectedWindow != NULL) {
			HRGN overlayrgn = CreateRectRgn(0,0,0,0);
			HRGN combine = CreateRectRgn(0,0,0,0);
			int n = GetWindowRgn(_handle, overlayrgn);
			HRGN hrgn = CreateRectRgn(0,0,0,0);
			int regionType = GetWindowRgn(_selectedWindow, hrgn);
			RECT r1, r2;
			GetWindowRect(_handle, &r1);
			GetWindowRect(_selectedWindow, &r2);
			if (regionType == 0) {
				hrgn = CreateRectRgn(r2.left, r2.top,r2.right,r2.bottom);
			} else {
				OffsetRgn(hrgn, r2.left - r1.left, r2.top - r1.top);
			}
			CombineRgn(combine, overlayrgn, hrgn, RGN_DIFF);
			SetWindowRgn(_handle, combine, TRUE);
			_selection->move(r2.left, r2.top, r2.right - r2.left, r2.bottom - r2.top);
			regionType = GetWindowRgn(_selectedWindow, hrgn);
			if (regionType == 0) {
				hrgn = CreateRectRgn(0, 0, r2.right - r2.left, r2.bottom - r2.top);
			}
			SetWindowRgn(_selection->getHandle(), hrgn, TRUE);
			_selection->show(SW_SHOW);
		}
	} else {
		int x, y, width, height;
		RECT r = getRect();
		HRGN overlayRgn = CreateRectRgn(0, 0, r.right, r.bottom);
		width = p.x - _firstPoint.x;
		height = p.y - _firstPoint.y;
		if (width < 0) {
			width = -width;
			x = p.x;
		} else {
			x = _firstPoint.x;
		}
		if (height < 0) {
			height = -height;
			y = p.y;
		} else {
			y = _firstPoint.y;
		}
		HRGN rgn = CreateRectRgn(0, 0, width, height);
		SetWindowRgn(_selection->getHandle(), rgn, TRUE);
		rgn = CreateRectRgn(0, 0, width, height);
		OffsetRgn(rgn, x, y);
		CombineRgn(overlayRgn, overlayRgn, rgn, RGN_DIFF);
		SetWindowRgn(_handle, overlayRgn, FALSE);
		_selection->move(x, y, width, height, false);
		_selection->show(SW_SHOW);
		_isSelecting = false;
	}
	
	return 0;
}
Example #17
0
int GetWindowVisibleState(HWND hWnd, int iStepX, int iStepY) {
	RECT rc = { 0 };
	POINT pt = { 0 };
	register int    i = 0,
                    j = 0,
                    width = 0,
                    height = 0,
                    iCountedDots = 0,
                    iNotCoveredDots = 0;
	HWND hAux = 0;

	if (hWnd == NULL) {
		SetLastError(0x00000006); //Wrong handle
		return -1;
	}
	//Some defaults now. The routine is designed for thin and tall windows.
	if (iStepX <= 0) iStepX = 8;
	if (iStepY <= 0) iStepY = 16;

	HWND hwndFocused = GetFocus();
	
	if (IsIconic(hWnd) || !IsWindowVisible(hWnd))
		return GWVS_HIDDEN;
	else if ( ModernGetSettingByte(NULL,"CList","OnDesktop",SETTING_ONDESKTOP_DEFAULT) || !ModernGetSettingByte(NULL, "CList", "BringToFront", SETTING_BRINGTOFRONT_DEFAULT) )
		return GWVS_VISIBLE;
	else if ( hwndFocused == pcli->hwndContactList || GetParent(hwndFocused) == pcli->hwndContactList )
		return GWVS_VISIBLE;
	else
	{
		int hstep,vstep;
		BITMAP bmp;
		HBITMAP WindowImage;
		int maxx=0;
		int maxy=0;
		int wx=0;
		int dx,dy;
		BYTE *ptr=NULL;
		HRGN rgn=NULL;
		WindowImage=g_CluiData.fLayered?ske_GetCurrentWindowImage():0;
		if (WindowImage&&g_CluiData.fLayered)
		{
			GetObject(WindowImage,sizeof(BITMAP),&bmp);
			ptr=(BYTE*)bmp.bmBits;
			maxx=bmp.bmWidth;
			maxy=bmp.bmHeight;
			wx=bmp.bmWidthBytes;
		}
		else
		{
			RECT rc;
			int i=0;
			rgn=CreateRectRgn(0,0,1,1);
			GetWindowRect(hWnd,&rc);
			GetWindowRgn(hWnd,rgn);
			OffsetRgn(rgn,rc.left,rc.top);
			GetRgnBox(rgn,&rc);
			i=i;
			//maxx=rc.right;
			//maxy=rc.bottom;
		}
		GetWindowRect(hWnd, &rc);
		{
			RECT rcMonitor={0};
			Docking_GetMonitorRectFromWindow(hWnd,&rcMonitor);
			rc.top=rc.top<rcMonitor.top?rcMonitor.top:rc.top;
			rc.left=rc.left<rcMonitor.left?rcMonitor.left:rc.left;
			rc.bottom=rc.bottom>rcMonitor.bottom?rcMonitor.bottom:rc.bottom;
			rc.right=rc.right>rcMonitor.right?rcMonitor.right:rc.right;
		}
		width = rc.right - rc.left;
		height = rc.bottom- rc.top;
		dx=-rc.left;
		dy=-rc.top;
		hstep=width/iStepX;
		vstep=height/iStepY;
		hstep=hstep>0?hstep:1;
		vstep=vstep>0?vstep:1;

		for (i = rc.top; i < rc.bottom; i+=vstep) {
			pt.y = i;
			for (j = rc.left; j < rc.right; j+=hstep) {
				BOOL po=FALSE;
				pt.x = j;
				if (rgn)
					po=PtInRegion(rgn,j,i);
				else
				{
					DWORD a=(GetDIBPixelColor(j+dx,i+dy,maxx,maxy,wx,ptr)&0xFF000000)>>24;
					a=((a*g_CluiData.bCurrentAlpha)>>8);
					po=(a>16);
				}
				if (po||(!rgn&&ptr==0))
				{
					BOOL hWndFound=FALSE;
					HWND hAuxOld=NULL;
					hAux = WindowFromPoint(pt);
					do
					{
						if (hAux==hWnd)
						{
							hWndFound=TRUE;
							break;
						}
						//hAux = GetParent(hAux);
						hAuxOld=hAux;
						hAux = fnGetAncestor(hAux,GA_ROOTOWNER);
						if (hAuxOld==hAux)
						{
							TCHAR buf[255];
							GetClassName(hAux,buf,SIZEOF(buf));
							if (!lstrcmp(buf,CLUIFrameSubContainerClassName))
							{
								hWndFound=TRUE;
								break;
							}
						}
					}while(hAux!= NULL &&hAuxOld!=hAux);

					if (hWndFound) //There's  window!
						iNotCoveredDots++; //Let's count the not covered dots.
					iCountedDots++; //Let's keep track of how many dots we checked.
				}
			}
		}
		if (rgn) DeleteObject(rgn);
		if ( iCountedDots - iNotCoveredDots<2) //Every dot was not covered: the window is visible.
			return GWVS_VISIBLE;
		else if (iNotCoveredDots == 0) //They're all covered!
			return GWVS_COVERED;
		else //There are dots which are visible, but they are not as many as the ones we counted: it's partially covered.
			return GWVS_PARTIALLY_COVERED;
	}
}
Example #18
0
void CTaskbarNotifier::OnTimer(UINT nIDEvent)
{
	switch (nIDEvent)
	{
		case IDT_APPEARING:
			m_nAnimStatus = IDT_APPEARING;
			switch (m_nTaskbarPlacement)
			{
				case ABE_BOTTOM:
					if (m_nCurrentHeight < m_nBitmapHeight)
					{
						m_nCurrentPosY -= m_nIncrementShow;
						m_nCurrentHeight += m_nIncrementShow;
					}
					else
					{
						KillTimer(IDT_APPEARING);
						SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
						m_nAnimStatus = IDT_WAITING;
					}
					break;

				case ABE_TOP:
					if (m_nCurrentHeight < m_nBitmapHeight)
						m_nCurrentHeight += m_nIncrementShow;
					else
					{
						KillTimer(IDT_APPEARING);
						SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
						m_nAnimStatus = IDT_WAITING;
					}
					break;

				case ABE_LEFT:
					if (m_nCurrentWidth < m_nBitmapWidth)
						m_nCurrentWidth += m_nIncrementShow;
					else
					{
						KillTimer(IDT_APPEARING);
						SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
						m_nAnimStatus = IDT_WAITING;
					}
					break;

				case ABE_RIGHT:
					if (m_nCurrentWidth < m_nBitmapWidth)
					{
						m_nCurrentPosX -= m_nIncrementShow;
						m_nCurrentWidth += m_nIncrementShow;
					}
					else
					{
						KillTimer(IDT_APPEARING);
						SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
						m_nAnimStatus = IDT_WAITING;
					}
					break;
			}
			{
				HRGN hRgn = CreateRectRgn(0,0,0,0);
				GetWindowRgn(hRgn);
				SetWindowPos(NULL/*&wndTopMost*/, m_nCurrentPosX, m_nCurrentPosY, m_nCurrentWidth, m_nCurrentHeight, SWP_NOACTIVATE | SWP_NOZORDER);
				SetWindowRgn(hRgn, TRUE);
			}
			break;

		case IDT_WAITING:
			KillTimer(IDT_WAITING);
			if (m_bAutoClose)
				SetTimer(IDT_DISAPPEARING, m_dwHideEvents, NULL);
			break;

		case IDT_DISAPPEARING:
			m_nAnimStatus = IDT_DISAPPEARING;
			switch (m_nTaskbarPlacement)
			{
				case ABE_BOTTOM:
					if (m_nCurrentHeight > 0)
					{
						m_nCurrentPosY += m_nIncrementHide;
						m_nCurrentHeight -= m_nIncrementHide;
					}
					else
					{
						KillTimer(IDT_DISAPPEARING);
						Hide();						
					}
					break;

				case ABE_TOP:
					if (m_nCurrentHeight > 0)
						m_nCurrentHeight -= m_nIncrementHide;
					else
					{
						KillTimer(IDT_DISAPPEARING);
						Hide();
					}
					break;

				case ABE_LEFT:
					if (m_nCurrentWidth > 0)
						m_nCurrentWidth -= m_nIncrementHide;
					else
					{
						KillTimer(IDT_DISAPPEARING);
						Hide();
					}
					break;

				case ABE_RIGHT:
					if (m_nCurrentWidth > 0)
					{					 
						m_nCurrentPosX += m_nIncrementHide;
						m_nCurrentWidth -= m_nIncrementHide;
					}
					else
					{
						KillTimer(IDT_DISAPPEARING);
						Hide();
					}
					break;
			}
			{
				HRGN hRgn = CreateRectRgn(0,0,0,0);
				GetWindowRgn(hRgn);
				SetWindowPos(NULL/*&wndTopMost*/, m_nCurrentPosX, m_nCurrentPosY, m_nCurrentWidth, m_nCurrentHeight, SWP_NOACTIVATE | SWP_NOZORDER);
				SetWindowRgn(hRgn, TRUE);
			}
			break;
	}

	CWnd::OnTimer(nIDEvent);
}
Example #19
0
void CTaskbarNotifier::Show(LPCTSTR szCaption, int nMsgType, LPCTSTR pszLink, BOOL bAutoClose)
{
	if (nMsgType == TBN_NONOTIFY)
		return;
	UINT nScreenWidth;
	UINT nScreenHeight;
	UINT nEvents;
	UINT nBitmapSize;
	CRect rcTaskbar;
	CTaskbarNotifierHistory* messagePTR;

	SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

	m_strCaption = szCaption;
	m_nActiveMessageType = nMsgType;
	m_strLink = pszLink;

	if (m_bAutoClose) // sets it only if already true, else wait for user action
		m_bAutoClose = bAutoClose;

	if ((nMsgType != TBN_NULL) && (nMsgType != TBN_LOG) && (nMsgType != TBN_IMPORTANTEVENT))
	{
		//Add element into string list. Max 5 elements.
		if (m_MessageHistory.GetCount() == 5) {
			messagePTR = (CTaskbarNotifierHistory*)m_MessageHistory.RemoveHead();
			delete messagePTR;
			messagePTR = NULL;
		}
		messagePTR = new CTaskbarNotifierHistory;
		messagePTR->m_strMessage = m_strCaption;
		messagePTR->m_nMessageType = nMsgType;
		messagePTR->m_strLink = m_strLink;
		m_MessageHistory.AddTail(messagePTR);
	}

	nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
	nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
	HWND hWndTaskbar = ::FindWindow(_T("Shell_TrayWnd"), 0);
	::GetWindowRect(hWndTaskbar, &rcTaskbar);

	// Daniel Lohmann: Calculate taskbar position from its window rect. However, on XP  it may be that 
	// the taskbar is slightly larger or smaller than the screen size. Therefore we allow some tolerance here.
	if (NearlyEqual(rcTaskbar.left, 0, TASKBAR_X_TOLERANCE) && NearlyEqual(rcTaskbar.right, nScreenWidth, TASKBAR_X_TOLERANCE))
	{
		// Taskbar is on top or on bottom
		m_nTaskbarPlacement = NearlyEqual(rcTaskbar.top, 0, TASKBAR_Y_TOLERANCE) ? ABE_TOP : ABE_BOTTOM;
		nBitmapSize = m_nBitmapHeight;
	}
	else
	{
		// Taskbar is on left or on right
		m_nTaskbarPlacement = NearlyEqual(rcTaskbar.left, 0, TASKBAR_X_TOLERANCE) ? ABE_LEFT : ABE_RIGHT;
		nBitmapSize = m_nBitmapWidth;
	}

	// We calculate the pixel increment and the timer value for the showing animation
	if (m_dwTimeToShow > m_dwTimerPrecision)
	{
		nEvents = min((m_dwTimeToShow / m_dwTimerPrecision) / 2, nBitmapSize); //<<-- enkeyDEV(Ottavio84) -Reduced frames of a half-
		//ADDED by VC-fengwen on 2007/10/08 <begin> : nEvents 有可能是0,则会出现异常。
		if (0 == nEvents)
			nEvents = 1;
		//ADDED by VC-fengwen on 2007/10/08 <end> : nEvents 有可能是0,则会出现异常。
		m_dwShowEvents = m_dwTimeToShow / nEvents;
		m_nIncrementShow = nBitmapSize / nEvents;
	}
	else
	{
		m_dwShowEvents = m_dwTimerPrecision;
		m_nIncrementShow = nBitmapSize;
	}

	// We calculate the pixel increment and the timer value for the hiding animation
	if (m_dwTimeToHide > m_dwTimerPrecision)
	{
		nEvents = min((m_dwTimeToHide / m_dwTimerPrecision / 2), nBitmapSize); //<<-- enkeyDEV(Ottavio84) -Reduced frames of a half-
		//ADDED by VC-fengwen on 2007/10/08 <begin> : nEvents 有可能是0,则会出现异常。
		if (0 == nEvents)
			nEvents = 1;
		//ADDED by VC-fengwen on 2007/10/08 <end> : nEvents 有可能是0,则会出现异常。
		m_dwHideEvents = m_dwTimeToHide / nEvents;
		m_nIncrementHide = nBitmapSize / nEvents;
	}
	else
	{
		m_dwShowEvents = m_dwTimerPrecision;
		m_nIncrementHide = nBitmapSize;
	}

	// Compute init values for the animation
	switch (m_nAnimStatus)
	{
		case IDT_HIDDEN:
			if (m_nTaskbarPlacement == ABE_RIGHT)
			{
				m_nCurrentPosX = rcTaskbar.left;
				m_nCurrentPosY = rcTaskbar.bottom - m_nBitmapHeight;
				m_nCurrentWidth = 0;
				m_nCurrentHeight = m_nBitmapHeight;
			}
			else if (m_nTaskbarPlacement == ABE_LEFT)
			{
				m_nCurrentPosX = rcTaskbar.right;
				m_nCurrentPosY = rcTaskbar.bottom - m_nBitmapHeight;
				m_nCurrentWidth = 0;
				m_nCurrentHeight = m_nBitmapHeight;
			}
			else if (m_nTaskbarPlacement == ABE_TOP)
			{
				m_nCurrentPosX = rcTaskbar.right - m_nBitmapWidth;
				m_nCurrentPosY = rcTaskbar.bottom;
				m_nCurrentWidth = m_nBitmapWidth;
				m_nCurrentHeight = 0;
			}
			else
			{
				// Taskbar is on the bottom or Invisible
				m_nCurrentPosX = rcTaskbar.right - m_nBitmapWidth;
				m_nCurrentPosY = rcTaskbar.top;
				m_nCurrentWidth = m_nBitmapWidth;
				m_nCurrentHeight = 0;
			}
			ShowWindow(SW_SHOWNOACTIVATE);
			SetTimer(IDT_APPEARING, m_dwShowEvents, NULL);
			break;

		case IDT_APPEARING:
			RedrawWindow();
			break;

		case IDT_WAITING:
			RedrawWindow();
			KillTimer(IDT_WAITING);
			SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
			break;

		case IDT_DISAPPEARING:
			KillTimer(IDT_DISAPPEARING);
			SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
			if (m_nTaskbarPlacement == ABE_RIGHT)
			{
				m_nCurrentPosX = rcTaskbar.left - m_nBitmapWidth;
				m_nCurrentWidth = m_nBitmapWidth;
			}
			else if (m_nTaskbarPlacement == ABE_LEFT)
			{
				m_nCurrentPosX = rcTaskbar.right;
				m_nCurrentWidth = m_nBitmapWidth;
			}
			else if (m_nTaskbarPlacement == ABE_TOP)
			{
				m_nCurrentPosY = rcTaskbar.bottom;
				m_nCurrentHeight = m_nBitmapHeight;
			}
			else
			{
				m_nCurrentPosY = rcTaskbar.top - m_nBitmapHeight;
				m_nCurrentHeight = m_nBitmapHeight;
			}
			HRGN hRgn = CreateRectRgn(0,0,0,0);
			GetWindowRgn(hRgn);
			SetWindowPos(NULL/*&wndTopMost*/, m_nCurrentPosX, m_nCurrentPosY, m_nCurrentWidth, m_nCurrentHeight, SWP_NOACTIVATE | SWP_NOZORDER);
			SetWindowRgn(hRgn,TRUE);
			RedrawWindow();
			break;
	}
}