1,183
社区成员




function PlainWinProc(hWnd:THandle; nMsg:UINT;
wParam,lParam:Cardinal):Cardinal;export;stdcall;
var
Rect:TRect;
begin
result:=0;
case nMsg of
wm_Create:
begin
CreateWindowEx(0,'Button','&HELLO',ws_Child or ws_Visible or
ws_Border or bs_PushButton,
0,0,80,30,hWnd,id_Button1,hInstance,nil);
CreateWindowEx(0,'Button','&退出',ws_Child or ws_Visible or
ws_Border or bs_PushButton,
0,0,80,30,hWnd,id_Button2,hInstance,nil);
CreateWindowEx(0,'Button','&安装服务',ws_Child or ws_Visible or
ws_Border or bs_PushButton,
0,0,80,30,hWnd,id_Button3,hInstance,nil);
CreateWindowEx(0,'Button','&启动服务',ws_Child or ws_Visible or
ws_Border or bs_PushButton,
0,0,80,30,hWnd,id_Button4,hInstance,nil);
CreateWindowEx(0,'Button','&停止服务',ws_Child or ws_Visible or
ws_Border or bs_PushButton,
0,0,80,30,hWnd,id_Button5,hInstance,nil);
CreateWindowEx(0,'Button','&卸载服务',ws_Child or ws_Visible or
ws_Border or bs_PushButton,
0,0,80,30,hWnd,id_Button6,hInstance,nil);
end;
wm_Size:
begin
GetClientRect(hWnd,Rect);
SetWindowPos(GetDlgItem(hWnd,id_Button1),0,Rect.Right div 2-215,
Rect.Bottom div 2-50,0,0,swp_NoZOrder or swp_NoSize);
SetWindowPos(GetDlgItem(hWnd,id_Button2),0,Rect.Right div 2-65,
Rect.Bottom div 2-50,0,0,swp_NoZOrder or swp_NoSize);
SetWindowPos(GetDlgItem(hWnd,id_Button3),0,Rect.Right div 2-300,
Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
SetWindowPos(GetDlgItem(hWnd,id_Button4),0,Rect.Right div 2-200,
Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
SetWindowPos(GetDlgItem(hWnd,id_Button5),0,Rect.Right div 2-100,
Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
SetWindowPos(GetDlgItem(hWnd,id_Button6),0,Rect.Right div 2,
Rect.Bottom div 2-10,0,0,swp_NoZOrder or swp_NoSize);
end;
wm_Command: //按键触发
begin
case LoWord(wParam) of
id_Button1:
begin
if HiWord(wParam)=bn_Clicked then
MessageBox(hWnd,'OK','Demo',MB_OK);
end;
id_Button2:
begin
if HiWord(wParam)=bn_Clicked then
Halt;
end;
id_Button3: //安装
begin
if HiWord(wParam)=bn_Clicked then
InstallService;
end;
id_Button4: //启动
begin
if HiWord(wParam)=bn_Clicked then
StartClick;
end;
id_Button5: //停止
begin
if HiWord(wParam)=bn_Clicked then
StopClick;
end;
id_Button6: //卸载
begin
if HiWord(wParam)=bn_Clicked then
UnInstallService;
end;
end;
end;
wm_DropFiles:
begin
MessageBox(hWnd,'Drop File','Plain API',MB_OK);
DragFinish(wParam);
end;
wm_Destroy:
PostQuitMessage(0);
else
result:=DefWindowProc(hWnd,nMsg,wParam,lParam);
end;
end;
procedure WinMain;
var
hWnd,hWnd2:THandle;
Msg:TMsg;
Rect:TRect;
WndClassEx:TWndClassEx;
wParam:Cardinal;
begin
WndClassEx.cbSize:=SizeOf(TWndClassEx);
WndClassEx.lpszClassName:='PlainWindow';
WndClassEx.style:=CS_HREDRAW or CS_VREDRAW;
WndClassEx.hInstance:=Hinstance;
WndClassEx.lpfnWndProc:=@PlainWinProc;
WndClassEx.cbClsExtra:=0;
WndClassEx.cbWndExtra:=0;
WndClassEx.hIcon:=LoadIcon(Hinstance,Pchar('MAINICON'));
WndClassEx.hIconSm:=LoadIcon(Hinstance,Pchar('MAINICON'));
WndClassEx.hCursor:=LoadCursor(0,idc_Arrow);
WndClassEx.hbrBackground:=GetStockObject(black_Brush);
WndClassEx.lpszMenuName:=nil;
if RegisterClassEx(WndClassEx)=0 then
begin
MessageBox(0,'Invaild Class registration','Plain API',MB_OK);
exit;
end
else begin
hWnd:=CreateWindowEx( WS_EX_ACCEPTFILES,
WndClassEx.lpszClassName,
'Demo',ws_OverlappedWindow,
cw_UseDefault,0,cw_UseDefault,0,0,0,
Hinstance,nil);
if hWnd=0 then
MessageBox(0,'Window not Created','Demo',MB_OK)
else begin
ShowWindow(hwnd,SW_ShowNormal);
while GetMessage(Msg,0,0,0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
ServiceTableEntry[0].lpServiceName:=ServiceName;
ServiceTableEntry[0].lpServiceProc:=TServiceMainFunction(@ServiceMain);
ServiceTableEntry[1].lpServiceName:=nil;
ServiceTableEntry[1].lpServiceProc:=nil;
if not StartServiceCtrlDispatcher(ServiceTableEntry[0]) then
begin
AddToMessageLog('StartServiceCtrlDispatcher Error!');
end;
end;
end;
end;
end;
begin
WinMain;
end.