Exemple #1
0
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
{
  MSG      msg;

  Globals.lpszIniFile         = "progman.ini";
  Globals.lpszIcoFile         = "progman.ico";

  Globals.hInstance           = hInstance;
  Globals.hGroups             = 0;
  Globals.hActiveGroup        = 0;

  /* Read Options from `progman.ini' */
  Globals.bAutoArrange =
    GetPrivateProfileInt("Settings", "AutoArrange", 0, Globals.lpszIniFile);
  Globals.bMinOnRun =
    GetPrivateProfileInt("Settings", "MinOnRun", 0, Globals.lpszIniFile);
  Globals.bSaveSettings =
    GetPrivateProfileInt("Settings", "SaveSettings", 0, Globals.lpszIniFile);

  /* Load default icons */
  Globals.hMainIcon    = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
  Globals.hGroupIcon   = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
  Globals.hDefaultIcon = ExtractIcon(Globals.hInstance, Globals.lpszIcoFile, 0);
  if (!Globals.hMainIcon)    Globals.hMainIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
  if (!Globals.hGroupIcon)   Globals.hGroupIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));
  if (!Globals.hDefaultIcon) Globals.hDefaultIcon = LoadIcon(0, MAKEINTRESOURCE(DEFAULTICON));

  /* Register classes */
  if (!prev)
    {
      if (!MAIN_RegisterMainWinClass()) return(FALSE);
      if (!GROUP_RegisterGroupWinClass()) return(FALSE);
      if (!PROGRAM_RegisterProgramWinClass()) return(FALSE);
    }

  /* Create main window */
  MAIN_CreateMainWindow();
  Globals.hAccel = LoadAccelerators(Globals.hInstance, STRING_ACCEL);

  /* Setup menu, stringtable and resourcenames */
  STRING_LoadMenus();

  MAIN_CreateMDIWindow();

  /* Initialize groups */
  MAIN_CreateGroups();

  /* Start initial applications */
  MAIN_AutoStart();

  /* Message loop */
  while (GetMessage (&msg, 0, 0, 0))
    if (!TranslateAccelerator(Globals.hMainWnd, Globals.hAccel, &msg))
      {
	TranslateMessage (&msg);
	DispatchMessage (&msg);
      }
  return 0;
}
Exemple #2
0
BOOL CWorldsDlg::OnInitDialogBar() 
{
	CMRCSizeDialogBar::OnInitDialogBar();
	
	// TODO: Add extra initialization here
	char szSysPath[MAX_PATH];
	char szIconDLL[MAX_PATH];

	GetSystemDirectory(szSysPath,MAX_PATH);
	sprintf(szIconDLL,"%s\\shell32.dll",szSysPath);

	if (m_pIconList)
	{
		delete m_pIconList;
	}
	if (m_pIconList2)
	{
		delete m_pIconList2;
	}
	m_pIconList=new CImageList;
	m_pIconList2=new CImageList;

	//tree control image list
	m_pIconList->Create(16,16,ILC_COLOR16,10,5);
	m_pIconList->SetBkColor(RGB(255,255,255));
	m_pIconList->Add(ExtractIcon(AfxGetInstanceHandle(),szIconDLL,3));	//closed folder
	m_pIconList->Add(ExtractIcon(AfxGetInstanceHandle(),szIconDLL,4));	//open folder
	m_WorldTree.SetImageList(m_pIconList,TVSIL_NORMAL);

	//list control image list
	m_pIconList2->Create(16,16,ILC_COLOR4,10,5);
	m_pIconList2->SetBkColor(RGB(255,255,255));
	m_pIconList2->Add(AfxGetApp()->LoadIcon(IDI_WORLDS_TAB_ICON));
	m_WorldList.SetImageList(m_pIconList2,LVSIL_SMALL);
	
	CRect rect;
	m_WorldList.GetClientRect( &rect );

	// Clear the world list
	m_WorldList.DeleteAllItems();

	while (m_WorldList.DeleteColumn(0))
	{
	}
	
	m_WorldList.InsertColumn(0,"Name",LVCFMT_LEFT,(rect.Width()-35)/3,-1);
	m_WorldList.InsertColumn(1,"Size",LVCFMT_RIGHT,(rect.Width()-35)/3,-1);
	m_WorldList.InsertColumn(2,"Modified",LVCFMT_LEFT,(rect.Width()-35)/3,-1);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
/*
 * Parse a filename to extract an icon:
 *  If fname is exactly ",nnn" then extract icon from our resource
 *  else if it is "file,nnn" then extract icon nnn from that file
 *  else try to load it as an .ico file and if that fails return NULL
 */
static HICON
LoadImageComma (char *fname, int sx, int sy, int flags)
{
  HICON  hicon;
  int    index;
  char   file[PATH_MAX+NAME_MAX+2];

  /* Some input error checking */
  if (!fname || !fname[0])
    return NULL;

  index = 0;
  hicon = NULL;

  if (fname[0]==',')
    {
      /* It's the XWIN.EXE resource they want */
      index = atoi (fname+1);
      hicon = LoadImage (g_hInstance,
                        MAKEINTRESOURCE(index),
                        IMAGE_ICON,
                        sx,
                        sy,
                        flags);
    }
  else
    {
      file[0] = 0;
      /* Prepend path if not given a "X:\" filename */
      if ( !(fname[0] && fname[1]==':' && fname[2]=='\\') )
        {
         strcpy (file, pref.iconDirectory);
         if (pref.iconDirectory[0])
           if (fname[strlen(fname)-1]!='\\')
             strcat (file, "\\");
        }
      strcat (file, fname);

      if (strrchr (file, ','))
       {
         /* Specified as <fname>,<index> */

         *(strrchr (file, ',')) = 0; /* End string at comma */
         index = atoi (strrchr (fname, ',') + 1);
         hicon = ExtractIcon (g_hInstance, file, index);
       }
      else
       {
         /* Just an .ico file... */

         hicon = (HICON)LoadImage (NULL,
                                   file,
                                   IMAGE_ICON,
                                   sx,
                                   sy,
                                   LR_LOADFROMFILE|flags);
       }
    }
  return hicon;
}
Exemple #4
0
HICON	CreateIconFromTemplate  ( char far *  def, int  size )
   {

/***  PASSAGE EN COMMENTAIRE : CREATION DE L'ICONE A PARTIR DE LA CHAINE EN
      MEMOIRE (DEF).

	char far *	entry		=  def + sizeof ( ICONHEADER ) ;
	int		Width,
			Height,
			ColorCount,
			Planes ;
	long int	Offset,
			Size ;
	char far *	XORBits,
		 *	ANDBits ;


// Récupération des paramètres
	Width 		=  ( ( ICONENTRY * ) entry ) -> Width ;
	Height 		=  ( ( ICONENTRY * ) entry ) -> Height ;
	ColorCount	=  ( ( ICONENTRY * ) entry ) -> ColorCount ;
	Size		=  ( ( ICONENTRY * ) entry ) -> Size ;
	Offset		=  ( ( ICONENTRY * ) entry ) -> Offset ;

	switch ( ColorCount )
	   {
		case	2 : Planes = 1 ; break ;
		case    4 : Planes = 2 ; break ;
		case    8 : Planes = 3 ; break ;
		case   16 : Planes = 4 ; break ;
	    }


// Adresse des bits XOR
	Size		=  ( Width * Height ) / ( 8 / Planes ) ;
	XORBits		=  def + ( int ) Offset + 0x7E ;
	ANDBits		=  def + ( int ) Offset + 0x7E + ( int ) Size ;


// On crée l'icône
	return ( CreateIcon ( * GetApplicationObject ( ),
			Width, Height, 1, Planes,
				ANDBits, XORBits ) ) ;

  FIN DU PASSAGE COMMENTE ***/

	char			tempname [ MAX_PARAMETER_LENGTH ] ;
	register FILE *		fp ;
	register HICON		HIcon ;

	tmpnam ( tempname ) ;
	fp = fopen ( tempname, "w" ) ;
	fwrite ( def, 1, size, fp ) ;
	fclose ( fp ) ;

	HIcon = ExtractIcon ( * GetApplicationObject ( ), tempname, 0 ) ;
	unlink ( tempname ) ;

	return ( HIcon ) ;
    }
Exemple #5
0
CScreenSpyDlg::CScreenSpyDlg(CWnd* pParent, CIOCPServer* pIOCPServer, ClientContext *pContext)
	: CDialog(CScreenSpyDlg::IDD, pParent)
{
	m_iocpServer	= pIOCPServer;
	m_pContext		= pContext;
	m_bIsFirst		= true; // 如果是第一次打开对话框,显示提示等待信息
	m_lpScreenDIB	= NULL;
	char szPath[MAX_PATH];
	GetSystemDirectory(szPath, MAX_PATH);
	lstrcat(szPath, "\\shell32.dll");
	m_hIcon = ExtractIcon(AfxGetApp()->m_hInstance, szPath, 17/*网上邻居图标索引*/);

	sockaddr_in  sockAddr;
	memset(&sockAddr, 0, sizeof(sockAddr));
	int nSockAddrLen = sizeof(sockAddr);
	BOOL bResult = getpeername(m_pContext->m_Socket,(SOCKADDR*)&sockAddr, &nSockAddrLen);

	m_IPAddress = bResult != INVALID_SOCKET ? inet_ntoa(sockAddr.sin_addr) : "";

	//重要的是这里,这里将服务端发送来的bmp结构头和服务端屏幕大小保存起来
	UINT	nBISize = m_pContext->m_DeCompressionBuffer.GetBufferLen() - 1;
	m_lpbmi = (BITMAPINFO *) new BYTE[nBISize];
	m_lpbmi_rect = (BITMAPINFO *) new BYTE[nBISize];
	
	//这里就是保存bmp位图头了
	memcpy(m_lpbmi, m_pContext->m_DeCompressionBuffer.GetBuffer(1), nBISize);
	memcpy(m_lpbmi_rect, m_pContext->m_DeCompressionBuffer.GetBuffer(1), nBISize);

	memset(&m_MMI, 0, sizeof(MINMAXINFO));

	m_bIsCtrl = false; // 默认不控制
	m_nCount = 0;
	m_bCursorIndex = 1;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CIconComboBox::InsertIcon( LPCTSTR pIconName, int ndx )
{
	//
	// create an icon from file
	// 
	// NULL - no icons in file
	// 1 - not a proper icon file
	//
	HICON hIcon = ExtractIcon( AfxGetInstanceHandle(), pIconName, 0 );
	if( ( hIcon == ( HICON )1 ) || !hIcon )
		return CB_ERR;

	//
	// insert the icon into the combo box -- returning the index
	//
	// CB_ERR - general error adding icon
	// CB_ERRSPACE - insufficient space necessary to add icon
	//
	int result = CComboBox::InsertString( ndx, pIconName );
	if( ( result == CB_ERR ) || ( result == CB_ERRSPACE ) )
		return result;

	//
	// associate the icon with the index
	//
	// CB_ERR - general error
	//
	result = SetItemData( ndx, ( DWORD )hIcon );
	if( result == CB_ERR )
		return result;
	
	// return the icon index
	return ndx;
}
Exemple #7
0
void TrayNotifyDlg::RefreshProperties(const NotifyIconDlgInfo& entry)
{
	SetDlgItemText(_hwnd, IDC_NOTIFY_TOOLTIP, entry._tipText);
	SetDlgItemText(_hwnd, IDC_NOTIFY_TITLE, entry._windowTitle);
	SetDlgItemText(_hwnd, IDC_NOTIFY_MODULE, entry._modulePath);

	CheckRadioButton(_hwnd, IDC_NOTIFY_SHOW, IDC_NOTIFY_AUTOHIDE, IDC_NOTIFY_SHOW+entry._mode);

	String change_str;
	if (entry._lastChange)
		change_str.printf(TEXT("before %d s"), (GetTickCount()-entry._lastChange+500)/1000);
	SetDlgItemText(_hwnd, IDC_LAST_CHANGE, change_str);

	HICON hicon = 0; //get_window_icon_big(entry._hWnd, false);

	 // If we could not find an icon associated with the owner window, try to load one from the owning module.
	if (!hicon && !entry._modulePath.empty()) {
		hicon = ExtractIcon(g_Globals._hInstance, entry._modulePath, 0);

		if (!hicon) {
			SHFILEINFO sfi;

			if (SHGetFileInfo(entry._modulePath, 0, &sfi, sizeof(sfi), SHGFI_ICON|SHGFI_LARGEICON))
				hicon = sfi.hIcon;
		}
	}

	if (hicon) {
		SendMessage(GetDlgItem(_hwnd, IDC_PICTURE), STM_SETICON, (LPARAM)hicon, 0);
		DestroyIcon(hicon);
	} else
		SendMessage(GetDlgItem(_hwnd, IDC_PICTURE), STM_SETICON, 0, 0);
}
Exemple #8
0
void CAclApp::AddAcl(PXACL pAcl, BOOL bIsSelect, BOOL bIsEdit, int iIndex)
{
	CString sString[ACL_APP_LIST_COUNT];
	sString[0].Format("%u", pAcl->ulAclID);
	sString[1] = (pAcl->sApplication[0] == '*' ? "*" : GetName(pAcl->sApplication));
	sString[2] = GUI_DIRECTION[pAcl->bDirection];
	sString[3] = ACL_NET_TYPE[pAcl->bRemoteNetType];
	sString[4].Format("%u", pAcl->uiServicePort);
	sString[5].Format("%u", pAcl->wLocalPort);
	sString[6] = GUI_ACTION[pAcl->bAction];
	sString[7] = GUI_SERVICE_TYPE[pAcl->bServiceType];
	sString[8] = ACL_TIME_TYPE[pAcl->bAccessTimeType];
	sString[9] = pAcl->sMemo[0] == 0 ? MEMO_CONST : pAcl->sMemo;
	sString[10] = (pAcl->sApplication[0] == '*' ? "*" : GetPath(pAcl->sApplication));

	HICON hIcon = ExtractIcon(theApp.m_hInstance, pAcl->sApplication, 0);
	if(hIcon == NULL)
		hIcon = theApp.LoadIcon(IDR_NULLAPP);
	int iIcon;
	if(bIsEdit)
		iIcon = m_ImageList.Replace(iIndex, hIcon);
	else
		iIcon = m_ImageList.Add(hIcon);
	DestroyIcon(hIcon);

	iIndex = AddList(&m_List, (LPCTSTR*)sString, ACL_APP_LIST_COUNT, bIsSelect, bIsEdit, iIndex, iIcon);
}
BOOL CWizardBasedProjectTemplateItem::InitItem(LPCTSTR lpszPath, CImageList &ImageList32, CImageList &ImageList16)
{
	m_strPath = lpszPath;

	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// retrieve the wizard interface
	CString strProgId;
	strProgId.Format(_T("%s.ProjectWizard"), CPathTool::GetFileTitle(m_strPath));

	BSTR bstrProgId = strProgId.AllocSysString();
	HRESULT result = m_wizard.CoCreateInstance(bstrProgId, NULL, CLSCTX_INPROC_SERVER);

	if (result != S_OK)
		return FALSE;

	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	// get the icon
	HICON hIcon = NULL;

	int nIconIndex = m_wizard.GetIconIndex();
	if (nIconIndex >= 0)
		hIcon = ExtractIcon(AfxGetInstanceHandle(), m_strPath, nIconIndex);
	if (!hIcon)
		hIcon = theApp.LoadIcon(IDR_LATEXWIZARD);

	m_nImageIndex = ImageList32.Add(hIcon);
	ImageList16.Add(hIcon);

	return TRUE;
}
jint DesktopIndicatorImages::add( const char *filename )
{
	// Extract icon from file
	HICON l_icon = ExtractIcon( g_instance, filename, 0 );

	if( !l_icon )
		return -1;

	return (jint) l_icon;
}
Exemple #11
0
QImage FhoIcon::getIconFromResource(QString fileName, int iconIdx) {
	// see ExtractIcon for a brief description.
	// In short:
	// mydll,-3 extracts icon with resource id (name) "3"
	// mydll,3 extracts icon with index 3 (4th icon)

	// iconIndex >= 0:
	// -> zero based index of icon (load by ordinal)
	//    e.g. 0: first icon (index 0)
	//         3: fourth icon (index 3)
	// iconIndex < -1:
	// -> icon with resouce identifier of abs(iconIndex) (load by name)
	//    e.g. -3: icon with resource identifier ('name') "3"
	// iconIndex == -1:
	// -> returns total number of icons in file!
	// => to extract icon with resouce identifier "1" (iconIndex -1), use ExtractIconEx()!

	if (iconIdx == -1) {
		// we want icon with name "1", but parameter -1 will return the icon count!
		// really get icon with name "1" instead of the first icon, e.g. using ExtractIconEx()?!
		return getDefaultIconFromResource(fileName);
	} else {
		// remove leading @
		if (fileName.startsWith('@')) {
			fileName = fileName.right(fileName.length()-1); // fileName.remove("@");
		}

		fileName = FhoEnv::expand(fileName);

        HICON hIcon = ExtractIcon(0, (LPCWSTR)fileName.utf16(), iconIdx);

		if ((hIcon) && ((int)hIcon != 1)) {
			QImage image = getIconFromHandle(hIcon);
				
			DestroyIcon(hIcon);

			return image;
		} else {
			if (iconIdx != 0) {
				// we did not try to get the resource's default icon yet
				return getDefaultIconFromResource(fileName);
			} else {
				// we already tried to get the resource's default icon
				return getDefaultIcon();
			}
		}
	}

	// Alternative method would be to use GetModuleHandle/LoadLibrary and LoadImage
	// we prefer ExtractIcon because this can potentially also handle resource files that cannot be loaded (e.g. because of missing dependencies, etc.)
	// also, it seems that LoadImage can only handle icon names (passed via makeintresource, however) and can not load icons by name!? (documentations states it can!)
	// Does it make sense to try this version first for performance reasons (at least for "name" case that works)?
}
Exemple #12
0
CScreenSpyDlg::CScreenSpyDlg(CWnd* Parent, IOCPServer* IOCPServer, CONTEXT_OBJECT* ContextObject)
: CDialog(CScreenSpyDlg::IDD, Parent)
{
	m_iocpServer	= IOCPServer;
	m_ContextObject	= ContextObject;

	CHAR szFullPath[MAX_PATH];
	GetSystemDirectory(szFullPath, MAX_PATH);
	lstrcat(szFullPath, "\\shell32.dll");  //图标
	m_hIcon = ExtractIcon(AfxGetApp()->m_hInstance, szFullPath, 17);
	m_hCursor = LoadCursor(AfxGetApp()->m_hInstance,IDC_ARROW);



	sockaddr_in  ClientAddr;
	memset(&ClientAddr, 0, sizeof(ClientAddr));
	int ulClientAddrLen = sizeof(sockaddr_in);
	BOOL bOk = getpeername(m_ContextObject->sClientSocket,(SOCKADDR*)&ClientAddr, &ulClientAddrLen);

	m_strClientIP = bOk != INVALID_SOCKET ? inet_ntoa(ClientAddr.sin_addr) : "";


	

	m_bIsFirst = TRUE;
    m_ulHScrollPos = 0;
	m_ulVScrollPos = 0;


	if (m_ContextObject==NULL)
	{
		return;
	}
	ULONG	ulBitmapInforLength = m_ContextObject->InDeCompressedBuffer.GetBufferLength() - 1;
	m_BitmapInfor_Full = (BITMAPINFO *) new BYTE[ulBitmapInforLength];

	if (m_BitmapInfor_Full==NULL)
	{
		return;
	}

	memcpy(m_BitmapInfor_Full, m_ContextObject->InDeCompressedBuffer.GetBuffer(1), ulBitmapInforLength);


	m_bIsCtrl = FALSE;
	m_bIsTraceCursor = FALSE;


//	m_szData = NULL;
//	m_bSend   = TRUE;
//	m_ulMsgCount = 0;;
}
Exemple #13
0
// Window Initialization
bool initWindow(HINSTANCE hInstance)
{

	// Get Handle for icon
    // Works only when running from within Visual Studio.
	icon = ExtractIcon( GetModuleHandle(NULL),"..\\..\\src\\novint.ico", 0);
	if(icon == NULL)
	{
	   MessageBox(NULL, "ExtractIcon() Failed!", "Error:", MB_OK);
	}

    WNDCLASSEX wcex;
    
    wcex.cbSize            = sizeof(WNDCLASSEX);
    wcex.style             = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc       = (WNDPROC)WndProc;
    wcex.cbClsExtra        = 0;
    wcex.cbWndExtra        = 0;
    wcex.hInstance         = hInstance;
    wcex.hIcon             = icon;
    wcex.hCursor           = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground     = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName      = NULL;   // No menu used in this version
    wcex.lpszClassName     = "BasicDirectX";
    wcex.hIconSm           = icon;
    
    RegisterClassEx(&wcex);

    // Now create the window
    hWin = CreateWindow(
               "BasicDirectX",    // OS name
               "Basic Direct X",  // Window title caption
               WS_OVERLAPPEDWINDOW,
               CW_USEDEFAULT,
               CW_USEDEFAULT,
               windowWidth,
               windowHeight,
               NULL,
               NULL,
               hInstance,
               NULL);

    bool result = false;
    if (hWin)
    {
        ShowWindow(hWin, SW_SHOW);
        UpdateWindow(hWin);
        result = true;
    }
    
    return result;
}
Exemple #14
0
HICON win_extract_icon_utf8(HINSTANCE inst, const char* exefilename, UINT iconindex)
{
	HICON icon = 0;
	TCHAR* t_exefilename = tstring_from_utf8(exefilename);
	if( !t_exefilename )
		return icon;

	icon = ExtractIcon(inst, t_exefilename, iconindex);

	osd_free(t_exefilename);

	return icon;
}
Exemple #15
0
BOOL CTrashSkipCtrl::_GetItemIcon(LPCTSTR lpFileName, HICON& icon)
{
    BOOL bRet = FALSE;
    KAppRes& res = KAppRes::Instance();

    if (lpFileName == NULL)
        goto Clear0;

    icon = ExtractIcon(NULL, lpFileName, 0);

Clear0:
    return bRet;
}
Exemple #16
0
HICON CCrashInfoReader::GetCustomIcon()
{
	// This method extracts custom icon from the specified resource file.
	// If the custom icon not specified, NULL is returned.

    if(!m_sCustomSenderIcon.IsEmpty())
    {
		// First parse the path (the path is in form of <filename>[,<icon_index>])
        CString sResourceFile;
        CString sIconIndex;
        int nIconIndex = 0;

		// Get position of comma
        int nComma = m_sCustomSenderIcon.ReverseFind(',');    
        if(nComma>=0)
        {
			// Split resource file path and icon index
            sResourceFile = m_sCustomSenderIcon.Left(nComma);      
            sIconIndex = m_sCustomSenderIcon.Mid(nComma+1);
            sIconIndex.TrimLeft();
            sIconIndex.TrimRight();
            nIconIndex = _ttoi(sIconIndex);      
        }
        else
        {
			// There is no icon index, just resource file path
            sResourceFile = m_sCustomSenderIcon;
        }

        sResourceFile.TrimRight();        

        if(nIconIndex==-1)
        {      
            return NULL;
        }

        // Check that custom icon can be loaded
        HICON hIcon = ExtractIcon(NULL, sResourceFile, nIconIndex);
        if(hIcon==NULL || hIcon==(HICON)1)
        { 
			// Failure
            return NULL;
        }

		// Return icon handle
        return hIcon;
    }

	// Return NULL to indicate custom icon not specified
    return NULL;
}
BOOL CChatDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	

	m_img.Create(GetSystemMetrics(SM_CXSMICON),
		GetSystemMetrics(SM_CYSMICON),
		ILC_COLOR24, 50, 50);
	m_img.SetBkColor(GetSysColor(COLOR_WINDOW));
	m_img.Add(ExtractIcon(AfxGetApp()->m_hInstance, "shell32.dll ", 4));
	m_img.Add(ExtractIcon(AfxGetApp()->m_hInstance, "shell32.dll ", 1));
	
	
	
	// TODO:  在此添加额外的初始化
	m_dirTree.SetBkColor(RGB(0, 250, 255));//设置m_mytree的背景色
	m_dirTree.SetImageList(&m_img, TVSIL_NORMAL);
	
	
	

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常:  OCX 属性页应返回 FALSE
}
Exemple #18
0
/*------------------------------------------------
  initialize
--------------------------------------------------*/
BOOL InitSelectIcon(HWND hDlg)
{
	int i, count, index;
	HICON hicon, hiconl;
	char msg[MAX_PATH];
	char fname[MAX_PATH], num[10];
	
	// common/tclang.c
	SetDialogLanguage(hDlg, "SelectIcon", g_hfontDialog);
	
	parse(fname, m_fname_index, 0, MAX_PATH);
	parse(num, m_fname_index, 1, 10);
	if(num[0] == 0) index = 0;
	else index = atoi(num);
	
	count = (int)(INT_PTR)ExtractIcon(m_hInst, fname, (UINT)-1);
	if(count == 0)
	{
		strcpy(msg, MyString(IDS_NOICON, "NoIcon"));
		strcat(msg, "\n");
		strcat(msg, fname);
		MessageBox(hDlg, msg, "TClock", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}
	
	EndSelectIcon(hDlg);
	SendDlgItemMessage(hDlg, IDC_LISTICON, LB_RESETCONTENT, 0, 0);
	
	for(i = 0; i < count; i++)
	{
		hiconl = NULL; hicon = NULL;
		ExtractIconEx(fname, i, &hiconl, &hicon, 1);
		if(hiconl) DestroyIcon(hiconl);
		SendDlgItemMessage(hDlg, IDC_LISTICON, LB_ADDSTRING, 0,
			(LPARAM)hicon);
	}
	SetDlgItemText(hDlg, IDC_FNAMEICON, fname);
	SendDlgItemMessage(hDlg, IDC_LISTICON, LB_SETCURSEL,
		index, 0);
	strcpy(m_fname_index, fname);
	return TRUE;
}
CCloseApplicationDlg::CCloseApplicationDlg(CString sApplicationName,
	CString sApplicationPath)
	: CDialog(CCloseApplicationDlg::IDD, NULL)
{
	// Set data
	m_sApplicationTitle = sApplicationName.IsEmpty() ? CLanguage::Instance()->GetString(IDS_CLOSEAPPLICATION_APPLICATION)
		: sApplicationName;
	m_sApplicationPath = sApplicationPath;
	m_iCountDown = CLOSEAPPLICATION_TIME;

	// Extract icon
	if (PathFileExists(sApplicationPath))
	{
		m_hIcon = ExtractIcon(NULL, sApplicationPath, 0);
	}
	else
	{
		m_hIcon = AfxGetApp()->LoadIcon(IDI_UPDATER);
	}
}
Exemple #20
0
bool CFileAssoc::ReAssocIcons(const CAtlList<CString>& exts)
{
    if (!LoadIconLib()) {
        return false;
    }
    SaveIconLibVersion();

    const CString progPath = GetProgramPath(true);

    CRegKey key;

    POSITION pos = exts.GetHeadPosition();
    while (pos) {
        const CString ext = exts.GetNext(pos);
        const CString strProgID = PROGID + ext;
        CString appIcon;

        int iconIndex = GetIconIndex(ext);

        /* icon_index value -1 means no icon was found in the iconlib for the file extension */
        if (iconIndex >= 0 && ExtractIcon(AfxGetApp()->m_hInstance, m_iconLibPath, iconIndex)) {
            appIcon.Format(_T("\"%s\",%d"), m_iconLibPath, iconIndex);
        }

        /* no icon was found for the file extension, so use MPC's icon */
        if (appIcon.IsEmpty()) {
            appIcon = "\"" + progPath + "\",0";
        }

        if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))
                || ERROR_SUCCESS != key.SetStringValue(NULL, appIcon)) {
            return false;
        }

        key.Close();
    }

    FreeIconLib();

    return true;
}
Exemple #21
0
bool CIconSelectDialog::UpdateIcon()
{
    ListView.DeleteAllItems();
    IconList.Destroy();
    //アイコン数の取得
    long IconCount=(long)ExtractIcon(GetModuleHandle(NULL),IconPath,-1);
    if(0==IconCount) {
        ListView.EnableWindow(false);
        return false;
    }
    ListView.EnableWindow(true);
    IconList.Create(32,32,ILC_COLOR32 | ILC_MASK,IconCount,1);
    for(long i=0; i<IconCount; i++) {
        CIcon Icon;
        Icon.ExtractIcon(IconPath,i);
        IconList.AddIcon(Icon);
    }
    ListView.SetImageList(IconList,LVSIL_NORMAL);
    for(long i=0; i<IconCount; i++) {
        ListView.AddItem(i,0,_T(""),i);
    }
    return true;
}
Exemple #22
0
BOOL ShellIcons::DrawIcon(CDC* pDC, SHELLICON nIndex, const CPoint& ptTopLeft, bool bLarge)
{
	// maintain a static list of large and small icons
	static CMap<SHELLICON, SHELLICON, HICON, HICON> mapLarge, mapSmall;

	// try lookup first
	HICON hIcon = NULL;

	if (bLarge)
		mapLarge.Lookup(nIndex, hIcon);
	else
		mapSmall.Lookup(nIndex, hIcon);

	// else extract
	if (hIcon == NULL)
		hIcon = ExtractIcon(nIndex, bLarge);

	ASSERT(hIcon);

	if (hIcon)
	{
		int nSize = bLarge ? 32 : 16;

		if (DrawIconEx(*pDC, ptTopLeft.x, ptTopLeft.y, hIcon, nSize, nSize, 0, NULL, DI_NORMAL))
		{
			if (bLarge)
				mapLarge[nIndex] = hIcon;
			else
				mapSmall[nIndex] = hIcon;

			return TRUE;
		}
	}

	// else
	return FALSE;
}
static int config(uint32_t width, uint32_t height, uint32_t d_width,uint32_t d_height, uint32_t flags, char *title, uint32_t format){
    title = "MPlayer VIDIX WIN32 Overlay";

    panscan_init();

    image_height = height;
    image_width = width;
    image_format = format;
    vo_screenwidth = GetSystemMetrics(SM_CXSCREEN);
    vo_screenheight = GetSystemMetrics(SM_CYSCREEN);
    vo_depthonscreen = GetDeviceCaps(GetDC(GetDesktopWindow()),BITSPIXEL);


    aspect_save_orig(width, height);
    aspect_save_prescale(d_width, d_height);
    aspect_save_screenres(vo_screenwidth, vo_screenheight);

    vo_dx = 0;
    vo_dy = 0;

    vo_dx=( vo_screenwidth - d_width ) / 2; vo_dy=( vo_screenheight - d_height ) / 2;
    geometry(&vo_dx, &vo_dy, &d_width, &d_height, vo_screenwidth, vo_screenheight);

    vo_fs = flags&VOFLAG_FULLSCREEN;


    aspect(&d_width, &d_height, A_NOZOOM);
    vo_dwidth=d_width; vo_dheight=d_height;
    window_aspect = (float)d_width / (float)d_height;


    if(!vo_config_count){
    HINSTANCE hInstance = GetModuleHandle(NULL);
    WNDCLASS   wc;
    RECT rd;
    rd.left = vo_dx;
    rd.top = vo_dy;
    rd.right = rd.left + vo_dwidth;
    rd.bottom = rd.top + vo_dheight;
    AdjustWindowRect(&rd,WS_OVERLAPPEDWINDOW| WS_SIZEBOX,0);
    wc.style =  CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    wc.hIcon =ExtractIcon(hInstance,"mplayer.exe",0);
//LoadIcon(NULL,IDI_APPLICATION);
    wc.hbrBackground = CreateSolidBrush(RGB(255,0,255));
    wc.lpszClassName = "MPlayer - The Movie Player";
    wc.lpszMenuName = NULL;
    RegisterClass(&wc);
    hWnd = CreateWindow("MPlayer - The Movie Player",
                        title,
                        WS_OVERLAPPEDWINDOW| WS_SIZEBOX,
                        rd.left,
                        rd.top,
                        rd.right - rd.left,
                        rd.bottom - rd.top,
                        NULL,
                        NULL,
                        hInstance,
                        NULL);
    wc.hbrBackground = CreateSolidBrush(RGB(0,0,0));
    wc.lpszClassName = "MPlayer - Fullscreen";
    RegisterClass(&wc);
    hWndFS = CreateWindow("MPlayer - Fullscreen","MPlayer VIDIX Fullscreen",WS_POPUP,0,0,vo_screenwidth,vo_screenheight,hWnd,NULL,hInstance,NULL);





    }
    ShowWindow(hWnd,SW_SHOW);
    if(vo_fs)ShowWindow(hWndFS,SW_SHOW);

    return 0;
}
Exemple #24
0
bool CPPageFormats::RegisterExt(CString ext, CString strLabel, bool fRegister)
{
	CRegKey		key;
	bool		bSetValue;
	CString strProgID = _T("mplayerc") + ext;

	if(!fRegister)
	{
		if(fRegister != IsRegistered(ext))
			SetFileAssociation (ext, strProgID, fRegister);
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID);
		return(true);
	}

	bSetValue = fRegister || (ERROR_SUCCESS != key.Open(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"), KEY_READ));

	// Create ProgID for this file type
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID)) return(false);
	if(ERROR_SUCCESS != key.SetStringValue(NULL, strLabel)) return(false);

	// Add to playlist option
	if(f_setContextFiles)
	{
		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue"))) return(false);
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_ADD_TO_PLAYLIST))) return(false);

		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\enqueue\\command"))) return(false);
		if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetEnqueueCommand()))) return(false);
	}
	else
	{
		key.Close();
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID + _T("\\shell\\enqueue"));
	}

	// Play option
	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open"))) return(false);
	if(f_setContextFiles)
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, ResStr(IDS_OPEN_WITH_MPC))) return(false);
	}
	else
	{
		if(ERROR_SUCCESS != key.SetStringValue(NULL, _T(""))) return(false);
	}

	if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\shell\\open\\command"))) return(false);
	if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, GetOpenCommand()))) return(false);

	if(ERROR_SUCCESS != key.Create(HKEY_LOCAL_MACHINE, g_strRegisteredKey + _T("\\FileAssociations"))) return(false);
	if(ERROR_SUCCESS != key.SetStringValue(ext, strProgID)) return(false);

	if(f_setAssociatedWithIcon)
	{
		CString AppIcon = _T("");
		TCHAR buff[_MAX_PATH];

		CString mpciconlib = GetProgramDir() + _T("\\mpciconlib.dll");

		if(FileExists(mpciconlib))
		{
			int icon_index = GetIconIndex(ext);
			CString m_typeicon = mpciconlib;

			/* icon_index value -1 means no icon was found in the iconlib for the file extension */
			if((icon_index >= 0) && ExtractIcon(AfxGetApp()->m_hInstance,(LPCWSTR)m_typeicon, icon_index))
			{
				m_typeicon = "\""+mpciconlib+"\"";
				AppIcon.Format(_T("%s,%d"), m_typeicon, icon_index);
			}
		}

		/* no icon was found for the file extension, so use MPC's icon */
		if((AppIcon.IsEmpty()) && (::GetModuleFileName(AfxGetInstanceHandle(), buff, MAX_PATH)))
		{
			AppIcon = buff;
			AppIcon = "\""+AppIcon+"\"";
			AppIcon += _T(",0");
		}

		if(ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon"))) return(false);
		if(bSetValue && (ERROR_SUCCESS != key.SetStringValue(NULL, AppIcon))) return(false);
	}
	else
	{
		key.Attach(HKEY_CLASSES_ROOT);
		key.RecurseDeleteKey(strProgID + _T("\\DefaultIcon"));
	}

	if(fRegister != IsRegistered(ext))
		SetFileAssociation (ext, strProgID, fRegister);

	return(true);
}
Exemple #25
0
LRESULT CErrorReportDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{   
    // Mirror this window if RTL language is in use
    CString sRTL = Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("Settings"), _T("RTLReading"));
    if(sRTL.CompareNoCase(_T("1"))==0)
    {
        Utility::SetLayoutRTL(m_hWnd);
    }

    SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("DlgCaption")));

    // Center the dialog on the screen
    CenterWindow();

    HICON hIcon = NULL;

    // Get custom icon
    hIcon = g_CrashInfo.GetCustomIcon();
    if(hIcon==NULL)
    {
        // Use default icon
        hIcon = ::LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME));
    }

    // Set window icon
    SetIcon(hIcon, 0);

    // Get the first icon in the EXE image
    m_HeadingIcon = ExtractIcon(NULL, g_CrashInfo.GetReport(0).m_sImageName, 0);

    // If there is no icon in crashed EXE module, use IDI_APPLICATION system icon
    if(m_HeadingIcon == NULL)
    {
        m_HeadingIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(IDI_APPLICATION));
    }  

    m_statSubHeader = GetDlgItem(IDC_SUBHEADER);

    m_link.SubclassWindow(GetDlgItem(IDC_LINK));   
    m_link.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON);
    m_link.SetLabel(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("WhatDoesReportContain")));

    m_linkMoreInfo.SubclassWindow(GetDlgItem(IDC_MOREINFO));
    m_linkMoreInfo.SetHyperLinkExtendedStyle(HLINK_COMMANDBUTTON);
    m_linkMoreInfo.SetLabel(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("ProvideAdditionalInfo")));

    m_statEmail = GetDlgItem(IDC_STATMAIL);
    m_statEmail.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("YourEmail")));

    m_editEmail = GetDlgItem(IDC_EMAIL);

    m_statDesc = GetDlgItem(IDC_DESCRIBE);
    m_statDesc.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("DescribeProblem")));

    m_editDesc = GetDlgItem(IDC_DESCRIPTION);

    m_statIndent =  GetDlgItem(IDC_INDENT);

    m_chkRestart = GetDlgItem(IDC_RESTART);
    CString sCaption;
    sCaption.Format(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("RestartApp")), g_CrashInfo.m_sAppName);
    m_chkRestart.SetWindowText(sCaption);
    m_chkRestart.SetCheck(BST_CHECKED);
    m_chkRestart.ShowWindow(g_CrashInfo.m_bAppRestart?SW_SHOW:SW_HIDE);

    m_statConsent = GetDlgItem(IDC_CONSENT);

    // Init font for consent string
    LOGFONT lf;
    memset(&lf, 0, sizeof(LOGFONT));
    lf.lfHeight = 11;
    lf.lfWeight = FW_NORMAL;
    lf.lfQuality = ANTIALIASED_QUALITY;
    _TCSCPY_S(lf.lfFaceName, 32, _T("Tahoma"));
    CFontHandle hConsentFont;
    hConsentFont.CreateFontIndirect(&lf);
    m_statConsent.SetFont(hConsentFont);

    if(g_CrashInfo.m_sPrivacyPolicyURL.IsEmpty())
        m_statConsent.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("MyConsent2")));
    else
        m_statConsent.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("MyConsent")));

    m_linkPrivacyPolicy.SubclassWindow(GetDlgItem(IDC_PRIVACYPOLICY));
    m_linkPrivacyPolicy.SetHyperLink(g_CrashInfo.m_sPrivacyPolicyURL);
    m_linkPrivacyPolicy.SetLabel(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("PrivacyPolicy")));

    BOOL bShowPrivacyPolicy = !g_CrashInfo.m_sPrivacyPolicyURL.IsEmpty();  
    m_linkPrivacyPolicy.ShowWindow(bShowPrivacyPolicy?SW_SHOW:SW_HIDE);

    m_statCrashRpt = GetDlgItem(IDC_CRASHRPT);
    m_statHorzLine = GetDlgItem(IDC_HORZLINE);  

    m_btnOk = GetDlgItem(IDOK);
    m_btnOk.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("SendReport")));

    m_btnCancel = GetDlgItem(IDC_CANCEL);  
    if(g_CrashInfo.m_bQueueEnabled)
        m_btnCancel.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("OtherActions")));
    else
        m_btnCancel.SetWindowText(Utility::GetINIString(g_CrashInfo.m_sLangFileName, _T("MainDlg"), _T("CloseTheProgram")));

    // Init font for heading text
    memset(&lf, 0, sizeof(LOGFONT));
    lf.lfHeight = 25;
    lf.lfWeight = FW_NORMAL;
    lf.lfQuality = ANTIALIASED_QUALITY;
    _TCSCPY_S(lf.lfFaceName, 32, _T("Tahoma"));
    m_HeadingFont.CreateFontIndirect(&lf);

    m_Layout.SetContainerWnd(m_hWnd);
    m_Layout.Insert(m_linkMoreInfo);
    m_Layout.Insert(m_statIndent);
    m_Layout.Insert(m_statEmail, TRUE);
    m_Layout.Insert(m_editEmail, TRUE);
    m_Layout.Insert(m_statDesc, TRUE);
    m_Layout.Insert(m_editDesc, TRUE);
    m_Layout.Insert(m_chkRestart);
    m_Layout.Insert(m_statConsent);
    m_Layout.Insert(m_linkPrivacyPolicy);  
    m_Layout.Insert(m_statCrashRpt);
    m_Layout.Insert(m_statHorzLine, TRUE);
    m_Layout.Insert(m_btnOk);
    m_Layout.Insert(m_btnCancel, TRUE);

    ShowMoreInfo(FALSE);

    m_dlgProgress.Create(m_hWnd);
    m_dlgProgress.Start(TRUE);

    // register object for message filtering and idle updates
    CMessageLoop* pLoop = _Module.GetMessageLoop();
    ATLASSERT(pLoop != NULL);
    if(pLoop)
    {
        pLoop->AddMessageFilter(this);
        pLoop->AddIdleHandler(this);
    }

    UIAddChildWindowContainer(m_hWnd);

    return TRUE;
}
Exemple #26
0
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow )
{
    UNREFERENCED_PARAMETER( prevInstance );
    UNREFERENCED_PARAMETER( cmdLine );

    WNDCLASSEX wndClass = { 0 };
    wndClass.cbSize = sizeof( WNDCLASSEX ) ;
    wndClass.style = CS_HREDRAW | CS_VREDRAW;
    wndClass.lpfnWndProc = WndProc;
    wndClass.hInstance = hInstance;
    wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
    wndClass.hbrBackground = ( HBRUSH )( COLOR_WINDOW + 1 );
    wndClass.lpszMenuName = NULL;
    wndClass.lpszClassName = L"DX11BookWindowClass";
	wndClass.hIcon = ExtractIcon( hInstance, L"icon.ico", 0 );

    if( !RegisterClassEx( &wndClass ) )
        return -1;

    RECT rc = { 0, 0, 800, 600 };
    AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );

    HWND hwnd = CreateWindow( L"DX11BookWindowClass", L"Not Blank Win32 Window",
        WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
        rc.bottom - rc.top, NULL, NULL, hInstance, NULL );

    if( !hwnd )
        return -1;

    ShowWindow( hwnd, cmdShow );

	//DXBase *demo = new SpriteDemo( );
	DXEngine demo;

	bool result = demo.initialize( hInstance, hwnd );
	if ( result == false )
		return -1;

	VisualEntity ar[2];

	wstring path1 = L"decal.dds";
	wstring path2 = L"wheel.dds";

	ar[0].bindTexture( path1 );
	ar[1].bindTexture( path2 );
	
	ar[0].setPosition( XMFLOAT2( 200.0f, 500.0f ) );
	ar[1].setPosition( XMFLOAT2( 400.0f, 200.0f ) );

	ar[0].setDepth( 0.5f );
	ar[1].setDepth( 0.5f );

	ar[0].setSize( XMFLOAT2( 500.0f, 500.0f ) );
	ar[1].setSize( XMFLOAT2( 100.0f, 100.0f ) );

	float px = 400;
	float py = 200;
	float deltaX = 0.2f;
	float deltaY = 0.2f;

	demo.loadEntities( ar, 2 );

    MSG msg = { 0 };

	bool firstUse = true;

    while( msg.message != WM_QUIT )
    {
        if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else
        {
            // Update
            // Draw
			demo.update( 0.0f );
			demo.render( );
			ar[1].setPosition( XMFLOAT2(px += deltaX, py += deltaY) );
			//deltaX += deltaX * 0.0005f;
			//deltaY += deltaY * 0.0005f;
			if ( px >= 700 || px <= 0 ) 
				deltaX *= -1;
			if ( py >= 600 || py <= 100 )
				deltaY *= -1;
        }
	}
    // Demo Shutdown
	// demo->shutdown( ); WHY?
    return static_cast<int>( msg.wParam );
}
bool gkDeviceRenderContext::SetWindow(int width, int height, bool fullscreen, HWND hWnd)
{
	if (!hWnd)
	{
		HINSTANCE hInstance = NULL;
		if( hInstance == NULL )
			hInstance = ( HINSTANCE )GetModuleHandle( NULL );
		//GetDXUTState().SetHInstance( hInstance );

		TCHAR szExePath[MAX_PATH];
		GetModuleFileName( NULL, szExePath, MAX_PATH );

		HICON hIcon = NULL;

		if( hIcon == NULL ) // If the icon is NULL, then use the first one found in the exe
			hIcon = ExtractIcon( hInstance, szExePath, 0 );

		// Register the windows class
		WNDCLASS wndClass;
		wndClass.style = CS_DBLCLKS; // CS_HREDRAW | CS_VREDRAW | CS_OWNDC;//
		wndClass.lpfnWndProc = (WNDPROC)WndProc;
		wndClass.cbClsExtra = 0;
		wndClass.cbWndExtra = 0;
		wndClass.hInstance = hInstance;
		wndClass.hIcon = hIcon;
		wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
		wndClass.hbrBackground = ( HBRUSH )GetStockObject( BLACK_BRUSH );
		wndClass.lpszMenuName = NULL;
		wndClass.lpszClassName = _T("EglWindowClass");

		if (!RegisterClass(&wndClass))
		{
			DWORD dwError = GetLastError();
			if( dwError != ERROR_CLASS_ALREADY_EXISTS )
				OutputDebugString( _T("Cannot Register Window Class.") );
			return false;
		}

		// Create the render window
		m_hWnd = CreateWindow( _T("EglWindowClass"), _T("gkENGINE"), WS_OVERLAPPEDWINDOW,
			20, 20, width, height, 0,
			NULL, hInstance, 0 );
	}
	else
		m_hWnd = (HWND)hWnd;

	RECT realRect;
	GetClientRect(m_hWnd, &realRect);

	int realwidth = realRect.right - realRect.left;
	int realheight = realRect.bottom - realRect.top;
	width = width * 2 - realwidth;
	height = height * 2 - realheight;

	MoveWindow(m_hWnd, GetSystemMetrics(SM_CXSCREEN) / 2 - width / 2, GetSystemMetrics(SM_CYSCREEN) / 2 - height / 2, width, height, FALSE);

	ShowWindow(m_hWnd, SW_SHOWNORMAL);
	UpdateWindow(m_hWnd);
	SetFocus(m_hWnd);
	SetForegroundWindow(m_hWnd);

	return true;
}
/**
 * \brief Initialize w32_common framework.
 *
 * The first function that should be called from the w32_common framework.
 * It handles window creation on the screen with proper title and attributes.
 * It also initializes the framework's internal variables. The function should
 * be called after your own preinit initialization and you shouldn't do any
 * window management on your own.
 *
 * Global libvo variables changed:
 * vo_w32_window
 * vo_depthonscreen
 * vo_screenwidth
 * vo_screenheight
 *
 * \return 1 = Success, 0 = Failure
 */
