E
Hi Leute, bin absoluter Neuling auf dem Gebiet der Windowsprogrammierung und habe so meine Schwierigkeiten. Folgendes ich möchte eine Dialogbox aus meinem Menu aufrufen. Das klappt auch irgendwie, allerdings wird die Dialogbox im
Hauptfenster angezeigt und nicht als verschiebbares Fenster (so wie eine Dialogbox eben sein sollte). Dann ist nichts mehr anwählbar und man muss das prog mit dem taskmanager schliessen (vielleicht auch weil die buttons nicht funktionieren.. aber warum?). Ich denke für jemanden, der Ahnung von der Materie hat, sollte das Lösen des Problems ein leichtes sein... Bitte um Hilfe, dennich trete seit tagen auf der stelle und alles gegoogle hat nichts geholfen. nutze visual studio 2005 c++ mit opengl.
vielen Dank im Voraus!
#define STRICT
#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input/Output
#include "GL.h"
#include "resource.h"
using namespace std;
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
//bool light; // Lighting ON/OFF
//bool lp; // L Pressed?
...
//Klassenobjekte erzeugen
GL gl;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
hInstance = 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 = MAKEINTRESOURCE(IDR_MENU1); // We Want A Menu
//wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name
if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
if (fullscreen) // Attempt Fullscreen Mode?
{
DEVMODE dmScreenSettings; // Device Mode
memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
// Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","CoPa GL Avatar",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
}
else
{
// Pop Up A Message Box Letting User Know The Program Is Closing.
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE; // Return FALSE
}
}
}
if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}
static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
gl.ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
return TRUE; // Success
}
LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
{
HMENU hMenu;
POINT point;
switch (uMsg) // Check For Windows Messages
{
case WM_COMMAND:
hMenu=GetMenu(hWnd);
switch (LOWORD (wParam))
{
case ID_FILE_EXIT:
if(MessageBox(hWnd, "Wollen Sie das Programm wirklich verlassen?", "Gaze Direction Avatar", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
SendMessage(hWnd, WM_CLOSE, 0, 0);
}
return 0;
...
case ID_\1:
DialogBox(hInstance, MAKEINTRESOURCE(IDD_PROPPAGE_MEDIUM), hWnd, reinterpret_cast<DLGPROC>(DlgProc));
break;
}
return 0;
case WM_ACTIVATE: // Watch For Window Activate Message
{
if (!HIWORD(wParam)) // Check Minimization State
{
active=TRUE; // Program Is Active
}
else
{
active=FALSE; // Program Is No Longer Active
}
return 0; // Return To The Message Loop
}
case WM_LBUTTONDOWN: //Wenn die linke Maustaste gedrückt wird
point.x=LOWORD(lParam);
point.y=HIWORD(lParam);
//MessageBox(hWnd, "SIE SIND HIER: " point.x " " point.y, "Achtung", MB_OK);
MessageBox(hWnd, "SIE SIND HIER: point.x point.y ", "Achtung", MB_OK);
return 1;
break;
case WM_RBUTTONDOWN: //Wenn die rechte Maustaste gedrückt wird, erscheint eine
MessageBox(hWnd, //MSGBOX, die dies bestätigt
"Die rechte Maustaste hat noch keine Funktion.",
"Achtung",
MB_OK);
Beep (1000,1000); //for tests
return 1;
break;
case WM_SYSCOMMAND: // Intercept System Commands
{
switch (wParam) // Check System Calls
{
case SC_SCREENSAVE: // Screensaver Trying To Start?
case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
return 0; // Prevent From Happening
}
break; // Exit
}
case WM_CLOSE: // Did We Receive A Close Message?
{
PostQuitMessage(0); // Send A Quit Message
return 0; // Jump Back
}
case WM_KEYDOWN: // Is A Key Being Held Down?
{
keys[wParam] = TRUE; // If So, Mark It As TRUE
return 0; // Jump Back
}
case WM_KEYUP: // Has A Key Been Released?
{
keys[wParam] = FALSE; // If So, Mark It As FALSE
return 0; // Jump Back
}
case WM_SIZE: // Resize The OpenGL Window
{
gl.ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
return 0; // Jump Back
}
}
// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd,uMsg,wParam,lParam);
//return FALSE;
}
LRESULT CALLBACK DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(wParam)
{
case IDC_BUTTON1:
gl.Head_ON=TRUE;
case IDC_BUTTON2:
EndDialog(hWnd, 0);
return TRUE;
case IDC_BUTTON3:
PostQuitMessage(0); // Send A Quit Message
return 0; // Jump Back
}
break;
}
return FALSE;
}
int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop
// Ask The User Which Screen Mode They Prefer
//if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
fullscreen=FALSE; // Windowed Mode
}
// Create Our OpenGL Window
if (!CreateGLWindow("Gaze Direction Avatar",800,600,32,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !gl.DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
//HEAD VISIBLE OR NOT VISIBLE VIA SHIFT+H OR H
if (keys['H'] && !fp)
{
fp=TRUE;
gl.Head_ON=FALSE;
}
if (keys['F']) // Is F1 Being Pressed?
{
keys['F']=FALSE; // If So Make Key FALSE
//KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("Gaze Direction Avatar",1440,900,32,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
}
// Shutdown
//KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
/////////////RESOURCE.H
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Avatar.rc
//
#define IDR_MENU1 101
#define IDD_PROPPAGE_MEDIUM 106 //DIALOG
#define IDC_EDIT1 1010
#define IDC_BUTTON1 1014 //BUTTONS 1-3
#define IDC_BUTTON2 1015
#define IDC_BUTTON3 1016
#define ID_FILE_OPEN40001 40001
#define ID_OPEN_MESH 40002
#define ID_MESH_HEAD 40003
#define ID_MESH_LEFTEYE 40004
#define ID_MESH_RIGHTEYE 40005
#define ID_OPEN_TEXTURE 40006
#define ID_TEXTURE_HEAD 40007
#define ID_TEXTURE_LEFTEYE 40008
#define ID_TEXTURE_RIGHTEYE 40009
#define ID_FILE_SAVE40010 40010
#define ID_FILE_EXIT 40011
#define ID_VISIBILITY_SHOWHEAD 40012
#define ID_VISIBILITY_SHOWEYES 40013
#define ID_VISIBILITY_SHOWCOORDINATESYSTEMS 40014
#define ID_VISIBILITY_SHOWGAZEOBJECTS 40015
#define ID_VISIBILITY_SHOWALL 40016
#define ID_ABOUT 40017
#define ID_HELP40018 40018
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40019
#define _APS_NEXT_CONTROL_VALUE 1017
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
/////////////////AVATAR.RC (HIER NUR DIALOG...)
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_PROPPAGE_MEDIUM DIALOGEX 0, 0, 106, 155
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_DISABLED | WS_CAPTION
CAPTION "Property Page"
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
PUSHBUTTON "Button1",IDC_BUTTON1,22,116,50,14
PUSHBUTTON "Button2",IDC_BUTTON2,24,71,50,14
PUSHBUTTON "Button3",IDC_BUTTON3,26,28,50,14
END
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////