//topic:
How to use Visual C to compile only 1536 bytes of window programs
// These skills are
Dreamtheater
The old big brother told me ... // After compiling, the file size is: 1536 bytes / / pretreatment
#include
// Use the following pretreatment, must be a release method when compiling connections, otherwise you cannot pass // to customize the program entry, if you want to optimize, you can use this // If you use vs.net, you can set it: "Solve The program manager is selected, right-click, select "Properties" -> "Limited" -> "Advanced" -> "Entry Point" // VC 6 also has similar settings, but don't remember // Other settings for project properties can be taken carefully, and other optimizations can be set here.
#pragma comment (Linker, "/ Entry: entrypoint")
/ / The following is the adjustment segment alignment, the default is 4K, can be loaded into the PE file faster in Win98, but will increase the size of the PE file // This line seems to be "invalid instructions", Therefore, it is also commented here, perhaps the reason for the paragraph is too small. / / Directly set directly in the project option: Item Properties -> "Limited" -> "Optimization" -> "Windows98 Optimization" -> "No (/ Opt: NOWIN98)" // # Pragma Comment (Linker, " / Opt: noin98 ") // The following optimization is the merger, not recommended, may not be used in many programs.
#pragma comment (Linker, "/ Section: MINIPE,") // Creating custom MINIPE Section
#pragma comment (Linker, "/merge:.data=minipe") // Merge.Data section to Minipe Section
#pragma comment (Linker, "/merge:.text=minipe") // Merge .Text Section to MINIPE Section
#pragma comment (Linker, "/merge:.rdata=minipe") // Merge. RData Section to Minipe Section
// Global variable
HWND G_HWND; // Main window handle, this variable is often used in general procedures, so use global variables
Hinstance g_hinst; // application process handle, this variable is often used in general programs, so use global variables
Const char c_szappname [] = "minipe";
// Function declaration
LResult Callback WindowProc (HWND HWND, UINT UMSG, WPARAM WPARAM, LPARAM LPARAM);
Int WinApi WinMain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT ICMDSHOW);
// Entrance function // use our own entry function, without using a large number of programs initialized by the connector to initialize the operation, in order to use this method in a normal Win32SDK program, the following functions will call WinMain () Function, and give the corresponding parameter void access ()
{
EXITPROCESS (WinModuleHandle (NULL), NULL, GETCOMMANDLINE (), SW_SHOWNORMAL);
}
// master function
Int WinApi Winmain (Hinstance Hinstance, Hinstance Hprevinstance, LPSTR LPCMDLINE, INT ICMDSHOW)
{
MSG SMSG;
WNDCLASSEX SWNDCLASSEX;
g_hinst = hinstance;
SWNDCLASSEX.CBSIZE = SizeOf (WNDCLASSEX);
SWNDCLASSEX.Style = CS_VREDRAW | CS_HREDRAW;
SWNDCLASSEX.LPFNWNDPROC = (WNDPROC) WindowProc;
SWNDCLASSEX.CBCLSEXTRA = 0;
SWNDCLASSEX.CBWNDEXTRA = 0;
SWNDCLASSEX.HINSTANCE = g_hinst;
SWNDCLASSEX.HICON = Loadicon (NULL, IDI_Application);
SWNDCLASSEX.HCURSOR = LoadCursor (NULL, IDC_ARROW);
SWNDCLASSEX.HBRBACKGROUND = (HBRUSH) (color_window);
SWNDCLASSEX.LPSZMENUNAME = NULL;
SWNDCLASSEX.LPSZCLASSNAME = C_SZAPNAME;
SWNDCLASSEX.HICONSM = NULL;
RegisterClassex (& SWNDCLASSEX);
g_hwnd = CreateWindowEx (0, c_szappname, c_szappname, ws_overlappedwindow,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, G_HINST, NULL;
ShowWindow (g_hwnd, icmdshow);
UpdateWindow (G_HWND);
While (GetMessage (& SMSG, NULL, 0, 0))
{
TranslateMessage (& SMSG);
DispatchMessage (& SMSG);
}
Return ((int) smsg.wparam;
}
// Main window callback function
Lresult Callback WindowProc (HWND HWND, UINT UMSG, WPARAM WPARAM, LPARAM LPARAM)
{
Switch (UMSG)
{
Case WM_DESTROY:
PostquitMessage (0);
Break;
DEFAULT:
Return (DEFWindowProc (HWND, UMSG, WPARAM, LPARAM);
}
Return (0);
}