int vo_w32_init(void) {
    HICON mplayerIcon = 0;
    char exedir[MAX_PATH];
    HINSTANCE user32;
    char *dev;

    if (vo_window)
        return 1;

    hInstance = GetModuleHandle(0);

    if (GetModuleFileName(0, exedir, MAX_PATH))
        mplayerIcon = ExtractIcon(hInstance, exedir, 0);
    if (!mplayerIcon)
        mplayerIcon = LoadIcon(0, IDI_APPLICATION);

  {
    WNDCLASSEX wcex = { sizeof wcex, CS_OWNDC | CS_DBLCLKS, WndProc, 0, 0, hInstance, mplayerIcon, LoadCursor(0, IDC_ARROW), NULL, 0, classname, mplayerIcon };

    if (!RegisterClassEx(&wcex)) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to register window class!\n");
        return 0;
    }
  }

    if (WinID >= 0)
    {
        RECT r;
        GetClientRect(WinID, &r);
        vo_dwidth = r.right; vo_dheight = r.bottom;
        vo_window = CreateWindowEx(WS_EX_NOPARENTNOTIFY, classname, classname,
                     WS_CHILD | WS_VISIBLE,
                     0, 0, vo_dwidth, vo_dheight, WinID, 0, hInstance, 0);
        EnableWindow(vo_window, 0);
    } else
        vo_window = CreateWindowEx(0, classname, classname,
                      vo_border ? (WS_OVERLAPPEDWINDOW | WS_SIZEBOX) : WS_POPUP,
                      CW_USEDEFAULT, 0, 100, 100, 0, 0, hInstance, 0);
    if (!vo_window) {
        mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to create window!\n");
        return 0;
    }

    myMonitorFromWindow = NULL;
    myGetMonitorInfo = NULL;
    myEnumDisplayMonitors = NULL;
    user32 = GetModuleHandle("user32.dll");
    if (user32) {
        myMonitorFromWindow = (void *)GetProcAddress(user32, "MonitorFromWindow");
        myGetMonitorInfo = GetProcAddress(user32, "GetMonitorInfoA");
        myEnumDisplayMonitors = GetProcAddress(user32, "EnumDisplayMonitors");
    }
    dev_hdc = 0;
    dev = get_display_name();
    if (dev) dev_hdc = CreateDC(dev, NULL, NULL, NULL);
    free(dev);
    updateScreenProperties();

    mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n", vo_screenwidth, vo_screenheight, vo_depthonscreen);

    return 1;
}
/*****************************************************************************
 * DirectXCreateWindow: create a window for the video.
 *****************************************************************************
 * Before creating a direct draw surface, we need to create a window in which
 * the video will be displayed. This window will also allow us to capture the
 * events.
 *****************************************************************************/
