Brauche Hilfe bei der Eingabe!



  • Hallo,
    ich will mit Hilfe der WINAPI eine Eingabe und danach eine Ausgabe eines Wertes(vom typ double) machen, das mit Hilfe von MessageBox und dem Entsprechenden Eingabebefehl, wie geht das?
    Brauche schnell eine Antwort, würde mich daher über direkte Lösungen, und keine Links freuen.
    Danke 😃



  • Direkte Lösungen (gegen Geld) bekommst Du im Forum "Projekte".

    Ansonsten ist das einfachste eine Dialog-Resource anzulegen, welche Du dann mit "DialogBox" anzeigst...
    http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/dialogboxes/usingdialogboxes.asp



  • Wie man mit MessageBox umgeht wusste ich schon, jedoch stellt sich noch die Frage, wie ich eine Eingabe Organisieren kann...



  • Hab ich in meiner Antwort irgendwas von MessageBox gesagt!?



  • Ja die zweite Überschrift:
    Displaying a Message Box
    sagt doch schon alles aus 😉



  • Tja, dann solltest du noch ein kleines bisschen weiterlesen 😉 in den folgenden Abschnitten geht es um vollwertige Dialogboxen.



  • Könnte mir mal jemand eine Lösung hinschreiben?
    Schließlich kann es ja nicht so viel Code sein, dass ihr euch die Finger abtippt, denn ich glaube ihr wollt auch, wenn ihr eine Frage habt eine Antwort haben und nicht eine Englische Seite von MSDN, wo man sich durch was weiß ich wie viele Links durchhangeln muss.



  • double a;

    MessageBox(0,a,"Fenstername",0);

    das ist doch was du meinst, oder???



  • Mitunter.
    Aber selbst das funktioniert nicht 😞 .
    Ich wollte eigentlich eine auch noch eine Eingabe steuern.



  • ich denke nicht das hier jemand einfach alles hinklascht. zeig uns deinen ansatz und es wird dir vermutlich geholfen. wenn du eine fertigte lösung willst dann bist du im projekte forum besser aufgehoben.



  • @Platy
    MessageBoxen sind so ziemlich das einfachste, was die WinAPI zu bieten hat. Wenn Du schon damit nicht klar kommst, solltest Du Dich vielleicht mal durch ein Tutorial beißen.

    http://www.win-api.de/tutorials.php?tutid=2

    Eingaben fragst Du mit WM_CHAR oder WM_KEYDOWN/ WM_KEYUP ab.



  • Platy schrieb:

    Mitunter.
    Aber selbst das funktioniert nicht 😞 .
    Ich wollte eigentlich eine auch noch eine Eingabe steuern.

    --> dann wandle deine double in ein char [] um und gib den aus.
    Das funktioniert auf jedenfall



  • Na ja gut hier ist mein Source, wo die Eingaben erfolgen sollen, habe ich gekennzeichnet.

    #include <windows.h>
    #include <gl\gl.h>
    #include <gl\glu.h>
    
    HGLRC hglrc=NULL;
    HDC hdc=NULL;
    HWND hwnd=NULL;
    HINSTANCE hInstance;
    
    bool keys[256];
    bool active = TRUE;
    bool fullscreen = TRUE;
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    
    struct Vertexs{
    	float x;
    	float y;
    	float z;
    };
    
    struct Player{
    	int points;
    	float x;
    	float y;
    	float z;
    	float length;
    	float width;
    };
    
    Player P1 = { 0, -4.9f,0.0f,0.0f,0.9f,0.3f};
    Player P2 = { 0, 4.9f,0.0f,0.0f,0.9f,0.3f}; 
    Vertexs speed = {0.05f,0.09f,0.0f};  // Für die Geschwindigkeit des Balles.
    Vertexs Ball = {0.0f,0.0f,0.0f};
    
    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
    {
    	if (height == 0)
    		height = 1;
    	glViewport(0,0,width, height);
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	gluPerspective(45.0F, (GLfloat)width/(GLfloat)height, 0.1F, 100.0F);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    }
    
    int InitGL()
    {
    	glShadeModel(GL_SMOOTH);
    	glClearColor(1.0F, 1.0F, 1.0F, 1.0F);
    	glClearDepth(1.0F);
    	glEnable(GL_DEPTH_TEST);
    	glDepthFunc(GL_LEQUAL);
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    	return TRUE;
    }
    
    int DrawGLScene()
    {
    	if (Ball.x >= 4.6)
    	{
    		P1.points += 1;
    		speed.x *= -1;  //in die andere Richtung.
    	}
    	if (Ball.x <= -4.6)
    	{
    		P2.points += 1;
    		speed.x *= -1;
    	}
    	if (Ball.y >= 4.6)
    		speed.y *= -1;
    	if (Ball.y <= -4.6)
    		speed.y *= -1;
    	if (Ball.x >= (4.6 - P2.width) && Ball.y <= (P2.y + P2.length) && Ball.y >= (P2.y - P2.length))
    		speed.x *= -1;
    	if (Ball.x <= (-4.6 + P1.width) && Ball.y <= (P1.y + P1.length) && Ball.y >= (P1.y - P2.length))
    		speed.x *= -1;
    
    	Ball.x += speed.x;
    	Ball.y += speed.y;
    	Vertexs topleft = {-4.9f,4.9f,0.0f};
    	Vertexs topright = {4.9f,4.9f,0.0f};
    	Vertexs bottomleft = {-4.9f,-4.9f,0.0f};
    	Vertexs bottomright = {4.9f,-4.9f,0.0f};
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glLoadIdentity();
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(-5.0, +5.0, -5.0, +5.0, -1.0, +1.0);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    	glBegin(GL_LINE_STRIP);		//Spielfeldbegrenzung
    		glColor3f(0.0f,1.0f,0.0f);
    		glVertex3fv(&topright.x);
    		glVertex3fv(&topleft.x);
    		glVertex3fv(&bottomleft.x);
    		glVertex3fv(&bottomright.x);
    		glVertex3fv(&topright.x);
    	glEnd();
    
    	glBegin(GL_QUADS);		// Viereck für den ersten Spieler
    		glColor3f(1.0f,0.0f,0.0f);
    		glVertex3f(P1.x + P1.width,P1.y + P1.length,P1.z);
    		glVertex3f(P1.x, P1.y + P1.length,P1.z);
    		glVertex3f(P1.x,P1.y - P1.length,P1.z);
    		glVertex3f(P1.x +P1.width, P1.y - P1.length, P1.z);
    	glEnd();
    
    	glBegin(GL_QUADS);		// Viereck für den zweiten Spieler
    		glColor3f(0.0f,0.0f,1.0f);
    		glVertex3f(P2.x - P2.width,P2.y + P2.length,P2.z);
    		glVertex3f(P2.x, P2.y + P2.length,P2.z);
    		glVertex3f(P2.x,P2.y - P2.length,P2.z);
    		glVertex3f(P2.x - P2.width, P2.y - P2.length, P2.z);
    	glEnd();
    
    	GLUquadricObj* pKugel;		//Ball zum Spielen
    	pKugel = gluNewQuadric();
    	glTranslatef(Ball.x,Ball.y, Ball.z);
    	gluQuadricTexture(pKugel, false);
    	gluQuadricOrientation(pKugel, GLU_OUTSIDE);
    	gluQuadricDrawStyle(pKugel, GL_FILL);
    	gluQuadricNormals(pKugel, GLU_FLAT);
    	gluQuadricCallback(pKugel, GLU_ERROR, NULL);
    	glColor3f(0.0f,0.5f,0.5f);
    	gluSphere(pKugel, (double)0.3, (int)18, (int)9);
    
    	glFlush();
    	glFinish();
    	return TRUE;
    }
    
    GLvoid KillGLWindow()
    {
    	if(fullscreen)
    	{
    		ChangeDisplaySettings(NULL, 0);
    		ShowCursor(TRUE);
    	}
    	if(hglrc)
    	{
    		wglMakeCurrent(NULL, NULL);
    		wglDeleteContext(hglrc);
    	}
    	if(hdc && !ReleaseDC(hwnd, hdc))
    	{
    		hdc = NULL;
    	}
    	if(hwnd && !DestroyWindow(hwnd))
    		hwnd = NULL;
    	if(!UnregisterClass("OpenGL", hInstance))
    		hInstance = NULL;
    }
    
    bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
    {
    	GLuint PixelFormat;
    	WNDCLASS wc;
    	DWORD dwExStyle;
    	DWORD dwStyle;
    	RECT WindowsRect;
    	WindowsRect.left=(long)0;
    	WindowsRect.right = (long)width;
    	WindowsRect.top = (long)0;
    	WindowsRect.bottom = (long)height;
    	fullscreen = fullscreenflag;
    	hInstance = GetModuleHandle(NULL);
    	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    	wc.lpfnWndProc = (WNDPROC)WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = NULL;
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "OpenGL";
    	RegisterClass(&wc);
    
    	if(fullscreen)
    	{
    		DEVMODE dmScreenSettings;
    		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
    		dmScreenSettings.dmSize = sizeof(dmScreenSettings);
    		dmScreenSettings.dmPelsWidth = width;
    		dmScreenSettings.dmPelsHeight = height;
    		dmScreenSettings.dmBitsPerPel = bits;
    		dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    		if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
    		{
    			if (MessageBox(NULL, "Vollbildmodus wird nicht unterstützt im Fenstermodus umschalten?", "OpenGL", MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
    				fullscreen = FALSE;
    			else
    				return FALSE;
    		}
    	}
    	if (fullscreen)
    	{
    		dwExStyle = WS_EX_APPWINDOW;
    		dwStyle = WS_POPUP;
    		ShowCursor(FALSE);
    	}
    	else
    	{
    		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    		dwStyle = WS_OVERLAPPEDWINDOW;
    	}
    
    	AdjustWindowRectEx(&WindowsRect, dwStyle, FALSE, dwExStyle);
    
    	if (!(hwnd=CreateWindowEx(dwExStyle, "OpenGL", title, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, NULL,NULL,
    		WindowsRect.right - WindowsRect.left, WindowsRect.bottom - WindowsRect.top, NULL, NULL, hInstance, NULL)))
    	{
    		KillGLWindow();
    		MessageBox(NULL, "Fenster konnte nicht erstellt werden", "Fehler", MB_OK | MB_ICONEXCLAMATION);
    		return FALSE;
    	}
    
    	PIXELFORMATDESCRIPTOR pfd = {
    		sizeof(PIXELFORMATDESCRIPTOR),
    		1,
    		PFD_DRAW_TO_WINDOW | PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
    		PFD_TYPE_RGBA,
    		bits,
    		0,0,0,0,0,0,0,0,0,0,0,0,0,
    		16,
    		0,0,
    		0,
    		0,0,0,0};
    	if(!(hdc = GetDC(hwnd))) 
    		MessageBox(NULL, "Fehler beim hdc = GetDC", "Fehler", MB_OK| MB_ICONINFORMATION);
    	PixelFormat = ChoosePixelFormat(hdc, &pfd);
    	SetPixelFormat(hdc, PixelFormat, &pfd);
    	hglrc = wglCreateContext(hdc);
    	wglMakeCurrent(hdc, hglrc);
    	ShowWindow(hwnd, SW_SHOW);
    	SetForegroundWindow(hwnd);
    	SetFocus(hwnd);
    	ReSizeGLScene(width, height);
    	InitGL();
    	return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch(uMsg)
    	{
    	case WM_ACTIVATE:
    		{
    			if(!HIWORD(wParam))
    				active = TRUE;
    			else
    				active = FALSE;
    			return 0;
    		}
    	case WM_SYSCOMMAND:
    		{
    			switch(wParam)
    			{
    			case SC_SCREENSAVE:
    			case SC_MONITORPOWER:
    				return 0;
    			}
    			break;
    		}
    	case WM_CLOSE:
    		{
    			PostQuitMessage(0);
    			return 0;
    		}
    	case WM_KEYDOWN:
    		{
    			keys[wParam] = TRUE;
    			return 0;
    		}
    	case WM_KEYUP:
    		{
    			keys[wParam] = FALSE;
    			return 0;
    		}
    	case WM_SIZE:
    		{
    			ReSizeGLScene(LOWORD(lParam), HIWORD(wParam));
    			return 0;
    		}
    	}
    
    	return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	MSG msg;
    	bool done = FALSE;
    	if(MessageBox(NULL, "Soll im Vollbildmodus gestartet werden?", "Vollbildmodus", MB_YESNO | MB_ICONQUESTION) == IDNO)
    		fullscreen = FALSE;
    	//MessageBox(NULL,"Wie viele Punkte, muss der Sieger haben?", "Siegbedingungen", MB_OK | MB_ICONQUESTION);  // Hier soll eine Eingabe erfolgen.
    	// Der restliche Source, der hier hin gehört folgt noch, wenn die Eingabe funktioniert.
    	//MessageBox(NULL,"Bitte geben sie den Schwirigkeitsgrad an.  (l,m,s)", "Schwierigkeitsgrad");   // Noch eine Eingabe...
    	if(!(CreateGLWindow("Das Fenster", 640, 480, 32, fullscreen)))
    		return 0;
    
    	while (!done)
    	{
    		if (PeekMessage(&msg, NULL, 0,0,PM_REMOVE))
    		{
    			if(msg.message==WM_QUIT)
    				done = TRUE;
    			else
    			{
    				TranslateMessage(&msg);
    				DispatchMessage(&msg);
    			}
    		}
    		else
    		{
    			if(active)
    			{
    				if(keys[VK_ESCAPE])
    					done = TRUE;
    				else
    				{
    					DrawGLScene();
    					SwapBuffers(hdc);
    				}
    			}
    			if(keys[VK_F1])
    			{
    				keys[VK_F1] = FALSE;
    				KillGLWindow();
    				fullscreen =! fullscreen;
    				if(!CreateGLWindow("Das Fenster", 640,480,32,fullscreen))
    					return 0;
    			}
    			if (keys['W'])
    			{
    				keys['W']=false;
    				if ((P1.y + 0.3f) >= (4.9f - P1.length))
    					P1.y = 4.9f - P1.length;
    				else
    					P1.y += 0.3f;
    			}
    			if (keys['S'])
    			{
    				keys['S']=false;
    				if ((P1.y - 0.3f) <= (-4.9f + P1.length))
    					P1.y = -4.9f + P1.length;
    				else
    					P1.y -= 0.3f;
    			}
    			if (keys[VK_DOWN])
    			{
    				keys[VK_DOWN]=false;
    				if ((P2.y - 0.3f) <= (-4.9f + P2.length))
    					P2.y = -4.9f + P2.length;
    				else
    					P2.y -= 0.3f;
    			}
    			if (keys[VK_UP])
    			{
    				keys[VK_UP]=false;
    				if ((P2.y + 0.3f) >= (4.9f - P2.length))
    					P2.y = 4.9f - P2.length;
    				else
    					P2.y += 0.3f;
    			}
    		}
    		if (P1.points >= 10)
    		{
    			MessageBox(NULL, "Sieger ist Spieler eins", "Sieger", MB_OK);
    			break;
    		}
    		if (P2.points >= 10)
    		{
    			MessageBox(NULL, "Sieger ist Spieler zwei", "Sieger", MB_OK);
    			break;
    		}
    	}
    	KillGLWindow();
    	return (msg.wParam);
    }
    

    Hoffentlich kann mir jetzt einer helfen.



  • Dann solltest du wohl fast einen richtigen Dialog machen, den du dann mit DialogBox startest. Dann kannst du dort in der DlgProc Tastendrücke abfängen, oder Buttons zum auswählen anbieten...


Anmelden zum Antworten