![]() |
[Non VCL] - Button erscheint nicht...
Moin!
Hab jetz ma ernsthafter mit non VCL angefangen, weil mir C++ doch nich so liegt ;) Jetz teste ich rum hier mit non VCL und hab gleich n Prob. Der Button erscheint einfach nicht. Es soll n Fenster werden mit nem Button, beim Klick erscheint n About Dialog. Funktioniert bis jetz nur das hauptfenster und der Button (sollte, tut er aber nicht). Hier was ich bis jetzt habe:
Delphi-Quellcode:
Thx schonmal!
program TestProg;
uses Windows, Messages; var WndMain, WndAbout: TWndClassEx; //Fensterhandles hWndMain, hWndAbout: HWND; //Buttonhandles hBtnAbout: HWND; msg: TMSG; function CreateButtons: Boolean; begin hBtnAbout := CreateWindow('BUTTON', 'About', WS_CHILD or WS_VISIBLE, 350, 270, 40, 24, hWndMain, 0, 0, nil); Result := True; end; function WndMainProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin case uMsg of WM_CREATE: if not CreateButtons then PostQuitMessage(0); end; Result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; function WndAboutProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin Result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; function RegisterWindowClasses: Boolean; begin WndMain.cbSize := SizeOf(TWndClassEx); WndMain.style := CS_OWNDC; WndMain.lpfnWndProc := @WndMainProc; WndMain.cbClsExtra := 0; WndMain.cbWndExtra := 0; WndMain.hInstance := hInstance; WndMain.hCursor := LoadCursor(0, IDC_ARROW); WndMain.hbrBackground := COLOR_WINDOW; WndMain.lpszMenuName := nil; WndMain.lpszClassName := 'wnd_Root'; RegisterClassEx(WndMain); WndAbout.cbSize := SizeOf(TWndClassEx); WndAbout.style := CS_OWNDC; WndAbout.lpfnWndProc := @WndAboutProc; WndAbout.cbClsExtra := 0; WndAbout.cbWndExtra := 0; WndAbout.hInstance := hInstance; WndAbout.hCursor := LoadCursor(0, IDC_ARROW); WndAbout.hbrBackground := COLOR_WINDOW; WndAbout.lpszMenuName := nil; WndAbout.lpszClassName := 'wnd_About'; RegisterClassEx(WndAbout); Result := True; end; begin if not RegisterWindowClasses then Exit; hWndMain := CreateWindowEx(WS_EX_APPWINDOW, 'wnd_Root', 'Haupt Fenster', WS_OVERLAPPED or WS_VISIBLE, 200, 300, 400, 400, 0, 0, hInstance, nil); while True do begin if not GetMessage(msg, 0, 0, 0) then break; TranslateMessage(msg); DispatchMessage(msg); end; end. |
Re: [Non VCL] - Button erscheint nicht...
Bei mir erscheint er ... :zwinker:
Zeilen in denen ich rumgespielt habe sind rot. Denk mal nach, du hast bei WM_CREATE versucht einen Button zu erstellen, doch zu diesem Zeitpunkt war CreateWindowEx für das Hauptfenster noch garnicht zurückgekehrt und ergo die entsprechende Variable (hWndMain) nicht zugewiesen. Du hast also deinem Button NULL als Elternfenster übergeben ;) ... da kann nichts angezeigt werden.
Code:
Nochmal die color-Tags angepaßt.
uses
Windows, Messages; var WndMain, WndAbout: TWndClassEx; //Fensterhandles hWndAbout: HWND; //Buttonhandles hBtnAbout: HWND; msg: TMSG; [color=red]function CreateButtons(parent: HWND): Boolean;[/color] begin [color=red] hBtnAbout := CreateWindow('BUTTON', 'About',[/color] WS_CHILD or WS_VISIBLE, 350, 270, 40, 24, parent, 0, 0, nil); [color=red] Result := IsWindow(hBtnAbout);[/color] end; function WndMainProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin case uMsg of [color=red] WM_CREATE: if not CreateButtons(hwnd) then[/color] PostQuitMessage(0); end; Result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; function WndAboutProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; begin Result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; function RegisterWindowClasses: Boolean; begin WndMain.cbSize := SizeOf(TWndClassEx); WndMain.style := CS_OWNDC; WndMain.lpfnWndProc := @WndMainProc; WndMain.cbClsExtra := 0; WndMain.cbWndExtra := 0; WndMain.hInstance := hInstance; WndMain.hCursor := LoadCursor(0, IDC_ARROW); WndMain.hbrBackground := COLOR_WINDOW; WndMain.lpszMenuName := nil; WndMain.lpszClassName := 'wnd_Root'; RegisterClassEx(WndMain); WndAbout.cbSize := SizeOf(TWndClassEx); WndAbout.style := CS_OWNDC; WndAbout.lpfnWndProc := @WndAboutProc; WndAbout.cbClsExtra := 0; WndAbout.cbWndExtra := 0; WndAbout.hInstance := hInstance; WndAbout.hCursor := LoadCursor(0, IDC_ARROW); WndAbout.hbrBackground := COLOR_WINDOW; WndAbout.lpszMenuName := nil; WndAbout.lpszClassName := 'wnd_About'; RegisterClassEx(WndAbout); Result := True; end; begin if not RegisterWindowClasses then Exit; [color=red] CreateWindowEx(WS_EX_APPWINDOW,[/color] 'wnd_Root', 'Haupt Fenster', WS_OVERLAPPED or WS_VISIBLE, 200, 300, 400, 400, 0, 0, hInstance, nil); while True do begin if not GetMessage(msg, 0, 0, 0) then Break; TranslateMessage(msg); DispatchMessage(msg); end; end. |
Re: [Non VCL] - Button erscheint nicht...
Heisst das auch ich brauche hWndMain und hWndAbout gar nicht :?:
|
Re: [Non VCL] - Button erscheint nicht...
Zitat:
|
Re: [Non VCL] - Button erscheint nicht...
Also eigentlich woillte ich bei Klick aufn Button das fenster erstellen und wenn es geschlossen wird DestroyWindow aufrufen, also eigentlich bräuchte ich es nicht, oder?
|
Re: [Non VCL] - Button erscheint nicht...
Zitat:
|
Re: [Non VCL] - Button erscheint nicht...
Da gab es mal zwei Genies, die haben eine recht große Sammlung zum Thema geschrieben.
Nennt sich ![]() Okay, da war noch ein 3. mit einem Beitrag. Kein Genie, einfach nur dabei :mrgreen: |
Re: [Non VCL] - Button erscheint nicht...
K thx guck ich mir mal an :thumb:
|
Re: [Non VCL] - Button erscheint nicht...
Zitat:
:mrgreen: :mrgreen: :mrgreen: |
Re: [Non VCL] - Button erscheint nicht...
Du warst gar nicht gemeint. Ich meinte den 3. Autoren. dum... äh tommie-lie, oder wie der heißt. :zwinker:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:43 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