| ■No85433 (K-1 さん) に返信 > Private Sub ddsView(ByRef temp_dds_name As String) 何故 ByRef に?
確かに GetPicture API の引数は LPCSTR ではなく LPSTR ですが、 だからといって、呼び出し元にその結果を返す意味が思い当たりませんでした。
> Private Declare Function LocalFree Lib "kernel32" (ByVal MemHandle As IntPtr) As Integer 何故 Integer 型に?
関数が失敗したときは、引数の値がそのまま返却される仕様だったはずなので、 引数と戻り値の型が異なるのは、すごく違和感があります。
> Dim LocalMemoryBMP As Long 何故 Long 型に?
他にも幾つか、暗黙の型変換で隠されている点がありますので、 「Option Strict On」にしておいたほうが良いですよ。
> ByVal CallBack As IntPtr 本来は ProgressCallback への Delegate にするべきではありますが、 どうせ使わないのなら IntPtr でも良いですね。
> Dim gp As Graphics = Picture1.CreateGraphics 'フォームのGraficsを作成 Dispose が漏れています。Using ブロックで囲みましょう。
> Dim hDC As IntPtr = gp.GetHdc() 'そのデバイスコンテキストを取得 ReleaseHdc メソッドも呼ばれていないようですが…。
> Picture1.Refresh() 'ピクチャーボックス更新 Refresh しているのは何故ですか?
Imports System.Runtime.InteropServices Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using bmp = Me.Icon.ToBitmap() Using g = PictureBox1.CreateGraphics() g.DrawImage(bmp, Point.Empty) End Using Using g = PictureBox2.CreateGraphics() g.DrawImage(bmp, Point.Empty) End Using Using g = PictureBox3.CreateGraphics() g.DrawImage(bmp, Point.Empty) End Using Using g = PictureBox4.CreateGraphics() g.DrawImage(bmp, Point.Empty) End Using 'PictureBox1 : 何もしない PictureBox2.Refresh() PictureBox3.Invalidate() PictureBox4.Update() End Using End Sub End Class
もし、PictureBox に表示することが目的なのであれば、 CreateGraphics するのではなく、 New Bitmap(w, h) で生成したビットマップを Graphics.FromImage して描画し、最後に PictureBox1 の BackgroundImage か Image に セットする形でも良いかも知れません。 |