Esempio n. 1
0
HRESULT PreviewGenerator::ShowPreviewWithShellItemImageFactory(CString filePath)
{
	HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
	IShellItemImageFactory *imageFactory;
	hr = SHCreateItemFromParsingName(filePath, NULL, IID_PPV_ARGS(&imageFactory));
	if (hr == S_OK)
	{
		CRect pRect;
		previewControl->GetWindowRect(pRect);

		int s = pRect.Height();
		if (s>pRect.Width())
			s = pRect.Width();
		//s = 256;
		_SIIGBF flag = SIIGBF_RESIZETOFIT;
		if (fileExt != L"pdf" && fileExt != L"PDF")
		{
			s = 256;
			flag = SIIGBF_BIGGERSIZEOK;
		}
		SIZE size = { s, s };
		
		HBITMAP btmap;
		hr = imageFactory->GetImage(size, flag, &btmap);
		if (hr == S_OK)
			DrawBitMap(btmap);
	}
	CoUninitialize();
	imageFactory->Release();
	return hr;


}
Esempio n. 2
0
int main(void)
{
    SystemInit();

    ////////////////// SPI2 - SD
    fpu_enable();
    delay_init( 168 );
    SPI_SD_Init();
    //////////////////

    RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);	  //rng
    RNG_Cmd(ENABLE); //switch on

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); //button

    InitEXTIButtonPA0();//accept
    InitEXTIButtonPA1();//up
    InitEXTIButtonPA2();//right
    InitEXTIButtonPA3();//down
    InitEXTIButtonPA4();//left

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); //timer
    ConfTim2();

    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //timer

    ConfTim3(350); //init with start_value game period
    SetSnakeSpeed(3);

    PCD8544_Init(0x38); 				//Initialize LCD with 0x38 software contrast
