Help with windows programming

Hi!
I have some experience with the c++ programming language and I started to read an old book,
"How to make your own games in c++";
Unfortunately, all of the book refers to c++ programming under DOS. I want to run it under windows 7 and I face many problems. For example, there is no int86() functions defined in the header file dos.h, that I can use to directly access the registers.

I was trying to make my own header file for mouse operations (as described in the book). It would be something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef __MOUSE_H
#define __MOUSE_H

#include <dos.h>


#define LEFT 1
#define RIGHT 2
#define CENTER 3



class Mouse
{
private:
	int mx, my,
	got_mouse,
	num_buttons,
	button;
	REGS inREGS;
	REGS outREGS;
public:
Mouse(void);
~Mouse(void);
int GotMouse(void){return got_mouse;}
void SetLimits(int minXLimit, int maxXLimit, int minYLimit, int maxYLimit);
void ShowMouse(void);
void HideMouse(void);
int Event(void);
int GetButton(void){return button;}
void GetXY(int &x, int &y){x=mx;y=my;}
void ButtonUP(void);
};

extern Mouse mouse;

Mouse::Mouse(void)
{
	got_mouse=0;
	if(getvect(0x33))
	{
		inREGS.x.ax=0x0000;
		int86(0x33,&inREGS,&outREGS);
		got_mouse=outREGS.x.ax;
		num_buttons=out.REGS.x.bs;
	}
	
}
Mouse::~Mouse(void)
{
	inREGS.x.ax=0x0000;
	int86(0x33,&inREGS,&outREGS);
}

void Mouse::SetLimits(int minXLimit, int maxXLimit, int minYLimit, int maxYLimit)
{
	if(!got_mouse)
		return;
	inRegs.x.ax=0x0007;
	inRegs.x.cx=minXLimit;
	inRegs.x.dx=maxXLimit;
	int86(0x33,&inRegs,&outRegs);
	inRegs.x.ax=0x0008;
	inRegs.x.cx=minYLimit;
	inRegs.x.dx=maxYLimit;
	int86(0x33,&inRegs,&outRegs);
}

void Mouse::ShowMouse(void)
{
	if(!got_mouse)
		return;
	inRegs.x.ax=0x0001;
	int86(0x33,&inRegs,&outRegs);
}

void Mouse::HideMouse(void)
{
	if(!got_mouse)
		return;
	inRegs.x.ax=0x0002;
	int86(0x33,&inRegs,&outRegs);
}

int Mouse::Event(void)
{
	if(!got_mouse)
		return 0;
	inRegs.x.ax=0x0003;
	int86(0x33,&inRegs,&outRegs);
	button=outRegs.x.bx;
	mx=outRegs.x.cx;
	my=outRegs.x.dx;
	if(button)
		return 1;
	else
		return 0;
}
void Mouse::ButtonUp(void)
{
	while(button)
		Event();
}

#endif 


Can anyone give me any indication how to make it work under windows?
If I install linux on a virtual machine and run it from there, will it work?

Thank you very much for your time,
Radu
Last edited on
Hopefully someone with better suggestions/knowledge will reply, as I am not familiar with C++ programming under DOS, but until then:

DOS programs experience several compatibility issues when run through Windows (starting from Windows XP onward I think). Development of DOS applications would face similar issues I suppose. I read here (http://hsmoore.com/blog/turbo-c-in-dosbox-for-windows-64bit/) that the author of this post wanted to compile a C++ application for DOS while running Windows 7 64-bit. What he suggests is to get a C++ compiler for DOS (he got Borland Turbo C++) and use it through DOSBox -- a DOS emulator.

I've used DOSBox in the past without issues, I guess the above suggestion could work provided you had the required development environment and compiler. Still, I would suggest -- if you're not necessarilly interested in development under DOS -- to consider implementing your application using a different API that will prove less troublesome to set up and more compatible with current operating systems. The main concepts and ideas presented in your DOS C++ programming book would remain, the actual functions for keyboard/mouse input, rendering etc would be different. If interested, you could look into something like SDL (an API for 2D graphics which is also cross-platform) , or OpenGL (and maybe combine it with something like freeGLUT to make window management and input handling cross-platform). Another option could be to use DirectX in conjunction with the Windows API (for window handling, user input etc). These suggestions would involve some additional research and reading on your part, but using them would allow your application greater compatibility with newer development environments.

Hope this helps you in some way, hopefully someone more knowledgeable with DOS development might have additional suggestions.

Ogoyant
Last edited on
google windows.h and win32
I strongly recommend you track down a more recent book.

Firstly, modern operating systems abstract the hardware, so an application is not able to control the mouse via registers like it was in the DOS day. So learning the DOS way would only be worth the effort if you're into really old games and other programs.

Secondly, given Microsoft stopped selling DOS in 1994. four years before C++ was first standardized (as C++98), the book is very probably teaching out of date C++. So it's likely to be bad in that way, too.

For Win32 console mouse handling, you need you app to handle console events.

See, for example,

Handling Mouse Events and Simulating Push Buttons and List Boxes in a Win32 Console
http://www.codeproject.com/Articles/81196/Handling-Mouse-Events-and-Simulating-Push-Buttons

Andy
Last edited on
Topic archived. No new replies allowed.