coreBugZJ

此 blog 已弃。

C# 调用SDK API

代码运行效果。




第一次写C#,可能有问题。


 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 
10 using System.Runtime.InteropServices; // 增加
11 
12 
13 namespace FirstCs
14 {
15         public partial class Form1 : Form
16         {
17                 public Form1()
18                 {
19                         InitializeComponent();
20                         this.Paint += new PaintEventHandler(Form1_Paint); // 增加
21                 }
22 
23                 // 增加 响应绘制
24                 void Form1_Paint(object sender, PaintEventArgs e)
25                 {
26                         IntPtr hdc = e.Graphics.GetHdc();
27                         TextOut(hdc, 5050"12345"5);
28                         Rectangle(hdc, 7070200200);
29                         e.Graphics.ReleaseHdc( hdc );
30                 }
31 
32                 // 增加 API 函数声明 begin
33                 [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
34                 private static extern bool TextOut(IntPtr hdc, int nXStart, int nYStart, string lpString, int cbString);
35 
36                 [DllImport("gdi32.dll", CharSet = CharSet.Auto)]
37                 private static extern bool Rectangle(IntPtr hdc, int le, int to, int ri, int bo);
38                 // end
39 
40                 private void button1_Click(object sender, EventArgs e)
41                 {
42                         MessageBox.Show("FirstBtn");
43                 }
44         }
45 }
46 

posted on 2011-06-22 20:43 coreBugZJ 阅读(609) 评论(0)  编辑 收藏 引用 所属分类: Windows课内作业


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理