Undeclared Identifer?

Alright I know this says general C++ but I am working with win32 api, it should be the same concept because the error I don't think has anything to do with the api aspect of it, (I got be wrong I am a beginner lol)

Error: IntelliSense: identifier "sysmetics" is undefined.

I am following a book so I don't really know where I got off..

Main:
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
#include "stdafx.h"
#include <Windows.h>
#include "SYSMETS.h"

using namespace std;

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

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

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")


	static wchar_t szAppName[] = TEXT("SysMets1");
	HWND hwnd;
	MSG msg;
	WNDCLASS wndclass;

	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WndProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;
	wndclass.hInstance = hInstance;
	wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = szAppName;

	if (!RegisterClass(&wndclass))
	{
		MessageBox(NULL, L"This program requires Windows 7!", szAppName, MB_ICONERROR);
		return 0;
	}

	hwnd = CreateWindow
		(szAppName,
		TEXT("Get System Metrics No. 1"),
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,
		NULL,
		hInstance,
		NULL,);

	ShowWindow(hwnd, iCmdShow);
	UpdateWindow(hwnd);

	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}   

LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	
	static int cxChar, cyChar, cxCaps;
	HDC hdc;
	int i;
	PAINTSTRUCT ps;
	TCHAR szBuffer[10];
	TEXTMETRIC tm;
	switch (message)
	{
	case WM_CREATE:
		hdc = GetDC(hwnd);
		GetTextMetrics(hdc, &tm);
		cxChar = tm.tmAveCharWidth;
		cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
		cyChar = tm.tmHeight + tm.tmExternalLeading;
		ReleaseDC(hwnd, hdc);
		return 0;

		case WM_PAINT:
			hdc = BeginPaint(hwnd, &ps);
			for (i = 0; i < NUMLINES; i++) // Error is here <----------------------
			{
				TextOut(hdc, 0, cyChar * i,
					sysmetrics[i].szLabel,
					lstrlen(sysmetrics[i].szLabel));

				TextOut(hdc, 22 * cxCaps, cyChar * i,
					sysmetrics[i].szDesc,
					lstrlen(sysmetrics[i].szDesc));

				SetTextAlign(hdc, TA_RIGHT | TA_TOP);

				TextOut(hdc, 22 * cxCaps + 40 * cxChar, cyChar * i, szBuffer, wsprintf(szBuffer, TEXT("%5d"), GetSystemMetrics(sysmetrics[i].iIndex)));
			}
			EndPaint(hwnd, &ps);
			return 0;

		case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
		}

		return DefWindowProc(hwnd, message, wParam, lParam);
}


SYSMETS.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#define NUMLINES ((int) (sizeof sysmetrics / sizeof sysmetics [0]))

struct 
{
	int iIndex;
	TCHAR * szLabel;
	TCHAR * szDesc;
}

sysmetrics[] =
{
	SM_CXSCREEN,		TEXT("SM_CXSCREEN"),
						TEXT("Screen width in pixels"),
	SM_CYSCREEN,		TEXT("SM_CYSCREEN"),
						TEXT("Screen hight in pixels"),

			
};
Last edited on
sysmetics
sysmetrics


By the way, IntelliSense is very bad at identifying errors in C++ code and tends to throw false positives very easily. Pay no attention to it, and just rely on the compiler.
Wow.. I would of never noticed that. Thank you I was about to go insane.
Topic archived. No new replies allowed.