スクリーンコピー&ファイルリスト

索引サイト

たぶんファイル一覧で最も簡単な方法↓




private void button1_Click(object sender, RoutedEventArgs e)
{
string[] files = System.IO.Directory.GetFiles(@"h:\png-TEST", "*", System.IO.SearchOption.AllDirectories);
foreach (string w_fileName in files)
{
listBox1.Items.Add(w_fileName);
}
}

スクリーンコピー↓(参考箇所、行方不明)




internal class NativeMethods
{
[DllImport("user32.dll")]
public extern static IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hwnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("gdi32.dll")]
public static extern UInt64 BitBlt(IntPtr hDestDC, int x, int y,int nWidth, int nHeight, IntPtr hSrcDC,int xSrc, int ySrc, System.Int32 dwRop);
}
public void CaptureScreen(double p_x, double p_y, double p_width, double p_height)
{
int w_int_x, w_int_y, w_int_w, w_int_h;

w_int_x = Convert.ToInt32(p_x);
w_int_y = Convert.ToInt32(p_y);
w_int_w = Convert.ToInt32(p_width);
w_int_h = Convert.ToInt32(p_height);

Bitmap w_image = new Bitmap(w_int_w, w_int_h, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics w_Graphics = Graphics.FromImage(w_image);
w_Graphics.CopyFromScreen(w_int_x, w_int_y, w_int_x, w_int_y, new System.Drawing.Size(w_int_w, w_int_h), CopyPixelOperation.SourceCopy);
w_Graphics.Dispose();

string w_fileName = "image" + String.Format("{0:yyyyMMdd-hhmmss}", DateTime.Now) + ".png";
w_image.Save(w_fileName, ImageFormat.Png);

System.Windows.MessageBox.Show("画面を保存しました。--> " + w_fileName);
}



AX