0

I started reading Programming Windows API 5th Edition by Charles Pretzold and I compiled and ran the first program and it worked fine but this one doesn't work and I have been messing with it and I don't know what do anymore, the problem is line 22 when I run the program it doesn't display the resolution it just says its 0 pixels by 0 pixels. Thanks ahead of time for taking a look.

#include <Windows.h>
#include <stdio.h>
#include <tchar.h>

int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
	TCHAR szBuffer [1024];
	va_list pArgList;
	va_start (pArgList, szFormat);
	_vsntprintf_s (szBuffer, sizeof(szBuffer) / sizeof(TCHAR),
		szFormat, pArgList);
	va_end(pArgList);
	return MessageBox (NULL, szBuffer, szCaption, 0);

}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	int cxScreen, cyScreen;
	cxScreen = GetSystemMetrics(SM_CXSCREEN);
	cyScreen = GetSystemMetrics(SM_CYSCREEN);
	MessageBoxPrintf (TEXT ("Screen Resolution"), 
			  TEXT ("The screen is %i pixels by %i pixels high."
			  ,cxScren, cyScreen)); 
	return 0;
}

Edited by L3gacy: n/a

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by L3gacy
Featured Replies
  • The code is actually incorrect. Although syntactically correct, your closing parenthesis is in the wrong place. On your line: [icode]MessageBoxPrintf (TEXT ("Screen Resolution"), TEXT ("The screen is %i pixels by %i pixels high." ,cxScren, cyScreen));[/icode] Now I have removed the line feeds you should be able to see the problem … Read More

0

Pretty sure what you just posted is trying to get the size of the window that was made by the running program. You haven't made a window so it is going to be 0 by 0 in size.

I can't compile what you have but I just threw in the lines of code I use for getting the fullscreen window size.

#include <windows.h>
#include <stdio.h>
#include <tchar.h>

int CDECL MessageBoxPrintf (TCHAR * szCaption, TCHAR * szFormat, ...)
{
	TCHAR szBuffer [1024];
	va_list pArgList;
	va_start (pArgList, szFormat);
	_vsntprintf_s (szBuffer, sizeof(szBuffer) / sizeof(TCHAR),
		szFormat, pArgList);
	va_end(pArgList);
	return MessageBox (NULL, szBuffer, szCaption, 0);

}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	int cxScreen, cyScreen;

	//handles for desktop
	HWND hDesktopWnd;
	HDC hDesktopDC;

	hDesktopWnd = GetDesktopWindow();
	hDesktopDC = GetDC(hDesktopWnd);

	cxScreen = GetDeviceCaps(hDesktopDC, HORZRES);
	cyScreen = GetDeviceCaps(hDesktopDC, VERTRES);

	ReleaseDC( hDesktopWnd, hDesktopDC );

	MessageBoxPrintf (TEXT ("Screen Resolution"),
			  TEXT ("The screen is %i pixels by %i pixels high."
			  ,cxScren, cyScreen));
	return 0;
}

Edited by sfuo: n/a

0

I've still been trying to fix it and it runs but now I get outrageously large numbers like 19982745 x 19927564

0

I am using Visual Studio 2010 pro I believe I got it free since I am a college student, is there a different IDE anyone thinks I should try even though it should be able to run normally with visual studio but it doesnt.

1

The code is actually incorrect. Although syntactically correct, your closing parenthesis is in the wrong place.

On your line: MessageBoxPrintf (TEXT ("Screen Resolution"), TEXT ("The screen is %i pixels by %i pixels high." ,cxScren, cyScreen)); Now I have removed the line feeds you should be able to see the problem ;)

Your arguments, cxScreen and cyScreen are being sent into the TEXT macro and not your MessageBoxPrintf function.

Also, you typo'd cxScreen as cxScren


EDIT: In my opinion Visual Studio is the best IDE you can get.

Edited by Ketsuekiame: n/a

Comments
thanks for hints
0

I cant believe the problem was as simple as adding a letter and moving my arguments into the correct position, thanks.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.