惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园_首页
WordPress大学
WordPress大学
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
酷 壳 – CoolShell
酷 壳 – CoolShell
Y
Y Combinator Blog
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
博客园 - 司徒正美
Engineering at Meta
Engineering at Meta
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
G
Google Developers Blog
Last Week in AI
Last Week in AI

博客园 - Phoenix

Server Explorer disappeared in VS 2008 如何在外部得到一个event是否已被注册 FlashGet的堕落 画一个立体的柱图 - Phoenix - 博客园 SQL2000自动备份数据库到远程机器 Vista: user does not have administrative privileges in command prompt mode. 将一个域中的MS CRM数据库部署到另外一个域中 求救手工设置笔记本IRQ的方法 Windows下安装SQLPlus的帮助 Oracle Listener报“TNSLSNR.exe 应用程序错误” 正则表达式超时 [导入]不使用COM组件弹出数据库连接对话框 [导入]C#: 通过动态编译获取字符串所表达的值 [导入]Asp.Net中连接Oracle [导入]全角字符的匹配 [导入]使用.Net获取OLEDB数据库的架构. [导入]使用C#在进度条中显示复制文件的进度 [导入]在SQL Server2000中修改系统表 [导入]已经毕业3个月了,怀念大学生活啊。。。
用纯API写的窗体
Phoenix · 2006-02-10 · via 博客园 - Phoenix

无聊的时候在.Net下用API写了一个Window窗户.
简单比较了一下,纯API的窗体运行启动要快点,起始占用内存也少点,大概6M,但比起用asm创建的一般才2M多点还是看得出.Net确实是吃内存的大户啊.^_^

代码

/*    Snippet Compiler
*    Author : Phoenix Chen    
*    Date   : 2006-02-10
*    Comment:
*/

using System;
using System.Runtime.InteropServices;

namespace CzG
{
    
public class MyClass
    
{
        
static IntPtr hInstance;
        
static IntPtr hWinMain;
        
static string strAppName;
        
static string strClassName;
        
        
public static void Main()
        
{
            WinMain();
        }

        
        
// Initialize Window
        public static void WinMain()
        
{
            strAppName         
= "API Window";
            strClassName     
= "MyClass";
            
            
// Get Application Module Handle
            
// API : GetModuleHandle
            hInstance = Marshal.GetHINSTANCE(typeof(MyClass).Assembly.GetModules()[0]);
            
            WinAPI.WNDCLASSEX wndClass 
= new WinAPI.WNDCLASSEX();
            wndClass.cbSize 
= Marshal.SizeOf(wndClass);
            wndClass.style 
= 3;//CS_HREDRAW | CS_VREDRAW;
            wndClass.lpfnWndProc = new WindowProc(WndProc); // using Marshal.GetFunctionPointerForDelegate to get a delegate's handle in .Net Framework 2.0
            wndClass.hInstance = hInstance;
            wndClass.hIcon 
= WinAPI.LoadIcon(IntPtr.Zero,32512); // IDI_APPLICATION , MAKEINTRESOURCE macro in C++ converts a WORD to DWORD
            wndClass.hCursor = WinAPI.LoadCursor(IntPtr.Zero,32512); // IDC_ARROW
            wndClass.hbrBackground = 6//COLOR_WINDOWFRAME 
            wndClass.lpszClassName = strClassName;
            
            
if(WinAPI.RegisterClassEx(ref wndClass) == 0)
            
{
                
return;
            }

            
            
// Create & Display Window
            
//                                 WS_EX_CLIENTEDGE              WS_DLGFRAME
            hWinMain = WinAPI.CreateWindowEx(0x200,strClassName,strAppName,WS_OVERLAPPEDWINDOW ,100,100,400,300,0,0,hInstance,0);
            
            WinAPI.ShowWindow(hWinMain,
1); //SW_SHOWNORMAL
            WinAPI.UpdateWindow(hWinMain);
            
            
// Message loop
            WinAPI.MSG msg = new WinAPI.MSG();
            
while(true)
            
{
                
if(!WinAPI.GetMessage(ref msg,0,0,0))
                
{
                    
break;
                }

                
                WinAPI.TranslateMessage(
ref msg);
                WinAPI.DispatchMessage(
ref msg);
            }

        }

        
        
// Window Procedure
        public static int WndProc(IntPtr hWnd,uint uMsg,int wParam,int lParam)
        
{
            
switch(uMsg)
            
{
                
case 0x10// WM_CLOSE
                    WinAPI.DestroyWindow(hWinMain);
                    WinAPI.PostQuitMessage(
0);
                    
break;
                
default:
                    
return WinAPI.DefWindowProc(hWnd,uMsg,wParam,lParam);
            }

            
return 0;
        }

    
public const int WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);    
    
public const int WS_MAXIMIZEBOX = 0x10000;
    
public const int WS_MINIMIZEBOX = 0x20000;
    
public const int WS_SYSMENU = 0x80000;
    
public const int WS_OVERLAPPED = 0x0;
    
public const int WS_THICKFRAME = 0x40000;
    
public const int WS_CAPTION = 0xC00000;

    }

    
    
public delegate int WindowProc(IntPtr hWnd,uint uMsg,int wParam,int lParam);

    
public class WinAPI
    
{
        
Structures
        
        
WINAPIs 
    }

}

.Net下的代码

/*    Snippet Compiler
*    Author : Phoenix Chen    
*    Date   :
*    Comment:
*/

using System;
using System.Windows.Forms;

namespace CzG
{
    
public class MyClass : Form
    
{
        
public MyClass()
        
{
            
this.Text = ".Net Window";
        }

        
public static void Main()
        
{
            Application.Run(
new MyClass());
        }

    }

}