用Api创建窗体

ContractedBlock.gifExpandedBlockStart.gifCode
program WindowFromApi; 
{ an example to how to create and design window with a button inside from API} 
{ berzek aka alcap0rn } 
// 01/07/09 : dd/mm/yy // 

uses 
   Windows, 
   Messages, 
   dialogs, 
   sysutils; 

const 
mButton1 
= 1
mButton2 
= 2
mEdit 
= 3

function WndProc(WindowHandler:HWND;Msj:UINT;Parameter1:WPARAM;Parameter2:LPARAM):LRESULT; stdcall

Begin 

   Case Msj 
of  // this are the events on the windows like keyboard,mouse etc.. 
             WM_CLOSE: Begin 
                       PostMessage(WindowHandler,WM_QUIT,
0,0);  // when u close the fuckin window 
                       
end

             WM_KEYDOWN : ShowMessage     (
'a key pressed'); 
             WM_LBUTTONDOWN : ShowMessage (
'mouse click pressed over the window'); 
             WM_COMMAND : Begin 
                           
case Parameter1 of 
                               mButton1 :   ShowMessage (
'hello Im the fucking button 1'); 
                               mButton2 :   ShowMessage (
'hello Im the fucking button 2'); 
                           
end
                          
end
             
else 
            Begin 
             wndProc:
= DefWindowProc(WindowHandler,Msj,Parameter1,Parameter2); 
             
end

end
End; 


procedure DefineWinClass (var WindowClass:TWndClass); 
Begin 
         WindowClass.style:
=CS_HREDRAW or CS_VREDRAW or CS_OWNDC or CS_DROPSHADOW; 
         WindowClass.lpszClassName:
='₧berzekakaalcaporn₧'
         WindowClass.lpfnWndProc:
=@WndProc; 
         WindowClass.cbClsExtra:
=0
         WindowClass.cbWndExtra:
=0
         WindowClass.hInstance:
=0;        // window instance. 
         WindowClass.hIcon:
=LoadIcon(0,IDI_WINLOGO);  // window icon 
         WindowClass.hCursor:
=LoadCursor(0,IDC_ARROW); // cursor type 
         WindowClass.hbrBackground:
=CreateSolidBrush(RGB(0,0,0)); //window color 
         WindowClass.lpszMenuName:
=nil;  // resourcename 

End; 

procedure   CreateBtn(WindowHandler : hwnd; x,y,mlong,mheight : integer ; ButtonNum:Integer); 
var 
         HandleButton : THandle; 
         HandleMenu : HMenu; 
Begin 

     HandleMenu :
= ButtonNum; 
     HandleButton :
=CreateWindowEX 
                        ( 
                          
0
                          
'BUTTON'
                          pchar(
'Dude '+intToStr(ButtonNum)),         // Title 
                          WS_VISIBLE 
or WS_CHILD or BS_PUSHBUTTON or BS_TEXT, 
                          x,y, 
                          mlong,mheight, 
                          WindowHandler, 
                          HandleMenu, 
                          
0
                          
nil); 

end

Procedure CreateEdit(WindowHandler: hwnd; x,y,Mlong,mheight:integer; EditNum:integer); 
var 
HandleEdit: THandle; 
HandleMenu: HMenu; 

begin 
     HandleMenu :
= EditNum; 
     HandleEdit :
=CreateWindowEX 
                        ( 
                          
0
                          
'EDIT',                     //   DWORD dwExStyle 
                                 
//LPCTSTR lpClassName 
                          pchar(
'write here little bitch'),        // value 
                          WS_CHILD 
or WS_VISIBLE or BS_FLAT, //DWORD dwStyle, 
                          x,y,                                     
//int x,int y 
                          mlong,mheight,                           
// int nWidth,int nHeight 
                          WindowHandler,                           
// HWND hWndParent 
                          HandleMenu,                              
//HMENU hMenu 
                          
0,                                       // HINSTANCE hInstance, 
                          
nil);                                   //   LPVOID lpParam 

end

procedure CreateWin(var WindowHandler:HWND); 
var 
         WindowClass:TWndClass; 
         ExtendedWindowStyle,WindowStyle:Dword; 

Begin 

         
{we define the class window } 
         DefineWinClass(WindowClass); 
         
if RegisterClass(WindowClass)=0 then 
         MEssageBox(
0,'cant get the class ','WARNING',MB_OK); 

         ExtendedWindowStyle :
= WS_EX_APPWINDOW; //or WS_EX_WINDOWEDGE; 
         WindowStyle :
= WS_OVERLAPPEDWINDOW;// or WS_CLIPSIBLINGS or WS_CLIPCHILDREN; 

         WindowHandler:
=CreateWindowEX 
                        ( 
                          ExtendedWindowStyle, 
                          
'₧berzekakaalcaporn₧'
                          
'Example of Window From API @ berzek A.K.A Alcap0rn',         // Title 
                          WindowStyle, 
                          
400,300
                          
379,274
                          
0
                          
0
                          
0
                          
nil); 

         If WindowHandler
=0 then MessageBox(0,'something bad ?, find yourself!','WARNING ERROR',MB_OK); 
         ShowWindow(WindowHandler,SW_SHOW); 
         SetFocus(WindowHandler); 
End; 



var 
Msj:TMsg; 
TheResult:Boolean; 
WindowHandler:HWND; 

begin 
   CreateWin(WindowHandler); 
   CreateBtn(WindowHandler,
100,100,80,40,mButton1); 
   CreateBtn(WindowHandler,
200,100,80,40,mButton2); 
   CreateEdit(WindowHandler,
100,150,250,30,mEdit); 

   TheResult:
=Windows.GetMessage(Msj,WindowHandler,0,0); 

     
while TheResult do 
    
begin 
       TheResult:
=Windows.GetMessage(Msj,WindowHandler,0,0); 
       TranslateMessage(Msj); 
       DispatchMessage(Msj); 
    
end

end

转载于:https://www.cnblogs.com/bsoom/archive/2009/11/14/1603050.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值