示例#1
0
文件: main.c 项目: AndreRH/wine
static void DrawMine( HDC hdc, HDC hMemDC, BOARD *p_board, unsigned col, unsigned row, BOOL IsPressed )
{
    MINEBMP_OFFSET offset = BOX_BMP;

    if( col == 0 || col > p_board->cols || row == 0 || row > p_board->rows )
           return;

    if( p_board->status == GAMEOVER ) {
        if( p_board->box[col][row].IsMine ) {
            switch( p_board->box[col][row].FlagType ) {
            case FLAG:
                offset = FLAG_BMP;
                break;
            case COMPLETE:
                offset = EXPLODE_BMP;
                break;
            case QUESTION:
                /* fall through */
            case NORMAL:
                offset = MINE_BMP;
            }
        } else {
            switch( p_board->box[col][row].FlagType ) {
            case QUESTION:
                offset = QUESTION_BMP;
                break;
            case FLAG:
                offset = WRONG_BMP;
                break;
            case NORMAL:
                offset = BOX_BMP;
                break;
            case COMPLETE:
                /* Do nothing */
                break;
            default:
                WINE_TRACE("Unknown FlagType during game over in DrawMine\n");
                break;
            }
        }
    } else {    /* WAITING or PLAYING */
        switch( p_board->box[col][row].FlagType ) {
        case QUESTION:
            if( !IsPressed )
                offset = QUESTION_BMP;
            else
                offset = QPRESS_BMP;
            break;
        case FLAG:
            offset = FLAG_BMP;
            break;
        case NORMAL:
            if( !IsPressed )
                offset = BOX_BMP;
            else
                offset = MPRESS_BMP;
            break;
        case COMPLETE:
            /* Do nothing */
            break;
        default:
            WINE_TRACE("Unknown FlagType while playing in DrawMine\n");
            break;
        }
    }

    if( p_board->box[col][row].FlagType == COMPLETE
        && !p_board->box[col][row].IsMine )
          offset = (MINEBMP_OFFSET) p_board->box[col][row].NumMines;

    BitBlt( hdc,
            (col - 1) * MINE_WIDTH + p_board->mines_rect.left,
            (row - 1) * MINE_HEIGHT + p_board->mines_rect.top,
            MINE_WIDTH, MINE_HEIGHT,
            hMemDC, 0, offset * MINE_HEIGHT, SRCCOPY );
}
示例#2
0
void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
{
    void *retval = NULL;

    switch ( dataFormat )
    {
#ifndef __WXWINCE__
        case wxDF_BITMAP:
            {
                BITMAP bm;
                HBITMAP hBitmap = (HBITMAP) GetClipboardData(CF_BITMAP);
                if (!hBitmap)
                    break;

                HDC hdcMem = CreateCompatibleDC((HDC) NULL);
                HDC hdcSrc = CreateCompatibleDC((HDC) NULL);

                HBITMAP old = (HBITMAP) ::SelectObject(hdcSrc, hBitmap);
                GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);

                HBITMAP hNewBitmap = CreateBitmapIndirect(&bm);

                if (!hNewBitmap)
                {
                    SelectObject(hdcSrc, old);
                    DeleteDC(hdcMem);
                    DeleteDC(hdcSrc);
                    break;
                }

                HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hNewBitmap);
                BitBlt(hdcMem, 0, 0, bm.bmWidth, bm.bmHeight,
                       hdcSrc, 0, 0, SRCCOPY);

                // Select new bitmap out of memory DC
                SelectObject(hdcMem, old1);

                // Clean up
                SelectObject(hdcSrc, old);
                DeleteDC(hdcSrc);
                DeleteDC(hdcMem);

                // Create and return a new wxBitmap
                wxBitmap *wxBM = new wxBitmap;
                wxBM->SetHBITMAP((WXHBITMAP) hNewBitmap);
                wxBM->SetWidth(bm.bmWidth);
                wxBM->SetHeight(bm.bmHeight);
                wxBM->SetDepth(bm.bmPlanes);
                retval = wxBM;
                break;
            }
#endif
        case wxDF_METAFILE:
        case CF_SYLK:
        case CF_DIF:
        case CF_TIFF:
        case CF_PALETTE:
        case wxDF_DIB:
            wxLogError(_("Unsupported clipboard format."));
            return NULL;

        case wxDF_OEMTEXT:
            dataFormat = wxDF_TEXT;
            // fall through

        case wxDF_TEXT:
            {
                HANDLE hGlobalMemory = ::GetClipboardData(dataFormat);
                if (!hGlobalMemory)
                    break;

                DWORD hsize = ::GlobalSize(hGlobalMemory);
                if (len)
                    *len = hsize;

                char *s = new char[hsize];
                if (!s)
                    break;

                LPSTR lpGlobalMemory = (LPSTR) GlobalLock(hGlobalMemory);

                memcpy(s, lpGlobalMemory, hsize);

                GlobalUnlock(hGlobalMemory);

                retval = s;
                break;
            }

        default:
            {
                HANDLE hGlobalMemory = ::GetClipboardData(dataFormat);
                if ( !hGlobalMemory )
                    break;

                DWORD size = ::GlobalSize(hGlobalMemory);
                if ( len )
                    *len = size;

                void *buf = malloc(size);
                if ( !buf )
                    break;

                LPSTR lpGlobalMemory = (LPSTR) GlobalLock(hGlobalMemory);

                memcpy(buf, lpGlobalMemory, size);

                GlobalUnlock(hGlobalMemory);

                retval = buf;
                break;
            }
    }

    if ( !retval )
    {
        wxLogSysError(_("Failed to retrieve data from the clipboard."));
    }

    return retval;
}
示例#3
0
DWORD CmdDrawZoom::CmdDrawAjustZooming::SetPoint(DWORD MouseAction, CPoint pt)
{
   CmdDrawZoom *p = dynamic_cast<CmdDrawZoom*>(m_pOwner);
   if (enCmdMouseNone == MouseAction)
   {
      LP_MATERIALINFO pTempInfo = p->m_pReceiver->getComicStripData()->getSelectedInfo();
      if (NULL == pTempInfo)
      {
         return FALSE;
      }
      CSize size = CSize(pt.x - pTempInfo->GetLTPoint().x, pt.y - pTempInfo->GetLTPoint().y);
      size.cx = max(size.cx, 24);
      size.cy = max(size.cy, 24);

      pTempInfo->SetFinalSize(size);
      if (pTempInfo->isPenDraw) {
         int width = pTempInfo->m_image.GetWidth();
         int height = pTempInfo->m_image.GetHeight();
         if (width<size.cx || height<size.cy)
         {
            int newWidth = max(width, size.cx);
            int newHeight = max(height, size.cy);
            CxImage tempImage = pTempInfo->m_image;
            pTempInfo->m_image.Create(newWidth, newHeight, 24, CXIMAGE_FORMAT_PNG);
            RGBQUAD rgb = pTempInfo->m_image.GetPixelColor(1,1);
            pTempInfo->m_image.SetTransIndex(0);
            pTempInfo->m_image.SetTransColor(rgb);

            HDC     memdcOrg   = CreateCompatibleDC(NULL);
            HBITMAP hbitmapOrg = tempImage.MakeBitmap();
            HGDIOBJ pOldGDIOBJOrg = SelectObject(memdcOrg, hbitmapOrg);

            HDC     memdc   = CreateCompatibleDC(NULL);
            HBITMAP hbitmap = pTempInfo->m_image.MakeBitmap();
            HGDIOBJ pOldGDIOBJ = SelectObject(memdc, hbitmap);
            BitBlt(memdc, 0, 0, width, height, memdcOrg, 0, 0, SRCCOPY);
            pTempInfo->m_image.CreateFromHBITMAP(hbitmap);

            SelectObject(memdc, pOldGDIOBJ);
            DeleteObject(hbitmap);
            DeleteDC(memdc);

            SelectObject(memdcOrg, pOldGDIOBJOrg);
            DeleteObject(hbitmapOrg);
            DeleteDC(memdcOrg);
         }
      }
      p->m_pReceiver->UpdateComicStrip(pTempInfo->nIDOwner);
   }
   else if (enCmdMouseLUp == MouseAction)
   {
      LP_MATERIALINFO pTempInfo = p->m_pReceiver->getComicStripData()->getSelectedInfo();
      if (NULL == pTempInfo)
      {
         return FALSE;
      }
      CSize size = CSize(pt.x - pTempInfo->GetLTPoint().x, pt.y - pTempInfo->GetLTPoint().y);
      size.cx = max(size.cx, 24);
      size.cy = max(size.cy, 24);

      pTempInfo->SetFinalSize(size);
      if (pTempInfo->isPenDraw) {
         int width = pTempInfo->m_image.GetWidth();
         int height = pTempInfo->m_image.GetHeight();
         if (width<size.cx || height<size.cy)
         {
            CxImage tempImage = pTempInfo->m_image;
            pTempInfo->m_image.Create(size.cx, size.cy, 24, CXIMAGE_FORMAT_PNG);
            RGBQUAD rgb = pTempInfo->m_image.GetPixelColor(1,1);
            pTempInfo->m_image.SetTransIndex(0);
            pTempInfo->m_image.SetTransColor(rgb);

            HDC     memdcOrg   = CreateCompatibleDC(NULL);
            HBITMAP hbitmapOrg = tempImage.MakeBitmap();
            HGDIOBJ pOldGDIOBJOrg = SelectObject(memdcOrg, hbitmapOrg);

            HDC     memdc   = CreateCompatibleDC(NULL);
            HBITMAP hbitmap = pTempInfo->m_image.MakeBitmap();
            HGDIOBJ pOldGDIOBJ = SelectObject(memdc, hbitmap);
            BitBlt(memdc, 0, 0, width, height, memdcOrg, 0, 0, SRCCOPY);
            pTempInfo->m_image.CreateFromHBITMAP(hbitmap);
            
            SelectObject(memdc, pOldGDIOBJ);
            DeleteObject(hbitmap);
            DeleteDC(memdc);

            SelectObject(memdcOrg, pOldGDIOBJOrg);
            DeleteObject(hbitmapOrg);
            DeleteDC(memdcOrg);
         }
      }
      p->m_pReceiver->SaveFile();
      p->m_pReceiver->UpdateComicStrip(pTempInfo->nIDOwner);
      p->m_pDsState = &p->m_dsZoomBgn;
      p->m_pReceiver->SetCursor();
      p->m_nDrawState = enDrawIdle;
   }
   return TRUE;
}
示例#4
0
BOOL CDIB::SetBitmap(HBITMAP hBitmap, HPALETTE hPal /*= NULL*/)
{
//    DeleteObject();

    if (!hBitmap)
        return FALSE;

    // Get dimensions of bitmap
    BITMAP bm;
    if (!::GetObject(hBitmap, sizeof(bm),(LPVOID)&bm))
        return FALSE;
    bm.bmHeight = abs(bm.bmHeight);

	HDC hDC = GetWindowDC(NULL);
    HPALETTE hOldPal = NULL;

    m_iColorTableSize = NumColorEntries(bm.bmBitsPixel, BI_RGB);

    // Initialize the BITMAPINFOHEADER in m_DIBinfo
    BITMAPINFOHEADER& bih = m_DIBinfo.bmiHeader;
    bih.biSize          = sizeof(BITMAPINFOHEADER);
    bih.biWidth         = bm.bmWidth;
    bih.biHeight        = bm.bmHeight;
    bih.biPlanes        = 1;                // Must always be 1 according to docs
    bih.biBitCount      = bm.bmBitsPixel;
    bih.biCompression   = BI_RGB;
    bih.biSizeImage     = BytesPerLine(bm.bmWidth, bm.bmBitsPixel) * bm.bmHeight;
    bih.biXPelsPerMeter = 0;
    bih.biYPelsPerMeter = 0;
    bih.biClrUsed       = 0;
    bih.biClrImportant  = 0;

    GetColorTableEntries(hDC, hBitmap);

    // If we have a palette supplied, then set the palette (and hance DIB color
    // table) using this palette
    if (hPal)
        SetPalette(hPal);

    if (hPal)
    {
        hOldPal = SelectPalette(hDC, m_hPal, FALSE);
        RealizePalette(hDC);
    }

    // Create it!
    m_hBitmap = CreateDIBSection(hDC, (const BITMAPINFO*) m_DIBinfo, m_iColorDataType, &m_ppvBits, NULL, 0);
    if (hOldPal)
        SelectPalette(hDC, hOldPal, FALSE);
    hOldPal = NULL; 

    if (! m_hBitmap)
    {
        TRACE0("Unable to CreateDIBSection\n");
        return FALSE;
    }

    // If palette was supplied then create a palette using the entries in the DIB
    // color table.
    if (! hPal)
        CreatePalette();

    // Need to copy the supplied bitmap onto the newly created DIBsection
    HDC hMemDC = CreateCompatibleDC(hDC);
	HDC hCopyDC = CreateCompatibleDC(hDC);
	
    if (! hMemDC || ! hCopyDC) 
    {
        TRACE0("Unable to create compatible DC's\n");
        //AfxThrowResourceException();
    }

    if (m_hPal)
    {
        SelectPalette(hMemDC, m_hPal, FALSE);   RealizePalette(hMemDC);
        SelectPalette(hCopyDC, m_hPal, FALSE);  RealizePalette(hCopyDC);
    }

    HBITMAP hOldMemBitmap  = (HBITMAP) SelectObject(hMemDC,  hBitmap);
    HBITMAP hOldCopyBitmap = (HBITMAP) SelectObject(hCopyDC, m_hBitmap);

    BitBlt(hCopyDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDC, 0, 0, SRCCOPY);

    SelectObject(hMemDC,  hOldMemBitmap);
    SelectObject(hCopyDC, hOldCopyBitmap);

    if (m_hPal)
    {
		HGDIOBJ hObj = ::GetStockObject(DEFAULT_PALETTE);
        SelectObject(hMemDC, hObj);
        SelectObject(hCopyDC, hObj);
    }

	ReleaseDC(NULL, hDC);
    return TRUE;
}
示例#5
0
// TODO code: optimise airspace drawing (same as DrawAirSpace())
// draw airspace using alpha blending
//static 
void MapWindow::DrawTptAirSpace(HDC hdc, const RECT rc) {
  // since standard GDI functions (brushes, pens...) ignore alpha octet in ARGB 
  // color value and don't set it in the resulting bitmap, we cannot use
  // perpixel alpha blending, instead we use global opacity for alpha blend 
  // (same opacity for all pixels); for fully "transparent" areas (without 
  // airspace) we must copy destination bitmap into source bitmap first so that 
  // alpha blending of such areas results in the same pixels as origin pixels 
  // in destination 
  CAirspaceList::const_iterator it;
  CAirspaceList::const_reverse_iterator itr;
  const CAirspaceList& airspaces_to_draw = CAirspaceManager::Instance().GetNearAirspacesRef();
  int airspace_type;
  bool found = false;
  bool borders_only = (GetAirSpaceFillType() == asp_fill_ablend_borders);
  HDC hdcbuffer = NULL;
  HBITMAP hbbufferold = NULL, hbbuffer = NULL;
  
  if (borders_only) {
    // Prepare layers
    hdcbuffer = CreateCompatibleDC(hdc);
    hbbuffer = CreateCompatibleBitmap(hdc, rc.right - rc.left, rc.bottom - rc.top);
    hbbufferold = (HBITMAP)SelectObject(hdcbuffer, hbbuffer);
    BitBlt(hdcbuffer, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, rc.left, rc.top, BLACKNESS );
    SelectObject(hdcbuffer, GetStockObject(NULL_PEN));
  
    BitBlt(hDCMask, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, NULL, rc.left, rc.top, BLACKNESS );
    SelectObject(hDCMask, hAirspaceBorderPen);
    SelectObject(hDCMask, GetStockObject(HOLLOW_BRUSH));
  }

  // Draw airspace area
    if (1) {
    CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef());
    if (borders_only) {
       // Draw in reverse order!
       // The idea behind this, is lower top level airspaces are smaller. (statistically)
       // They have to be draw later, because inside border area have to be in correct color,
       // not the color of the bigger airspace above this small one.
      for (itr=airspaces_to_draw.rbegin(); itr != airspaces_to_draw.rend(); ++itr) {
            if ((*itr)->DrawStyle() == adsFilled) {
              airspace_type = (*itr)->Type();
              if (!found) {
                found = true;
                ClearTptAirSpace(hdc, rc);
              }
              // set filling brush
              SelectObject(hdcbuffer, GetAirSpaceSldBrushByClass(airspace_type));
              (*itr)->Draw(hdcbuffer, rc, true);
              (*itr)->Draw(hDCMask, rc, false);
            }
      }//for
    } else {
       // Draw in direct order!
      for (it=airspaces_to_draw.begin(); it != airspaces_to_draw.end(); ++it) {
            if ((*it)->DrawStyle() == adsFilled) {
              airspace_type = (*it)->Type();
              if (!found) {
                found = true;
                ClearTptAirSpace(hdc, rc);
              }
              // set filling brush
              SelectObject(hDCTemp, GetAirSpaceSldBrushByClass(airspace_type));
              (*it)->Draw(hDCTemp, rc, true);
            }
      }//for
    }//else borders_only
    }//mutex release

  // alpha blending
  if (found) {
    if (borders_only) {
      #if (WINDOWSPC<1)
        TransparentImage(hdcbuffer,
                rc.left,rc.top,
                rc.right-rc.left,rc.bottom-rc.top,
                hDCMask,
                rc.left,rc.top,
                rc.right-rc.left,rc.bottom-rc.top,
                RGB_WHITE
                );
        TransparentImage(hDCTemp,
                rc.left,rc.top,
                rc.right-rc.left,rc.bottom-rc.top,
                hdcbuffer,
                rc.left,rc.top,
                rc.right-rc.left,rc.bottom-rc.top,
                RGB_BLACK
                );
        #else
        TransparentBlt(hdcbuffer,
                      rc.left,rc.top,
                      rc.right-rc.left,rc.bottom-rc.top,
                      hDCMask,
                      rc.left,rc.top,
                      rc.right-rc.left,rc.bottom-rc.top,
                      RGB_WHITE
                      );
        TransparentBlt(hDCTemp,
                      rc.left,rc.top,
                      rc.right-rc.left,rc.bottom-rc.top,
                      hdcbuffer,
                      rc.left,rc.top,
                      rc.right-rc.left,rc.bottom-rc.top,
                      RGB_BLACK
                      );
        #endif
    }
    DoAlphaBlend(hdc, rc, hDCTemp, rc, (255 * GetAirSpaceOpacity()) / 100);
  }
  
  // draw it again, just the outlines
  
  // we will be drawing directly into given hdc, so store original PEN object
  HPEN hOrigPen = (HPEN) SelectObject(hdc, GetStockObject(WHITE_PEN));

    if (1) {
    CCriticalSection::CGuard guard(CAirspaceManager::Instance().MutexRef());
	for (it=airspaces_to_draw.begin(); it != airspaces_to_draw.end(); ++it) {
        if ((*it)->DrawStyle()) {
		  airspace_type = (*it)->Type();
		  if (bAirspaceBlackOutline) {
			SelectObject(hdc, GetStockObject(BLACK_PEN));
		  } else {
			SelectObject(hdc, hAirspacePens[airspace_type]);
		  }
		  (*it)->Draw(hdc, rc, false);
        }
	}//for
    }

  if (borders_only) {
    // Free up GDI resources
    SelectObject(hdcbuffer, hbbufferold);
    DeleteObject(hbbuffer);
    DeleteDC(hdcbuffer);
  }
  
  // restore original PEN
  SelectObject(hdc, hOrigPen);
} // DrawTptAirSpace()
示例#6
0
文件: Scope.cpp 项目: Endox/Deskope
void Scope::CaptureScreen()
{	
	GetSourceCoordinates(&m_intScreenCapX, &m_intScreenCapY);
	// calculate coordinates of source rectangle
	RECT SourceRect;
	SourceRect.left = m_intScreenCapX;
	SourceRect.top = m_intScreenCapY;
	SourceRect.right = SourceRect.left + m_intSrcWidth * 2 + long((m_intSBSOffset + m_intImageSeparation) / m_fltZoom);
	SourceRect.bottom = SourceRect.top + m_intSrcHeight;

	// blit a copy of the screen so you don't have to draw on the screen DC
	BITMAP WinCopyBMInfo;
	GetObjectW(m_winCopyBM, sizeof(BITMAP), &WinCopyBMInfo);
	BitBlt(m_winCopyDC, 0, 0, WinCopyBMInfo.bmWidth, WinCopyBMInfo.bmHeight, m_winDC, 0, 0, SRCCOPY | CAPTUREBLT);
	
	//Draw the cursor
	m_GlobalCursor.cbSize = sizeof(CURSORINFO);
	GetCursorInfo(&m_GlobalCursor);
	if (m_GlobalCursor.flags == CURSOR_SHOWING)	{
		ICONINFO CursorInfo;
		GetIconInfo((HICON)m_GlobalCursor.hCursor, &CursorInfo);
		DrawIconEx(m_winCopyDC,
			       m_GlobalCursor.ptScreenPos.x, m_GlobalCursor.ptScreenPos.y,
				   m_GlobalCursor.hCursor,
				   int(m_intCursorWidth * m_fltZoom), int(m_intCursorHeight * m_fltZoom),
				   0, NULL, DI_COMPAT | DI_NORMAL);		
		DeleteObject(CursorInfo.hbmColor);
		DeleteObject(CursorInfo.hbmMask);
	}

	// Rotate and offset the desktop

	// Build the destination parallelogram using glm
	glm::vec2 pts_vec2[3];
	pts_vec2[0] = glm::vec2(0, 0);
	pts_vec2[1] = glm::vec2(m_intMainDisplayWidth, 0);
	pts_vec2[2] = glm::vec2(0, m_intMainDisplayHeight);
	
	glm::vec2 center(m_intMainDisplayWidth / 2, m_intMainDisplayHeight / 2);

	const float roll = -m_fltRoll;
	glm::mat2 R = glm::mat2(cos(roll), -sin(roll), sin(roll), cos(roll));
	glm::mat2 S = glm::mat2(m_fltZoom, 0, 0, m_fltZoom);

	// Transform the points and convert to GDI format
	POINT pts[3];
	for (int i = 0; i < 3; ++i) {
		// Move to origin [0, 0]
		pts_vec2[i] -= center;

		// Scale (zoom)
		pts_vec2[i] = S * pts_vec2[i];

		// Offset according to HMD orientation
		pts_vec2[i].x -= m_intScreenCapX;
		pts_vec2[i].y -= m_intScreenCapY;

		// Rotate
		pts_vec2[i] = R * pts_vec2[i];

		// Move back
		pts_vec2[i] += center;

		// Convert to GDI format
		pts[i].x = pts_vec2[i].x;
		pts[i].y = pts_vec2[i].y;
	}
	
	// Clear the back buffer 
	RECT ClearRect = {0, 0, m_intMainDisplayWidth, m_intMainDisplayHeight};
	FillRect(m_BackDC, &ClearRect, (HBRUSH)COLOR_WINDOWTEXT);

	// Blit the rotated desktop to back buffer
	PlgBlt(m_BackDC, pts, m_winCopyDC, 0, 0, m_intMainDisplayWidth, m_intMainDisplayHeight, NULL, 0, 0);
}
示例#7
0
文件: Rectangle.c 项目: GYGit/reactos
void Test_Rectangle(void)
{
    HDC hdc;
    HBITMAP hBmp;
    BOOL ret;
    HBRUSH hBrush;
    HPEN hPen;
    COLORREF color;
    
    hdc = CreateCompatibleDC(NULL);
    ok(hdc != NULL, "Failed to create the DC!\n");
    hBmp = CreateCompatibleBitmap(hdc, 4, 4);
    ok(hBmp != NULL, "Failed to create the Bitmap!\n");
    hBmp = SelectObject(hdc, hBmp);
    ok(hBmp != NULL, "Failed to select the Bitmap!\n");
    
    hBrush = CreateSolidBrush(RGB(0, 0, 0));
    ok(hBrush != NULL, "Failed to create a solid brush!\n");
    hBrush = SelectObject(hdc, hBrush);
    ok(hBrush != NULL, "Failed to select the brush!\n");
    
    /* Blank the bitmap */
    ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
    ok(ret, "BitBlt failed to blank the bitmap!\n");
    
    /* Try inverted rectangle coordinates */
    ret = Rectangle(hdc, 0, 2, 2, 0);
    ok(ret, "Rectangle failed!");
    color = GetPixel(hdc, 0, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 2);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 0, 2);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 0);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 1, 1);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);

    ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
    ok(ret, "BitBlt failed to blank the bitmap!\n");
    /* Try well ordered rectangle coordinates */
    ret = Rectangle(hdc, 0, 0, 2, 2);
    ok(ret, "Rectangle failed!");
    color = GetPixel(hdc, 0, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 2);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 0, 2);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 0);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 1, 1);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    
    /* tests with NULL pen */
    hPen = SelectObject(hdc, GetStockObject(NULL_PEN));
    
    /* Blank the bitmap */
    ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
    ok(ret, "BitBlt failed to blank the bitmap!\n");
    
    ret = Rectangle(hdc, 0, 0, 3, 3);
    ok(ret, "Rectangle failed!");
    color = GetPixel(hdc, 0, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 2);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 0, 2);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 0);
    ok( color == RGB(255, 255, 255), "Expected 0x00FFFFFF, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 1, 1);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    
    SelectObject(hdc, hPen);
    
    /* Same tests with GM_ADVANCED */
    ok(SetGraphicsMode(hdc, GM_ADVANCED) == GM_COMPATIBLE, "Default mode for the DC is not GM_COMPATIBLE.\n");
    
    /* Blank the bitmap */
    ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
    ok(ret, "BitBlt failed to blank the bitmap!\n");
    
    /* Try inverted rectangle coordinates */
    ret = Rectangle(hdc, 0, 2, 2, 0);
    ok(ret, "Rectangle failed!");
    color = GetPixel(hdc, 0, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 2);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 0, 2);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 1, 1);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);

    ret = BitBlt(hdc, 0, 0, 4, 4, NULL, 0, 0, WHITENESS);
    ok(ret, "BitBlt failed to blank the bitmap!\n");    
    /* Try well ordered rectangle coordinates */
    ret = Rectangle(hdc, 0, 0, 2, 2);
    ok(ret, "Rectangle failed!");
    color = GetPixel(hdc, 0, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 2);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 0, 2);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 2, 0);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    color = GetPixel(hdc, 1, 1);
    ok( color == RGB(0, 0, 0), "Expected 0, got 0x%08x\n", (UINT)color);
    
    
    hBmp = SelectObject(hdc, hBmp);
    hBrush = SelectObject(hdc, hBrush);
    DeleteObject(hBmp);
    DeleteObject(hBrush);
    DeleteDC(hdc);
}
示例#8
0
文件: gr.c 项目: iruka-/ORANGEpico
//	====================================================
//	ウィンドウプロシージャー
//	====================================================
LRESULT CALLBACK mainwnd_proc(HWND hwnd, UINT msgid, WPARAM wparam, LPARAM lparam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	LPRECT prc;
	RECT r;

	switch(msgid) {

	case WM_MOUSEMOVE: /* マウスカーソル移動 */
		gr.mouse_x=LOWORD(lparam); /* マウスカーソルの位置取得 */
		gr.mouse_y=HIWORD(lparam);
		return 0;

	case WM_CREATE:
		return 0;

	case WM_SIZE:
		InvalidateRect(hwnd,NULL,FALSE);
		UpdateWindow (hwnd);             // 再描画
//		SetWindowPos(hwMain, NULL, 0, 0,
//			     gr.client_rect.right - gr.client_rect.left,
//			     gr.client_rect.bottom - gr.client_rect.top,
//			     SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
		return 0;

	case WM_SIZING:
		prc = (LPRECT) lparam;
		switch(wparam) {
		case WMSZ_TOP:
		case WMSZ_TOPLEFT:
		case WMSZ_TOPRIGHT:
		case WMSZ_BOTTOMLEFT:
		case WMSZ_LEFT:
			prc->left = prc->right - (gr.client_rect.right
						  - gr.client_rect.left);
			prc->top = prc->bottom - (gr.client_rect.bottom
						  - gr.client_rect.top);
			break;

		case WMSZ_BOTTOM:
		case WMSZ_BOTTOMRIGHT:
		case WMSZ_RIGHT:
			prc->right = prc->left + (gr.client_rect.right
						  - gr.client_rect.left);
			prc->bottom = prc->top + (gr.client_rect.bottom
						  - gr.client_rect.top);
			break;
		}
		return 0;

	case WM_PAINT:
		{ int x,y;
			GetClientRect(hwnd,&r); /* クライアント領域取得 */
			x=(r.right -gr.width) /2; /* ビットマップの表示位置計算 */
			y=(r.bottom-gr.height)/2;

			hdc=BeginPaint(gr.hwMain,&ps);

			BitBlt(hdc,x,y,gr.width,gr.height,gr.hdcMem,0,0,SRCCOPY);

			EndPaint(gr.hwMain,&ps);
		}
		SetEvent(gr.paint_event);
//	BringWindowToTop(gr.hwMain);
		return 0;

	case WM_KEYDOWN:
		if(wparam == VK_ESCAPE) {
			gr.esc_flag = 1;
			gr.end_flag = 1;
			SetEvent(gr.esc_event);
		}
		if(lparam & (1 << 30))
			return 0;

		if(wparam == VK_F5) {
			hdc = GetDC(gr.hwMain);
			redraw(hdc, &gr.client_rect);
			ReleaseDC(gr.hwMain, hdc);
			return 0;
		}

	case WM_LBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_MBUTTONDOWN:
		SetEvent(gr.hitanykey_event);
		return 0;

	case WM_DESTROY:
		DeleteDC(gr.hdcMem); /* デバイスコンテキスト開放 */
		gr.hdcMem = NULL;
#if	0
		DeleteObject(gr.hBMP); /* ビットマップ開放 */
		gr.hBMP   = NULL;

		if(	gr.lpBuf ) {
			GlobalFree(gr.lpBuf); /* メモリを解放 */
			gr.lpBuf = NULL;
		}
#endif
		PostQuitMessage(0);
		gr.end_flag = 1;
		return 0;
	}

	return DefWindowProc(hwnd, msgid, wparam, lparam);
}
示例#9
0
/*****************************************************************************
 * x11_copy_to_screen
 *
 * Helper function that blts the front buffer contents to the target window
 *
 * Params:
 *  This: Surface to copy from
 *  rc: Rectangle to copy
 *
 *****************************************************************************/
