111,126
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Drawing;
using System.Windows.Forms;
class Entry
{
static Form form1, form2;
public static void Main()
{
form1 = new Form();
form2 = new Form();
form1.Text = "First Form";
form1.BackColor = Color.White;
form1.Paint += new PaintEventHandler( MyPaintHandler );
form2.Text = "Second Form";
form2.BackColor = Color.White;
form2.Paint += new PaintEventHandler( MyPaintHandler );
form2.Show();
Application.Run( form1 );
}
static void MyPaintHandler( object sender, PaintEventArgs e )
{
Form form = (Form)sender;
Graphics grfx = e.Graphics;
string str;
if( form == form1 )
{
str = "hello from the first form";
}
else
{
str = "hello from the second form";
}
grfx.DrawString( str, form.Font, Brushes.Black, 0, 0 );
}
}//最简单的Windows程序
#define WINDOW_CLASS "StrandedGame" // 窗口类名
#define WINDOW_NAME "Stranded" // 窗口名
#define WIN_WIDTH 800 // 初始窗口宽度
#define WIN_HEIGHT 600 // 初始窗口高度
#include <windows.h>
// 窗口处理函数
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
// 设计窗口类
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, (HBRUSH)(COLOR_WINDOW+1), NULL,
WINDOW_CLASS, NULL };
// 注册窗口类
RegisterClassEx( &wc );
// 创建窗口
HWND hWnd = CreateWindow( WINDOW_CLASS, WINDOW_NAME,
WS_OVERLAPPEDWINDOW, 0, 0, WIN_WIDTH, WIN_HEIGHT,
NULL, NULL, wc.hInstance, NULL );
// 显示窗口
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// 消息循环(消息被转化以后,由窗口处理函数处理)
MSG msg;
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// 取消窗口注册
UnregisterClass( "D3D Tutorial", wc.hInstance );
return 0;
}
// 消息处理
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
// 消息处理
switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
Application.Run就相当于
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}