
22.05.2012, 19:22
|
 |
Новичок
|
|
Регистрация: 05.05.2011
Сообщения: 75
Версия Delphi: Turbo Delphi
Репутация: 11
|
|
Запись в файл
Открываю файл
Код:
hFile := OpenFile('log.txt', info, GENERIC_WRITE or OF_SHARE_DENY_NONE);
И пытаюсь записать в него
Код:
OK := writefile(hFile, temp, length(temp), bw, 0);
Не фурычит, в чем подвох?
Полный код
Код:
program Win1;
uses
Windows,
Messages, SysUtils;
var
WndClass: TWndClass;
szAppName: PChar;
WinHandle: hwnd;
info: ofstruct;
bw: cardinal;
hFile: THandle;
Msg: TMsg;
temp: char = 'C';
ok: boolean;
function MyWndProc(hWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: LPARAM): LResult; stdcall;
var
i: Integer;
begin
case Msg of
WM_DESTROY:
begin
PostQuitMessage(0);
Result := 0;
end;
WM_KEYDOWN:
begin
OK := writefile(hFile, temp, length(temp), bw, 0);
Result := DefWindowProc(hWnd, Msg, wParam, lParam);
end
else
Result := DefWindowProc(hWnd, Msg, wParam, lParam);
end;
end;
begin
szAppName := 'Hello windows.';
WndClass.style := CS_HREDRAW or CS_VREDRAW;
WndClass.lpfnWndProc := @MyWndProc;
WndClass.cbClsExtra := 0;
WndClass.cbWndExtra := 0;
WndClass.hInstance := hInstance;
WndClass.hIcon := LoadIcon(hInstance, IDI_APPLICATION);
WndClass.hCursor := LoadCursor(hInstance, IDC_ARROW);
WndClass.hbrBackground := CreateSolidBrush($FFFFFF);
WndClass.lpszMenuName := nil;
WndClass.lpszClassName := szAppName;
RegisterClass(WndClass);
WinHandle := CreateWindow(WndClass.lpszClassName, 'The Hello Program',
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
hInstance,
nil);
ShowWindow(WinHandle, SW_SHOW);
UpdateWindow(WinHandle);
hFile := OpenFile('log.txt', info, GENERIC_WRITE or OF_SHARE_DENY_NONE);
while GetMessage(Msg, 0, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.
|