void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc)
{
    IWineD3DSurfaceImpl *front = This->front_buffer;

    if(front->resource.usage & WINED3DUSAGE_RENDERTARGET) {
        POINT offset = {0,0};
        HWND hDisplayWnd;
        HDC hDisplayDC;
        HDC hSurfaceDC = 0;
        RECT drawrect;
        TRACE("(%p)->(%p): Copying to screen\n", front, rc);

        hSurfaceDC = front->hDC;

        hDisplayWnd = This->win_handle;
        hDisplayDC = GetDCEx(hDisplayWnd, 0, DCX_CLIPSIBLINGS|DCX_CACHE);
        if(rc) {
            TRACE(" copying rect (%d,%d)->(%d,%d), offset (%d,%d)\n",
                  rc->left, rc->top, rc->right, rc->bottom, offset.x, offset.y);
        }

        /* Front buffer coordinates are screen coordinates. Map them to the destination
         * window if not fullscreened
         */
        if(This->presentParms.Windowed) {
            ClientToScreen(hDisplayWnd, &offset);
        }
#if 0
        /* FIXME: This doesn't work... if users really want to run
        * X in 8bpp, then we need to call directly into display.drv
        * (or Wine's equivalent), and force a private colormap
        * without default entries. */
        if (front->palette) {
        SelectPalette(hDisplayDC, front->palette->hpal, FALSE);
        RealizePalette(hDisplayDC); /* sends messages => deadlocks */
    }
#endif
        drawrect.left   = 0;
        drawrect.right  = front->resource.width;
        drawrect.top    = 0;
        drawrect.bottom = front->resource.height;

#if 0
        /* TODO: Support clippers */
        if (front->clipper)
        {
        RECT xrc;
        HWND hwnd = ((IWineD3DClipperImpl *) front->clipper)->hWnd;
        if (hwnd && GetClientRect(hwnd,&xrc))
        {
        OffsetRect(&xrc,offset.x,offset.y);
        IntersectRect(&drawrect,&drawrect,&xrc);
    }
    }
#endif
        if (rc) {
            IntersectRect(&drawrect,&drawrect,rc);
        }
        else {
            /* Only use this if the caller did not pass a rectangle, since
            * due to double locking this could be the wrong one ...
            */
            if (front->lockedRect.left != front->lockedRect.right) {
                IntersectRect(&drawrect,&drawrect,&front->lockedRect);
            }
        }

        BitBlt(hDisplayDC,
               drawrect.left-offset.x, drawrect.top-offset.y,
               drawrect.right-drawrect.left, drawrect.bottom-drawrect.top,
               hSurfaceDC,
               drawrect.left, drawrect.top,
               SRCCOPY);
        ReleaseDC(hDisplayWnd, hDisplayDC);
    }
}
示例#10
0
static void paintArea(HWND hwnd, void *data)
{
	RECT xrect;
	PAINTSTRUCT ps;
	HDC hdc;
	HDC rdc;
	HBITMAP rbitmap, prevrbitmap;
	RECT rrect;
	BITMAPINFO bi;
	VOID *ppvBits;
	HBITMAP ibitmap;
	HDC idc;
	HBITMAP previbitmap;
	BLENDFUNCTION blendfunc;
	void *i;
	intptr_t dx, dy;
	int hscroll, vscroll;

	// FALSE here indicates don't send WM_ERASEBKGND
	if (GetUpdateRect(hwnd, &xrect, FALSE) == 0)
		return;		// no update rect; do nothing

	getScrollPos(hwnd, &hscroll, &vscroll);

	hdc = BeginPaint(hwnd, &ps);
	if (hdc == NULL)
		xpanic("error beginning Area repaint", GetLastError());

	// very big thanks to Ninjifox for suggesting this technique and helping me go through it

	// first let's create the destination image, which we fill with the windows background color
	// this is how we fake drawing the background; see also http://msdn.microsoft.com/en-us/library/ms969905.aspx
	rdc = CreateCompatibleDC(hdc);
	if (rdc == NULL)
		xpanic("error creating off-screen rendering DC", GetLastError());
	// the bitmap has to be compatible with the window
	// if we create a bitmap compatible with the DC we just created, it'll be monochrome
	// thanks to David Heffernan in http://stackoverflow.com/questions/23033636/winapi-gdi-fillrectcolor-btnface-fills-with-strange-grid-like-brush-on-window
	rbitmap = CreateCompatibleBitmap(hdc, xrect.right - xrect.left, xrect.bottom - xrect.top);
	if (rbitmap == NULL)
		xpanic("error creating off-screen rendering bitmap", GetLastError());
	prevrbitmap = (HBITMAP) SelectObject(rdc, rbitmap);
	if (prevrbitmap == NULL)
		xpanic("error connecting off-screen rendering bitmap to off-screen rendering DC", GetLastError());
	rrect.left = 0;
	rrect.right = xrect.right - xrect.left;
	rrect.top = 0;
	rrect.bottom = xrect.bottom - xrect.top;
	if (FillRect(rdc, &rrect, areaBackgroundBrush) == 0)
		xpanic("error filling off-screen rendering bitmap with the system background color", GetLastError());

	i = doPaint(&xrect, hscroll, vscroll, data, &dx, &dy);
	if (i == NULL)			// cliprect empty
		goto nobitmap;		// we need to blit the background no matter what

	// now we need to shove realbits into a bitmap
	// technically bitmaps don't know about alpha; they just ignore the alpha byte
	// AlphaBlend(), however, sees it - see http://msdn.microsoft.com/en-us/library/windows/desktop/dd183352%28v=vs.85%29.aspx
	ZeroMemory(&bi, sizeof (BITMAPINFO));
	bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
	bi.bmiHeader.biWidth = (LONG) dx;
	bi.bmiHeader.biHeight = -((LONG) dy);			// negative height to force top-down drawing;
	bi.bmiHeader.biPlanes = 1;
	bi.bmiHeader.biBitCount = 32;
	bi.bmiHeader.biCompression = BI_RGB;
	bi.bmiHeader.biSizeImage = (DWORD) (dx * dy * 4);
	// this is all we need, but because this confused me at first, I will say the two pixels-per-meter fields are unused (see http://blogs.msdn.com/b/oldnewthing/archive/2013/05/15/10418646.aspx and page 581 of Charles Petzold's Programming Windows, Fifth Edition)
	// now for the trouble: CreateDIBSection() allocates the memory for us...
	ibitmap = CreateDIBSection(NULL,		// Ninjifox does this, so do some wine tests (http://source.winehq.org/source/dlls/gdi32/tests/bitmap.c#L725, thanks vpovirk in irc.freenode.net/#winehackers) and even Raymond Chen (http://blogs.msdn.com/b/oldnewthing/archive/2006/11/16/1086835.aspx), so.
		&bi, DIB_RGB_COLORS, &ppvBits, 0, 0);
	if (ibitmap == NULL)
		xpanic("error creating HBITMAP for image returned by AreaHandler.Paint()", GetLastError());

	// now we have to do TWO MORE things before we can finally do alpha blending
	// first, we need to load the bitmap memory, because Windows makes it for us
	// the pixels are arranged in RGBA order, but GDI requires BGRA
	// this turns out to be just ARGB in little endian; let's convert into this memory
	dotoARGB(i, (void *) ppvBits, FALSE);		// FALSE = not NRGBA

	// the second thing is... make a device context for the bitmap :|
	// Ninjifox just makes another compatible DC; we'll do the same
	idc = CreateCompatibleDC(hdc);
	if (idc == NULL)
		xpanic("error creating HDC for image returned by AreaHandler.Paint()", GetLastError());
	previbitmap = (HBITMAP) SelectObject(idc, ibitmap);
	if (previbitmap == NULL)
		xpanic("error connecting HBITMAP for image returned by AreaHandler.Paint() to its HDC", GetLastError());

	// AND FINALLY WE CAN DO THE ALPHA BLENDING!!!!!!111
	blendfunc.BlendOp = AC_SRC_OVER;
	blendfunc.BlendFlags = 0;
	blendfunc.SourceConstantAlpha = 255;		// only use per-pixel alphas
	blendfunc.AlphaFormat = AC_SRC_ALPHA;	// premultiplied
	if (AlphaBlend(rdc, 0, 0, (int) dx, (int) dy,		// destination
		idc, 0, 0, (int) dx, (int)dy,				// source
		blendfunc) == FALSE)
		xpanic("error alpha-blending image returned by AreaHandler.Paint() onto background", GetLastError());

	// clean up after idc/ibitmap here because of the goto nobitmap
	if (SelectObject(idc, previbitmap) != ibitmap)
		xpanic("error reverting HDC for image returned by AreaHandler.Paint() to original HBITMAP", GetLastError());
	if (DeleteObject(ibitmap) == 0)
		xpanic("error deleting HBITMAP for image returned by AreaHandler.Paint()", GetLastError());
	if (DeleteDC(idc) == 0)
		xpanic("error deleting HDC for image returned by AreaHandler.Paint()", GetLastError());

nobitmap:
	// and finally we can just blit that into the window
	if (BitBlt(hdc, xrect.left, xrect.top, xrect.right - xrect.left, xrect.bottom - xrect.top,
		rdc, 0, 0,			// from the rdc's origin
		SRCCOPY) == 0)
		xpanic("error blitting Area image to Area", GetLastError());

	// now to clean up
	if (SelectObject(rdc, prevrbitmap) != rbitmap)
		xpanic("error reverting HDC for off-screen rendering to original HBITMAP", GetLastError());
	if (DeleteObject(rbitmap) == 0)
		xpanic("error deleting HBITMAP for off-screen rendering", GetLastError());
	if (DeleteDC(rdc) == 0)
		xpanic("error deleting HDC for off-screen rendering", GetLastError());

	EndPaint(hwnd, &ps);
}
示例#11
0
void DrawIconSatnHue (
    HDC hDC,
    int px,
    int py,
    HICON IconHop,
    int size_x,
    int size_y,
    UINT istepIfAniCur, // index of frame in animated cursor
    HBRUSH hbrFlickerFreeDraw,  // handle to background brush
    UINT diFlags, // icon-drawing flags
    int apply_satnhue,
    int saturationValue,
    int hueIntensity
    )
{
    if (0 == apply_satnhue || (saturationValue >= 255 && hueIntensity <= 0)) {
        DrawIconEx(hDC, px, py, IconHop, size_x, size_y, istepIfAniCur, hbrFlickerFreeDraw, diFlags);
        return;
    }

    BITMAPINFOHEADER bv4info;

    ZeroMemory(&bv4info,sizeof(bv4info));
    bv4info.biSize = sizeof(bv4info);
    bv4info.biWidth = size_x;
    bv4info.biHeight = size_y * 3;
    bv4info.biPlanes = 1;
    bv4info.biBitCount = 32;
    bv4info.biCompression = BI_RGB;

    BYTE* pixels;

    HBITMAP bufbmp = CreateDIBSection(NULL, (BITMAPINFO*)&bv4info, DIB_RGB_COLORS, (PVOID*)&pixels, NULL, 0);

    if (NULL == bufbmp)
        return;

    HDC bufdc = CreateCompatibleDC(hDC);
    HGDIOBJ other = SelectObject(bufdc, bufbmp);

    // draw the required three things side by side

    // background for hue
    BitBlt(bufdc,       0, 0,       size_x, size_y, hDC, px, py, SRCCOPY);

    // background for icon
    BitBlt(bufdc,       0, size_y,    size_x, size_y, hDC, px, py, SRCCOPY);

    // icon, in colors
    DrawIconEx(bufdc,   0, size_y,    IconHop, size_x, size_y, 0, NULL, DI_NORMAL);

    // icon mask
    DrawIconEx(bufdc,   0, size_y*2,  IconHop, size_x, size_y, 0, NULL, DI_MASK);

    perform_satnhue(pixels, size_x, size_y, saturationValue, hueIntensity);

    BitBlt(hDC, px, py, size_x, size_y, bufdc, 0, 0, SRCCOPY);

    DeleteObject(SelectObject(bufdc, other));
    DeleteDC(bufdc);
}
示例#12
0
文件: main.cpp 项目: CulDeVu/IfAThenB
int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE,
                     LPSTR,
                     int nCmdShow)
{
  HWND hwnd;               /* This is the handle for our window */
  WNDCLASSEX wincl;        /* Data structure for the windowclass */

  /* The Window structure */
  wincl.hInstance = hThisInstance;
  wincl.lpszClassName = szClassName;
  wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
  wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
  wincl.cbSize = sizeof (WNDCLASSEX);

  /* Use default icon and mouse-pointer */
  wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
  wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
  wincl.lpszMenuName = NULL;                 /* No menu */
  wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
  wincl.cbWndExtra = 0;                      /* structure or the window instance */
  /* Use Windows's default colour as the background of the window */
  wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

  /* Register the window class, and if it fails quit the program */
  if (!RegisterClassEx (&wincl))
      return 0;

  int width = windowWidth + GetSystemMetrics(SM_CXFIXEDFRAME) * 2;
  int height = windowHeight + GetSystemMetrics(SM_CYFIXEDFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);

  /* The class is registered, let's create the program*/
  hwnd = CreateWindowEx (
         0,                   /* Extended possibilites for variation */
         szClassName,         /* Classname */
         "IF, THEN",       /* Title Text */
         WS_CAPTION, /* default window */
         CW_USEDEFAULT,       /* Windows decides the position */
         CW_USEDEFAULT,       /* where the window ends up on the screen */
         width,                 /* The programs width */
         height,                 /* and height in pixels */
         HWND_DESKTOP,        /* The window is a child-window to desktop */
         NULL,                /* No menu */
         hThisInstance,       /* Program Instance handler */
         NULL                 /* No Window Creation data */
         );

  /* Make the window visible on the screen */
  ShowWindow (hwnd, SW_SHOW);

  /* Run the message loop. It will run until GetMessage() returns 0 */

  HDC hdc = GetDC(hwnd);

  hBufferDC = CreateCompatibleDC(hdc);
  hBufferBmp = CreateCompatibleBitmap(hdc, windowWidth, windowHeight);
  hOldBufferBmp = (HBITMAP)SelectObject(hBufferDC, hBufferBmp);

  DWORD lastTime = GetTickCount();

  NextLevel();

  while (!bGameOver)
  {
    MSG msg;
    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
      if (msg.message == WM_QUIT)
        bGameOver = true;
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
    if (bGameOver)
      break;

    if (GetAsyncKeyState(VK_ESCAPE))
      break;

    updateGame();
    PaintGame(hBufferDC);

    BitBlt(hdc, 0, 0, windowWidth, windowHeight, hBufferDC, 0, 0, SRCCOPY);

    do
      Sleep(0);
    while (GetTickCount() - lastTime < 15);

    lastTime = GetTickCount();
  }

  SelectObject(hBufferDC, hOldBufferBmp);
  DeleteObject(hBufferBmp);
  DeleteObject(hBufferDC);

  ReleaseDC(hwnd, hdc);

  /* The program return-value is 0 - The value that PostQuitMessage() gave */
  return 0;
}
示例#13
0
HBITMAP CSplashScreen::CopyScreenToBitmap(CRect& rect/*lpRect 代表选定区域*/)
{
	HDC hScrDC;						// 屏幕设备描述表
	HDC	hMemDC;						// 内存设备描述表

	HBITMAP hBitmap, hOldBitmap;	// 位图句柄

	int nX, nY, nX2, nY2;           // 选定区域坐标
	
	int nWidth, nHeight;			// 位图宽度和高度

	int xScrn, yScrn;				// 屏幕分辨率

	// 确保选定区域不为空矩形
	//if (IsRectEmpty(lpRect))
	//{
	//	return NULL;
	//}

	//为屏幕创建设备描述表
	hScrDC = CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
	//为屏幕设备描述表创建兼容的内存设备描述表
	hMemDC = CreateCompatibleDC(hScrDC);
	
	// 获得选定区域坐标
	//nX = lpRect -> left;
	//nY = lpRect -> top;
	//nX2 = lpRect -> right;
	//nY2 = lpRect -> bottom;

	nX = rect.left;
	nY = rect.top;
	nX2 = rect.right;
	nY2 = rect.bottom;

	// 获得屏幕分辨率
	xScrn = GetDeviceCaps(hScrDC, HORZRES);
	yScrn = GetDeviceCaps(hScrDC, VERTRES);
	
	//nX  = (xScrn - rect.Width())/2;
	//nY  = (yScrn - rect.Height())/2;
	//nX2 = xScrn - nX + rect.Width();
	//nY2 = yScrn - nY + rect.Height();
	//确保选定区域是可见的

	if (nX<0)
		nX = 0;
	if (nY<0)
		nY = 0;
	if (nX2 > xScrn)
		nX2 = xScrn;
	if (nY2 > yScrn)
		nY2 = yScrn;
	nWidth = nX2 - nX;
	nHeight = nY2 - nY;
	
	// 创建一个与屏幕设备描述表兼容的位图
	hBitmap = CreateCompatibleBitmap(hScrDC, nWidth, nHeight);
	// 把新位图选到内存设备描述表中
	hOldBitmap = (HBITMAP)SelectObject(hMemDC, hBitmap);
	// 把屏幕设备描述表拷贝到内存设备描述表中
	BitBlt(hMemDC, 0, 0, nWidth, nHeight, hScrDC, nX, nY, SRCCOPY);
	//得到屏幕位图的句柄
	hBitmap = (HBITMAP)SelectObject(hMemDC, hOldBitmap);
	//清除
	DeleteDC(hScrDC);
	DeleteDC(hMemDC);
	 //返回位图句柄
	return hBitmap;
}
示例#14
0
void CSplashScreen::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	CDC dcMem;

	GetWindowRect(&rect);//获得要抓图的区域
	m_hbm = CopyScreenToBitmap(rect);//抓图
	GetObject(m_hbm, sizeof(m_bitmap),&m_bitmap);//获得抓到的图的尺寸

	if (dcMem.CreateCompatibleDC(&dc))
	{
		SelectObject(dcMem, m_hbm);
		BitBlt(dc,0,0,m_bitmap.bmWidth, m_bitmap.bmHeight, dcMem,0 ,0, SRCCOPY);
			
		//m_image->Draw(dc.m_hDC,m_bitmap.bmWidth/2 - 380/2,m_bitmap.bmHeight/2 - 350/2,380,350);
		m_image->Draw(dc.m_hDC, m_rtImg.left, m_rtImg.top, -1, -1);

		DrawText(&dc);

		//CRect rc(0, m_bitmap.bmHeight/2 + 70, m_bitmap.bmWidth ,m_bitmap.bmHeight);

		//LOGFONT lf = {0};
		//lf.lfHeight = 26;
		//lf.lfWeight = FW_BOLD;
		//lf.lfQuality = afxData.bWin95 ? NONANTIALIASED_QUALITY : ANTIALIASED_QUALITY;
		//_tcscpy(lf.lfFaceName, _T("Arial"));
		//	
		//CFont font;
		//font.CreateFontIndirect(&lf);
		//CFont* pOldFont = dc.SelectObject(&font);

		//CString strAppVersion;
		//strAppVersion.Format(_T("eMule %u.%u%c VeryCD"), CGlobalVariable::m_nVersionMjr, CGlobalVariable::m_nVersionMin, _T('a') + CGlobalVariable::m_nVersionUpd);
		//	
		//rc.top += 30;
		//rc.top += dc.DrawText(strAppVersion, &rc, DT_CENTER | DT_NOPREFIX);

		//if (pOldFont)
		//{
		//	dc.SelectObject(pOldFont);
		//}
		//font.DeleteObject();

		//rc.top += 8;

		//lf.lfHeight = 14;
		//lf.lfWeight = FW_NORMAL;
		//lf.lfQuality = afxData.bWin95 ? NONANTIALIASED_QUALITY : ANTIALIASED_QUALITY;
		//_tcscpy(lf.lfFaceName, _T("Arial"));
		//font.CreateFontIndirect(&lf);
		//pOldFont = dc.SelectObject(&font);
		//dc.DrawText(_T("Copyright (C) 2002-2006 Merkur"), &rc, DT_CENTER | DT_NOPREFIX);

		//if (pOldFont)
		//{
		//	dc.SelectObject(pOldFont);
		//}
		//font.DeleteObject();
	}
}
示例#15
0
	LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint( &ps );

		HDC hdcMem, hdcBB;
		HBITMAP hbmOld, hbmOldBB;
		BLENDFUNCTION func = { AC_SRC_OVER, 0, 0, 0 };

		ps.rcPaint.right -= ps.rcPaint.left;
		ps.rcPaint.bottom -= ps.rcPaint.top;

		if (frame < 400)
		{
			hdcMem = CreateCompatibleDC( hdc );
			hbmOld = (HBITMAP) SelectObject( hdcMem, frames[0] );

			BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcMem,
				ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

			SelectObject( hdcMem, hbmOld );
			DeleteDC( hdcMem );
		}
		else if (frame < 500)
		{
			hdcBB = CreateCompatibleDC( hdc );
			hbmOldBB = (HBITMAP) SelectObject( hdcBB, backbuffer );

			hdcMem = CreateCompatibleDC( hdc );
			hbmOld = (HBITMAP) SelectObject( hdcMem, frames[0] );

			BitBlt( hdcBB, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcMem,
				ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

			SelectObject( hdcMem, frames[1] );

			func.SourceConstantAlpha = (frame - 400) * 255 / 100;

			AlphaBlend( hdcBB, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcMem,
				ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, func);

			SelectObject( hdcMem, hbmOld );
			DeleteDC( hdcMem );

			BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcBB,
				ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

			SelectObject( hdcBB, hbmOldBB );
			DeleteDC( hdcBB );
		}
		else if (frame < 900)
		{
			hdcMem = CreateCompatibleDC( hdc );
			hbmOld = (HBITMAP) SelectObject( hdcMem, frames[1] );

			BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcMem,
				ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

			SelectObject( hdcMem, hbmOld );
			DeleteDC( hdcMem );
		}
		else if (frame < 1000)
		{
			hdcBB = CreateCompatibleDC( hdc );
			hbmOldBB = (HBITMAP) SelectObject( hdcBB, backbuffer );

			hdcMem = CreateCompatibleDC( hdc );
			hbmOld = (HBITMAP) SelectObject( hdcMem, frames[1] );

			BitBlt( hdcBB, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcMem,
				ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

			SelectObject( hdcMem, frames[0] );

			func.SourceConstantAlpha = (frame - 900) * 255 / 100;

			AlphaBlend( hdcBB, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcMem,
				ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, func);

			SelectObject( hdcMem, hbmOld );
			DeleteDC( hdcMem );

			BitBlt( hdc, ps.rcPaint.left, ps.rcPaint.top,
				ps.rcPaint.right, ps.rcPaint.bottom, hdcBB,
				ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

			SelectObject( hdcBB, hbmOldBB );
			DeleteDC( hdcBB );
		}

		EndPaint( &ps );

		return 0;
	}
示例#16
0
文件: debugger.c 项目: fesh0r/b-em
void _debugthread(PVOID pvoid)
{
        MSG messages = {0};     /* Here messages to the application are saved */
        WNDCLASSEX wincl;        /* Data structure for the windowclass */

        HDC hDC;
                HDC memDC;
                HBITMAP memBM;
                BITMAPINFO lpbmi;
        int x;
        int c,d;

        usdat = malloc(256 * 256 * 4);
        if (!debugstarted)
        {
                wincl.hInstance = hinst;
                wincl.lpszClassName = DebugszClassName;
                wincl.lpfnWndProc = DebugWindowProcedure;      /* This function is called by windows */
                wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
                wincl.cbSize = sizeof (WNDCLASSEX);

                /* Use default icon and mouse-pointer */
                wincl.hIcon = LoadIcon(hinst, "allegro_icon");
                wincl.hIconSm = LoadIcon(hinst, "allegro_icon");
                wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
                wincl.lpszMenuName = NULL;                 /* No menu */
                wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
                wincl.cbWndExtra = 0;                      /* structure or the window instance */
                /* Use Windows's default color as the background of the window */
                wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

                /* Register the window class, and if it fails quit the program */
                if (!RegisterClassEx(&wincl))
                {
                        printf("Registerclass failed\n");
                        return;
                }
        }
        dhwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           DebugszClassName,         /* Classname */
           "Memory viewer",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           256 + (GetSystemMetrics(SM_CXFIXEDFRAME) * 2),/* The programs width */
           256 + (GetSystemMetrics(SM_CYFIXEDFRAME) * 2) + GetSystemMetrics(SM_CYCAPTION) + 2,/* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL, /* No menu */
           hinst,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );
           printf("Window create %08X\n", (uint32_t)dhwnd);
        ShowWindow (dhwnd, SW_SHOWNORMAL);

        hDC = GetDC(dhwnd);

        memDC = CreateCompatibleDC ( hDC );
        if (!memDC) printf("memDC failed!\n");
        memBM = CreateCompatibleBitmap ( hDC, 256, 256 );
        if (!memBM) printf("memBM failed!\n");
        SelectObject ( memDC, memBM );

        lpbmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
        lpbmi.bmiHeader.biWidth        = 256;
        lpbmi.bmiHeader.biHeight       = -256;
        lpbmi.bmiHeader.biPlanes       = 1;
        lpbmi.bmiHeader.biBitCount     = 32;
        lpbmi.bmiHeader.biCompression  = BI_RGB;
        lpbmi.bmiHeader.biSizeImage    = 256 * 256 * 4;
        lpbmi.bmiHeader.biClrUsed      = 0;
        lpbmi.bmiHeader.biClrImportant = 0;

        debugstarted = 1;
        while (debugon)
        {
                Sleep(20);


                c += 16;
                d = 0;
                for (x = 0; x < 65536; x++)
                {
                        usdat[d++] = fetchc[x] * 8;
                        usdat[d++] = readc[x]  * 8;
                        usdat[d++] = writec[x] * 8;
                        usdat[d++] = 0;
                        if (fetchc[x]) fetchc[x]--;
                        if (readc[x])  readc[x]--;
                        if (writec[x]) writec[x]--;
                }

                SetDIBitsToDevice(memDC, 0, 0, 256, 256, 0, 0, 0, 256, usdat, &lpbmi, DIB_RGB_COLORS);
                BitBlt(hDC, 0, 0, 256, 256, memDC, 0, 0, SRCCOPY);

                if (PeekMessage(&messages, NULL, 0, 0, PM_REMOVE))
                {
                        /* Translate virtual-key messages into character messages */
                        TranslateMessage(&messages);
                        /* Send message to WindowProcedure */
                        DispatchMessage(&messages);
                }
//                if (indebug) pollmainwindow();
        }
        free(usdat);
}
示例#17
0
void	MDIOSprite_UpdateWindow (MIOWinInfoPtr pmInfoPtr, 
				 BOOL pmCopyToOffscreen)
{
    MYRECTLIST  *myDirtyRect, *myNextDirtyRect;
    MYRECT	myRect;
    SpriteInfo	*mySpritePtr;
    BOOL	mySpriteNotDrawn, myBackgroundNotDrawn;
    int		myWidth, myHeight;

//int gdiRes, userRes, gdiRes1, userRes1;
//gdiRes = GetGuiResources (GetCurrentProcess(), GR_GDIOBJECTS);
//userRes = GetGuiResources (GetCurrentProcess(), GR_USEROBJECTS);
    myDirtyRect = pmInfoPtr -> dirtyRectHead;

    // Set up the window.
    // TW

    // Now, if there are no items that are behind the offscreen window (i.e.
    // all sprites have positive height), then simply do a copy of the 
    // offscreen window.  However, if there are, then we start by filling
    // the entire area with the transparent colour of the offscreen window, 
    // then drawing the non-postive height sprites in MERGE mode, then drawing
    // the offscreen window in MERGE mode, then drawing the rest of the 
    // sprites in MERGE mode.
    while (myDirtyRect != NULL)
    {
	myRect = myDirtyRect -> rect;

	// Convert from Turing coordinates to Windows coordinates
	myWidth = myRect.right - myRect.left;
	myHeight = myRect.bottom - myRect.top;

	// Now draw each sprite 
	mySpritePtr = (SpriteInfo *) (pmInfoPtr -> spriteQueueHead);
	mySpriteNotDrawn = TRUE;
	myBackgroundNotDrawn = TRUE;

	while (mySpritePtr != NULL)
	{
	    // If the sprite is not visible or does not intersect with the
	    // dirty rectangle, ignore it.
	    if ((!mySpritePtr -> visible) ||
		!MIO_RectanglesIntersect (&myDirtyRect -> rect, 
					  &mySpritePtr -> spriteRect))
	    {
		// Sprite not visible or doesn't intersect, don't draw it!
		mySpritePtr = mySpritePtr -> next;
		continue;
	    }

	    // If we haven't drawn a sprite before we either have to draw the
	    // offscreen window (if the first sprite's height is positive, 
	    // or just fill the sprite space with the transparent colour).
	    if (mySpriteNotDrawn)
	    {
		if (mySpritePtr -> spriteHeight >= 0)
		{
		    // The lowest sprite is above the background.  Draw the
		    // background using COPY
		    BitBlt (pmInfoPtr -> spriteDeviceContext, 
			    myRect.left, myRect.top, myWidth, myHeight, 
			    pmInfoPtr -> offscreenDeviceContext, 
			    myRect.left, myRect.top, SRCCOPY);
		    myBackgroundNotDrawn = FALSE;
		}
		else
		{
		    // Fill the background with the offscreen window's
		    // transparent color
		    HPEN 	myNewPen, myOldPen;
		    HBRUSH	myNewBrush, myOldBrush;
		    COLORREF	myTransparentColour;

		    myTransparentColour = 
			(COLORREF) MIORGB_ConvertColour (
					pmInfoPtr -> transparentColour);
		    myNewPen = CreatePen (PS_SOLID, 1, myTransparentColour);
		    myNewBrush = CreateSolidBrush (myTransparentColour);
		    myOldPen = SelectPen (pmInfoPtr -> spriteDeviceContext, 
					  myNewPen);
		    myOldBrush = SelectBrush (pmInfoPtr -> spriteDeviceContext, 
					      myNewBrush);
		    Rectangle (pmInfoPtr -> spriteDeviceContext, myRect.left, 
			       myRect.top, myRect.right + 1, myRect.bottom + 1);
		    SelectBrush (pmInfoPtr -> spriteDeviceContext, myOldBrush);
		    DeleteBrush (myNewBrush);
    		    SelectPen (pmInfoPtr -> spriteDeviceContext, myOldPen);
		    DeletePen (myNewPen);
		}
		mySpriteNotDrawn = FALSE;
	    }
	    else
	    {
		// If we haven't drawn the background before, and this sprite
		// is above the background (height >= 0), then its time to
		// draw the background in MERGE mode
		if (myBackgroundNotDrawn && (mySpritePtr -> spriteHeight >= 0))
		{
		    MDIOPic_SpriteDraw (pmInfoPtr, NULL, myRect.left, myRect.top, 
					myWidth, myHeight, 
					pmInfoPtr -> transparentColour);
		    
		    myBackgroundNotDrawn = FALSE;
		}
	    }

	    // Draw Sprite
	    MDIOPic_SpriteDraw (pmInfoPtr, mySpritePtr -> picMDPicInfo, 
				mySpritePtr -> x, mySpritePtr -> y,
				mySpritePtr -> picWidth, 
				mySpritePtr -> picHeight,
				mySpritePtr -> picTransparentColour);

	    mySpritePtr = mySpritePtr -> next;
	}
	// If we still haven't drawn the background after having drawn all the
	// sprites, then it is time to draw the background.  If we've drawn
	// any sprites above, then the background has already been drawn, and
	// we draw in MERGE mode.  If we haven't drawn a sprite, then we draw
	// the background in copy mode.
	if (myBackgroundNotDrawn)
	{
	    if (mySpriteNotDrawn)
	    {
		BitBlt (pmInfoPtr -> spriteDeviceContext, 
			myRect.left, myRect.top, myWidth, myHeight, 
			pmInfoPtr -> offscreenDeviceContext, 
			myRect.left, myRect.top, SRCCOPY);
	    }
	    else
	    {
		MDIOPic_SpriteDraw (pmInfoPtr, NULL, myRect.left, myRect.top, 
				    myWidth, myHeight, 
				    pmInfoPtr -> transparentColour);
	    }
	    myBackgroundNotDrawn = FALSE;
	}

	// Finally, draw the completed sprite surface to the on-screen window.
	BitBlt (pmInfoPtr -> deviceContext, myRect.left, myRect.top, 
		myWidth, myHeight, pmInfoPtr -> spriteDeviceContext, 
		myRect.left, myRect.top, SRCCOPY);

	// Okay, if pmCopyToOffscreen is true, then copy all of this to the
	// offscreen bitmap as well.  This is used when Turing is finished and
	// the sprites are about to be deallocated.
	if (pmCopyToOffscreen)
	{
	    BitBlt (pmInfoPtr -> offscreenDeviceContext, myRect.left, 
		    myRect.top, myWidth, myHeight, 
		    pmInfoPtr -> spriteDeviceContext, 
		    myRect.left, myRect.top, SRCCOPY);
	}

	// Free the current dirty rect and get the next dirty rectangle.
	myNextDirtyRect = myDirtyRect -> next;
	free (myDirtyRect);
	myDirtyRect = myNextDirtyRect;
    } // while

    pmInfoPtr -> dirtyRectHead = NULL;
//gdiRes1 = GetGuiResources (GetCurrentProcess(), GR_GDIOBJECTS);
//userRes1 = GetGuiResources (GetCurrentProcess(), GR_USEROBJECTS);
} // MDIOSprite_UpdateWindow
示例#18
0
static BOOL CALLBACK 
sSplashDlgProc (
		HWND	hDlg, 
		UINT	uMsg, 
		WPARAM	wParam, 
		LPARAM	lParam) 
{
	PSPLASHSTRUCT	pss;

	switch (uMsg) {

	case WM_INITDIALOG:
		{
			HWND hWndControl;

			SetWindowLong (hDlg, GWL_USERDATA, lParam);
			pss = (PSPLASHSTRUCT)lParam;

			g_hWndSplash = hDlg;
			SetWindowPos (hDlg, HWND_TOP, pss->uXpos, pss->uYpos, 
											pss->uXsize, pss->uYsize, 0);

			hWndControl = GetDlgItem (hDlg, IDOK);
			EnableWindow (hWndControl, FALSE);
			ShowWindow (hWndControl, SW_HIDE);
			hWndControl = GetDlgItem (hDlg, IDC_BUYNOW);
			EnableWindow (hWndControl, FALSE);
			ShowWindow (hWndControl, SW_HIDE);
			pss->uTimerTime = 0;
			SetTimer (hDlg, TIMER_ID, TIMER_PERIOD, NULL);
		}
		return TRUE;

	case WM_PAINT:
		{
			HDC			hDC, hMemDC;
			PAINTSTRUCT ps;
			HBITMAP		hBitmapOld;

			pss = (PSPLASHSTRUCT)GetWindowLong (hDlg, GWL_USERDATA);

			hDC = BeginPaint (hDlg, &ps);
			hMemDC = CreateCompatibleDC (hDC);
			if (pss->hPaletteSplash) {
				SelectPalette (hDC, pss->hPaletteSplash, FALSE);
				RealizePalette (hDC);
			}
			hBitmapOld = SelectObject (hMemDC, pss->hBitmapSplash);
			CLPaintUserInfo (MemMgr, hDlg, hMemDC, NULL);
			BitBlt (hDC, 0, 0, pss->uXsize, pss->uYsize, 
											hMemDC, 0, 0, SRCCOPY);
			SelectObject (hMemDC, hBitmapOld);
			DeleteDC (hMemDC);
			EndPaint (hDlg, &ps);
		}
		return FALSE;

	case WM_LBUTTONDOWN:
		if (hWndSplashParent) EndDialog (hDlg, 0);
		return TRUE;

	case WM_DESTROY:
		KillTimer (hDlg, TIMER_ID);
		return FALSE;

	case WM_TIMER:
		pss = (PSPLASHSTRUCT)GetWindowLong (hDlg, GWL_USERDATA);
		if (pss->uTimerTime < pss->uTimeOut) 
			pss->uTimerTime += TIMER_PERIOD;
		else 
			if (hWndSplashParent) EndDialog (hDlg, 0);
		return TRUE;

	case WM_CLOSE :
		EndDialog (hDlg, 0);
		break;

	case WM_COMMAND :
		switch(LOWORD (wParam)) {

		case IDOK: 
			if (hWndSplashParent) EndDialog (hDlg, 0);
			break;
		}
		return TRUE;

	default:
		return FALSE;

	}

	return FALSE;
}
示例#19
0
文件: WinApp.cpp 项目: lijiqi/WinSln
int CWinApp::CaptureAnImage(HWND hWnd)
{
	HDC hdcScreen;
	HDC hdcWindow;
	HDC hdcMemDC = NULL;
	HBITMAP hbmScreen = NULL;
	BITMAP bmpScreen;

	// Retrieve the handle to a display device context for the client 
	// area of the window. 
	hdcScreen = GetDC(NULL);
	hdcWindow = GetDC(hWnd);
	
	// Create a compatible DC which is used in a BitBlt from the window DC
	hdcMemDC = CreateCompatibleDC(hdcWindow); 

	if(!hdcMemDC)
	{
		MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK);
		goto done;
	}
	
	// Get the client area for size calculation
	RECT rcClient;
	GetClientRect(hWnd, &rcClient);
	DrawText(hdcWindow,L"客户区字画",_countof(L"客户区字画"),&rcClient,DT_LEFT);
	//This is the best stretch mode
	SetStretchBltMode(hdcWindow,HALFTONE);

	//The source DC is the entire screen and the destination DC is the current window (HWND)
	if(!StretchBlt(hdcWindow, 
		0,0, 
		rcClient.right, rcClient.bottom, 
		hdcScreen, 
		0,0,
		GetSystemMetrics (SM_CXSCREEN),
		GetSystemMetrics (SM_CYSCREEN),
		SRCCOPY))
	{
		MessageBox(hWnd, L"StretchBlt has failed",L"Failed", MB_OK);
		goto done;
	}
	
	// Create a compatible bitmap from the Window DC
	hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top);

	if(!hbmScreen)
	{
		MessageBox(hWnd, L"CreateCompatibleBitmap Failed",L"Failed", MB_OK);
		goto done;
	}
	
	// Select the compatible bitmap into the compatible memory DC.
	SelectObject(hdcMemDC,hbmScreen);

	// Bit block transfer into our compatible memory DC.
	if(!BitBlt(hdcMemDC,
		0,0,
		rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, 
		hdcWindow, 
		0,0,
		SRCCOPY))
	{
		MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK);
		goto done;
	}
	
	// Get the BITMAP from the HBITMAP
	GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen);

	BITMAPFILEHEADER   bmfHeader;    
	BITMAPINFOHEADER   bi;

	bi.biSize = sizeof(BITMAPINFOHEADER);    
	bi.biWidth = bmpScreen.bmWidth;    
	bi.biHeight = bmpScreen.bmHeight;  
	bi.biPlanes = 1;    
	bi.biBitCount = 32;    
	bi.biCompression = BI_RGB;    
	bi.biSizeImage = 0;  
	bi.biXPelsPerMeter = 0;    
	bi.biYPelsPerMeter = 0;    
	bi.biClrUsed = 0;    
	bi.biClrImportant = 0;

	DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;

	// Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that 
	// call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc 
	// have greater overhead than HeapAlloc.
	HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); 
	char *lpbitmap = (char *)GlobalLock(hDIB);    

	// Gets the "bits" from the bitmap and copies them into a buffer 
	// which is pointed to by lpbitmap.
	GetDIBits(hdcWindow, hbmScreen, 0,
		(UINT)bmpScreen.bmHeight,
		lpbitmap,
		(BITMAPINFO *)&bi, DIB_RGB_COLORS);

	// A file is created, this is where we will save the screen capture.
	HANDLE hFile = CreateFile(L"d:\\captureqwsx.bmp",
		GENERIC_WRITE,
		0,
		NULL,
		CREATE_ALWAYS,
		FILE_ATTRIBUTE_NORMAL, NULL);   

	// Add the size of the headers to the size of the bitmap to get the total file size
	DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);

	//Offset to where the actual bitmap bits start.
	bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER); 

	//Size of the file
	bmfHeader.bfSize = dwSizeofDIB; 

	//bfType must always be BM for Bitmaps
	bmfHeader.bfType = 0x4D42; //BM   

	DWORD dwBytesWritten = 0;
	WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
	WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
	WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL);

	//Unlock and Free the DIB from the heap
	GlobalUnlock(hDIB);    
	GlobalFree(hDIB);

	//Close the handle for the file that was created
	CloseHandle(hFile);

	//Clean up
