Advertisement

Cursor

Started by June 28, 2002 09:39 PM
3 comments, last by Wachar 22 years, 4 months ago
Why doesn''t the cursor appear?
  
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include "resource.h"
#include <ddraw.h>

#define KEYDOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)

#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
	
HWND global_hwnd = NULL;

LPDIRECTDRAW lpdd = NULL;
LPDIRECTDRAW4 lpdd4 = NULL;

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:break;

	}

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

}

int Game_Init(int num_param = 0)
{
	
	if(FAILED(DirectDrawCreate(NULL, &lpdd, NULL)))
		{	
			return(0);
		}

		if(FAILED(lpdd->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpdd4)))
		{
			return(0);	
		}

		lpdd->Release();
		lpdd = NULL;

		lpdd4->SetCooperativeLevel(global_hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE |
								DDSCL_ALLOWREBOOT | DDSCL_ALLOWMODEX);
	
		if(FAILED(lpdd4->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, 8, 0, 0)))
		{
			return(0);
		}

		return(1);
}

int Game_Main(int num_param = 0)
{
		if(KEYDOWN(VK_ESCAPE))
			SendMessage(global_hwnd, WM_CLOSE, 0 , 0);

		return(1);
}

void Game_ShutDown(int num_param = 0)
{
	lpdd4->Release();
	lpdd4 = NULL;
}

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
	WNDCLASSEX winclass;
	HWND hwnd;
	MSG msg;

	winclass.cbSize = sizeof(WNDCLASSEX);
	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_VREDRAW | CS_HREDRAW;

	winclass.lpfnWndProc = WinProc;
	winclass.hInstance = hinstance;
	winclass.cbClsExtra = NULL;
	winclass.cbWndExtra = NULL;
	winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	winclass.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(IDC_CURSOR1));
	winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
	winclass.lpszClassName = "Winclass1";
	winclass.lpszMenuName = NULL;
	
	if(!(RegisterClassEx(&winclass)))
		return(0);

	if(!(hwnd = CreateWindowEx(NULL,
					"Winclass1",
					"My First Ecounter with DirectX!",
					WS_POPUP | WS_VISIBLE,
					0,0,
					SCREEN_WIDTH, SCREEN_HEIGHT,
					NULL,
					NULL,
					hinstance,
					NULL)))

					return(0);

	Game_Init();
	
	while(1)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	
		Game_Main();

	}

	Game_ShutDown();
	return(msg.wParam);

}
  
Yes the resource file is ok! K I L A H M A N J A R O !
Wachar's Eternity <-<-<-<-<- Me own site!
That code seem to be from TOTWGPG book, but slightly modified. I couldn''t figure out how resources work with TOTWGPG, but later on when I learned how to manipulate directinput, I just make my own cursor and take the coordinates of mouse and blit my own bitmap there. To me, it''s a lot easier than messing around with windows Just my $.02.

Study the directinput part, they''re a piece of cake, then make your own cursor. (Also, your windows cursor don''t line up exactly with your game''s cursor position, so this could cause you problems later.) But if someone explain clearly how resources work, I''ll study that.

(BTW, how easy is a piece of cake? What if you choke on it?)

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"
Advertisement
When Lamothe says that you''re supposed to include your "own" header file resource.h, and make your own defines, I don''t think you can do that. When you compile a resource script(with the resources made), a header file is made. Although you can''t see it in your files menu, you can see it if you go to File->Open. Since the file is already made, you just have to include resource.h into your main .cpp file. If you want to see what number has been assigned to a certain resource, just open up that one header file. I can make the cursor appear with pure win32 API but I can''t with DirectX. Hmm...


K I L A H M A N J A R O !

Wachar's Eternity <-<-<-<-<- Me own site!
Did you read that part about integrating Windows GPI (or something like that) into DirectX? I think thats what you have to do. Not sure about this though.

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"
I haven''t seen that yet.



Gamma Games <-<-<-<-<- Me own games!
Wachar's Eternity <-<-<-<-<- Me own site!

This topic is closed to new replies.

Advertisement