zwz_good  

program HelloWin;

uses
  Windows, SysUtils, Messages, MMSystem;

function WndProc(HWindow: HWND; message, wParam, lParam: Longint): Longint; stdcall;
var
  hdc1: HDC;
  ps1: PAINTSTRUCT;
  rect: TRECT;
begin
  Result:= 0; //很重要
  case message of
    WM_CREATE:
    begin
      PlaySound('hellowin.wav', 0, SND_FILENAME or SND_ASYNC);
    end;
    WM_PAINT:
    begin
      hdc1:= BeginPaint(HWindow, ps1);
      GetClientRect(HWindow, rect);
      //DrawText(HWindow, 'Hello, Windows 98!', -1, rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER);
      DrawText(hdc1, 'Hello, Windows 98!', -1, rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER);
      EndPaint(HWindow, ps1);
    end;
    WM_DESTROY:
    begin
      PostQuitMessage(0);
    end
    else
    begin
      Result:= DefWindowProc(HWindow, message, wParam, lParam);
    end;
  end;
end;

var
  szAppName: array[0..63] of char;
  hwnd1: HWND;
  msg1: TMSG;
  wndclass1: WNDCLASS;
  str: string;
begin
  wndclass1.style:= CS_VREDRAW or CS_HREDRAW;
  wndclass1.lpfnWndProc:= @WndProc;
  wndclass1.cbClsExtra:= 0;
  wndclass1.cbWndExtra:= 0;
  wndclass1.hInstance:= HInstance;
  wndclass1.hIcon:= LoadIcon(0, IDI_APPLICATION);
  wndclass1.hCursor:= LoadCursor(0, IDC_ARROW);
  //wndclass1.hbrBackground:= HBRUSH(GetStockObject(WHITE_BRUSH));
  wndclass1.hbrBackground:= GetStockObject(WHITE_BRUSH);
  wndclass1.lpszMenuName:= nil;
  ZeroMemory(@szAppName[0], 64);
  str:= 'HelloWin';
  strpcopy(szAppName, str);
  wndclass1.lpszClassName:= szAppName;

  if RegisterClass(wndclass1) = 0 then
  begin
    MessageBox(0, 'This program requires Windows NT!', szAppName, MB_ICONERROR);
  end
  else
  begin
    hwnd1:= CreateWindow(szAppName, 'The Hello Program', WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                         0, 0, HInstance, 0);
    ShowWindow(hwnd1, CmdShow);
    UpdateWindow(hwnd1);

    while GetMessage(msg1, 0, 0, 0) do
    begin
      TranslateMessage(msg1);
      DispatchMessage(msg1);
    end;
  end;

end.

posted on 2009-04-19 11:07  zwz_good  阅读(201)  评论(0编辑  收藏  举报