done:
	DeleteObject(hbmScreen);
	ReleaseDC(hWnd, hdcMemDC);
	ReleaseDC(NULL,hdcScreen);
	ReleaseDC(hWnd,hdcWindow);

	return 0;
}
示例#20
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND  - process the application menu
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc = GetDC(hWnd);
	switch (mode)
	{
	case 0:
		FreeDrawProc(hWnd, message, wParam, lParam);
		break;
	case 1:
		DrawLineProc(hWnd, message, wParam, lParam);
	case 2:
		DrawEllipseProc(hWnd, message, wParam, lParam);
	case 3:
		DrawRoundProc(hWnd, message, wParam, lParam);
	case 4:
		DrawSquareProc(hWnd, message, wParam, lParam);
	case 5:
		DrawRectangleProc(hWnd, message, wParam, lParam);
	}
	
	switch (message)
    {
	case WM_CREATE:
	{
		p1.x = p1.y = 0;
		p2 = p1;
		mode = 1;
		enTrainDessin = FALSE;

		//Tạo bitmap
	
		RECT rect;
		GetClientRect(hWnd, &rect);
		//Tạo ra một bitmap tương thích với DC màn hình
		hBitmap = CreateCompatibleBitmap(hdc, rect.right - rect.left, rect.bottom - rect.top);
		
		//Tô background cho bitmap
		//Tạo memory dc để tương tác với Bitmap
		HDC memDC = CreateCompatibleDC(hdc);
		SelectObject(memDC, hBitmap);
		HBRUSH hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
		FillRect(memDC, &rect, hBrush);
		DeleteObject(hBrush);
		DeleteDC(memDC);
		ReleaseDC(hWnd, hdc);
		break;
	}
    case WM_COMMAND:
        {
			
            int wmId = LOWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {
			case ID_LINE_STRAIGHTLINE:
				mode = 1;
			break;
			case ID_LINE_FREESTYLE:
				mode = 0;
				break;
			
			case ID_SHAPE_ELLIPSE:
				mode = 2;
				break;
			
			case ID_SHAPE_ROUND:
				mode = 3;
				break;
			
			case ID_SHAPE_SQUARE:
				mode = 4;
				break;
			
			case ID_SHAPE_RECTANGLE:
				mode = 5;
				break;

			case ID_DRAW_WIDTH:
				DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG2), hWnd, AboutBox);
				break;

			case ID_COLOR_RED:
				R = 255;
				G = 0;
				B = 0;
					break;

			case ID_COLOR_GREEN:
				R = 0;
				G = 255;
				B = 0;
					break;


			case ID_COLOR_BLUE:
				R = 0;
				G = 0;
				B = 255;
					break;

			case ID_FORMAT_COLOR:
				doChooseColor(hEdit);

				break;
            
			case ID_FILE_OPEN:

				OPENFILENAME ofn;
				TCHAR szFile[260];
				ZeroMemory(&ofn, sizeof(ofn));
				ofn.lStructSize = sizeof(ofn);
				ofn.hwndOwner = hWnd;
				ofn.lpstrFile = szFile;
				ofn.lpstrFile[0] = '\0';
				ofn.nMaxFile = sizeof(szFile);
				ofn.lpstrFilter = _T("All Files *.*\0*.*\0Text Files *.txt\0*.TXT\0 Doc Files\0*.TXT;*.DOC;*.BAK\0");
				ofn.nFilterIndex = 1;
				ofn.lpstrInitialDir = _T("C:\\");
				ofn.lpstrTitle = _T("My Application - Open file");
				ofn.lpstrDefExt = _T("txt");
				ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

				// Display the Open dialog box. 
				if (GetOpenFileName(&ofn) == TRUE) {
					PAINTSTRUCT ps;
					HDC hdc = GetDC(hWnd);
					//			HDC hdcDestination;
					HBITMAP hbitmap = (HBITMAP)::LoadImage(NULL, ofn.lpstrFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
					//	MessageBox(NULL, ofn.lpstrFile, _T("Selected file"), MB_OK);
					//hdc = getOb
					HDC memDC = CreateCompatibleDC(hdc);
					SelectObject(memDC, hbitmap);
					RECT rect;
					GetClientRect(hWnd, &rect);
					BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, memDC, 0, 0, SRCCOPY);
				}

				break;
			case ID_FILE_SAVE:
			{
				OPENFILENAME ofn;
				ZeroMemory(&ofn, sizeof(ofn));
				char szFileName[MAX_LOADSTRING];
				ZeroMemory(szFileName, MAX_LOADSTRING);
				ofn.lStructSize = sizeof(ofn);
				ofn.hwndOwner = NULL;
				ofn.lpstrFilter = _T("All Files(*.*)\0 * .*\0Bmp Files(*.bmp)\0 * .bmp\0Text Files(*.txt)\0 * .txt\0");
				ofn.lpstrFile = (LPWSTR)szFileName;
				ofn.nMaxFile = MAX_LOADSTRING;
				ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
				ofn.lpstrDefExt = (LPCWSTR)L"bmp";
				GetSaveFileName(&ofn);
				PBITMAPINFO PBi = CreateBitmapInfoStruct(hWnd, hBitmap);
				CreateBMPFile(hWnd, ofn.lpstrFile, PBi, hBitmap, hdc);
				/*save = 1;*/
			}
				break;
			case ID_FILE_EXIT:
				DestroyWindow(hWnd);
				break;
			default:
				return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;


    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            
            // TODO: Add any drawing code that uses hdc here...
			HDC hdc = BeginPaint(hWnd, &ps);
			//Vẽ bitmap ra màn hình trước
			HDC memDC = CreateCompatibleDC(hdc);
			SelectObject(memDC, hBitmap);
			RECT rect;
			GetClientRect(hWnd, &rect);
			BitBlt(hdc, 0, 0, rect.right - rect.left, rect.bottom - rect.top, memDC, 0, 0, SRCCOPY);
				switch (mode)
				{
				case 0:
					//Vẽ tự do thì ta vẽ luôn trên màn hình và bitmap
					FreeDraw(memDC);
					FreeDraw(hdc);
					break;
				case 1:
					//Vẽ đường thẳng thì ta chỉ vẽ lên màn hình
					DrawLine(hdc);
					break;
				case 2:
					
					DrawEllipse(hdc);
					break;
				case 3:

					DrawRound(hdc);
					break;
				case 4:

					DrawSquare(hdc);
					break;
				case 5:
					//DrawRectangle(memDC);
					DrawRectangle(hdc);
					break;
				}
				
				DeleteObject(memDC);
			//SelectObject(hdc, oldPen);
			
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
示例#21
0
LRESULT CALLBACK PropsTabWndWndProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    static int selected, sizingbottom;
    static HIMAGELIST tabIml;
    static int ilProps, ilToolbox;
    RECT r;
    TC_ITEM tie;
    NMHDR *h;
    DRAWITEMSTRUCT *dr;
    HFONT font;
    HBITMAP hbmp;
    HDC hMemDC;
    PAINTSTRUCT paint;
    HDC dc;
    switch (iMessage)
    {
        case WM_SYSCOMMAND:
            if (wParam == SC_CLOSE)
            {
                PostMessage(hwnd, WM_CLOSE, 0, 0);
                return 0;
            }
            break;
        case WM_NOTIFY:
            h = (NMHDR*)lParam;
            switch (h->code)
            {
            case TCN_SELCHANGE:
                switch (selected = TabCtrl_GetCurSel(hwndPropsTabCtrl))
                {
                case 0:
                    ShowWindow(hwndToolbox, SW_HIDE) ;
                    ShowWindow(hwndProps, SW_SHOW) ;
                    break;
                case 1:
                    ShowWindow(hwndProps, SW_HIDE) ;
                    ShowWindow(hwndToolbox, SW_SHOW) ;
                    break;
                }
            }
            break;
        case WM_SETTEXT:
            return SendMessage(hwndPropsTabCtrl, iMessage, wParam, lParam);
        case WM_DRAWITEM:
            dr = (DRAWITEMSTRUCT*)lParam;
            hMemDC = CreateCompatibleDC(dr->hDC);
            hbmp = SelectObject(hMemDC,  *bitmaps[dr->itemID]);
            BitBlt(dr->hDC, dr->rcItem.left + 2, dr->rcItem.bottom - 18, 16, 16,
                hMemDC, 0, 0, SRCCOPY);
            font = SelectObject(dr->hDC, font);
            TextOut(dr->hDC, dr->rcItem.left + 18, dr->rcItem.bottom - 16,
                nameTags[dr->itemID], strlen(nameTags[dr->itemID]));
            font = SelectObject(dr->hDC, font);
            SelectObject(dr->hDC, hbmp);
            DeleteDC(hMemDC);
            break;
        case WM_CREATE:
            hwndPropsTab = hwnd;
            GetClientRect(hwnd, &r);
            hwndPropsTabCtrl = CreateWindow(WC_TABCONTROL, 0, WS_CHILD +
                WS_CLIPSIBLINGS + WS_VISIBLE + TCS_FLATBUTTONS /*+ TCS_OWNERDRAWFIXED */
                + TCS_FOCUSNEVER /*+ TCS_FIXEDWIDTH*/ + TCS_BOTTOM, r.left, r.top,
                r.right - r.left, r.bottom - r.top, hwnd, 0, hInstance, 0);
            ApplyDialogFont(hwndPropsTabCtrl);
            propsBitMap = LoadImage(hInstance, "ID_PROPSBMP", IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADMAP3DCOLORS);
            toolsBitMap = LoadImage(hInstance, "ID_TOOLBOXBMP", IMAGE_BITMAP,0,0,LR_DEFAULTSIZE | LR_LOADMAP3DCOLORS);
            tabIml = ImageList_Create(16, 16, ILC_COLOR32, 1, 0);
            ilProps = ImageList_Add(tabIml, propsBitMap, 0);
            ilToolbox = ImageList_Add(tabIml, toolsBitMap, 0);
            TabCtrl_SetImageList(hwndPropsTabCtrl, tabIml);

            CreatePropsWindow();
            CreateCtlTbWindow();
            tie.mask = TCIF_TEXT | TCIF_IMAGE;
            tie.iImage = ilProps;
            tie.pszText = nameTags[0];
            TabCtrl_InsertItem(hwndPropsTabCtrl, 0, &tie);
            tie.mask = TCIF_TEXT | TCIF_IMAGE ;
            tie.iImage = ilToolbox ;
            tie.pszText  = nameTags[1] ;
            TabCtrl_InsertItem(hwndPropsTabCtrl,1, &tie) ;
            ShowWindow(hwndToolbox,SW_HIDE) ;
            return 0;
        case WM_COMMAND:
            break;
		case WM_SELERRWINDOW:
			{
				NMHDR xx;
				memset(&xx, 0, sizeof(xx));
				xx.code = TCN_SELCHANGE;
				TabCtrl_SetCurSel(hwndPropsTabCtrl, lParam);
				SendMessage(hwnd, WM_NOTIFY, 0, (LPARAM)&xx);
			}
			break;
        case WM_PAINT:
            dc = BeginPaint(hwnd, &paint);
            EndPaint(hwnd, &paint);
            break;
        case WM_DESTROY:
            DestroyWindow(hwndToolbox) ;
            DestroyWindow(hwndProps);
            DestroyWindow(hwndPropsTabCtrl);
            DeleteObject(propsBitMap);
            DeleteObject(toolsBitMap);
            hwndPropsTab = 0;
            break;
        case WM_SIZE:
            r.right = LOWORD(lParam);
            r.bottom = HIWORD(lParam);
            r.left = r.top = 0;
            MoveWindow(hwndPropsTabCtrl, r.left, r.top, r.right - r.left, r.bottom -
                r.top, 1);
            GetPropsTabRect(&r);
            MoveWindow(hwndProps, r.left, r.top, r.right - r.left, r.bottom -
                r.top, 1);
            MoveWindow( hwndToolbox,r.left,r.top,r.right-r.left,r.bottom-r.top,TRUE) ;
            break;
        case WM_CLOSE:
            break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}
示例#22
0
LRESULT CALLBACK WindowProc(HWND hwnd, 
						                UINT msg, 
                            WPARAM wparam, 
                            LPARAM lparam)
{
	//these hold the dimensions of the client window area
	static int cxClient, cyClient;

	//used to create the back buffer
	static HDC		  hdcBackBuffer;
	static HBITMAP	hBitmap;
	static HBITMAP	hOldBitmap; 

	switch(msg)
	{	
		case WM_CREATE: 
		{
			//seed the random number generator
			srand((unsigned) time(NULL));

			//get the size of the client window
			RECT rect;
			GetClientRect(hwnd, &rect);

			cxClient = rect.right;
			cyClient = rect.bottom;

			//setup the controller
			g_pController = new T(hwnd);
			g_pController -> Initialize();
			//create a surface for us to render to(backbuffer)
			hdcBackBuffer = CreateCompatibleDC(NULL);

			HDC hdc = GetDC(hwnd);

			hBitmap = CreateCompatibleBitmap(hdc,
											                cxClient,
											                cyClient);
			ReleaseDC(hwnd, hdc);

			hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap); 
		} 
			
		break;
		
		//check key press messages
		case WM_KEYUP:
		{
			switch(wparam)
			{

				case VK_ESCAPE:
				{
					PostQuitMessage(0);
				}

				break;

				case 'F':
					{
						g_pController->FastRenderToggle();
					}
					
					break;

        //reset the demo
        case 'R':
          {
             if (g_pController)
             {
               delete g_pController;
             }

             //setup the new controller
			       g_pController = new T(hwnd);
				   g_pController -> Initialize();
          }

          break;

			}//end WM_KEYUP switch
		}

		break;

		//has the user resized the client area?
		case WM_SIZE:
		{
 			cxClient = LOWORD(lparam);
			cyClient = HIWORD(lparam);

			//resize the backbuffer accordingly
			SelectObject(hdcBackBuffer, hOldBitmap);

			HDC hdc = GetDC(hwnd);

			hBitmap = CreateCompatibleBitmap(hdc,
											                 cxClient,
											                 cyClient);
			ReleaseDC(hwnd, hdc);
			
			hOldBitmap = (HBITMAP)SelectObject(hdcBackBuffer, hBitmap); 
		} 

		break;

		case WM_PAINT: 
		{
      PAINTSTRUCT ps;
      
		  BeginPaint(hwnd, &ps);
		
			//fill our backbuffer with white
			BitBlt(hdcBackBuffer,
             0,
             0,
             cxClient,
             cyClient,
             NULL,
             NULL,
             NULL,
             WHITENESS);
			
			//render the mines and sweepers
			g_pController->Render(hdcBackBuffer);
			
			//now blit backbuffer to front
			BitBlt(ps.hdc, 0, 0, cxClient, cyClient, hdcBackBuffer, 0, 0, SRCCOPY); 

			EndPaint(hwnd, &ps);
		} 
			
		break;

		case WM_DESTROY: 
		{
			SelectObject(hdcBackBuffer, hOldBitmap);
			delete g_pController;
			g_pController = nullptr;
			//clean up our backbuffer objects
			DeleteDC(hdcBackBuffer);
			DeleteObject(hBitmap); 

      // kill the application, this sends a WM_QUIT message 
			PostQuitMessage(0);
 		} 
			
		break;

		default:break;

	}//end switch

	// default msg handler 
	return (DefWindowProc(hwnd, msg, wparam, lparam));

}//end WinProc
示例#23
0
/*****************************************************************************
 * SIC_OverlayShortcutImage			[internal]
 *
 * NOTES
 *  Creates a new icon as a copy of the passed-in icon, overlayed with a
 *  shortcut image. 
 */
