|
本帖最后由 lxl1638 于 2011-6-9 16:50 编辑
附件内的 VC2005_TEST.VCPROJ 是 VC2005 的工程文件,已设置好了X86、X64编译选项,
当然也可以用VC2008、VC2010打开;
附件内的 VC2010_TEST.VCXPROJ 是 VC2010 的工程文件,也设置好了X86、X64编译选项;
MSVCRT-X86.LIB、MSVCRT-X64.LIB就是VC++安装目录中的MSVCRT.LIB,本人改了文件名,
前者是Win32版本(来自VC6),后者是Win64版本(记不起VC2005的还是VC2010的,都可用)。
链接这两个MSVCRT.LIB,EXE文件不需要msvcrXXXX.dll,体积也减小了,本例程源码编译
出的X86、X64版的EXE都只有2、3K。
BIN.rar
(1.98 KB, 下载次数: 6732)
EXE
核心源码:
- //////////////////////////////////////////////////////////////////////////////////////////
- #pragma comment(linker, "/ENTRY:EntryPoint")
- #pragma comment(linker, "/MERGE:.rdata=.text")
- #if defined(_M_X64)
- #pragma comment(lib, "MSVCRT-X64.LIB")
- //#define NTDWORD DWORD_PTR
- //#define PDWORD_PTR PNTDWORD
- #else
- #pragma comment(lib, "MSVCRT-X86.LIB")
- //#define NTDWORD DWORD
- //#define PDWORD PNTDWORD
- #endif
- #pragma comment(lib, "Comctl32.lib")
- #include <Windows.h>
- #include <CommCtrl.h>
- #define WINDOW_STYLE (WS_VISIBLE|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX)
- #define CHILD_STYLE (WS_VISIBLE|WS_CHILD)
- #define STATIC_STYLE (CHILD_STYLE|BS_TEXT)
- #define BUTTON_STYLE (STATIC_STYLE|BS_PUSHLIKE)
- #define STR_MessageBoxW TEXT("MessageBoxW")
- #define STR_TEST TEXT("TEST")
- //////////////////////////////////////////////////////////////////////////////////////////////////
- HINSTANCE g_hInst = NULL;
- //////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////
- HWND NewWindow(PCTSTR Caption,UINT Left,UINT Top,UINT Width,UINT Height,HWND hParent, HFONT hFONT,DWORD dwStyle)
- {
- HWND _hNewWindowBox = CreateWindow(TEXT("Button"),
- Caption,
- dwStyle,
- Left, Top, Width, Height,
- hParent,
- NULL,
- g_hInst,
- NULL);
- if (_hNewWindowBox)
- {
- SendMessage(_hNewWindowBox, WM_SETFONT, (WPARAM)hFONT, 0);
- }
- return _hNewWindowBox;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////
- HWND NewButton(PCTSTR Caption,UINT Left,UINT Top,UINT Width,UINT Height,HWND hParent, HFONT hFONT,CONST DWORD uAddStyle = 0)
- {
- return NewWindow(Caption,Left,Top,Width,Height,hParent,hFONT,BUTTON_STYLE|uAddStyle);
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////
- LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- static HWND hButton = NULL;
- switch (uMsg)
- {
- case WM_CREATE:
- {
- HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
- hButton = NewButton(STR_MessageBoxW,52,32,100,28,hWnd,hFont);
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- case WM_COMMAND:
- if ((HWND)lParam == hButton)
- {
- MessageBoxW(hWnd,STR_MessageBoxW,STR_TEST,MB_OK);
- }
- break;
- default:
- return DefWindowProc(hWnd, uMsg, wParam, lParam);
- }
- return S_OK;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////
- HWND AppWindow(PCTSTR AppName,UINT Width,UINT Height,WNDPROC WndProc)
- {
- WNDCLASSEX sWndClassEx ={0};
- sWndClassEx.cbSize = sizeof(WNDCLASSEX);
- sWndClassEx.style = (CS_VREDRAW | CS_HREDRAW);
- sWndClassEx.lpfnWndProc = WndProc;
- sWndClassEx.hInstance = g_hInst;
- sWndClassEx.hCursor = LoadCursor(0, IDC_ARROW);
- sWndClassEx.hbrBackground = (HBRUSH)(COLOR_BTNSHADOW);
- sWndClassEx.lpszClassName = (LPCWSTR)AppName;
- if (RegisterClassEx(&sWndClassEx))
- {
- UINT x,y;
- x = (GetSystemMetrics(SM_CXSCREEN) - Width)/2;
- y = (GetSystemMetrics(SM_CYSCREEN) - Height)/2;
- return CreateWindow(AppName,
- AppName,
- WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
- x,y,
- Width,Height,
- NULL, NULL,
- g_hInst, NULL);
- }
- else
- {
- return NULL;
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////////////////
- INT WINAPI EntryPoint(HINSTANCE hInstance,HINSTANCE hPrevInstance,PTSTR lpCmdLine,INT nShowCmd)
- {
- if (AppWindow(STR_TEST,200,120,WindowProc))
- {
- MSG sMsg;
- while (GetMessage(&sMsg, NULL, 0, 0))
- {
- TranslateMessage(&sMsg);
- DispatchMessage(&sMsg);
- }
- }
- return S_OK;
- }
- //////////////////////////////////////////////////////////////////////////////////////////
复制代码 |
|