static int DirectXCreateWindow( event_thread_t *p_event )
{
    vout_display_t *vd = p_event->vd;
    HINSTANCE  hInstance;
    HMENU      hMenu;
    RECT       rect_window;
    WNDCLASS   wc;                            /* window class components */
    HICON      vlc_icon;
    char       vlc_path[MAX_PATH+1];
    int        i_style, i_stylex;

    msg_Dbg( vd, "DirectXCreateWindow" );

    /* Get this module's instance */
    hInstance = GetModuleHandle(NULL);

    #ifdef MODULE_NAME_IS_direct3d
    if( !p_event->use_desktop )
    {
    #endif
        /* If an external window was specified, we'll draw in it. */
        p_event->parent_window = vout_display_NewWindow(vd, &p_event->wnd_cfg );
        if( p_event->parent_window )
            p_event->hparent = p_event->parent_window->handle.hwnd;
        else
            p_event->hparent = NULL;
    #ifdef MODULE_NAME_IS_direct3d
    }
    else
    {
        /* Find Program Manager */
        HWND hwnd = FindWindow( _T("Progman"), NULL );
        if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SHELLDLL_DefView"), NULL );
        if( hwnd ) hwnd = FindWindowEx( hwnd, NULL, _T("SysListView32"), NULL );
        if( !hwnd )
            msg_Err( vd, "Couldn't find desktop icon window. Desktop mode can't be established." );
        p_event->parent_window = NULL;
        p_event->hparent = hwnd;
    }
    #endif
    p_event->cursor_arrow = LoadCursor(NULL, IDC_ARROW);
#ifndef UNDER_CE
    p_event->cursor_empty = EmptyCursor(hInstance);
#endif

    /* Get the Icon from the main app */
    vlc_icon = NULL;
#ifndef UNDER_CE
    if( GetModuleFileName( NULL, vlc_path, MAX_PATH ) )
    {
        vlc_icon = ExtractIcon( hInstance, vlc_path, 0 );
    }
#endif

    /* Fill in the window class structure */
    wc.style         = CS_OWNDC|CS_DBLCLKS;          /* style: dbl click */
    wc.lpfnWndProc   = (WNDPROC)DirectXEventProc;       /* event handler */
    wc.cbClsExtra    = 0;                         /* no extra class data */
    wc.cbWndExtra    = 0;                        /* no extra window data */
    wc.hInstance     = hInstance;                            /* instance */
    wc.hIcon         = vlc_icon;                /* load the vlc big icon */
    wc.hCursor       = p_event->is_cursor_hidden ? p_event->cursor_empty :
                                                   p_event->cursor_arrow;
    wc.hbrBackground = GetStockObject(BLACK_BRUSH);  /* background color */
    wc.lpszMenuName  = NULL;                                  /* no menu */
    wc.lpszClassName = p_event->class_main;       /* use a special class */

    /* Register the window class */
    if( !RegisterClass(&wc) )
    {
        if( vlc_icon )
            DestroyIcon( vlc_icon );

        msg_Err( vd, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
        return VLC_EGENERIC;
    }

    /* Register the video sub-window class */
    wc.lpszClassName = p_event->class_video;
    wc.hIcon = 0;
    wc.hbrBackground = NULL; /* no background color */
    if( !RegisterClass(&wc) )
    {
        msg_Err( vd, "DirectXCreateWindow RegisterClass FAILED (err=%lu)", GetLastError() );
        return VLC_EGENERIC;
    }

    /* When you create a window you give the dimensions you wish it to
     * have. Unfortunatly these dimensions will include the borders and
     * titlebar. We use the following function to find out the size of
     * the window corresponding to the useable surface we want */
    rect_window.left   = 10;
    rect_window.top    = 10;
    rect_window.right  = rect_window.left + p_event->wnd_cfg.width;
    rect_window.bottom = rect_window.top  + p_event->wnd_cfg.height;

    if( var_GetBool( vd, "video-deco" ) )
    {
        /* Open with window decoration */
        AdjustWindowRect( &rect_window, WS_OVERLAPPEDWINDOW|WS_SIZEBOX, 0 );
        i_style = WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE|WS_CLIPCHILDREN;
        i_stylex = 0;
    }
    else
    {
        /* No window decoration */
        AdjustWindowRect( &rect_window, WS_POPUP, 0 );
        i_style = WS_POPUP|WS_VISIBLE|WS_CLIPCHILDREN;
        i_stylex = 0; // WS_EX_TOOLWINDOW; Is TOOLWINDOW really needed ?
                      // It messes up the fullscreen window.
    }

    if( p_event->hparent )
    {
        i_style = WS_VISIBLE|WS_CLIPCHILDREN|WS_CHILD;
        i_stylex = 0;

        /* allow user to regain control over input events if requested */
        bool b_mouse_support = var_InheritBool( vd, "mouse-events" );
        bool b_key_support = var_InheritBool( vd, "keyboard-events" );
        if( !b_mouse_support && !b_key_support )
            i_style |= WS_DISABLED;
    }

    p_event->i_window_style = i_style;

    /* Create the window */
    p_event->hwnd =
        CreateWindowEx( WS_EX_NOPARENTNOTIFY | i_stylex,
                    p_event->class_main,             /* name of window class */
                    _T(VOUT_TITLE) _T(" (DirectX Output)"),  /* window title */
                    i_style,                                 /* window style */
                    (!p_event->wnd_cfg.x) ? CW_USEDEFAULT :
                        (UINT)p_event->wnd_cfg.x,   /* default X coordinate */
                    (!p_event->wnd_cfg.y) ? CW_USEDEFAULT :
                        (UINT)p_event->wnd_cfg.y,   /* default Y coordinate */
                    rect_window.right - rect_window.left,    /* window width */
                    rect_window.bottom - rect_window.top,   /* window height */
                    p_event->hparent,                       /* parent window */
                    NULL,                          /* no menu in this window */
                    hInstance,            /* handle of this program instance */
                    (LPVOID)p_event );           /* send vd to WM_CREATE */

    if( !p_event->hwnd )
    {
        msg_Warn( vd, "DirectXCreateWindow create window FAILED (err=%lu)", GetLastError() );
        return VLC_EGENERIC;
    }

    if( p_event->hparent )
    {
        LONG i_style;

        /* We don't want the window owner to overwrite our client area */
        i_style = GetWindowLong( p_event->hparent, GWL_STYLE );

        if( !(i_style & WS_CLIPCHILDREN) )
            /* Hmmm, apparently this is a blocking call... */
            SetWindowLong( p_event->hparent, GWL_STYLE,
                           i_style | WS_CLIPCHILDREN );

        /* Create our fullscreen window */
        p_event->hfswnd =
            CreateWindowEx( WS_EX_APPWINDOW, p_event->class_main,
                            _T(VOUT_TITLE) _T(" (DirectX Output)"),
                            WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN|WS_SIZEBOX,
                            CW_USEDEFAULT, CW_USEDEFAULT,
                            CW_USEDEFAULT, CW_USEDEFAULT,
                            NULL, NULL, hInstance, NULL );
    }
    else
    {
        p_event->hfswnd = NULL;
    }

    /* Append a "Always On Top" entry in the system menu */
    hMenu = GetSystemMenu( p_event->hwnd, FALSE );
    AppendMenu( hMenu, MF_SEPARATOR, 0, _T("") );
    AppendMenu( hMenu, MF_STRING | MF_UNCHECKED,
                       IDM_TOGGLE_ON_TOP, _T("Always on &Top") );

    /* Create video sub-window. This sub window will always exactly match
     * the size of the video, which allows us to use crazy overlay colorkeys
     * without having them shown outside of the video area. */
    /* FIXME vd->source.i_width/i_height seems wrong */
    p_event->hvideownd =
    CreateWindow( p_event->class_video, _T(""),   /* window class */
        WS_CHILD,                   /* window style, not visible initially */
        0, 0,
        vd->source.i_width,          /* default width */
        vd->source.i_height,        /* default height */
        p_event->hwnd,               /* parent window */
        NULL, hInstance,
        (LPVOID)p_event );    /* send vd to WM_CREATE */

    if( !p_event->hvideownd )
        msg_Warn( vd, "can't create video sub-window" );
    else
        msg_Dbg( vd, "created video sub-window" );

    /* Now display the window */
    ShowWindow( p_event->hwnd, SW_SHOW );

    return VLC_SUCCESS;
}
Exemple #30
0
/**
**  Initialize the video part for SDL.
*/
void InitVideoSdl()
{
	Uint32 flags = 0;

	if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
#ifndef USE_WIN32
		// Fix tablet input in full-screen mode
		SDL_putenv(strdup("SDL_MOUSE_RELATIVE=0"));
#endif
		int res = SDL_Init(
#ifdef DEBUG
					  SDL_INIT_NOPARACHUTE |
#endif
					  SDL_INIT_AUDIO | SDL_INIT_VIDEO |
					  SDL_INIT_TIMER);
		if (res < 0) {
			fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
			exit(1);
		}

		// Clean up on exit
		atexit(SDL_Quit);

#ifdef USE_MAEMO
		maemo_init();
#endif

		// If debug is enabled, Stratagus disable SDL Parachute.
		// So we need gracefully handle segfaults and aborts.
#if defined(DEBUG) && !defined(USE_WIN32)
		signal(SIGSEGV, CleanExit);
		signal(SIGABRT, CleanExit);
#endif
		// Set WindowManager Title
		if (!FullGameName.empty()) {
			SDL_WM_SetCaption(FullGameName.c_str(), FullGameName.c_str());
		} else if (!Parameters::Instance.applicationName.empty()) {
			SDL_WM_SetCaption(Parameters::Instance.applicationName.c_str(), Parameters::Instance.applicationName.c_str());
		} else {
			SDL_WM_SetCaption("Stratagus", "Stratagus");
		}

#if ! defined(USE_WIN32) && ! defined(USE_MAEMO)

#if defined(USE_OPENGL) || defined(USE_GLES)
		// Make sure, that we not create OpenGL textures (and do not call OpenGL functions), when creating icon surface
		bool UseOpenGL_orig = UseOpenGL;
		UseOpenGL = false;
#endif

		SDL_Surface *icon = NULL;
		CGraphic *g = NULL;
		struct stat st;

		std::string FullGameNameL = FullGameName;
		for (size_t i = 0; i < FullGameNameL.size(); ++i) {
			FullGameNameL[i] = tolower(FullGameNameL[i]);
		}

		std::string ApplicationName = Parameters::Instance.applicationName;
		std::string ApplicationNameL = ApplicationName;
		for (size_t i = 0; i < ApplicationNameL.size(); ++i) {
			ApplicationNameL[i] = tolower(ApplicationNameL[i]);
		}

		std::vector <std::string> pixmaps;
		pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameName + ".png");
		pixmaps.push_back(std::string() + PIXMAPS + "/" + FullGameNameL + ".png");
		pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameName + ".png");
		pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + FullGameNameL + ".png");
		pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationName + ".png");
		pixmaps.push_back(std::string() + PIXMAPS + "/" + ApplicationNameL + ".png");
		pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationName + ".png");
		pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + ApplicationNameL + ".png");
		pixmaps.push_back(std::string() + PIXMAPS + "/" + "Stratagus" + ".png");
		pixmaps.push_back(std::string() + PIXMAPS + "/" + "stratagus" + ".png");
		pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "Stratagus" + ".png");
		pixmaps.push_back(std::string() + "/usr/share/pixmaps" + "/" + "stratagus" + ".png");

		for (size_t i = 0; i < pixmaps.size(); ++i) {
			if (stat(pixmaps[i].c_str(), &st) == 0) {
				if (g) { CGraphic::Free(g); }
				g = CGraphic::New(pixmaps[i].c_str());
				g->Load();
				icon = g->Surface;
				if (icon) { break; }
			}
		}

		if (icon) {
			SDL_WM_SetIcon(icon, 0);
		}

		if (g) {
			CGraphic::Free(g);
		}

