Simulating a DOS box

I would like to simulate a DOS box using a window. What i mean is i would like to create a window that will use the same style as an MS-DOS box running in 80x25 text mode with Fixedsys font at 8x12 pixels, only i cant seem to get this to work. Here is the code i have for the program thus far:
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
106
107
108
109
110
#include <windows.h>
#include <fstream>

using namespace std;

char *mem = (char *) malloc ((80*2)*25);
LPLOGFONT to_save;

BOOL CALLBACK SaveFont (LPLOGFONT lplf, LPNEWTEXTMETRIC lpntm, DWORD FontType, LPVOID aFontCount)
{
	to_save = lplf;
	return false;
}

LRESULT CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	int cur_line = 0, cur_pos = 0;
	char *out = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab";

	switch (msg)
	{
	case WM_PAINT:

		hdc = BeginPaint (hwnd, &ps);

		EnumFontFamilies (hdc, "Fixedsys", (FONTENUMPROC) SaveFont, 0);
		to_save->lfHeight = 12;
		to_save->lfWidth  = 8;

		SelectObject (hdc, (HGDIOBJ) CreateFontIndirect (to_save));
		
		SetBkColor (hdc, RGB(0,0,0));
		SetTextColor (hdc, RGB(200,200,200));
		
		TextOut (hdc, 0, 0, out, 80);

		EndPaint (hwnd, &ps);
		UpdateWindow (hwnd);

		break;

	case WM_CLOSE:

		DestroyWindow (hwnd);
		break;

	case WM_DESTROY:

		PostQuitMessage (0);
		break;

	default:
		
		return DefWindowProc (hwnd, msg, wParam, lParam);
	}
	return 0;
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	HWND window;
	MSG Msg;
	WNDCLASSEX wc;

	MessageBox (NULL, mem, "Memory Contents:", MB_OK);

	wc.cbSize        = sizeof(WNDCLASSEX);
	wc.style         = 0;
	wc.lpfnWndProc   = WindowProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = CreateSolidBrush (RGB (0,0,0));
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = "WindowClass";
	wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
	
	if (!RegisterClassEx (&wc))
		return -1;

	window = CreateWindow ("WindowClass",
		"Hello all",
		WS_OVERLAPPEDWINDOW,
		10,
		10,
		80*8,
		25*12,
		NULL,
		NULL,
		hInstance,
		NULL);

	if (!window)
		return -1;

	ShowWindow   (window, SW_SHOW);
	UpdateWindow (window);

	while (GetMessage (&Msg, NULL, 0, 0) > 0)
	{
		TranslateMessage (&Msg);
		DispatchMessage  (&Msg);
	}

	return 0;
}


The problem is i'm not sure how to make this look like the DOS box... actually, i would prefer the text to look like BIOS raster font, if possible, but Fixedsys will be fine as well. Can anyone tell me how to adapt this code to suit what i am trying to do? I need to figure out how to convert the font to the appropriate size, and also when the window is maximized to fullscreen the font should adjust itself accordingly.
If you're making a console app it shouldn't be too hard...try using int main() and including <iostream>
Writing a DOS type window is an advanced subject, and not for the faint of heart.

Your font size is off on line 29, which should read:
1
2
		to_save->lfHeight = -12;  // notice that fixed pixel resolution is a negative number 
          


The next thing to keep in mind is that CreateWindow() has no provision for specifying the window size in terms of the client area. You will need to resize the window once it is mapped to make the client area the exact size you want. See the following link for more:
http://windows-programming.suite101.com/article.cfm/client_area_size_with_movewindow

Lastly, you should be specifying the client area based upon the font size, not assuming the font will match. When you add in maximize, etc. message handling (WM_SYSCOMMAND messages with SC_MAXIMIZE and SC_RESTORE wParam values) you will need to calculate the new font size based upon what font data you have. Make sure to stick with fixed-pitch fonts (like FixedSys and Courier New).

Hope this helps.
Last edited on
Why might one want to create a DOS-looking window, other than to deceive users?
Because the MS-supplied DOS window is underpowered and unfriendly.


There is no deceit involved. If the application does what it presents itself to do, then its UI is well designed. If it doesn't, only then is it deceitful.

For example, it is not deceitful for MS Word and Open Office Writer to look and behave similarly -- they both accomplish basically the same task and their UI is designed to fit the standards of doing that.

However, it is deceitful when losers send spam with viruses named "look-at-this.jpg.exe" (which in default Windows installations will appear as "look-at-this.jpg"), because it behaves differently than what it says it will do.

Likewise, a text-application only needs a window so that it can appear in the GUI environment. It does not matter whether Windows provides that window or not. So long as the application does what it portends, all is well.

Hope this helps.


[edit]
If you are interested in a better command prompt, google "windows command prompt replacement" for a pretty good list of stuff.
Last edited on
Topic archived. No new replies allowed.