static HICON SIC_OverlayShortcutImage(HICON SourceIcon, BOOL large)
{	ICONINFO SourceIconInfo, ShortcutIconInfo, TargetIconInfo;
	HICON ShortcutIcon, TargetIcon;
	BITMAP SourceBitmapInfo, ShortcutBitmapInfo;
	HDC SourceDC = NULL,
	  ShortcutDC = NULL,
	  TargetDC = NULL,
	  ScreenDC = NULL;
	HBITMAP OldSourceBitmap = NULL,
	  OldShortcutBitmap = NULL,
	  OldTargetBitmap = NULL;

	static int s_imgListIdx = -1;

	/* Get information about the source icon and shortcut overlay */
	if (! GetIconInfo(SourceIcon, &SourceIconInfo)
	    || 0 == GetObjectW(SourceIconInfo.hbmColor, sizeof(BITMAP), &SourceBitmapInfo))
	{
	  return NULL;
	}

	/* search for the shortcut icon only once */
	if (s_imgListIdx == -1)
	    s_imgListIdx = SIC_LoadOverlayIcon(- IDI_SHELL_SHORTCUT);
                           /* FIXME should use icon index 29 instead of the
                              resource id, but not all icons are present yet
                              so we can't use icon indices */

	if (s_imgListIdx != -1)
	{
	    if (large)
	        ShortcutIcon = ImageList_GetIcon(ShellBigIconList, s_imgListIdx, ILD_TRANSPARENT);
	    else
	        ShortcutIcon = ImageList_GetIcon(ShellSmallIconList, s_imgListIdx, ILD_TRANSPARENT);
	} else
	    ShortcutIcon = NULL;

	if (NULL == ShortcutIcon
	    || ! GetIconInfo(ShortcutIcon, &ShortcutIconInfo)
	    || 0 == GetObjectW(ShortcutIconInfo.hbmColor, sizeof(BITMAP), &ShortcutBitmapInfo))
	{
	  return NULL;
	}

	TargetIconInfo = SourceIconInfo;
	TargetIconInfo.hbmMask = NULL;
	TargetIconInfo.hbmColor = NULL;

	/* Setup the source, shortcut and target masks */
	SourceDC = CreateCompatibleDC(NULL);
	if (NULL == SourceDC) goto fail;
	OldSourceBitmap = SelectObject(SourceDC, SourceIconInfo.hbmMask);
	if (NULL == OldSourceBitmap) goto fail;

	ShortcutDC = CreateCompatibleDC(NULL);
	if (NULL == ShortcutDC) goto fail;
	OldShortcutBitmap = SelectObject(ShortcutDC, ShortcutIconInfo.hbmMask);
	if (NULL == OldShortcutBitmap) goto fail;

	TargetDC = CreateCompatibleDC(NULL);
	if (NULL == TargetDC) goto fail;
	TargetIconInfo.hbmMask = CreateCompatibleBitmap(TargetDC, SourceBitmapInfo.bmWidth,
	                                                SourceBitmapInfo.bmHeight);
	if (NULL == TargetIconInfo.hbmMask) goto fail;
	ScreenDC = GetDC(NULL);
	if (NULL == ScreenDC) goto fail;
	TargetIconInfo.hbmColor = CreateCompatibleBitmap(ScreenDC, SourceBitmapInfo.bmWidth,
	                                                 SourceBitmapInfo.bmHeight);
	ReleaseDC(NULL, ScreenDC);
	if (NULL == TargetIconInfo.hbmColor) goto fail;
	OldTargetBitmap = SelectObject(TargetDC, TargetIconInfo.hbmMask);
	if (NULL == OldTargetBitmap) goto fail;

	/* Create the target mask by ANDing the source and shortcut masks */
	if (! BitBlt(TargetDC, 0, 0, SourceBitmapInfo.bmWidth, SourceBitmapInfo.bmHeight,
	             SourceDC, 0, 0, SRCCOPY) ||
	    ! BitBlt(TargetDC, 0, SourceBitmapInfo.bmHeight - ShortcutBitmapInfo.bmHeight,
	             ShortcutBitmapInfo.bmWidth, ShortcutBitmapInfo.bmHeight,
	             ShortcutDC, 0, 0, SRCAND))
	{
	  goto fail;
	}

	/* Setup the source and target xor bitmap */
	if (NULL == SelectObject(SourceDC, SourceIconInfo.hbmColor) ||
	    NULL == SelectObject(TargetDC, TargetIconInfo.hbmColor))
	{
	  goto fail;
	}

	/* Copy the source xor bitmap to the target and clear out part of it by using
	   the shortcut mask */
	if (! BitBlt(TargetDC, 0, 0, SourceBitmapInfo.bmWidth, SourceBitmapInfo.bmHeight,
	             SourceDC, 0, 0, SRCCOPY) ||
	    ! BitBlt(TargetDC, 0, SourceBitmapInfo.bmHeight - ShortcutBitmapInfo.bmHeight,
	             ShortcutBitmapInfo.bmWidth, ShortcutBitmapInfo.bmHeight,
	             ShortcutDC, 0, 0, SRCAND))
	{
	  goto fail;
	}

	if (NULL == SelectObject(ShortcutDC, ShortcutIconInfo.hbmColor)) goto fail;

	/* Now put in the shortcut xor mask */
	if (! BitBlt(TargetDC, 0, SourceBitmapInfo.bmHeight - ShortcutBitmapInfo.bmHeight,
	             ShortcutBitmapInfo.bmWidth, ShortcutBitmapInfo.bmHeight,
	             ShortcutDC, 0, 0, SRCINVERT))
	{
	  goto fail;
	}

	/* Clean up, we're not goto'ing to 'fail' after this so we can be lazy and not set
	   handles to NULL */
	SelectObject(TargetDC, OldTargetBitmap);
	DeleteObject(TargetDC);
	SelectObject(ShortcutDC, OldShortcutBitmap);
	DeleteObject(ShortcutDC);
	SelectObject(SourceDC, OldSourceBitmap);
	DeleteObject(SourceDC);

	/* Create the icon using the bitmaps prepared earlier */
	TargetIcon = CreateIconIndirect(&TargetIconInfo);

	/* CreateIconIndirect copies the bitmaps, so we can release our bitmaps now */
	DeleteObject(TargetIconInfo.hbmColor);
	DeleteObject(TargetIconInfo.hbmMask);

	return TargetIcon;

fail:
	/* Clean up scratch resources we created */
	if (NULL != OldTargetBitmap) SelectObject(TargetDC, OldTargetBitmap);
	if (NULL != TargetIconInfo.hbmColor) DeleteObject(TargetIconInfo.hbmColor);
	if (NULL != TargetIconInfo.hbmMask) DeleteObject(TargetIconInfo.hbmMask);
	if (NULL != TargetDC) DeleteObject(TargetDC);
	if (NULL != OldShortcutBitmap) SelectObject(ShortcutDC, OldShortcutBitmap);
	if (NULL != ShortcutDC) DeleteObject(ShortcutDC);
	if (NULL != OldSourceBitmap) SelectObject(SourceDC, OldSourceBitmap);
	if (NULL != SourceDC) DeleteObject(SourceDC);

	return NULL;
}
示例#24
0
INT_PTR CALLBACK DlgSkinOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_DESTROY:
	{
		if (hPreviewBitmap) ske_UnloadGlyphImage(hPreviewBitmap);
		break;
	}

	case WM_INITDIALOG:
	{
		TranslateDialogDefault(hwndDlg);
		SetDlgItemText(hwndDlg, IDC_SKINFOLDERLABEL, SkinsFolder);
		HTREEITEM it = FillAvailableSkinList(hwndDlg);
		HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1);
		TreeView_SelectItem(wnd, it);
	}
	return 0;
	case WM_COMMAND:
	{
		switch (LOWORD(wParam)) {
		case IDC_COLOUR_MENUNORMAL:
		case IDC_COLOUR_MENUSELECTED:
		case IDC_COLOUR_FRAMES:
		case IDC_COLOUR_STATUSBAR:
			SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_BUTTON_INFO:
		{
			TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000];
			SkinListData *sd = NULL;
			HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1));
			if (hti == 0) return 0;
			{
				TVITEM tvi = { 0 };
				tvi.hItem = hti;
				tvi.mask = TVIF_HANDLE | TVIF_PARAM;
				TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi);
				sd = (SkinListData*)(tvi.lParam);
			}
			if (!sd) return 0;
			if (sd->File && !_tcschr(sd->File, _T('%')))
			{
				GetPrivateProfileString(_T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF(Author), sd->File);
				GetPrivateProfileString(_T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF(URL), sd->File);
				GetPrivateProfileString(_T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF(Contact), sd->File);
				GetPrivateProfileString(_T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF(Description), sd->File);
				mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s):\t %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"),
					sd->Name, Description, Author, Contact, URL, sd->File);
			}
			else
			{
				mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAuthor(s): %s\nContact:\t %s\nWeb:\t %s\n\nFile:\t %s"),
					TranslateT("reVista for Modern v0.5"),
					TranslateT("This is second default Modern Contact list skin in Vista Aero style"),
					TranslateT("Angeli-Ka (graphics), FYR (template)"),
					_T("JID: [email protected]"),
					_T("fyr.mirandaim.ru"),
					TranslateT("Inside library"));
			}
			MessageBox(hwndDlg, text, TranslateT("Skin information"), MB_OK | MB_ICONINFORMATION);
		}
		break;
		case IDC_BUTTON_APPLY_SKIN:
			if (HIWORD(wParam) == BN_CLICKED)
			{
				SkinListData *sd = NULL;
				HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1));
				if (hti == 0) return 0;
				{
					TVITEM tvi = { 0 };
					tvi.hItem = hti;
					tvi.mask = TVIF_HANDLE | TVIF_PARAM;
					TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi);
					sd = (SkinListData*)(tvi.lParam);
				}
				if (!sd) return 0;
				ske_LoadSkinFromIniFile(sd->File, FALSE);
				ske_LoadSkinFromDB();
				pcli->pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0);
				Sync(CLUIFrames_OnClistResize_mod, 0, 0);
				ske_RedrawCompleteWindow();
				Sync(CLUIFrames_OnClistResize_mod, 0, 0);
				{
					HWND hwnd = pcli->hwndContactList;
					RECT rc = { 0 };
					GetWindowRect(hwnd, &rc);
					Sync(CLUIFrames_OnMoving, hwnd, &rc);
				}
				if (g_hCLUIOptionsWnd)
				{
					SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_LEFTMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "LeftClientMargin", SETTING_LEFTCLIENTMARIGN_DEFAULT));
					SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_RIGHTMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "RightClientMargin", SETTING_RIGHTCLIENTMARIGN_DEFAULT));
					SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_TOPMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "TopClientMargin", SETTING_TOPCLIENTMARIGN_DEFAULT));
					SendDlgItemMessage(g_hCLUIOptionsWnd, IDC_BOTTOMMARGINSPIN, UDM_SETPOS, 0, db_get_b(NULL, "CLUI", "BottomClientMargin", SETTING_BOTTOMCLIENTMARIGN_DEFAULT));
				}
			}
			break;
		case IDC_BUTTON_RESCAN:
			if (HIWORD(wParam) == BN_CLICKED)
			{
				HTREEITEM it = FillAvailableSkinList(hwndDlg);
				HWND wnd = GetDlgItem(hwndDlg, IDC_TREE1);
				TreeView_SelectItem(wnd, it);
			}
		}
		break;
	}
	case WM_DRAWITEM:
		if (wParam == IDC_PREVIEW)
		{
			//TODO:Draw hPreviewBitmap here
			int mWidth, mHeight;
			HBRUSH hbr = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
			DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
			mWidth = dis->rcItem.right - dis->rcItem.left;
			mHeight = dis->rcItem.bottom - dis->rcItem.top;
			HDC memDC = CreateCompatibleDC(dis->hDC);
			HBITMAP hbmp = ske_CreateDIB32(mWidth, mHeight);
			HBITMAP holdbmp = (HBITMAP)SelectObject(memDC, hbmp);
			RECT workRect = dis->rcItem;
			OffsetRect(&workRect, -workRect.left, -workRect.top);
			FillRect(memDC, &workRect, hbr);
			DeleteObject(hbr);
			if (hPreviewBitmap)
			{
				//variables
				BITMAP bmp = { 0 };
				POINT imgPos = { 0 };
				float xScale = 1, yScale = 1;
				//GetSize
				GetObject(hPreviewBitmap, sizeof(BITMAP), &bmp);
				int wWidth = workRect.right - workRect.left;
				int wHeight = workRect.bottom - workRect.top;
				if (wWidth < bmp.bmWidth) xScale = (float)wWidth / bmp.bmWidth;
				if (wHeight < bmp.bmHeight) yScale = (float)wHeight / bmp.bmHeight;
				xScale = min(xScale, yScale);
				yScale = xScale;
				int dWidth = (int)(xScale*bmp.bmWidth);
				int dHeight = (int)(yScale*bmp.bmHeight);
				//CalcPosition
				imgPos.x = workRect.left + ((wWidth - dWidth) >> 1);
				imgPos.y = workRect.top + ((wHeight - dHeight) >> 1);
				//DrawImage
				DrawAvatarImageWithGDIp(memDC, imgPos.x, imgPos.y, dWidth, dHeight, hPreviewBitmap, 0, 0, bmp.bmWidth, bmp.bmHeight, 8, 255);
			}
			BitBlt(dis->hDC, dis->rcItem.left, dis->rcItem.top, mWidth, mHeight, memDC, 0, 0, SRCCOPY);
			SelectObject(memDC, holdbmp);
			DeleteObject(hbmp);
			DeleteDC(memDC);
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case IDC_TREE1:
		{
			NMTREEVIEW * nmtv = (NMTREEVIEW *)lParam;
			if (nmtv == NULL)
				return 0;

			if (nmtv->hdr.code == TVN_SELCHANGEDA || nmtv->hdr.code == TVN_SELCHANGEDW) {
				SkinListData * sd = NULL;
				if (hPreviewBitmap) {
					ske_UnloadGlyphImage(hPreviewBitmap);
					hPreviewBitmap = NULL;
				}

				if (nmtv->itemNew.lParam) {
					sd = (SkinListData*)nmtv->itemNew.lParam;

					TCHAR buf[MAX_PATH];
					PathToRelativeT(sd->File, buf);
					SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, buf);

					TCHAR prfn[MAX_PATH] = { 0 }, imfn[MAX_PATH] = { 0 }, skinfolder[MAX_PATH] = { 0 };
					GetPrivateProfileString(_T("Skin_Description_Section"), _T("Preview"), _T(""), imfn, SIZEOF(imfn), sd->File);
					IniParser::GetSkinFolder(sd->File, skinfolder);
					mir_sntprintf(prfn, SIZEOF(prfn), _T("%s\\%s"), skinfolder, imfn);
					PathToAbsoluteT(prfn, imfn);
					hPreviewBitmap = ske_LoadGlyphImage(imfn);

					EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_APPLY_SKIN), TRUE);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_INFO), TRUE);
					if (hPreviewBitmap)
						InvalidateRect(GetDlgItem(hwndDlg, IDC_PREVIEW), NULL, TRUE);
					else { //prepare text
						TCHAR Author[255], URL[MAX_PATH], Contact[255], Description[400], text[2000];
						SkinListData* sd = NULL;
						HTREEITEM hti = TreeView_GetSelection(GetDlgItem(hwndDlg, IDC_TREE1));
						if (hti == 0) return 0;
						{
							TVITEM tvi = { 0 };
							tvi.hItem = hti;
							tvi.mask = TVIF_HANDLE | TVIF_PARAM;
							TreeView_GetItem(GetDlgItem(hwndDlg, IDC_TREE1), &tvi);
							sd = (SkinListData*)(tvi.lParam);
						}
						if (!sd) return 0;

						if (sd->File && !_tcschr(sd->File, _T('%')))
						{
							GetPrivateProfileString(_T("Skin_Description_Section"), _T("Author"), TranslateT("( unknown )"), Author, SIZEOF(Author), sd->File);
							GetPrivateProfileString(_T("Skin_Description_Section"), _T("URL"), _T(""), URL, SIZEOF(URL), sd->File);
							GetPrivateProfileString(_T("Skin_Description_Section"), _T("Contact"), _T(""), Contact, SIZEOF(Contact), sd->File);
							GetPrivateProfileString(_T("Skin_Description_Section"), _T("Description"), _T(""), Description, SIZEOF(Description), sd->File);
							mir_sntprintf(text, SIZEOF(text), TranslateT("Preview is not available\n\n%s\n----------------------\n\n%s\n\nAUTHOR(S):\n%s\n\nCONTACT:\n%s\n\nHOMEPAGE:\n%s"),
								sd->Name, Description, Author, Contact, URL);
						}
						else
						{
							mir_sntprintf(text, SIZEOF(text), TranslateT("%s\n\n%s\n\nAUTHORS:\n%s\n\nCONTACT:\n%s\n\nWEB:\n%s\n\n\n"),
								TranslateT("reVista for Modern v0.5"),
								TranslateT("This is second default Modern Contact list skin in Vista Aero style"),
								TranslateT("graphics by Angeli-Ka\ntemplate by FYR"),
								_T("JID: [email protected]"),
								_T("fyr.mirandaim.ru"));
						}
						ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), SW_HIDE);
						ShowWindow(GetDlgItem(hwndDlg, IDC_STATIC_INFO), SW_SHOW);
						SetDlgItemText(hwndDlg, IDC_STATIC_INFO, text);
					}
				}
				else {
					//no selected
					SetDlgItemText(hwndDlg, IDC_EDIT_SKIN_FILENAME, TranslateT("Select skin from list"));
					EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_APPLY_SKIN), FALSE);
					EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON_INFO), FALSE);
					SetDlgItemText(hwndDlg, IDC_STATIC_INFO, TranslateT("Please select skin to apply"));
					ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), SW_HIDE);
				}
				ShowWindow(GetDlgItem(hwndDlg, IDC_PREVIEW), hPreviewBitmap ? SW_SHOW : SW_HIDE);
				return 0;
			}
			else if (nmtv->hdr.code == TVN_DELETEITEMA || nmtv->hdr.code == TVN_DELETEITEMW) {
				mir_free_and_nil(nmtv->itemOld.lParam);
				return 0;
			}
		}
		break;

		case 0:
			switch (((LPNMHDR)lParam)->code) {
			case PSN_APPLY:
				pcli->pfnClcBroadcast(INTM_RELOADOPTIONS, 0, 0);
				NotifyEventHooks(g_CluiData.hEventBkgrChanged, 0, 0);
				pcli->pfnClcBroadcast(INTM_INVALIDATE, 0, 0);
				RedrawWindow(GetParent(pcli->hwndContactTree), NULL, NULL, RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
			}
			break;
		}
	}
