HWND hwndButton;
int cx
LRESULT CALLBACK MainWndProc (HWND hWindow
{
HDC dc;
PAINTSTRUCT ps;
RECT rc;
switch (nMsg)
{
case WM_CREATE:
{
TEXTMETRIC tm;
dc = GetDC (hWindow);
SelectObject (dc
GetTextMetrics (dc
cx = tm
cy = (tm
ReleaseDC (hWindow
hwndButton = CreateWindow (
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
hWindow
(HMENU)
((LPCREATESTRUCT) lPrm)
NULL
);
return
break;
}
case WM_DESTROY:
{
PostQuitMessage (
return
break;
}
case WM_PAINT:
{
dc = BeginPaint (hWindow
GetClientRect (hWindow
rc
DrawText (dc
DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint (hWindow
return
break;
}
case WM_SIZE:
{
if (hwndButton && (wPrm == SIZEFULLSCREEN ||wPrm == SIZENORMAL))
{
rc
rc
MoveWindow (hwndButton
}
return
break;
}
case WM_COMMAND:
{
if (LOWORD(wPrm) ==
(HWND) lPrm == hwndButton)
{
DestroyWindow (hWindow);
}
return
break;
}
}
return DefWindowProc (hWindow
}
//winmain
int __stdcall WinMain (HINSTANCE hInst
{
HWND hWindowMain;
MSG MyMsg;
WNDCLASSEX wcex;
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
RegisterClassEx (&wcex);
hWindowMain = CreateWindow (
WS_OVERLAPPEDWINDOW
CW_USEDEFAULT
CW_USEDEFAULT
CW_USEDEFAULT
CW_USEDEFAULT
hInst
NULL
);
ShowWindow (hWindowMain
UpdateWindow (hWindowMain);
while (GetMessage (&MyMsg
{
TranslateMessage (&MyMsg);
DispatchMessage (&MyMsg);
}
return MyMsg
}
其中選擇Release方式編譯
然後將其翻譯成Delphi代碼
program WinTest;
uses
Windows
var
hwndButton:HWND;
cx
function MainWndProc (hWindow:HWND;nMsg:UINT;wPrm:WPARAM;lPrm:LPARAM):LRESULT;stdcall;
var
dc:HDC;
ps:PAINTSTRUCT;
rc:TRect;
tm:TEXTMETRIC;
pctst:PCREATESTRUCT;
begin
case nMsg of
WM_CREATE:
begin
dc := GetDC (hWindow);
SelectObject (dc
GetTextMetrics (dc
cx := tm
cy := (tm
ReleaseDC (hWindow
pctst:= PCREATESTRUCT(lPrm);
hwndButton := CreateWindow(
WS_CHILD or WS_VISIBLE or BS_PUSHBUTTON
hWindow
HMENU(
pctst^
nil
);
Result:=
Exit;
end;
WM_DESTROY:
begin
PostQuitMessage(
Result:=
Exit;
end;
WM_PAINT:
begin
dc := BeginPaint (hWindow
GetClientRect (hWindow
rc
DrawText (dc
DT_SINGLELINE or DT_CENTER or DT_VCENTER);
EndPaint (hWindow
Result:=
Exit;
end;
WM_SIZE:
begin
if (hwndButton<>
begin
rc
rc
MoveWindow (hwndButton
end;
Result:=
Exit;
end;
WM_COMMAND:
begin
if (LOWORD(wPrm) =
(HWND(lPrm) = hwndButton) then
begin
DestroyWindow (hWindow);
end;
Result:=
Exit;
end;
end;
Result:=DefWindowProc (hWindow
end;
//winmain
var
hWindowMain:HWND;
MyMsg:MSG;
wcex:WNDCLASSEX;
begin
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
wcex
RegisterClassEx (wcex);
hWindowMain := CreateWindow (
WS_OVERLAPPEDWINDOW
CW_USEDEFAULT
CW_USEDEFAULT
CW_USEDEFAULT
CW_USEDEFAULT
MainInstance
nil
);
ShowWindow (hWindowMain
UpdateWindow (hWindowMain);
while GetMessage (MyMsg
begin
TranslateMessage (MyMsg);
DispatchMessage (MyMsg);
end;
end
最後發現Delphi生成的代碼僅有
From:http://tw.wingwit.com/Article/program/Delphi/201311/8414.html