////////////////////////////////////////////

    DrawBitMap(SnakeBitMap);

    PCD8544_Refresh();
    WaitForAcceptButton();
    PCD8544_Clear();

    MainMenu();

    while (1)
	{

	}
}
Esempio n. 3
0
HRESULT PreviewGenerator::ShowPreviewWithThumbnailProvider(IStream *stream, CLSID cls)
{
	IThumbnailProvider *iTP;
	IInitializeWithStream	*iIStream;

	HRESULT hr = CoCreateInstance(cls, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IThumbnailProvider, (LPVOID*)&iTP);
	if (hr == S_OK)
	{
		hr = iTP->QueryInterface(IID_IInitializeWithStream, (LPVOID*)&iIStream);
		IInitializeWithFile *pInitFile;
		hr = iTP->QueryInterface(IID_IInitializeWithFile, (void**)&pInitFile);
		if (hr != S_OK)
			return hr;
		if (iIStream)
		{
			hr = iIStream->Initialize(stream, STGM_READ);
			HBITMAP bmp;
			WTS_ALPHATYPE type;
			CRect pRect;
			previewControl->GetWindowRect(pRect);
			int size = pRect.Width();
			if (pRect.Height()<pRect.Width())
				size = pRect.Height();

			hr = iTP->GetThumbnail(size, &bmp, &type);
			if (hr == S_OK)
			{
				DrawBitMap(bmp);
			}
			else
				return hr;
		}
		else
			return E_FAIL;
	}
	else
		return hr;
	return S_OK;
}
Esempio n. 4
0
void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
    
    *pResult = 0;
	
    // Request item-specific notifications if this is the
    // beginning of the paint cycle.
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        *pResult = CDRF_NOTIFYITEMDRAW;
	}
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        LVITEM   rItem;
        int      nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
        CDC*     pDC   = CDC::FromHandle ( pLVCD->nmcd.hdc );
        COLORREF crBkgnd;
        BOOL     bListHasFocus;
        CRect    rcItem;
		
        bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
        
        // Get the image index and selected/focused state of the
        // item being drawn.
        ZeroMemory ( &rItem, sizeof(LVITEM) );
        rItem.mask  = LVIF_STATE;
        rItem.iItem = nItem;
        rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
        GetItem(&rItem);
		
        // Get the rect that bounds the text label.
        GetItemRect(nItem, rcItem, LVIR_LABEL);
		rcItem.left -= DUMMY_COL_WIDTH;
		
		COLORREF OldColor = -1;
		int nOldBKMode = -1;

		CString csText;
		LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
		GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
		csText.ReleaseBuffer();

		// extract symbols
		CString strSymbols;
		int nSymEnd = csText.Find('|');
		if (nSymEnd >= 0)
		{
			strSymbols = csText.Left(nSymEnd);
			csText = csText.Mid(nSymEnd + 1);
		}
		
		// Draw the background of the list item.  Colors are selected 
		// according to the item's state.
		if(rItem.state & LVIS_SELECTED)
		{
            if(bListHasFocus)
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
			}
            else
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
			}
		}
        else
		{
            //Shade alternating Rows
			if((nItem % 2) == 0)
			{
				crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
			}
			else
			{
				crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
			}
		}
		
        pDC->FillSolidRect(rcItem, crBkgnd);
        nOldBKMode = pDC->SetBkMode(TRANSPARENT);
		
        CRect rcText = rcItem;
        rcText.left += ROW_LEFT_BORDER;
		rcText.top++;
		
		if (m_showIfClipWasPasted &&
			strSymbols.GetLength() > 0 &&
			strSymbols.Find(_T("<pasted>")) >= 0) //clip was pasted from ditto 
		{
			CRect pastedRect(rcItem);
			pastedRect.left++;
			pastedRect.right = rcItem.left + theApp.m_metrics.ScaleX(3);
				
			pDC->FillSolidRect(pastedRect, g_Opt.m_Theme.ClipPastedColor());

			rcText.left += theApp.m_metrics.ScaleX(4);
		}
		        		
		// set firstTenNum to the first ten number (1-10) corresponding to
		//  the current nItem.
		// -1 means that nItem is not in the FirstTen block.
		int firstTenNum = GetFirstTenNum(nItem);
		
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			rcText.left += theApp.m_metrics.ScaleX(12);
		}
		
		bool drawInGroupIcon = true;
		// if we are inside a group, don't display the "in group" flag
		if( theApp.m_GroupID > 0 )
		{
			int nFlag = strSymbols.Find(_T("<ingroup>"));
			if (nFlag >= 0)
				drawInGroupIcon = false;
		}
		
		DrawBitMap(nItem, rcText, pDC, csText);			

		// draw the symbol box
		if( strSymbols.GetLength() > 0 )
		{
			if(strSymbols.Find(_T("<group>")) >= 0) //group 
			{
				m_groupFolder.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_groupFolder.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (strSymbols.Find(_T("<noautodelete>")) >= 0 &&
				strSymbols.Find(_T("<group>")) < 0 &&
				strSymbols.Find(_T("<sticky>")) < 0) //don't auto delete
			{
				m_dontDeleteImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_dontDeleteImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (strSymbols.Find(_T("<shortcut>")) >= 0) // has shortcut
			{
				m_shortCutImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_shortCutImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (drawInGroupIcon &&
				strSymbols.Find(_T("<ingroup>")) >= 0) // in group
			{
				m_inFolderImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_inFolderImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}
			if (strSymbols.Find(_T("<qpastetext>")) >= 0) // has quick paste text
			{
			}
			if (strSymbols.Find(_T("<sticky>")) >= 0) //sticky clip
			{
				m_stickyImage.Draw(pDC, this, rcText.left, rcText.top, false, false);
				rcText.left += m_stickyImage.ImageWidth() + theApp.m_metrics.ScaleX(2);
			}			
		}
		
		if(DrawRtfText(nItem, rcText, pDC) == FALSE)
		{
			if (m_searchText.GetLength() > 0 &&
				FindNoCaseAndInsert(csText, m_searchText, _T("<font color='#ff0000'>"), _T("</font>")) > 0)
			{				
				DrawHTML(pDC->m_hDC, csText, csText.GetLength(), rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
			}
			else
			{
				pDC->DrawText(csText, rcText, DT_VCENTER | DT_EXPANDTABS | DT_NOPREFIX);
			}
		}
		
        // Draw a focus rect around the item if necessary.
        if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
			pDC->DrawFocusRect(rcItem);
						
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			CString cs;
			if( firstTenNum == 10 )
				cs = "0";
			else
				cs.Format(_T("%d"), firstTenNum);
			
			CRect crClient;
			
			GetWindowRect(crClient);
			ScreenToClient(crClient);
			
			CRect crHotKey = rcItem;

			int extraFromClipWasPaste = 0;
			if (m_showIfClipWasPasted)
				extraFromClipWasPaste = 3;
			
			crHotKey.right = crHotKey.left + theApp.m_metrics.ScaleX(11);
			crHotKey.left += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
			crHotKey.top += theApp.m_metrics.ScaleX(1 + extraFromClipWasPaste);
			
			HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
			
			pDC->DrawText(cs, crHotKey, DT_BOTTOM);
			
			pDC->MoveTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.top));
			pDC->LineTo(CPoint(rcItem.left + theApp.m_metrics.ScaleX(8 + extraFromClipWasPaste), rcItem.bottom));
			
			pDC->SelectObject(hOldFont);
		}
		
		// restore the previous values		
		if(OldColor > -1)
			pDC->SetTextColor(OldColor);
		
		if(nOldBKMode > -1)
			pDC->SetBkMode(nOldBKMode);
		
        *pResult = CDRF_SKIPDEFAULT;    // We've painted everything.
	}
}
Esempio n. 5
0
int
main(void)
{
  Stream *graph_id;
  int fnrc;
  word i;
  LOGPALETTE *pal;
  word colors[PERMS];
  
  /* initialise the graphics system, without any event handlers */
  
  if (!InitGraphics(NULL, NULL)) {
      fprintf(stderr,"Unable to find graphics server\n\n");
      exit(EXIT_FAILURE);
    }
  
  /* open the window in its maximum form with resizable border and */
  /* do not give the window the input focus.                       */
  
  graph_id = OpenGraph("Test", 200, 200, 64, 64, 
		       WS_OVERLAPPEDWINDOW, SW_SHOWNA);
  
  if (graph_id == (Stream *) NULL) {
      TidyGraphics();
      fprintf(stderr, "Unable to open window\n\n");
      exit(EXIT_FAILURE);
    }
  
  /* set up the values which will be used to generate the palette */
  /* create a palette with enough space */
  pal = CreatePalette(PERMS);
  
  
  for (i=0; i<PERMS; i++) {
      /* either set up the same RGB values in colors : */
      colors[i] = PALETTERGB(i, i, i);
      
      /* set up the user defined palette */
      pal->pal[i].red   = (int)i;
      pal->pal[i].green = (int)i;
      pal->pal[i].blue  = (int)i;
      pal->pal[i].flags = 0;    /* setting this to zero will generally be */
      /* sufficient                             */
      
    }
  
  
  /* enable the use of the palette */
  fnrc = SelectPalette(graph_id, pal);
  
    {
      BITMAP *bmp;
      char map[256*4];
      int k,l;
      
      bmp = CreateDIBitMap(graph_id,16,16);
      
      for (l = 0; l < 4; l++)
	for (k = 0; k < 256; k++)
	  map[l*256 + k] = 0xff ;
      
      for (l = 0; l < 256; l++)
	{
	  for (k = 0; k < 256; k++)
	    {
	      map[k*4]   = 0x00;
	      map[k*4+1] = l;
	      map[k*4+2] = l;
	      map[k*4+3] = l;
	    }
	  SetBitMapBits(bmp,map);
	  DrawBitMap(graph_id,bmp,0,0,SRCCOPY);
	  (void) getchar();
	}
    }
  
  TidyGraphics();
  
  return(0);
}
Esempio n. 6
0
void CQListCtrl::OnCustomdrawList(NMHDR* pNMHDR, LRESULT* pResult)
{
	NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );
    
    *pResult = 0;
	
    // Request item-specific notifications if this is the
    // beginning of the paint cycle.
    if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        *pResult = CDRF_NOTIFYITEMDRAW;
	}
    else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
	{
        LVITEM   rItem;
        int      nItem = static_cast<int>( pLVCD->nmcd.dwItemSpec );
        CDC*     pDC   = CDC::FromHandle ( pLVCD->nmcd.hdc );
        COLORREF crBkgnd;
        BOOL     bListHasFocus;
        CRect    rcItem;
		
        bListHasFocus = ( GetSafeHwnd() == ::GetFocus() );
        
        // Get the image index and selected/focused state of the
        // item being drawn.
        ZeroMemory ( &rItem, sizeof(LVITEM) );
        rItem.mask  = LVIF_STATE;
        rItem.iItem = nItem;
        rItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
        GetItem(&rItem);
		
        // Get the rect that bounds the text label.
        GetItemRect(nItem, rcItem, LVIR_LABEL);
		rcItem.left -= DUMMY_COL_WIDTH;
		
		COLORREF OldColor = -1;
		int nOldBKMode = -1;
		
		// Draw the background of the list item.  Colors are selected 
		// according to the item's state.
		if(rItem.state & LVIS_SELECTED)
		{
            if(bListHasFocus)
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedText());
			}
            else
			{
                crBkgnd = g_Opt.m_Theme.ListBoxSelectedNoFocusBG();
                OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxSelectedNoFocusText());
			}
		}
        else
		{
            //Shade alternating Rows
			if((nItem % 2) == 0)
			{
				crBkgnd = g_Opt.m_Theme.ListBoxOddRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxOddRowsText());
			}
			else
			{
				crBkgnd = g_Opt.m_Theme.ListBoxEvenRowsBG();
				OldColor = pDC->SetTextColor(g_Opt.m_Theme.ListBoxEvenRowsText());
			}
		}
		
        pDC->FillSolidRect(rcItem, crBkgnd);
        nOldBKMode = pDC->SetBkMode(TRANSPARENT);
		
        CRect rcText = rcItem;
        rcText.left += ROW_LEFT_BORDER;
		rcText.top++;
		
        // Draw the text.
        //CString csText = GetItemText(nItem, 0);
		
		CString csText;
		LPTSTR lpszText = csText.GetBufferSetLength(g_Opt.m_bDescTextSize);
		GetItemText(nItem, 0, lpszText, g_Opt.m_bDescTextSize);
		csText.ReleaseBuffer();
		
		// extract symbols
		CString strSymbols;
		int nSymEnd = csText.Find('|');
		if( nSymEnd >= 0 )
		{
			strSymbols = csText.Left(nSymEnd);  
			csText = csText.Mid(nSymEnd+1);
		}
		
		// set firstTenNum to the first ten number (1-10) corresponding to
		//  the current nItem.
		// -1 means that nItem is not in the FirstTen block.
		int firstTenNum = GetFirstTenNum(nItem);
		
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			rcText.left += 12;
		}
		
		// if we are inside a group, don't display the "in group" flag
		if( theApp.m_GroupID > 0 )
		{
			int nFlag = strSymbols.Find(_T("!"));
			if( nFlag >= 0 )
				strSymbols.Delete(nFlag);
		}
		
		DrawBitMap(nItem, rcText, pDC, csText);

		// draw the symbol box
		if( strSymbols.GetLength() > 0 )
		{
			strSymbols = " " + strSymbols + " "; // leave space for box
			// add spaces to leave room for the symbols
			CRect rectSym(rcText.left, rcText.top+1, rcText.left, rcText.top+1);
			CRect rectSpace(0,0,0,0);
			//Get text bounds
			pDC->DrawText(" ", &rectSpace, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
			pDC->DrawText(strSymbols, &rectSym, DT_VCENTER | DT_EXPANDTABS | DT_CALCRECT);
			VERIFY( rectSpace.Width() > 0 );
			
//			int numSpaces = rectSym.Width() / rectSpace.Width();
//			numSpaces++;
//			csText = CString(' ',numSpaces) + csText;
			
			// draw the symbols
			pDC->FillSolidRect( rectSym, GetSysColor(COLOR_ACTIVECAPTION) );
			//pDC->FillSolidRect( rectSym, RGB(0,255,255) );
			pDC->Draw3dRect(rectSym, GetSysColor(COLOR_3DLIGHT), GetSysColor(COLOR_3DDKSHADOW));
			//		COLORREF crOld = pDC->SetTextColor(GetSysColor(COLOR_INFOTEXT));
			COLORREF crOld = pDC->SetTextColor(RGB(255, 255, 255));
			pDC->DrawText(strSymbols, rectSym, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
			pDC->SetTextColor(crOld);

			rcText.left += rectSym.Width() + 2;
		}
		
		if(DrawRtfText(nItem, rcText, pDC) == FALSE)
		{
			pDC->DrawText(csText, rcText, DT_VCENTER|DT_EXPANDTABS|DT_NOPREFIX);
		}
		
        // Draw a focus rect around the item if necessary.
        if(bListHasFocus && (rItem.state & LVIS_FOCUSED))
			pDC->DrawFocusRect(rcItem);
		
		if( m_bShowTextForFirstTenHotKeys && firstTenNum > 0 )
		{
			CString cs;
			if( firstTenNum == 10 )
				cs = "0";
			else
				cs.Format(_T("%d"), firstTenNum);
			
			CRect crClient;
			
			GetWindowRect(crClient);
			ScreenToClient(crClient);
			
			CRect crHotKey = rcItem;
			
			crHotKey.right = crHotKey.left + 11;
			crHotKey.left += 2;
			crHotKey.top += 2;
			
			HFONT hOldFont = (HFONT)pDC->SelectObject(m_SmallFont);
			
			pDC->DrawText(cs, crHotKey, DT_BOTTOM);
			
			pDC->MoveTo(CPoint(rcItem.left + 11, rcItem.top));
			pDC->LineTo(CPoint(rcItem.left + 11, rcItem.bottom));
			
			pDC->SelectObject(hOldFont);
		}
		
		// restore the previous values		
		if(OldColor > -1)
			pDC->SetTextColor(OldColor);
		
		if(nOldBKMode > -1)
			pDC->SetBkMode(nOldBKMode);
		
        *pResult = CDRF_SKIPDEFAULT;    // We've painted everything.
	}
}