D Paste by dazoe
Description: useing Graphics and MemoryGraphics to screenshot
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
class MyForm : Form {
    Button btn;
    PictureBox pb;
    
    this() {
        initializeMyForm();
    }
    private void initializeMyForm() {
        text = "My Form";
        clientSize = Size(292, 273);

        btn = new Button();
        btn.parent(this);
        btn.text("Click ME");
        btn.dock(DockStyle.TOP);
        btn.click ~= &btn_click;
        
        pb = new PictureBox();
        pb.parent(this);
        pb.dock(DockStyle.FILL);
    }
    private void btn_click(Control sender, EventArgs ea) {
        HWND hWnd = FindWindowExA(cast(HWND)0, cast(HWND)0, null, toStringz("WINDOW TO FIND.")); //or 0 for desktop...
        writefln("HWND = %d", hWnd);
        Graphics g = MemoryGraphics.fromHwnd(hWnd);
        MemoryGraphics mg = new MemoryGraphics(1024,768);
        g.copyTo(mg, 0,0,100,100);
        Bitmap bmp = mg.toBitmap(mg);
        pb.image(bmp);
    }
}

Replies:
Reply by QaIysMNkj
Your post captures the issue pefretcly!

    (some replies deleted)