示例#25
0
bool wxSetClipboardData(wxDataFormat dataFormat,
                        const void *data,
                        int width, int height)
{
    HANDLE handle = 0; // return value of SetClipboardData

    switch (dataFormat)
    {
        case wxDF_BITMAP:
            {
                wxBitmap *bitmap = (wxBitmap *)data;

                HDC hdcMem = CreateCompatibleDC((HDC) NULL);
                HDC hdcSrc = CreateCompatibleDC((HDC) NULL);
                HBITMAP old = (HBITMAP)
                    ::SelectObject(hdcSrc, (HBITMAP)bitmap->GetHBITMAP());
                HBITMAP hBitmap = CreateCompatibleBitmap(hdcSrc,
                                                         bitmap->GetWidth(),
                                                         bitmap->GetHeight());
                if (!hBitmap)
                {
                    SelectObject(hdcSrc, old);
                    DeleteDC(hdcMem);
                    DeleteDC(hdcSrc);
                    return false;
                }

                HBITMAP old1 = (HBITMAP) SelectObject(hdcMem, hBitmap);
                BitBlt(hdcMem, 0, 0, bitmap->GetWidth(), bitmap->GetHeight(),
                       hdcSrc, 0, 0, SRCCOPY);

                // Select new bitmap out of memory DC
                SelectObject(hdcMem, old1);

                // Set the data
                handle = ::SetClipboardData(CF_BITMAP, hBitmap);

                // Clean up
                SelectObject(hdcSrc, old);
                DeleteDC(hdcSrc);
                DeleteDC(hdcMem);
                break;
            }

#if wxUSE_WXDIB
        case wxDF_DIB:
            {
                wxBitmap *bitmap = (wxBitmap *)data;

                if ( bitmap && bitmap->Ok() )
                {
                    wxDIB dib(*bitmap);
                    if ( dib.IsOk() )
                    {
                        handle = ::SetClipboardData(CF_DIB, dib.Detach());
                    }
                }
                break;
            }
#endif

    // VZ: I'm told that this code works, but it doesn't seem to work for me
    //     and, anyhow, I'd be highly surprised if it did. So I leave it here
    //     but IMNSHO it is completely broken.
#if wxUSE_METAFILE && !defined(wxMETAFILE_IS_ENH) && !defined(__WXWINCE__)
        case wxDF_METAFILE:
            {
                wxMetafile *wxMF = (wxMetafile *)data;
                HANDLE data = GlobalAlloc(GHND, sizeof(METAFILEPICT) + 1);
                METAFILEPICT *mf = (METAFILEPICT *)GlobalLock(data);

                mf->mm = wxMF->GetWindowsMappingMode();
                mf->xExt = width;
                mf->yExt = height;
                mf->hMF = (HMETAFILE) wxMF->GetHMETAFILE();
                GlobalUnlock(data);
                wxMF->SetHMETAFILE((WXHANDLE) NULL);

                handle = SetClipboardData(CF_METAFILEPICT, data);
                break;
            }
#endif // wxUSE_METAFILE

#if wxUSE_ENH_METAFILE && !defined(__WXWINCE__)
        case wxDF_ENHMETAFILE:
            {
                wxEnhMetaFile *emf = (wxEnhMetaFile *)data;
                wxEnhMetaFile emfCopy = *emf;

                handle = SetClipboardData(CF_ENHMETAFILE,
                                          (void *)emfCopy.GetHENHMETAFILE());
            }
            break;
#endif // wxUSE_ENH_METAFILE

        case CF_SYLK:
        case CF_DIF:
        case CF_TIFF:
        case CF_PALETTE:
        default:
            {
                wxLogError(_("Unsupported clipboard format."));
                return false;
            }

        case wxDF_OEMTEXT:
            dataFormat = wxDF_TEXT;
            // fall through

        case wxDF_TEXT:
            {
                char *s = (char *)data;

                width = strlen(s) + 1;
                height = 1;
                DWORD l = (width * height);
                HANDLE hGlobalMemory = GlobalAlloc(GHND, l);
                if ( hGlobalMemory )
                {
                    LPSTR lpGlobalMemory = (LPSTR)GlobalLock(hGlobalMemory);

                    memcpy(lpGlobalMemory, s, l);

                    GlobalUnlock(hGlobalMemory);
                }

                handle = SetClipboardData(dataFormat, hGlobalMemory);
                break;
            }
            // Only tested with Visual C++ 6.0 so far
#if defined(__VISUALC__)
        case wxDF_HTML:
            {
                char* html = (char *)data;

                // Create temporary buffer for HTML header...
                char *buf = new char [400 + strlen(html)];
                if(!buf) return false;

                // Get clipboard id for HTML format...
                static int cfid = 0;
                if(!cfid) cfid = RegisterClipboardFormat(wxT("HTML Format"));

                // Create a template string for the HTML header...
                strcpy(buf,
                    "Version:0.9\r\n"
                    "StartHTML:00000000\r\n"
                    "EndHTML:00000000\r\n"
                    "StartFragment:00000000\r\n"
                    "EndFragment:00000000\r\n"
                    "<html><body>\r\n"
                    "<!--StartFragment -->\r\n");

                // Append the HTML...
                strcat(buf, html);
                strcat(buf, "\r\n");
                // Finish up the HTML format...
                strcat(buf,
                    "<!--EndFragment-->\r\n"
                    "</body>\r\n"
                    "</html>");

                // Now go back, calculate all the lengths, and write out the
                // necessary header information. Note, wsprintf() truncates the
                // string when you overwrite it so you follow up with code to replace
                // the 0 appended at the end with a '\r'...
                char *ptr = strstr(buf, "StartHTML");
                sprintf(ptr+10, "%08u", strstr(buf, "<html>") - buf);
                *(ptr+10+8) = '\r';

                ptr = strstr(buf, "EndHTML");
                sprintf(ptr+8, "%08u", strlen(buf));
                *(ptr+8+8) = '\r';

                ptr = strstr(buf, "StartFragment");
                sprintf(ptr+14, "%08u", strstr(buf, "<!--StartFrag") - buf);
                *(ptr+14+8) = '\r';

                ptr = strstr(buf, "EndFragment");
                sprintf(ptr+12, "%08u", strstr(buf, "<!--EndFrag") - buf);
                *(ptr+12+8) = '\r';

                // Now you have everything in place ready to put on the
                // clipboard.

                // Allocate global memory for transfer...
                HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE |GMEM_DDESHARE, strlen(buf)+4);

                // Put your string in the global memory...
                ptr = (char *)GlobalLock(hText);
                strcpy(ptr, buf);
                GlobalUnlock(hText);

                handle = ::SetClipboardData(cfid, hText);

                // Free memory...
                GlobalFree(hText);

                // Clean up...
                delete [] buf;
                break;
            }
#endif
    }

    if ( handle == 0 )
    {
        wxLogSysError(_("Failed to set clipboard data."));

        return false;
    }

    return true;
}
示例#26
0
LRESULT APIENTRY MainWndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	int				i;
	PAINTSTRUCT		ps;

	switch( message ){
	case WM_CREATE:
		InitCommonControls();
		break;
	case WM_MOUSEWHEEL:
		sysInf.zDelta = (short) HIWORD(wParam);
		break;
    case WM_DESTROY:
	case WM_QUIT:
	case WM_CLOSE:
		if(IDYES==MessageBox(sysInf.hWnd,"アルルゥとあそぼ!!を終了してよろしいですか?","終了確認",MB_YESNO)){
			sysInf.bGameEnd = on;
		}
		return 0;
	case WM_ACTIVATE:
		for(i=0;i<g_iDIDeviceNum;i++){
			if(LOWORD(wParam) == WA_INACTIVE){
				g_pDIDevice[i]->Unacquire();
			}else{
				g_pDIDevice[i]->Acquire();
				g_pDIDevice[i]->Poll();
			}
		}
		sysInf.bIsActive = LOWORD(wParam) ? TRUE : FALSE;
		myOutputDebugString("ActivateHandle: ");
		if(sysInf.bIsActive)myOutputDebugString("Active\n");
		else myOutputDebugString("Non Active\n");
		if(sysInf.bIsActive)clearPadState();
		break;
	case WM_COMMAND:
		switch( LOWORD(wParam) ){
		  case ID_MYAPP_EXIT:
			if(IDYES==MessageBox(sysInf.hWnd,"アルルゥとあそぼ!!を終了してよろしいですか?","終了確認",MB_YESNO)){
				sysInf.bGameEnd = on;
			}
			return 0;
		  case ID_DISPCHANGE:
			if(lpMovie)	lpMovie->StopMovie();
			if(0==sysInf.full_screen){
				if(CheckOSw2k()){
					ScreenChange( 1 ,TRUE);
					for(i=0;i<DispFreqMax;i++){
						EnableMenuItem( sysInf.hMenu, ID_SUBMENU+i,  MF_ENABLED  );
						CheckMenuItem( sysInf.hMenu, ID_SUBMENU+i,   MF_UNCHECKED );
					}
					EnableMenuItem( sysInf.hMenu, ID_SUBMENU,  MF_GRAYED  );
					CheckMenuItem( sysInf.hMenu, ID_SUBMENU,   MF_CHECKED );
					EnableMenuItem( sysInf.hMenu, ID_DISPWINDOW, MF_ENABLED );
					CheckMenuItem( sysInf.hMenu, ID_DISPWINDOW,  MF_UNCHECKED );
				}else{
					ScreenChange(1,0);
					EnableMenuItem( sysInf.hMenu,ID_DISPFULL,   MF_GRAYED  );
					CheckMenuItem( sysInf.hMenu, ID_DISPFULL,   MF_CHECKED );
					EnableMenuItem( sysInf.hMenu,ID_DISPWINDOW, MF_ENABLED );
					CheckMenuItem( sysInf.hMenu, ID_DISPWINDOW, MF_UNCHECKED );
				}
			}else{
				ScreenChange(0,0);
				if(CheckOSw2k()){
					for(i=0;i<DispFreqMax;i++){
						EnableMenuItem( sysInf.hMenu, ID_SUBMENU+i,  MF_ENABLED  );
						CheckMenuItem( sysInf.hMenu, ID_SUBMENU+i,   MF_UNCHECKED );
					}
				}else{
					EnableMenuItem( sysInf.hMenu, ID_DISPFULL,  MF_ENABLED );
					CheckMenuItem( sysInf.hMenu, ID_DISPFULL,   MF_UNCHECKED );
				}
				EnableMenuItem( sysInf.hMenu, ID_DISPWINDOW, MF_GRAYED  );
				CheckMenuItem( sysInf.hMenu, ID_DISPWINDOW,  MF_CHECKED   );
			}
			break;
		  case ID_DISPFULL:
			if(lpMovie)	lpMovie->StopMovie();
			ScreenChange(1,0);
			EnableMenuItem( sysInf.hMenu,ID_DISPFULL,   MF_GRAYED  );
			CheckMenuItem( sysInf.hMenu, ID_DISPFULL,   MF_CHECKED );
			EnableMenuItem( sysInf.hMenu,ID_DISPWINDOW, MF_ENABLED );
			CheckMenuItem( sysInf.hMenu, ID_DISPWINDOW, MF_UNCHECKED );
			break;
		  case ID_DISPWINDOW:
			if(lpMovie)	lpMovie->StopMovie();
			ScreenChange(0,0);
			if(CheckOSw2k()){
				for(i=0;i<DispFreqMax;i++){
					EnableMenuItem( sysInf.hMenu, ID_SUBMENU+i,  MF_ENABLED  );
					CheckMenuItem( sysInf.hMenu, ID_SUBMENU+i,   MF_UNCHECKED );
				}
			}else{
				EnableMenuItem( sysInf.hMenu, ID_DISPFULL,  MF_ENABLED );
				CheckMenuItem( sysInf.hMenu, ID_DISPFULL,   MF_UNCHECKED );
			}
			EnableMenuItem( sysInf.hMenu, ID_DISPWINDOW, MF_GRAYED  );
			CheckMenuItem( sysInf.hMenu, ID_DISPWINDOW,  MF_CHECKED   );
			break;
		  case ID_SUBMENU:		case ID_SUBMENU+1:	case ID_SUBMENU+2:	case ID_SUBMENU+3:
		  case ID_SUBMENU+4:	case ID_SUBMENU+5:	case ID_SUBMENU+6:	case ID_SUBMENU+7:
			if(lpMovie)	lpMovie->StopMovie();
			ScreenChange( wParam-ID_SUBMENU+1 ,TRUE);
			for(i=0;i<DispFreqMax;i++){
				EnableMenuItem( sysInf.hMenu, ID_SUBMENU+i,  MF_ENABLED  );
				CheckMenuItem( sysInf.hMenu, ID_SUBMENU+i,   MF_UNCHECKED );
			}
			EnableMenuItem( sysInf.hMenu, LOWORD(wParam),  MF_GRAYED  );
			CheckMenuItem( sysInf.hMenu, LOWORD(wParam),   MF_CHECKED );
			EnableMenuItem( sysInf.hMenu, ID_DISPWINDOW, MF_ENABLED );
			CheckMenuItem( sysInf.hMenu, ID_DISPWINDOW,  MF_UNCHECKED );
			break;
		  case ID_AUTOREAD:
			sysInf.bAutoRead = !sysInf.bAutoRead;
			if(sysInf.bAutoRead){
				CheckMenuItem( sysInf.hMenu, ID_AUTOREAD,   MF_CHECKED );
			}else{
				CheckMenuItem( sysInf.hMenu, ID_AUTOREAD,   MF_UNCHECKED );
			}
			break;
		  case ID_READSKIP:
			sysInf.bReadSkip = !sysInf.bReadSkip;
			if(sysInf.bReadSkip){
				CheckMenuItem( sysInf.hMenu, ID_READSKIP,   MF_CHECKED );
				sysInf.bAlreadyRead = AVG_CheckScenarioFlag();
			}else{
				CheckMenuItem( sysInf.hMenu, ID_READSKIP,   MF_UNCHECKED );
			}
			break;
		  case ID_UPDATE:
			ShellExecute( sysInf.hWnd, NULL, "http://leaf.aquaplus.co.jp", NULL, NULL, SW_SHOWNORMAL );
			break;
		  case ID_VER:
			DialogBox( sysInf.hInstance, MAKEINTRESOURCE(IDD_ABOUTDIALOG), sysInf.hWnd, AboutDialogBoxProc );
			break;
		  case ID_CONFIG:
			DialogBox( sysInf.hInstance, MAKEINTRESOURCE(IDD_CONFIGDIALOG), sysInf.hWnd, ConfDialogBoxProc );
			break;
		  case ID_LOADEXEC:
			if(lpMovie)break;
			if(NULL==EXEC_LangBuf){
				EXEC_LangBuf  = (char *)&LangData.LangBuf;
				EXEC_LangInfo = &LangData;
			}
			if(NULL==saveWnd)saveWnd = new SaveWnd(load_mode);
			break;
		  case ID_SAVEEXEC:
			if(lpMovie || NULL==EXEC_LangBuf)break;
			if(NULL==saveWnd)saveWnd = new SaveWnd(save_mode);
			break;
		  case ID_BACKTITLE:
			selectWnd.selectEnd();
			ESC_InitEOprFlag();
			lpSoundDS->ChangeMusic(bgmHandle,pack_bgmfile,2,FALSE,0);
			my_delete(lpMenuWnd);
			my_delete(lpKabeSetWnd);
			my_delete(lpStaffmodeWnd);
			my_delete(lpStaffRoll);
			my_delete(lpMovie);
			lpMovie = new CMovie;
			lpMovie->OpenMovie("title.avi",-1,TRUE);
			break;
		}
		break;
	case WM_SYSCOMMAND:
		if(sysInf.full_screen){
			switch (wParam) {
				case SC_KEYMENU :
					return 0;
			}
		}
		break;
	case WM_DISPLAYCHANGE:
		if(!sysInf.bDisplayChange)break;
		SetTimer(sysInf.hWnd,1,500,NULL);
		break;
	case WM_TIMER:
		if(!sysInf.bDisplayChange || 1!=wParam)break;
		KillTimer(sysInf.hWnd,1);
		if(0==sysInf.full_screen){
			MoveWindow(sysInf.hWnd,
				(GetSystemMetrics(SM_CXSCREEN)-sysInf.ScreenW)/2,(GetSystemMetrics(SM_CYSCREEN)-sysInf.ScreenH)/2,
				sysInf.ScreenW +GetSystemMetrics(SM_CXDLGFRAME)*2,
				sysInf.ScreenH +GetSystemMetrics(SM_CYDLGFRAME)*2 +GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYSIZE) +GetSystemMetrics(SM_CYMENU),
				TRUE);
		}else{
			MoveWindow(sysInf.hWnd,
				0, 0, sysInf.ScreenW, sysInf.ScreenH, TRUE);
			if(NULL==sysInf.hMenuWnd){
				sysInf.hMenuWnd = CreateWindow(className,"menuWnd",WS_POPUP,
					0,0,
					WIN_SIZEX,GetSystemMetrics(SM_CYMENUSIZE),sysInf.hWnd,sysInf.hMenu,sysInf.hInstance,NULL);
			}
		}
		sysInf.bDisplayChange = FALSE;
		break;
	case WM_PAINT:
		if(lpMovie)break;
		BeginPaint( sysInf.hWnd, &ps );
		BitBlt( ps.hdc, 0, 0, WIN_SIZEX, WIN_SIZEY, g_DibInf.memDC, 0, 0, SRCCOPY );
		EndPaint( sysInf.hWnd, &ps );
		break;
	case WM_SETCURSOR:
	default:
		break;
    }
	return DefWindowProc(hWnd, message, wParam, lParam);

} // MainWndProc
示例#27
0
void debugview_info::draw_contents(HDC windc)
{
	debug_view_char const *viewdata = m_view->viewdata();
	debug_view_xy const visarea = m_view->visible_size();

	// get the client rect
	RECT client;
	GetClientRect(m_wnd, &client);

	// create a compatible DC and an offscreen bitmap
	HDC const dc = CreateCompatibleDC(windc);
	if (dc == NULL)
		return;
	HBITMAP const bitmap = CreateCompatibleBitmap(windc, client.right, client.bottom);
	if (bitmap == NULL)
	{
		DeleteDC(dc);
		return;
	}
	HGDIOBJ const oldbitmap = SelectObject(dc, bitmap);

	// set the font
	HGDIOBJ const oldfont = SelectObject(dc, metrics().debug_font());
	COLORREF const oldfgcolor = GetTextColor(dc);
	int const oldbkmode = GetBkMode(dc);
	SetBkMode(dc, TRANSPARENT);

	// iterate over rows and columns
	for (UINT32 row = 0; row < visarea.y; row++)
	{
		// loop twice; once to fill the background and once to draw the text
		for (int iter = 0; iter < 2; iter++)
		{
			COLORREF fgcolor;
			COLORREF bgcolor = RGB(0xff,0xff,0xff);
			HBRUSH bgbrush = NULL;
			int last_attrib = -1;
			TCHAR buffer[256];
			int count = 0;
			RECT bounds;

			// initialize the text bounds
			bounds.left = bounds.right = 0;
			bounds.top = row * metrics().debug_font_height();
			bounds.bottom = bounds.top + metrics().debug_font_height();

			// start with a brush on iteration #0
			if (iter == 0)
				bgbrush = CreateSolidBrush(bgcolor);

			// iterate over columns
			for (UINT32 col = 0; col < visarea.x; col++)
			{
				// if the attribute changed, adjust the colors
				if (viewdata[col].attrib != last_attrib)
				{
					COLORREF oldbg = bgcolor;

					// reset to standard colors
					fgcolor = RGB(0x00,0x00,0x00);
					bgcolor = RGB(0xff,0xff,0xff);

					// pick new fg/bg colors
					if (viewdata[col].attrib & DCA_VISITED) bgcolor = RGB(0xc6, 0xe2, 0xff);
					if (viewdata[col].attrib & DCA_ANCILLARY) bgcolor = RGB(0xe0,0xe0,0xe0);
					if (viewdata[col].attrib & DCA_SELECTED) bgcolor = RGB(0xff,0x80,0x80);
					if (viewdata[col].attrib & DCA_CURRENT) bgcolor = RGB(0xff,0xff,0x00);
					if ((viewdata[col].attrib & DCA_SELECTED) && (viewdata[col].attrib & DCA_CURRENT)) bgcolor = RGB(0xff,0xc0,0x80);
					if (viewdata[col].attrib & DCA_CHANGED) fgcolor = RGB(0xff,0x00,0x00);
					if (viewdata[col].attrib & DCA_INVALID) fgcolor = RGB(0x00,0x00,0xff);
					if (viewdata[col].attrib & DCA_DISABLED) fgcolor = RGB((GetRValue(fgcolor) + GetRValue(bgcolor)) / 2, (GetGValue(fgcolor) + GetGValue(bgcolor)) / 2, (GetBValue(fgcolor) + GetBValue(bgcolor)) / 2);
					if (viewdata[col].attrib & DCA_COMMENT) fgcolor = RGB(0x00,0x80,0x00);

					// flush any pending drawing
					if (count > 0)
					{
						bounds.right = bounds.left + (count * metrics().debug_font_width());
						if (iter == 0)
							FillRect(dc, &bounds, bgbrush);
						else
							ExtTextOut(dc, bounds.left, bounds.top, 0, NULL, buffer, count, NULL);
						bounds.left = bounds.right;
						count = 0;
					}

					// set the new colors
					if (iter == 0 && oldbg != bgcolor)
					{
						DeleteObject(bgbrush);
						bgbrush = CreateSolidBrush(bgcolor);
					}
					else if (iter == 1)
						SetTextColor(dc, fgcolor);
					last_attrib = viewdata[col].attrib;
				}

				// add this character to the buffer
				buffer[count++] = viewdata[col].byte;
			}

			// flush any remaining stuff
			if (count > 0)
			{
				bounds.right = bounds.left + (count * metrics().debug_font_width());
				if (iter == 0)
					FillRect(dc, &bounds, bgbrush);
				else
					ExtTextOut(dc, bounds.left, bounds.top, 0, NULL, buffer, count, NULL);
			}

			// erase to the end of the line
			if (iter == 0)
			{
				bounds.left = bounds.right;
				bounds.right = client.right;
				FillRect(dc, &bounds, bgbrush);
				DeleteObject(bgbrush);
			}
		}

		// advance viewdata
		viewdata += visarea.x;
	}

	// erase anything beyond the bottom with white
	GetClientRect(m_wnd, &client);
	client.top = visarea.y * metrics().debug_font_height();
	FillRect(dc, &client, (HBRUSH)GetStockObject(WHITE_BRUSH));

	// reset the font
	SetBkMode(dc, oldbkmode);
	SetTextColor(dc, oldfgcolor);
	SelectObject(dc, oldfont);

	// blit the final results
	BitBlt(windc, 0, 0, client.right, client.bottom, dc, 0, 0, SRCCOPY);

	// undo the offscreen stuff
	SelectObject(dc, oldbitmap);
	DeleteObject(bitmap);
	DeleteDC(dc);
}
示例#28
0
/*********************************************************************\
*                                                                     *
*  BOOL DoAlphaBlend()                                                *
*                                                                     *
*  Purpose:                                                           *
*      Captures a copy of the source and destination areas and        *
*      alpha blends them into a memory surface that it displays       *
*      into the destination area.                                     *     *                                                                     *
*  Notes:                                                             *
*      Takes the same parameters as the AlphaBlend function except    *
*      that the last parameter is a source weighting value rather     *
*      than a BLENDFUNCTION structure.                                *
*                                                                     *
\*********************************************************************/
BOOL DoAlphaBlend_internal(
  HDC hdcDest,                 // Handle to destination DC.
  int nXOriginDest,            // X-coord of upper-left corner.
  int nYOriginDest,            // Y-coord of upper-left corner.
  int nWidthDest,              // Destination width.
  int nHeightDest,             // Destination height.
  HDC hdcSrc,                  // Handle to source DC.
  int nXOriginSrc,             // X-coord of upper-left corner.
  int nYOriginSrc,             // Y-coord of upper-left corner.
  int nWidthSrc,               // Source width.
  int nHeightSrc,              // Source height.
  DWORD dwSourceWeight)        // Source weighting (between 0 and 255).
{
    if(pfnSetStretchBltMode) {
#ifdef PNA
        pfnSetStretchBltMode = (pfnSetStretchBltMode_t) GetProcAddress(GetModuleHandle(TEXT("coredll.dll")), TEXT("SetStretchBltMode"));
#else
        pfnSetStretchBltMode = SetStretchBltMode;
#endif
    }



    HDC      hdcSrc1 = NULL;
    HDC      hdcSrc2 = NULL;
    HDC      hdcDst  = NULL;
    HBITMAP  hbmSrc1 = NULL;
    HBITMAP  hbmSrc2 = NULL;
    HBITMAP  hbmDst  = NULL;
    BOOL     bReturn;

    // Create surfaces for sources and destination images.
    hbmSrc1 = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest);
    if (!hbmSrc1) goto HANDLEERROR;

    hbmSrc2 = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest);
    if (!hbmSrc2) goto HANDLEERROR;

    hbmDst  = Create24BPPDIBSection(hdcDest, nWidthDest,nHeightDest);
    if (!hbmDst) goto HANDLEERROR;


    // Create HDCs to hold our surfaces.
    hdcSrc1 = CreateCompatibleDC(hdcDest);
    if (!hdcSrc1) goto HANDLEERROR;

    hdcSrc2 = CreateCompatibleDC(hdcDest);
    if (!hdcSrc2) goto HANDLEERROR;

    hdcDst  = CreateCompatibleDC(hdcDest);
    if (!hdcDst) goto HANDLEERROR;


    // Prepare the surfaces for drawing.
    SelectObject(hdcSrc1, hbmSrc1);
    SelectObject(hdcSrc2, hbmSrc2);
    SelectObject(hdcDst,  hbmDst);

    if(pfnSetStretchBltMode) {
        pfnSetStretchBltMode(hdcSrc1, COLORONCOLOR);
        pfnSetStretchBltMode(hdcSrc2, COLORONCOLOR);
    }

    // Capture a copy of the source area.
    if (!StretchBlt(hdcSrc1, 0,0,nWidthDest,nHeightDest,
                    hdcSrc,  nXOriginSrc, nYOriginSrc, nWidthSrc, nHeightSrc,
                    SRCCOPY))
         goto HANDLEERROR;

    // Capture a copy of the destination area.
    if (!StretchBlt(hdcSrc2, 0,0,nWidthDest,nHeightDest,
                    hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
                    SRCCOPY))
         goto HANDLEERROR;


    // Blend the two source areas to create the destination image.
    bReturn = BlendImages(hbmSrc1, hbmSrc2, hbmDst, dwSourceWeight);


    // Clean up objects you do not need any longer.
    // You cannot delete an object that's selected into an
    // HDC so delete the HDC first.
    DeleteDC(hdcSrc1);
    DeleteDC(hdcSrc2);
    DeleteObject(hbmSrc1);
    DeleteObject(hbmSrc2);


    // Display the blended (destination) image to the target HDC.
    if (bReturn) {
        BitBlt(hdcDest, nXOriginDest, nYOriginDest, nWidthDest, nHeightDest,
               hdcDst, 0,0, SRCCOPY);
    }


    // Clean up the rest of the objects you created.
    DeleteDC(hdcDst);
    DeleteObject(hbmDst);

    return bReturn;

