Click here to Skip to main content
15,915,086 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Captions with files Pin
enhzflep15-Apr-12 8:23
enhzflep15-Apr-12 8:23 
GeneralRe: Captions with files Pin
Anthony Appleyard15-Apr-12 8:58
Anthony Appleyard15-Apr-12 8:58 
GeneralRe: Captions with files Pin
enhzflep15-Apr-12 9:02
enhzflep15-Apr-12 9:02 
GeneralRe: Captions with files Pin
Anthony Appleyard15-Apr-12 19:31
Anthony Appleyard15-Apr-12 19:31 
GeneralRe: Captions with files Pin
enhzflep15-Apr-12 20:17
enhzflep15-Apr-12 20:17 
GeneralRe: Captions with files Pin
Anthony Appleyard15-Apr-12 22:23
Anthony Appleyard15-Apr-12 22:23 
AnswerRe: Captions with files Pin
enhzflep3-May-12 22:21
enhzflep3-May-12 22:21 
QuestionCan someone show me how to draw 3D lines? Pin
xy50518814-Apr-12 21:55
xy50518814-Apr-12 21:55 
This is my code:
C++
#include "stdafx.h"
#include <windows.h>
#include <glut.h>
#include <glaux.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glaux.lib")

LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
void EnableOpenGL(HWND hwnd,HDC* ,HGLRC*);
void DisableOpenGL(HWND,HDC,HGLRC);

int APIENTRY WinMain(
	HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPSTR nCmdLine,
	int nCmdShow)
{
	WNDCLASSEX wcex;
	HWND hwnd;
	HDC hDC;
	HGLRC hRC;
	MSG msg;
	BOOL bQuit=FALSE;
	float i=0.0f,Angle=0.0f;

	wcex.cbSize=sizeof(WNDCLASSEX);
	wcex.cbClsExtra=0;
	wcex.cbWndExtra=0;
	wcex.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	wcex.hCursor=LoadCursor(NULL,IDC_CROSS);
	wcex.hIcon=LoadIcon(NULL,IDI_INFORMATION);
	wcex.hIconSm=NULL;
	wcex.hInstance=hInstance;
	wcex.lpfnWndProc=WindowProc;
	wcex.lpszClassName="OpenGL___Xiang";
	wcex.lpszMenuName=NULL;
	wcex.style=CS_HREDRAW|CS_VREDRAW;
	if (!RegisterClassEx(&wcex))
	{
		MessageBox(NULL,"注册类失败!","Error",MB_ICONERROR);
		return 0;
	}

	hwnd=CreateWindowEx(0,
		"OpenGL___Xiang","OpenGL Sample",WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
		NULL,NULL,hInstance,0);
	ShowWindow(hwnd,SW_MAXIMIZE);

	EnableOpenGL(hwnd,&hDC,&hRC);
	while (!bQuit)
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			if (msg.message==WM_QUIT)
			{
				bQuit=TRUE;
			}
			else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}				
		}
		else
		{
			glClearColor(0.0f,0.0f,0.0f,0.5f);
			glClearDepth(1.0f);
			glEnable(GL_SMOOTH);
			glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);

			glPushMatrix();
			glTranslatef(0.0f,0.0f,0.0f);
			glColor3f(0.0f,1.0f,0.0f);

			for (i=-50;i<=50;i+=1)
			{
                               ///Draw method is here
				glBegin(GL_LINES);
				glVertex3f(	-50,0,i);
				glVertex3f(	50,0,i);

				glVertex3f(	i,0,-50);
				glVertex3f(	i,0,50);
				glEnd();
			}
			glPopMatrix();

			SwapBuffers(hDC);
		}
	}
	DisableOpenGL(hwnd,hDC,hRC);
	DestroyWindow(hwnd);
	return msg.wParam;
}

LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	switch (msg)
	{
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	case WM_KEYDOWN:
		{
			switch (wparam)
			{
			case VK_ESCAPE:
				PostQuitMessage(0);
				break;
			}
		}
		break;
	default:
		return DefWindowProc(hwnd,msg,wparam,lparam);
	}
	return 0;
}

