![]() |
[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:
|
Re: [Non VCL] - Button erscheint nicht...
Naja gut ich steh vor dem nächsten Problem mit den Buttons...
Folgendes hab ich bis jetzt:
Code:
Das funktioniert nicht.
program TestProg;
uses Windows, Messages; var WndMain, WndAbout: TWndClassEx; hWndMain: HWND; //Button Handles msg: TMSG; function WndMainProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var hBtnAbout, hBtnExit: DWORD; begin case uMsg of WM_CREATE: begin hBtnAbout := CreateWindow('BUTTON', 'About', WS_CHILD or WS_VISIBLE, 220, 235, 70, 24, hwnd, 0, 0, nil); hBtnExit := CreateWindow('BUTTON', 'Beenden', WS_CHILD or WS_VISIBLE, 310, 235, 70, 24, hwnd, 0, 0, nil); end; WM_DESTROY: PostQuitMessage(0); [color=red] WM_COMMAND: if wParam = BN_CLICKED then if lParam = hBtnAbout then begin CreateWindowEx(0, 'wnd_About', 'About', WS_DLGFRAME or WS_VISIBLE, 300, 300, 300, 200, hwnd, 0, 0, nil); EnableWindow(hwnd, False); end else if lParam = hBtnExit then SendMessage(hwnd, WM_DESTROY, 0, 0); end; Result := DefWindowProc(hwnd, uMsg, wParam, lParam); end; [/color] function WndAboutProc(hwnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; var hBtnOk: DWORD; begin case uMsg of WM_CREATE: begin hBtnOk := CreateWindow('BUTTON', 'OK', WS_CHILD or WS_VISIBLE, 210, 260, 70, 24, hwnd, 0, 0, nil); end; end; 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_BTNSHADOW; 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_SYSMENU or WS_MINIMIZEBOX or WS_VISIBLE, 200, 300, 400, 300, 0, 0, hInstance, nil); while True do begin if not GetMessage(msg, 0, 0, 0) then break; TranslateMessage(msg); DispatchMessage(msg); end; end. Wenn ich aber die beiden Buttonvariablen hBtnAbout und hBtnExit als globale Variable deklariere funktioniert es. Ich habs (wenn die beiden lokal waren) schon mit allem Hi und Lo usw. probiert aber nix klappt... Woran liegt das :wall: |
Re: [Non VCL] - Button erscheint nicht...
Die WndProc wird ja jedes mal von deiner Nachrichtenschleife aufgerufen, wenn eine Nachricht kommt. Da dein Programm also nicht ständig in der WndProc hängt, sind die okalen Variablen natürlich nach verlassen der WndProc ungültig und WM_CREATE wird ja nicht jedes mal aufgerufen. Ergo müssen deine Variablen für Childfenster global sein, wenn du wieder draufzugreifen möchtest. Eleganter ist es, wenn du deinen Childfenster eine ID gibst, das kann eine Konstante sein und dann kannst du dir das Handle wieder mit
![]() Aber wenn du dir die Tutorials anguckst, da sthet eigentlich drinne, wie man auf Buttonklicks reagiert. |
Re: [Non VCL] - Button erscheint nicht...
Das is ja mal n digges Ding :mrgreen:
DANGÖÖÖÖ! |
Re: [Non VCL] - Button erscheint nicht...
Das wurde dir aber schon vor drei Stunden von Mathias ans Herz gelegt.
|
Re: [Non VCL] - Button erscheint nicht...
Naja ich habs auch gelesen die Start.chm zum Thema Buttons.
Allerdings konnt ich damit nur recht wenig anfangen zu dem Zeitpunkt :pale: |
Re: [Non VCL] - Button erscheint nicht...
"start.chm"? :gruebel: Luckie?
|
Re: [Non VCL] - Button erscheint nicht...
Zitat:
|
Re: [Non VCL] - Button erscheint nicht...
Jupp, die CHM Version ist noch auf dem Server, weil für die HxS Version muss ja zwinged MSXML nstalliert sein und das hat ja nicht jeder oder?
|
Re: [Non VCL] - Button erscheint nicht...
Ach so. Ich würde ja gern auf mein .NET-Tool wechseln, aber dann höre ich als Argument wieder, .NET hat nicht jeder drauf. :stupid: Vom Help 2.0-System ganz zu schweigen. :zwinker: Andererseits gibt´s ja auch noch deine PDF. Dann würde ich doch eher die vorziehen, anstelle die veraltete CHM anzubieten.
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:41 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