Form + neues Fenster = Zugriffsverletzung?
-
Ich habe ein form erschaffen und einen Button. Dem Button habe ich zugeweisen, dass er wenn man ihn drückt ein neues Fenster öffnen soll (welches später OpenGL initialisiert). Jedoch tritt dabei immer ein Fehler auf. Hier der Source für die Header und Source-Datei:
/////////////////////////////////////////////////////////////////////////////
/////////////////////Here's the code of the Header-File//////////////////////
///////////////////////////////////////////////////////////////////////////////---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>HWND hWnd=NULL;
HINSTANCE hInstance = NULL;
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // Von der IDE verwaltete Komponenten
TButton *Button1;
void __fastcall Button1Click(TObject Sender);
private: // Anwender-Deklarationen
public: // Anwender-Deklarationen
__fastcall TForm1(TComponent Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif/////////////////////////////////////////////////////////////////////////////
////////////////and here's the code of the *.cpp-File////////////////////////
/////////////////////////////////////////////////////////////////////////////void __fastcall TForm1::Button1Click(TObject *Sender)
{
WNDCLASS wc; // Windows class structure
DWORD dwExStyle; // Window extended style
DWORD dwStyle; // Window style
RECT WindowRect; // Grabs rctangle upper left / lower right values
WindowRect.left = (long)0; // Set left value to 0
WindowRect.right = (long)400; // Set right value to requested width
WindowRect.top = (long)0; // Set top value to 0
WindowRect.bottom = (long)400; // Set bottom value to requested heighthInstance = GetModuleHandle(NULL); // Grab an instance for our window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw on size, and own DC for window
// wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc handles messages
wc.cbClsExtra = 0; // No extra window data
wc.cbWndExtra = 0; // No extra window data
wc.hInstance = hInstance; // Set the Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the default icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the arrow pointer
wc.hbrBackground = NULL; // No background required for GL
wc.lpszMenuName = NULL; // We don't want a menu
wc.lpszClassName = "OpenGL"; // Set the class nameif (!RegisterClass(&wc)) // Attempt to register the window class
{
MessageBox(NULL,"Failed to register the window class.","Error",MB_OK|MB_ICONEXCLAMATION);}
if(!(hWnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window
"OpenGL", // Class name
"Open GL Fenster", // Window title
WS_OVERLAPPEDWINDOW | // Defined window style
WS_CLIPSIBLINGS | // Required window style
WS_CLIPCHILDREN, // Required window style
0, 0, // Window position
(long) 640, // Calculate window width
(long) 480, // Calculate window height
NULL, // No parent window
NULL, // No menu
hInstance, // Instance
NULL))) // Dont pass anything to WM_CREATE{
MessageBox(NULL,"Konnte Fenster nicht initialisieren","ERROR",MB_OK|MB_ICONEXCLAMATION);
}}
//---------------------------------------------------------------------------
-
Und wie lautet jetzt die Fehlermeldung??
[Edit]
Wäre es nicht einfacher eine 2. Form anzulegen und diese dann per Show() oder so aufzurufen und dort dann OpenGL zu initialisieren?
[/Edit][ Dieser Beitrag wurde am 04.07.2003 um 11:53 Uhr von PuppetMaster2k editiert. ]
-
Ja natürlich wäre das einfacher, aber bisher wusste ich nicht wie das geht.
Dann benötige ich aber zumindest das Handle. Ist das Handle dann der Name (nicht die Caption) des Forms?
Kannste mir mal zur Initialisierung von OpenGL in diesem Fenster ein Beispiel geben?
-
Also das mit der 2. Form is ganz easy. einfach bei dein Projekt öffnen und auf Datei->Neues Formular, fertig
Aufrufen kannst du es dann mit dem Namen der Form z.B. Form2->Show() *voila*
Die OGL Initialisierung kannst du ja im Konstruktor der 2. Form machen oder rufst sie im OnShow-Event auf.
[Edit]
Für die initialisierung der OGL kannst du dir ja mal das Beispiel im Ordner Exampels angucken. da ist alles relevante drin
[/Edit][ Dieser Beitrag wurde am 04.07.2003 um 12:13 Uhr von PuppetMaster2k editiert. ]
-
Doppelposting, geschlossen.