![]() |
AW: 1400 Error beim Erstellen eines Fensters via API
Fundstelle:
Zitat:
|
AW: 1400 Error beim Erstellen eines Fensters via API
Jaja, das "ach so bequeme" with :twisted:
|
AW: 1400 Error beim Erstellen eines Fensters via API
Zitat:
Ich versuchs mal ohne. Edit: Habe es so versucht:
Delphi-Quellcode:
Aber immer noch 1400. Falls es vielleicht hilft, ich arbeite auf Win 5.1/XP Professional 32 bit.
with self.windowClass do
begin Style:= CS_HREDRAW or CS_VREDRAW; lpfnWndProc:= @TSForm.WindowProcedure; cbClsExtra:= 0; cbWndExtra:= 0; hbrBackground:= COLOR_APPWORKSPACE; lpszMenuName:= nil; lpszClassName:= 'WinAPITestWindow'; hIcon := LoadIcon(0, IDI_WINLOGO); hCursor := LoadCursor(0, IDC_ARROW); end; self.windowClass.hInstance := SysInit.HInstance; |
AW: 1400 Error beim Erstellen eines Fensters via API
Mann kann auch den entsprechenden Namespace mit angeben.
HInstance ist doch in der Unit System (glaub ich) deklariert, also
Delphi-Quellcode:
.
hInstance := System.hInstance
[edit] oder eventuell auch SysInit :stupid: Eventuell mal self.windowClass über FillChar/ZeroMemory vorher komplett auf 0 sezten? Ansonsten bleibt noch die Möglichkeit mal über den Debugger die ganzen Werte zu prüfen. |
AW: 1400 Error beim Erstellen eines Fensters via API
Zitat:
Edit:
Delphi-Quellcode:
bringt nichts :(
ZeroMemory(@self.windowClass.hInstance, SizeOf(Cardinal));
|
AW: 1400 Error beim Erstellen eines Fensters via API
Laut Debugger ist alles mit einem validen Wert bestückt(hInstance : 4194304). Bei CreateWindow durchläuft der Debugger mehrmals die WndProc mit dem Parametern (hwnd:36, uMsg:0, wParam:1243444, lParam:4268636), (hwnd:129, uMsg:0, wParam:1243412, lParam:4268636) und
(hwnd:130, uMsg:0, wParam:0, lParam:4268636). Danach bekommt self.hwnd von CreateWindow den Wert 0 und der 1400 wird geworfen. |
AW: 1400 Error beim Erstellen eines Fensters via API
Es ist definitiv so das du das erstellen des Windows nicht abhängig von deiner Classe machen darfst.
Das wird immer fehlschlagen. Die WinProc muss Statisch also Global definiert sein darf nicht in der Classe gekapselt werden. PS: Vorallem darfst du niemals einen Breakpoint bei WinHandle := CreateWindow( setzen auch dann wird das erstellen des Windows jedesmal fehlschlagen. gruss |
AW: 1400 Error beim Erstellen eines Fensters via API
Zitat:
(damals in Delphi 7 und TDE) |
AW: 1400 Error beim Erstellen eines Fensters via API
Zitat:
Es ist aber so! Habe es gerade nach deinem Post nochmalig getestet. Das setzen eines Breakpoint auf WinHandle := CreateWindow( schlägt immer ohne ausnahme fehl. Ist auch unabhängig von der Delphi Version Das ist Winapi muss überall laufen egal welche Delphi Version das ist. Schlägt es in D7 fehl dann auch in allen anderen Versionen wie bei mir d2009 Hier deine Lösung!
Delphi-Quellcode:
program API;
uses Windows, Messages, SHFolder, inifiles, SysUtils; type TSForm = class private run: Boolean; ClassNamen: PAnsiChar; windowClass: TWndClass; Winhandle: HWND; AppName: PAnsiChar; w, h: Integer; msg: TMsg; procedure finale; procedure init; procedure ShowError(ErrorText: PChar); function getAppData() : String; procedure keypress(c : Char); protected // public constructor Create(); procedure Show(); destructor Close(); end; var win : TSForm; procedure TSForm.finale; begin // end; function WindowProcedure(Winhandle: HWND; uMsg: UINT; wParam: wParam; lParam: LParam): lresult; stdcall; var x, y : integer; begin Result := 0; case uMsg of WM_CREATE: begin x := GetSystemMetrics(SM_CXSCREEN); y := GetSystemMetrics(SM_CYSCREEN); MoveWindow(Winhandle, (x div 2) - (win.w div 2), (y div 2) - (win.h div 2), win.w, win.h, true); end; WM_DESTROY: begin win.run := false; win.finale(); PostQuitMessage(0); end; WM_KEYDOWN: begin win.KeyPress(Char(Word(wParam))); end; else Result := DefWindowProc(Winhandle, uMsg, wParam, lParam); end; end; destructor TSForm.Close; begin UnregisterClass(windowClass.lpszClassName, hInstance); end; constructor TSForm.Create; begin w := 640; h := 400; end; function TSForm.getAppData: String; var path : array[0..MAX_PATH] of char; begin if SUCCEEDED(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, PChar(path[0]))) then result := path else result := ''; end; procedure TSForm.init; begin run := true; end; procedure TSForm.keypress(c: Char); begin // end; procedure TSForm.Show; begin // end; procedure TSForm.ShowError(ErrorText: PChar); begin MessageBox(Winhandle, ErrorText, 'Error', MB_ICONERROR); Halt; end; begin win := TSForm.Create(); win.appName := 'WinAPITestApp'; win.ClassNamen := 'WinAPITestWindow'; win.windowClass.hInstance := hInstance; with win.windowClass do begin Style := CS_HREDRAW or CS_VREDRAW; lpfnWndProc := @WindowProcedure; cbClsExtra := 0; cbWndExtra := 0; hbrBackground := COLOR_APPWORKSPACE; lpszMenuName := nil; lpszClassName := win.ClassNamen; hIcon := LoadIcon(0, IDI_WINLOGO); hCursor := LoadCursor(0, IDC_ARROW); end; if RegisterClass(win.windowClass) = 0 then win.ShowError(PChar('#' + IntToStr(GetLastError) + ' : ' + SysErrorMessage(GetLastError))); win.WinHandle := CreateWindow(win.windowClass.lpszClassName, win.AppName, WS_CAPTION or WS_VISIBLE or WS_SYSMENU or WS_MINIMIZEBOX or WS_MAXIMIZEBOX or WS_SIZEBOX, 400, 400, win.w, win.h, 0, 0, hInstance, nil); if win.WinHandle <> 0 then begin win.init(); while win.run do begin if PeekMessage(win.msg, win.WinHandle, 0, 0, PM_REMOVE) then begin TranslateMessage(win.msg); DispatchMessage(win.msg); end; end; end else win.ShowError(PChar('#' + IntToStr(GetLastError) + ' : ' + SysErrorMessage(GetLastError))); ExitCode := win.msg.wParam; win.Show(); win.Close(); end. gruss |
AW: 1400 Error beim Erstellen eines Fensters via API
Zitat:
Ich probiere mal die globale WndProc. Edit : Danke für die Lösung. Ich teste das mal. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:57 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz