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

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 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());
        }

    }

}