المشاركات : 97
المواضيع 38
:
: 0
الإنتساب : May 2015
السلام عليكم ورحمة الله وبركاته
ماهي الطريقة التي نستطيع فيها من بناء وجهة Form عن طريق Console Application
PHP كود :
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
windows,
forms,
Unit1 in 'Unit1.pas' {Form1};
const
ConsoleClass = 'ConsoleWindowClass';
var
console: HWND;
len: DWORD;
title: array [0 .. MAX_PATH] of Char;
begin
try
len := GetConsoleTitle(title, SizeOf(title));
Win32Check(Bool(len));
console := FindWindow(ConsoleClass, title);
Win32Check(Bool(console));
Form1 := TForm1.Create(nil);
try
EnableWindow(console, False);
try
Form1.HandleNeeded;
SetWindowLongPtr(Form1.Handle, GWLP_HWNDPARENT, console);
Form1.ShowModal;
finally
EnableWindow(console, True);
end;
finally
Form1.Free;
end;
except
on E:Exception do
Writeln(E.Classname, ': ', E.Message);
end;
end.
هذا الكود لم يعمل معي وظهرت به اخطاء
اللهم علمنا ما ينفعنا و انفعنا بما علمتنا وَ زِدْنا علماً
المشاركات : 654
المواضيع 34
:
: 106
الإنتساب : Aug 2010
وعليكم السلام
أعتقد أنك تقصد إستخدام Windows API
أي عدم إستخدام VCL
كود :
program Project1;
uses
windows, messages;
// Main Window Procedure
function MainWndProc(hWindow: HWND; Msg: UINT; wParam: wParam;
lParam: lParam): LRESULT; stdcall; export;
var
ps: TPaintStruct;
begin
Result := 0;
case Msg of
WM_PAINT:
begin
BeginPaint(hWindow, ps);
SetBkMode(ps.hdc, TRANSPARENT);
TextOut(ps.hdc, 10, 10, 'Hello, World!', 13);
EndPaint(hWindow, ps);
end;
WM_DESTROY: PostQuitMessage(0);
else
begin
Result := DefWindowProc(hWindow, Msg, wParam, lParam);
Exit;
end;
end;
end;
// Main Procedure
var
wc: TWndClass;
hWindow: HWND;
Msg: TMsg;
begin
wc.lpszClassName := 'YourAppClass';
wc.lpfnWndProc := @MainWndProc;
wc.Style := CS_VREDRAW or CS_HREDRAW;
wc.hInstance := hInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.hbrBackground := (COLOR_WINDOW + 1);
wc.lpszMenuName := nil;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
RegisterClass(wc);
hWindow := CreateWindowEx(WS_EX_CONTROLPARENT or WS_EX_WINDOWEDGE,
'YourAppClass',
'API',
WS_VISIBLE or WS_CLIPSIBLINGS or
WS_CLIPCHILDREN or WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0,
400, 300,
0,
0,
hInstance,
nil);
ShowWindow(hWindow, CmdShow);
UpDateWindow(hWindow);
//Prevents the application from closing.
while GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
Halt(Msg.wParam);
end.
الكود مقتبس من
هنا
سبحان الله وبحمده سبحان الله العظيم
المشاركات : 97
المواضيع 38
:
: 0
الإنتساب : May 2015
شكرا لك أخي جزاك الجنه ولكن أستطعت جعل الكنسل ينشاء فورم وبداخلها زر وينفذ أمر في حدث OnClick
والحمدالله
اللهم علمنا ما ينفعنا و انفعنا بما علمتنا وَ زِدْنا علماً