#if defined(USE_OPENGL) || defined(USE_GLES)
		UseOpenGL = UseOpenGL_orig;
#endif

#endif
#ifdef USE_WIN32
		HWND hwnd = NULL;
		HICON hicon = NULL;
		SDL_SysWMinfo info;
		SDL_VERSION(&info.version);

		if (SDL_GetWMInfo(&info)) {
			hwnd = info.window;
		}

		if (hwnd) {
			hicon = ExtractIcon(GetModuleHandle(NULL), Parameters::Instance.applicationName.c_str(), 0);
		}

		if (hicon) {
			SendMessage(hwnd, (UINT)WM_SETICON, ICON_SMALL, (LPARAM)hicon);
			SendMessage(hwnd, (UINT)WM_SETICON, ICON_BIG, (LPARAM)hicon);
		}
#endif
	}

	// Initialize the display

#ifdef USE_MAEMO
	// TODO: Support window mode and portrait mode resolution on Maemo - Nokia N900
	Video.FullScreen = 1;
	Video.Width = 800;
	Video.Height = 480;
#endif

#if !defined(USE_OPENGL) && !defined(USE_GLES)
	flags = SDL_HWSURFACE | SDL_HWPALETTE;
#endif

	// Sam said: better for windows.
	/* SDL_HWSURFACE|SDL_HWPALETTE | */
	if (Video.FullScreen) {
		flags |= SDL_FULLSCREEN;
	}

