Windows 編程[5] – 學習表單產生的過程五

來源:互聯網
上載者:User
根據前面的介紹, 可以完成一個視窗的建立了:
program Project1;uses  Windows, Messages;{視窗回呼函數, 必須聲明在使用它的程式前面}function WndProc(wnd: HWND; msg: UINT; wParam: Integer; lParam: Integer): Integer; stdcall;begin  Result := 0;  if msg = WM_DESTROY then {當視窗銷毀時}    PostQuitMessage(0)     {告訴 GetMessage: 退出吧!}  else    Result := DefWindowProc(wnd, msg, wParam, lParam); {其他訊息做預設處理}end;{主程式}var  hWnd      : THandle;  Msg       : TMsg;  MyWndClass: TWndClass;begin  {指定視窗類別型}  MyWndClass.style         := CS_HREDRAW or CS_VREDRAW; {改變大小時重繪}  MyWndClass.lpfnWndProc   := @WndProc;                 {回呼函數指標}  MyWndClass.cbClsExtra    := 0;                        {沒有額外的視窗類別資訊}  MyWndClass.cbWndExtra    := 0;                        {沒有額外的視窗資訊}  MyWndClass.hInstance     := HInstance;                {程式執行個體控制代碼}  MyWndClass.hIcon         := 0;                        {沒指定表徵圖}  MyWndClass.hCursor       := LoadCursor(0, IDC_ARROW); {選用了系統提供的指標}  MyWndClass.hbrBackground := HBRUSH(COLOR_WINDOW + 1); {背景色使用 Windows 預設的視窗顏色}  MyWndClass.lpszMenuName  := nil;                      {不指定預設菜單}  MyWndClass.lpszClassName := 'MyWindowClass';          {給視窗類別型命名}  {註冊視窗類別型}  RegisterClass(MyWndClass);  {建立視窗並返回控制代碼}  hWnd := CreateWindow('MyWindowClass',        {視窗類別型名}                       '新視窗',               {標題}                       WS_OVERLAPPEDWINDOW,    {視窗的常規樣式}                       Integer(CW_USEDEFAULT), {預設水平位置}                       Integer(CW_USEDEFAULT), {預設垂直位置}                       Integer(CW_USEDEFAULT), {預設寬度}                       Integer(CW_USEDEFAULT), {預設高度}                       0,                      {無父視窗}                       0,                      {無主菜單}                       HInstance,              {執行個體控制代碼}                       nil                     {無附加資訊}                       );  {顯示視窗}  ShowWindow(hWnd, SW_SHOWNORMAL);  //UpdateWindow(hWnd); {這個更新視窗要不要好像都可以}  {訊息迴圈}  while(GetMessage(Msg, 0, 0, 0)) do  begin    TranslateMessage(Msg); {對部分鍵盤訊息的再處理}    DispatchMessage(Msg);  {將訊息發送給回呼函數}  end;end.

接下來再繼續完善這些代碼!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.