HANDLEERROR:

    if (hdcSrc1) DeleteDC(hdcSrc1);
    if (hdcSrc2) DeleteDC(hdcSrc2);
    if (hdcDst)  DeleteDC(hdcDst);
    if (hbmSrc1) DeleteObject(hbmSrc1);
    if (hbmSrc2) DeleteObject(hbmSrc2);
    if (hbmDst)  DeleteObject(hbmDst);

    return FALSE;
}
示例#29
0
void draw_button( int button_id, DRAWITEMSTRUCT FAR * draw )
{
    HBITMAP     bmp;
    HBITMAP oldbmp;
    HPEN blackpen, shadowpen, brightpen, facepen;
    HPEN oldpen;
    BITMAP      bitmap;
    HDC memdc;
    HINSTANCE inst;
    int shift;

    inst = GET_HINSTANCE( draw->hwndItem );
    bmp = LoadBitmap( inst, MAKEINTRESOURCE( button_id ) );
    if( !bmp ) return;
    GetObject( bmp, sizeof(BITMAP), &bitmap );
    memdc = CreateCompatibleDC( draw->hDC );
    oldbmp = SelectObject( memdc, bmp );
    if( draw->itemState & ODS_SELECTED ) {
        shift = 4;
    } else {
        shift = 2;
    }
    BitBlt( draw->hDC, draw->rcItem.left + shift, draw->rcItem.top + shift,
            bitmap.bmWidth, bitmap.bmHeight, memdc, 0, 0, SRCCOPY );
    SelectObject( memdc, oldbmp );
    DeleteDC( memdc );
    DeleteObject( bmp );
    // Draw four sides of the button except one pixel in each corner
    blackpen = CreatePen( PS_SOLID, 0, RGB(0,0,0) );
    brightpen = CreatePen( PS_SOLID, 0, RGB(255,255,255) );
    shadowpen = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNSHADOW ) );
    facepen = CreatePen( PS_SOLID, 0, GetSysColor( COLOR_BTNFACE ) );
    oldpen = SelectObject( draw->hDC, blackpen );
    horizontal( draw, draw->rcItem.top );
    horizontal( draw, draw->rcItem.bottom - 1 );
    vertical( draw, draw->rcItem.left );
    vertical( draw, draw->rcItem.right - 1 );
    // Now the shading
    SelectObject( draw->hDC, shadowpen );
    if( draw->itemState & ODS_SELECTED ) {
        horizontal( draw, draw->rcItem.top + 1 );
        vertical( draw, draw->rcItem.left + 1 );
        SelectObject( draw->hDC, facepen );
        horizontal( draw, draw->rcItem.top + 2 );
        vertical( draw, draw->rcItem.left + 2 );
        horizontal( draw, draw->rcItem.top + 3 );
        vertical( draw, draw->rcItem.left + 3 );
    } else {
        horizontal( draw, draw->rcItem.bottom - 2 );
        horizontal( draw, draw->rcItem.bottom - 3 );
        vertical( draw, draw->rcItem.right - 2 );
        vertical( draw, draw->rcItem.right - 3 );
        SelectObject( draw->hDC, brightpen );
        horizontal( draw, draw->rcItem.top + 1 );
        vertical( draw, draw->rcItem.left + 1 );
    }
    SelectObject( draw->hDC, oldpen );
    DeleteObject( blackpen );
    DeleteObject( brightpen );
    DeleteObject( shadowpen );
    DeleteObject( facepen );
}
示例#30
0
static PassRefPtr<SharedCursor> createSharedCursor(Image* img, const IntPoint& hotSpot)
{
    RefPtr<SharedCursor> impl;

    IntPoint effectiveHotSpot = determineHotSpot(img, hotSpot);
    static bool doAlpha = windowsVersion() >= WindowsXP;

//wke++++++
    BitmapInfo cursorImage = BitmapInfo::createBottomUp(IntSize(img->width(), img->height()));
    if (cursorImage.bmiHeader.biWidth == 0)
        cursorImage.bmiHeader.biWidth = 16;

    if (cursorImage.bmiHeader.biHeight == 0)
        cursorImage.bmiHeader.biHeight = -16;
//wke++++++

    HDC dc = GetDC(0);
    HDC workingDC = CreateCompatibleDC(dc);
    if (doAlpha) {
        OwnPtr<HBITMAP> hCursor = adoptPtr(CreateDIBSection(dc, (BITMAPINFO *)&cursorImage, DIB_RGB_COLORS, 0, 0, 0));
        ASSERT(hCursor);

        img->getHBITMAP(hCursor.get()); 
        HBITMAP hOldBitmap = (HBITMAP)SelectObject(workingDC, hCursor.get());
        SetBkMode(workingDC, TRANSPARENT);
        SelectObject(workingDC, hOldBitmap);

        Vector<unsigned char, 128> maskBits;
        maskBits.fill(0xff, (img->width() + 7) / 8 * img->height());
        OwnPtr<HBITMAP> hMask = adoptPtr(CreateBitmap(img->width(), img->height(), 1, 1, maskBits.data()));

        ICONINFO ii;
        ii.fIcon = FALSE;
        ii.xHotspot = effectiveHotSpot.x();
        ii.yHotspot = effectiveHotSpot.y();
        ii.hbmMask = hMask.get();
        ii.hbmColor = hCursor.get();

        impl = SharedCursor::create(CreateIconIndirect(&ii));
    } else {
        // Platform doesn't support alpha blended cursors, so we need
        // to create the mask manually
        HDC andMaskDC = CreateCompatibleDC(dc);
        HDC xorMaskDC = CreateCompatibleDC(dc);
        OwnPtr<HBITMAP> hCursor = adoptPtr(CreateDIBSection(dc, &cursorImage, DIB_RGB_COLORS, 0, 0, 0));
        ASSERT(hCursor);
        img->getHBITMAP(hCursor.get()); 
        BITMAP cursor;
        GetObject(hCursor.get(), sizeof(BITMAP), &cursor);
        OwnPtr<HBITMAP> andMask = adoptPtr(CreateBitmap(cursor.bmWidth, cursor.bmHeight, 1, 1, NULL));
        OwnPtr<HBITMAP> xorMask = adoptPtr(CreateCompatibleBitmap(dc, cursor.bmWidth, cursor.bmHeight));
        HBITMAP oldCursor = (HBITMAP)SelectObject(workingDC, hCursor.get());
        HBITMAP oldAndMask = (HBITMAP)SelectObject(andMaskDC, andMask.get());
        HBITMAP oldXorMask = (HBITMAP)SelectObject(xorMaskDC, xorMask.get());

        SetBkColor(workingDC, RGB(0,0,0));  
        BitBlt(andMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC, 0, 0, SRCCOPY);
    
        SetBkColor(xorMaskDC, RGB(255, 255, 255));
        SetTextColor(xorMaskDC, RGB(255, 255, 255));
        BitBlt(xorMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, andMaskDC, 0, 0, SRCCOPY);
        BitBlt(xorMaskDC, 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC, 0,0, SRCAND);

        SelectObject(workingDC, oldCursor);
        SelectObject(andMaskDC, oldAndMask);
        SelectObject(xorMaskDC, oldXorMask);

        ICONINFO icon = {0};
        icon.fIcon = FALSE;
        icon.xHotspot = effectiveHotSpot.x();
        icon.yHotspot = effectiveHotSpot.y();
        icon.hbmMask = andMask.get();
        icon.hbmColor = xorMask.get();
        impl = SharedCursor::create(CreateIconIndirect(&icon));

        DeleteDC(xorMaskDC);
        DeleteDC(andMaskDC);
    }
    DeleteDC(workingDC);
    ReleaseDC(0, dc);

    return impl.release();
}