#if defined(USE_OPENGL) || defined(USE_GLES)
	if (UseOpenGL) {
#ifdef USE_GLES_NATIVE
		flags |= SDL_OPENGLES;
#endif
#ifdef USE_GLES_MAEMO
		if (SDL_GLES_Init(SDL_GLES_VERSION_1_1) < 0) {
			fprintf(stderr, "Couldn't initialize SDL_GLES: %s\n", SDL_GetError());
			exit(1);
		}

		// Clean up GLES on exit
		atexit(SDL_GLES_Quit);

		flags |= SDL_SWSURFACE;
#endif
#ifdef USE_OPENGL
		flags |= SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
#endif
	}
#endif

	if (!Video.Width || !Video.Height) {
		Video.Width = 640;
		Video.Height = 480;
	}

	if (!Video.Depth) {
		Video.Depth = 32;
	}

#if defined(USE_OPENGL) || defined(USE_GLES)
	if (!Video.ViewportWidth || !Video.ViewportHeight) {
		Video.ViewportWidth = Video.Width;
		Video.ViewportHeight = Video.Height;
	}
	TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, Video.Depth, flags);
#else
	TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, Video.Depth, flags);
#endif
	if (TheScreen && (TheScreen->format->BitsPerPixel != 16
					  && TheScreen->format->BitsPerPixel != 32)) {
		// Only support 16 and 32 bpp, default to 16
#if defined(USE_OPENGL) || defined(USE_GLES)
		TheScreen = SDL_SetVideoMode(Video.ViewportWidth, Video.ViewportHeight, 16, flags);
#else
		TheScreen = SDL_SetVideoMode(Video.Width, Video.Height, 16, flags);
#endif
	}
	if (TheScreen == NULL) {
		fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n",
				Video.Width, Video.Height, Video.Depth, SDL_GetError());
		exit(1);
	}

	Video.FullScreen = (TheScreen->flags & SDL_FULLSCREEN) ? 1 : 0;
	Video.Depth = TheScreen->format->BitsPerPixel;

