Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

tonymontana

WON'T I MAKE A WÝNDOW AT LEAST...

This topic is 5282 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

RegisterClassEx(& blabla...) parts causing an error why??
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <math.h>

LRESULT CALLBACK WinProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	switch(msg)
	{
		case WM_CREATE:
			{
				
				return 0;
			}
		    break;
		case WM_PAINT:
			{
			
				hdc=BeginPaint(hwnd,&ps);
				EndPaint(hwnd,&ps);
				return 0;
			}
			break;
		case WM_DESTROY:
			{
			
				PostQuitMessage(0);
				return 0;
			}
			break;
		default:
			{
				
				return 0;
			}
			// to process any messages that we didn''t take care of

			return (DefWindowProc(hwnd,msg,wparam,lparam));

	}
}


int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,int nCmdShow)
{
	HWND hwnd;
	MSG msg;
	WNDCLASSEX myclass;            //This the FÝRST STEP making the myclass structure

	myclass.cbClsExtra=0;
	myclass.cbWndExtra=0;
	myclass.cbSize=sizeof(myclass);
	myclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
	myclass.hCursor=LoadCursor(NULL,IDC_ARROW);
	myclass.hIcon=LoadIcon(NULL,IDI_WINLOGO);
	myclass.hIconSm=LoadIcon(NULL,IDI_EXCLAMATION);
	myclass.hInstance=hinstance;
	myclass.lpfnWndProc=WinProc;
	myclass.lpszClassName="MYCLASS1";
	myclass.style=CS_HREDRAW||CS_VREDRAW||CS_OWNDC||CS_DBLCLKS;
	if(!(RegisterClassEx(&myclass)))   //this is SECOND STEP Registerin myclass

	{
		return 0;
	}
	// This is the THÝRD  STEP Creatin myclass

	if(!(hwnd=CreateWindowEx(NULL,"MYCLASS1","BU BENÝM ÝLK PENCEREM AMA SON OLMAYACAK....",WS_POPUP,0,0
		,600,600,NULL,NULL,hinstance,NULL)))
	{
		
		return 0;
	}
	ShowWindow(hwnd,nCmdShow);
	while(GetMessage(&msg,NULL,0,0))
	{
		//translate any accelerator keys

		TranslateMessage(&msg);
		//send the message to the window proc

		DispatchMessage(&msg);
	}
	//return to windows like this

	return (msg.wParam);

}
the archer who shoots his arrow beyond his target is no more successful than the one who''s arrow didn''t even reach the target.

Share this post


Link to post
Share on other sites
Advertisement
ok i did it But are not we (OR'ing these CS_blabla why do i have to write single |
and this also didn't solve the problem...

[edited by - tonymontana on March 4, 2004 7:45:35 PM]

Share this post


Link to post
Share on other sites
You dont state what error you are recieving. Here is my code (as a for instance) for building a simple window to the screen. Tested in Codewarrior 6.
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
LRESULT CALLBACK TextDraw(HWND, UINT, WPARAM, LPARAM);

static char AppTitle[] = "Adventure game test V1.0";

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // window styles to use

wc.lpfnWndProc = TextDraw; // function name of event handler

wc.hInstance = hInstance; // handle to this apps instance

wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // background colour of window

wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); // icon for the app window

wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // icon when minimized to taskbar

wc.hCursor = LoadCursor(NULL, IDC_ARROW); // cursor to use for this window

wc.lpszClassName = AppTitle; // name for this class


RegisterClassEx( &wc );

// CreateWindow( Program_name, Window_name, Window_style, locationX, locationY, width, height, _

// Parent_Window, Menu_displayed, Class_instance, Parameters)

HWND hWnd = CreateWindow(AppTitle, AppTitle, WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, NULL, NULL, wc.hInstance, NULL);

ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

MSG msg;

ZeroMemory( &msg, sizeof(msg) );
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
// no winmessages, idle code here

}
}

UnregisterClass( AppTitle, wc.hInstance );
return 0;
}

//-----------------------------------------------------------------------------

// Name: MsgProc()

// Desc: The window's message handler

//-----------------------------------------------------------------------------

LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
HDC hDC;
PAINTSTRUCT PaintStruct; switch( msg )
{
case WM_PAINT:
{
hDC=BeginPaint(hWnd, &PaintStruct); // Tell windows we want to update the window

// GDI Drawing here

EndPaint(hWnd, &PaintStruct);
return 0;
}

case WM_DESTROY:
{
PostQuitMessage( 0 );
return 0;
}

default:

return DefWindowProc( hWnd, msg, wParam, lParam );
}

}

LRESULT CALLBACK TextDraw(HWND hWnd, UINT messg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;

switch (messg)
{
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);

MoveToEx(hdc,0,17,NULL);
LineTo(hdc, 639, 17);

// TextOut command:

// TextOut HDC, x, y, string, stringlen


TextOut(hdc, 1, 1, "Enter a command", 15);

ValidateRect(hWnd, NULL);
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hWnd,messg,wParam,lParam));
break;
}
return(0);
}
If you could give the error you are recieving it may help. Incidentally, yes you are "OR"ing, but you are using a bitwise OR rather than a logical OR. A logical OR equates to True or False while a bitwise OR evaluates all the bits in each byte.

[edited by - Neo Genesis10 on March 4, 2004 7:55:10 PM]

Share this post


Link to post
Share on other sites
error is ACCESS VİOLATİON ERROR ...
i am taking that when i am trying to run the program.
i used debug to solve and realized that it is related the
line with RegisterClassEx(..)

Share this post


Link to post
Share on other sites
You should use the | not the || because you want a bitwise OR, not a logical OR.

The real problem is the fact that you haven''t initialised the lpszMenuName member of the WNDCLASSEX structure. Just set it to NULL and everything will be shiny and happy.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!