Object Pascal開發windows原生程式

來源:互聯網
上載者:User

program Project1;

uses
  Windows ,Messages ,SysUtils;
const
  appname='fancydemo';
  function windowproc(window:HWND ;amessage:UINT ;wparam:WPARAM ;
  lparam:LPARAM ):LRESULT ;stdcall ;export ;
  var
    dc:HDC ;
    ps:TPaintStruct ;
    r:TRect ;

begin
  windowproc:=0;
  case amessage of
  WM_PAINT :
  begin
    dc:=BeginPaint(window ,ps);
    GetClientRect(window ,r);
    DrawText(dc,'op 語言寫的windows程式',-1,r,DT_SINGLELINE or DT_CENTER );
    EndPaint(window ,ps);
    exit;
  end;
  WM_DESTROY :
  begin
    PostQuitMessage(0);
    Exit;
  end;
  end;
  windowproc:=DefWindowProc(window,amessage ,wparam ,lparam );
end;
     function winregister:Boolean ;
     var
       windowclass:WNDCLASS ;
       begin
         windowclass .style :=CS_HREDRAW or CS_VREDRAW ;
         windowclass .lpfnWndProc :=TFNWndProc(@windowproc);
         windowclass .cbClsExtra :=0;
         windowclass .cbWndExtra :=0;
         windowclass .hInstance :=SYSTEM.MainInstance ;
         windowclass .hIcon :=LoadIcon(0,IDI_APPLICATION );
         windowclass .hCursor :=LoadCursor(0,IDC_ARROW );
         windowclass .hbrBackground :=GetStockObject(WHITE_BRUSH );
         windowclass .lpszMenuName :=nil;
         windowclass .lpszClassName :=appname ;
         result:=RegisterClass(windowclass )<>0;
       end;
       function wincreate:HWND ;
       var
        hwindow:HWND ;
        begin
          hwindow :=CreateWindow(appname ,'hello,fancy',WS_OVERLAPPEDWINDOW ,CW_usedefault,cw_usedefault,cw_usedefault,cw_usedefault,0,0,SYSTEM.MainInstance ,nil );
          if hwindow <> 0 then
             begin
               ShowWindow(hwindow ,cmdshow);
               ShowWindow(hwindow ,SW_SHOW );
               UpdateWindow(hwindow );
             end;
               Result :=hwindow ;
        end;
        var
           amessage:TMsg ;
           hwindow:HWND ;
         begin
           if not winregister then
           begin
            MessageBox(0,'Register failed',nil,MB_OK );
            Exit;
           end;
           hwindow:=wincreate ;
           if LongInt (hwindow)=0 then
           begin
           MessageBox(0,'wincreate failed',nil,MB_OK );
           Exit ;
           end ;
           while GetMessage(amessage ,0,0,0) do
           begin
           TranslateMessage(amessage );
           DispatchMessage(amessage );
           end;
           Halt (amessage .wParam );
         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.