Printing

Hi guys,
Ive been looking at mini projects for myself to do to train myself up, and i found one about how to print a message (Hello World). It worked but now i would like to be able to be able to change the message by using a string variable. Heres the code with the non variable message:
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
#include <iostream>
#include <Windows.h>

using namespace std;
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hprev, LPSTR lpcmdline, int ncmdshow)

{
	PRINTDLG pd;

	memset( &pd, 0, sizeof( pd ) );

	pd.lStructSize = sizeof( pd );

	pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
	if( !PrintDlg( &pd) )
	{
		MessageBox( NULL, "Printing Failed", "Fatal Error", MB_OK | MB_ICONERROR);

		return -1;
	}

	DOCINFO di;
	HDC hPrinter = pd.hDC;

	memset( &di, 0, sizeof( di ) );
	di.cbSize = sizeof( di );
	StartDoc( hPrinter, &di );

		StartPage( hPrinter );
		TextOut( hPrinter, 100, 100, "Hello World", 13);
		EndPage( hPrinter );

	EndDoc( hPrinter );
	DeleteDC( hPrinter );
	return 0;
}


Ive tried to use an LPSTR as the variable... but to no success.

BTW, i did have a lot of help to write this code as i am still pretty much a novice. Any help would be greatly appreciated :)
Well, what is the version that did not work? That's much more interesting in this case, don't you think so too?
Fair point. sorry haha.
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
#include <iostream>
#include <Windows.h>

using namespace std;
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hprev, LPSTR lpcmdline, int ncmdshow)

{
	LPSTR PrintIn;
	cout <<  "Enter in code to print:" << endl;
	cin >> PrintIn;
	cin.get();

	PRINTDLG pd;

	memset( &pd, 0, sizeof( pd ) );

	pd.lStructSize = sizeof( pd );

	pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;
	if( !PrintDlg( &pd) )
	{
		MessageBox( NULL, "Printing Failed", "Fatal Error", MB_OK | MB_ICONERROR);

		return -1;
	}

	DOCINFO di;
	HDC hPrinter = pd.hDC;

	memset( &di, 0, sizeof( di ) );
	di.cbSize = sizeof( di );
	StartDoc( hPrinter, &di );

		StartPage( hPrinter );
		TextOut( hPrinter, 100, 100, PrintIn, 13);
		EndPage( hPrinter );

	EndDoc( hPrinter );
	DeleteDC( hPrinter );
	return 0;
}


Ive been looking through many forums and generally theres isnt much on printing and im pretty confused and its getting embaressing -.-
Last edited on
1
2

	LPSTR PrintIn = new char[256];


try that.
Topic archived. No new replies allowed.