1、
“{$O-}”关闭优化
“{$O-}”打开优化
2、
unit NativeWindow;interfaceuses Windows, Messages, SysUtils;procedure CreateWindow;implementationfunction ProcWindow(_hWnd :HWND; _uMsg :UINT; _wParam :WPARAM; _lParam :LPARAM):longint;stdcall;var hDc1 :HDC; ps :PAINTSTRUCT;begin if (_uMsg = WM_LBUTTONUP) then begin MessageBox(0, 'Up', '1', 0); end else if (_uMsg = WM_PAINT) then begin hDc1 := BeginPaint(_hWnd, ps); TextOut(hDc1, 0, 0, 'ASDFG zxcvb', strlen('ASDFG zxcvb')); EndPaint(_hWnd, ps); Result := 0; Exit; end else if (_uMsg = WM_DESTROY) then begin DestroyWindow(_hwnd); PostQuitMessage(0); Result := 0; Exit; end; Result := DefWindowProc(_hWnd, _uMsg, _wParam, _lParam);end;{ $O-}procedure CreateWindow;var wndcls :WNDCLASS; hInstance :THandle; hWnd1 :HWND; iErr :integer;begin hInstance := Windows.GetModuleHandle(nil); ZeroMemory(@wndcls, sizeof(wndcls)); wndcls.cbClsExtra := 0; wndcls.cbWndExtra := 0; wndcls.hbrBackground := HBRUSH(GetStockObject(WHITE_BRUSH)); // 背景画刷 wndcls.hCursor := LoadCursor(0, IDC_CROSS); wndcls.hIcon := LoadIcon(0, IDI_ERROR); // 窗口图标 wndcls.hInstance := hInstance; wndcls.lpfnWndProc := @ProcWindow; wndcls.lpszClassName:= 'zc20110929'; wndcls.lpszMenuName := nil; wndcls.style := CS_HREDRAW or CS_VREDRAW; RegisterClass(wndcls); hWnd1 := CreateWindowEx( WS_EX_CLIENTEDGE, wndcls.lpszClassName, 'ZC Window', WS_OVERLAPPEDWINDOW, 100, 100, 400, 300, 0, 0, //g_hMenu, hInstance, 0); if (hWnd1 = 0) then iErr := GetLastError;// ShowWindow(hWnd1, SW_SHOWNORMAL); UpdateWindow(hWnd1);end;{ $O+}end.
3、