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;
}

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;
}

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

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.

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.

commented: thanks for hints +2

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.