1. 程式人生 > >《windows程序設計》字符消息(14)

《windows程序設計》字符消息(14)

uri cal phi mes 顏色 程序 case lap uname

技術分享圖片

代碼如下:

program Project2;

  {$APPTYPE CONSOLE}

  {$R *.res}

uses
  System.SysUtils,
  windows,
  Winapi.Messages,
  Vcl.Dialogs;

type
  Point = record
    x: Integer;
    y: Integer;
  end;

var
  swndClass: tagWNDCLASS;
  message: MSG;
  mHwnd: hwnd;
  cxClient, cyClient: Integer;

function WindowProc(hwnd: hwnd; uMsg: UINT; wParam: wParam; lParam: lParam): LRESULT; stdcall
; var i: integer; uhdc: HDC; ps: PAINTSTRUCT; begin case uMsg of WM_CREATE: begin end; WM_SIZE: begin cxclient := loword(lParam); cyclient := HiWord(lParam); result := 0; Exit; end; wm_paint: begin uhdc := BeginPaint(hwnd, ps); EndPaint(hwnd, ps); Exit;
end; wm_char: begin Writeln(chr(wparam)); end; end; result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; begin swndClass.cbClsExtra := 0; //窗口類擴展,無 swndClass.cbWndExtra := 0; //窗口實例擴展 swndClass.hbrBackground := COLOR_BACKGROUND; //窗口背景顏色黑色 //LoadCursor() swndClass.hCursor := LoadCursor(0
, IDC_ARROW); //窗口采用箭頭光標 swndClass.hIcon := LoadIcon(0, IDI_APPLICATION); //窗口最小化圖標:采用缺省圖標 swndClass.hInstance := hInstance; //窗口實例句柄 swndClass.lpfnWndProc := @WindowProc; //窗口處理函數 swndClass.lpszClassName := myWnd; //窗口類名 swndClass.lpszMenuName := nil; //窗口菜單 swndClass.style := CS_DBLCLKS; //窗口樣式 if RegisterClass(swndClass) = 0 then begin Writeln(windows class register error!); Exit; end; mHwnd := CreateWindowEx(0, myWnd, Delphi Windows, WS_OVERLAPPEDWINDOW, {滾動條添加} CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, HWND_DESKTOP, 0, hInstance, 0); ShowWindow(mHwnd, SW_SHOW); UpdateWindow(mHwnd); while GetMessage(message, 0, 0, 0) do begin TranslateMessage(message); DispatchMessage(message); end; end.

《windows程序設計》字符消息(14)