API创建窗口,程序体积缩小到4KB---
VC2008-VC2013只要重新定义函数入口程序体积马上下降-
#include <windows.h>
#pragma comment(linker, "/ENTRY:EntryPoint") //定义入口函数
//窗口回调函数
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM Lparar);
//窗口WinMain函数
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd);
void EntryPoint()
{
//中止一个进程
ExitProcess(WinMain(GetModuleHandle(NULL), NULL, (LPSTR)GetCommandLine(), SW_SHOWNORMAL));
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
HWND hWnd;//窗口句柄
MSG sMsg;//消息结构
WNDCLASSEX sWndClassEx;//窗口类结构
/*=========================================*/
sWndClassEx.cbSize = sizeof(sWndClassEx);//获取结构大小赋值
sWndClassEx.style = CS_VREDRAW | CS_HREDRAW;//窗口重绘风格 垂直 水平
sWndClassEx.lpfnWndProc = (WNDPROC)WndProc;//回调函数
sWndClassEx.cbClsExtra = 0;
sWndClassEx.cbWndExtra = 0;
sWndClassEx.hInstance = hInstance;
sWndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);//图标
sWndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);//鼠标指针
sWndClassEx.hbrBackground = (HBRUSH)(COLOR_WINDOW);//背景
sWndClassEx.lpszMenuName = NULL;
sWndClassEx.lpszClassName = TEXT("MiniWinGUI");
sWndClassEx.hIconSm = NULL;
if (RegisterClassEx(&sWndClassEx))
{
hWnd = CreateWindowEx(0, TEXT("MiniWinGUI"), TEXT("MiniWinGUI"), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
}
if (!hWnd)
{
return 0;
}
ShowWindow(hWnd, nShowCmd);//显示窗口
UpdateWindow(hWnd);//刷新窗口
//消息循环
while (GetMessage(&sMsg, NULL, 0, 0))
{
TranslateMessage(&sMsg);
DispatchMessage(&sMsg);
}
return((int)sMsg.wParam);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_DESTROY)//窗口销毁
{
PostQuitMessage(0);
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
感谢楼主的分享!!!!! {:7_126:} LZ您知道这样做的具体原理是什么呢?为什么微软不这么用呢?
求高人指点!
页:
[1]