我在C#Visual Studio 2010中有这些行:
IntPtr a = new IntPtr(10);
IntPtr b = a + 10;
Run Code Online (Sandbox Code Playgroud)
它说:
运算符'+'不能应用于'System.IntPtr'和'int'类型的操作数.
我创建了一个在某些目录中搜索某些文件的应用程序.当一个目录不存在时,它会抛出DirectoryNotFoundException.我捕获了该异常,但它没有DirectoryName属性或像FileNotFoundException(FileName)那样的东西.如何从例外属性中找到目录名称?
我想制作一个小应用程序来更改 Windows 7 中的默认播放设备。唯一的解决方案是与声音小程序交互。我成功获取了包含设备名称的 SysListView32 窗口的句柄,但无法从 ListView 获取文本。
这是使用的代码:
IntPtr sListView = (window handle received from another function)
LVITEM lvi = new LVITEM();
lvi.mask = LVIF_TEXT;
lvi.cchTextMax = 1024;
lvi.iItem = 0; // i tried with a loop trought all the items
lvi.iSubItem = 0;
lvi.pszText = Marshal.AllocHGlobal(1024);
IntPtr ptrLvi = Marshal.AllocHGlobal(Marshal.SizeOf(lvi));
Marshal.StructureToPtr(lvi, ptrLvi, false);
SendMessage(sListView, (int)WinMesages.LVM_GETITEMW, IntPtr.Zero, ptrLvi);
string strLvi = Marshal.PtrToStringAuto(lvi.pszText);
Run Code Online (Sandbox Code Playgroud)
结果(strLvi)是一些中文字母。脚本中有什么问题?
更新: LVITEM 结构是这样的:
private struct LVITEM
{
public uint mask;
public int iItem;
public int …Run Code Online (Sandbox Code Playgroud) 我有这个代码:
$im = imagecreatetruecolor(70, 25);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, imagecolorallocate($im, 0,0,0));
$font = 'font.ttf';
imagettftext($im, 20, 0, 3, 22, $white, $font, $randomnr);
header("Expires: Wed, 1 Jan 1997 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header ("Content-type: image/png");
imagepng($im);
imagedestroy($im);
Run Code Online (Sandbox Code Playgroud)
就像我在标题中所说的,它会在文本周围创建一些黑色边缘.我也试过imagealphablending/ imagesavealpha和我有相同的结果(我在透明背景上使用白色文字,以便你可以看到我在说什么):

更新:解决方案是:
$im = imagecreatetruecolor(70, …Run Code Online (Sandbox Code Playgroud) 我有一个复杂的数组,类似这样:
Array {
k1 => text1
k2 => Array {
k3 =>text2
k4 => Array {
k5 => text3
}
k6 => text4
}
}
Run Code Online (Sandbox Code Playgroud)
我想回显该数组,但要缩进每个子数组,如下所示:
key: k1 >> value: text1
Array key: k2 >> values:
key: k3 >> value: text2
Array key: k4 >> values:
key: k5 >> value: text3
key: k6 >> value: text4
Run Code Online (Sandbox Code Playgroud)
如果您需要任何详细信息,请告诉我。
c# ×3
php ×2
addition ×1
arrays ×1
exception ×1
imagettftext ×1
int ×1
intptr ×1
listviewitem ×1
marshalling ×1
sendmessage ×1
text-indent ×1