#if defined(USE_TOUCHSCREEN) && defined(USE_WIN32)
	// Must not allow SDL to switch to relative mouse coordinates
	// with touchscreen when going fullscreen. So we don't hide the
	// cursor, but instead set a transparent 1px cursor
	Uint8 emptyCursor[] = {'\0'};
	Video.blankCursor = SDL_CreateCursor(emptyCursor, emptyCursor, 1, 1, 0, 0);
	SDL_SetCursor(Video.blankCursor);
#else
	// Turn cursor off, we use our own.
	SDL_ShowCursor(SDL_DISABLE);
#endif

	// Make default character translation easier
	SDL_EnableUNICODE(1);

#if defined(USE_OPENGL) || defined(USE_GLES)
	if (UseOpenGL) {
#ifdef USE_GLES_MAEMO
		SDL_GLES_Context *context = SDL_GLES_CreateContext();
		if (!context) {
			fprintf(stderr, "Couldn't initialize SDL_GLES_CreateContext: %s\n", SDL_GetError());
			exit(1);
		}
		if (SDL_GLES_MakeCurrent(context) < 0) {
			fprintf(stderr, "Couldn't initialize SDL_GLES_MakeCurrent: %s\n", SDL_GetError());
			exit(1);
		}
		// atexit(GLES_DeleteContext(context));
#endif
#ifdef USE_GLES_EGL
		// Get the SDL window handle
		SDL_SysWMinfo sysInfo; //Will hold our Window information
		SDL_VERSION(&sysInfo.version); //Set SDL version
		if (SDL_GetWMInfo(&sysInfo) <= 0) {
			fprintf(stderr, "Unable to get window handle\n");
			exit(1);
		}

		eglDisplay = eglGetDisplay((EGLNativeDisplayType)sysInfo.info.x11.display);
		if (!eglDisplay) {
			fprintf(stderr, "Couldn't open EGL Display\n");
			exit(1);
		}

		if (!eglInitialize(eglDisplay, NULL, NULL)) {
			fprintf(stderr, "Couldn't initialize EGL Display\n");
			exit(1);
		}

		// Find a matching config
		EGLint configAttribs[] = {EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE};
		EGLint numConfigsOut = 0;
		EGLConfig eglConfig;
		if (eglChooseConfig(eglDisplay, configAttribs, &eglConfig, 1, &numConfigsOut) != EGL_TRUE || numConfigsOut == 0) {
			fprintf(stderr, "Unable to find appropriate EGL config\n");
			exit(1);
		}

		eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (EGLNativeWindowType)sysInfo.info.x11.window, 0);
		if (eglSurface == EGL_NO_SURFACE) {
			fprintf(stderr, "Unable to create EGL surface\n");
			exit(1);
		}

		// Bind GLES and create the context
		eglBindAPI(EGL_OPENGL_ES_API);
		EGLint contextParams[] = {EGL_CONTEXT_CLIENT_VERSION, 1, EGL_NONE};
		EGLContext eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL);
		if (eglContext == EGL_NO_CONTEXT) {
			fprintf(stderr, "Unable to create GLES context\n");
			exit(1);
		}

		if (eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext) == EGL_FALSE) {
			fprintf(stderr, "Unable to make GLES context current\n");
			exit(1);
		}
#endif
		InitOpenGL();
	}
#endif

	InitKey2Str();

	ColorBlack = Video.MapRGB(TheScreen->format, 0, 0, 0);
	ColorDarkGreen = Video.MapRGB(TheScreen->format, 48, 100, 4);
	ColorLightBlue = Video.MapRGB(TheScreen->format, 52, 113, 166);
	ColorBlue = Video.MapRGB(TheScreen->format, 0, 0, 252);
	ColorOrange = Video.MapRGB(TheScreen->format, 248, 140, 20);
	ColorWhite = Video.MapRGB(TheScreen->format, 252, 248, 240);
	ColorLightGray = Video.MapRGB(TheScreen->format, 192, 192, 192);
	ColorGray = Video.MapRGB(TheScreen->format, 128, 128, 128);
	ColorDarkGray = Video.MapRGB(TheScreen->format, 64, 64, 64);
	ColorRed = Video.MapRGB(TheScreen->format, 252, 0, 0);
	ColorGreen = Video.MapRGB(TheScreen->format, 0, 252, 0);
	ColorYellow = Video.MapRGB(TheScreen->format, 252, 252, 0);

	UI.MouseWarpPos.x = UI.MouseWarpPos.y = -1;
}