delphi实现简单window窗口程序

WindowDemo.dpr


//
//
//  FileName    :   WindowDemo.dpr
//  Creator     :   Shen Min
//  Date        :   2002-3-2
//  Comment     :   Create Window Demo for <>
//
//


program WindowDemo;

uses Windows, Messages;

function WindowProc(hwnd : HWND; uMsg : Cardinal; wParam : WPARAM; lParam : LPARAM) : LResult; stdcall;
begin
    Result := 0;
    case uMsg of

    WM_CLOSE : PostMessage(hwnd, WM_QUIT, 0, 0);

    WM_LBUTTONDOWN : MessageBox(hwnd, 'Hello!', '和您打个招呼', MB_ICONINFORMATION);

    else
        Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
    end;
end;

var
    wndcls : WNDCLASS;
    hWnd : THandle;
    Msg : tagMSG;
begin
    wndcls.style         := CS_DBLCLKS;
    wndcls.lpfnWndProc   := @WindowProc;
    wndcls.cbClsExtra    := 0;
    wndcls.cbWndExtra    := 0;
    wndcls.hInstance     := hInstance;
    wndcls.hIcon         := 0;
    wndcls.hCursor       := LoadCursor(hInstance, 'IDC_ARROW');
    wndcls.hbrBackground := COLOR_WINDOWFRAME;
    wndcls.lpszMenuName  := nil;
    wndcls.lpszClassName := 'WindowClassDemo';
    if RegisterClass(wndcls) = 0 then
        Exit;

    hWnd := CreateWindow(
        'WindowClassDemo',
        'WindowDemo',
        WS_BORDER or WS_CAPTION or WS_SYSMENU,
        Integer(CW_USEDEFAULT),
        Integer(CW_USEDEFAULT),
        Integer(CW_USEDEFAULT),
        Integer(CW_USEDEFAULT),
        0,
        0,
        hInstance,
        nil
    );
    if hWnd = 0 then
        Exit;
    ShowWindow(hWnd, SW_SHOWNORMAL);
    UpdateWindow(hWnd);

    while GetMessage(Msg, hWnd, 0, 0) do
    begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
    end;
end.
使用delphi7的 dcc32.exe -b WindowDemo.dpr -U {系统dcu路径}命令编译即可生成,在RAD XE5 delphi的系统架构改变了不再是vcl而是Firemonkey。
本源码在delphi7和RAD Studio 2010编译通过。

你可能感兴趣的:(delphi)