void EnableOpenGL(HWND hwnd,HDC* hDC,HGLRC* hRC)
{
	PIXELFORMATDESCRIPTOR pfd;
	int iFormat;
	*hDC=GetDC(hwnd);
	ZeroMemory(&pfd,sizeof(pfd));
	pfd.nSize=sizeof(pfd);
	pfd.nVersion=1;
	pfd.dwFlags=PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
	pfd.iPixelType=PFD_TYPE_RGBA;
	pfd.cColorBits=24;
	pfd.cDepthBits=16;
	pfd.iLayerType=PFD_MAIN_PLANE;     //颜色输出单通道?
	iFormat=ChoosePixelFormat(*hDC,&pfd);
	SetPixelFormat(*hDC,iFormat,&pfd);
	*hRC=wglCreateContext(*hDC);
	wglMakeCurrent(*hDC,*hRC);
}

void DisableOpenGL(HWND hwnd,HDC hdc,HGLRC hRC)
{
	wglMakeCurrent(NULL,NULL);
	wglDeleteContext(hRC);
	ReleaseDC(hwnd,hdc);
}
//Just draw a single line,Why? how to draw?

AnswerRe: Can someone show me how to draw 3D lines? Pin
enhzflep14-Apr-12 23:44
enhzflep14-Apr-12 23:44 
QuestionProgress Bar not worked well with larger values? Pin
Le@rner14-Apr-12 2:43
Le@rner14-Apr-12 2:43 
AnswerRe: Progress Bar not worked well with larger values? Pin
Wes Aday14-Apr-12 2:56
professionalWes Aday14-Apr-12 2:56 
AnswerRe: Progress Bar not worked well with larger values? PinPopular
enhzflep14-Apr-12 3:04
enhzflep14-Apr-12 3:04 
GeneralRe: Progress Bar not worked well with larger values? Pin
Le@rner16-Apr-12 18:55
Le@rner16-Apr-12 18:55 
GeneralRe: Progress Bar not worked well with larger values? Pin
enhzflep16-Apr-12 20:54
enhzflep16-Apr-12 20:54 
AnswerRe: Progress Bar not worked well with larger values? Pin
Maximilien14-Apr-12 3:34
Maximilien14-Apr-12 3:34 
QuestionCreateWindowEx, DestroyWindow, CreateWindowEx Pin
jkirkerx13-Apr-12 10:31
professionaljkirkerx13-Apr-12 10:31 
AnswerThat was just a bad idea - went back to hide and show Pin
jkirkerx13-Apr-12 12:28
professionaljkirkerx13-Apr-12 12:28 
AnswerRe: CreateWindowEx, DestroyWindow, CreateWindowEx Pin
Binu MD16-Apr-12 21:22
Binu MD16-Apr-12 21:22 
GeneralRe: CreateWindowEx, DestroyWindow, CreateWindowEx Pin
jkirkerx17-Apr-12 7:12
professionaljkirkerx17-Apr-12 7:12 
GeneralRe: CreateWindowEx, DestroyWindow, CreateWindowEx Pin
Binu MD17-Apr-12 14:59
Binu MD17-Apr-12 14:59 
GeneralRe: CreateWindowEx, DestroyWindow, CreateWindowEx Pin
jkirkerx17-Apr-12 15:49
professionaljkirkerx17-Apr-12 15:49 
AnswerRe: CreateWindowEx, DestroyWindow, CreateWindowEx Pin
JohnCz25-Apr-12 1:29
JohnCz25-Apr-12 1:29 
GeneralRe: CreateWindowEx, DestroyWindow, CreateWindowEx Pin
jkirkerx25-Apr-12 6:05
professionaljkirkerx25-Apr-12 6:05 
Questionhow is boost_scoped_ptr RAII ? Pin
elelont213-Apr-12 6:56
elelont213-Apr-12 6:56 
AnswerRe: how is boost_scoped_ptr RAII ? Pin
Chris Losinger13-Apr-12 10:33
professionalChris Losinger13-Apr-12 10:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.