Why u shouldnt learn for a book...
OK... i recently got Windows 95 Programming For Dummies... (ill wait till u guys stop laughing) and i've have a problem with this code (im just pasting the whole damn thing):
Code:
#include <windows.h>
static int nRowSpacing;
static int nCharSpacing;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR pszCmdLine,
int nCmdShow
);
LRESULT CALLBACK WindowProc(
HWND hWnd,
UINT uMsgId,
WPARAM wParam,
LPARAM lParam
);
void OutputLine(
HDC hDC,
int nRowNumber,
char *pszDescription,
int nValue
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR pszCmdLine,
int nCmdShow
)
{
static char szAppName[] = "Prog2";
HWND hWnd;
MSG msg;
WNDCLASS wndClass;
wndClass.style = 0;
wndClass.lpfnWndProc = WindowProc;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hInstance = hInstance;
wndClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndClass.hbrBackground = GetStockObject(WHITE_BRUSH); //<--Right HERE
wndClass.lpszMenuName = NULL;
wndClass.lpszClassName = szAppName;
if (RegisterClass(&wndClass) == 0)
{
return 0;
}
hWnd = CreateWindow(
szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if (hWnd == 0)
{
return 0;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WindowProc(
HWND hWnd,
UINT uMsgId,
WPARAM wParam,
LPARAM lParam
)
{
HDC hDC;
switch (uMsgId)
{
case WM_CREATE:
hDC = GetDC(hWnd);
TEXTMETRIC textMetrics;
GetTextMetrics(hDC, &textMetrics);
nRowSpacing = textMetrics.tmHeight + textMetrics.tmExternalLeading;
nCharSpacing = textMetrics.tmAveCharWidth;
ReleaseDC(hWnd, hDC);
return 0;
case WM_PAINT:
PAINTSTRUCT paintStruct;
hDC = BeginPaint(hWnd, &paintStruct);
OutputLine(hDC, 1,
"Avg Char Spactin = ",
nCharSpacing);
OutputLine(hDC, 2,
"Row spacing = ",
nRowSpacing);
RECT rectWindow;
GetWindowRect(hWnd, &rectWindow);
OutputLine(hDC, 4,
"Window x location = ",
rectWindow.left);
OutputLine(hDC, 5,
"Window y location = ",
rectWindow.top);
OutputLine(hDC, 7,
"Window x dimension = ",
rectWindow.right - rectWindow.left);
OutputLine(hDC, 8,
"Window y dimension = ",
rectWindow.bottom - rectWindow.top);
EndPaint(hWnd, &paintStruct);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,uMsgId,wParam,lParam);
}
}
void OutputLine(
HDC hDC,
int nRowNumber,
char *pszDescription,
int nValue
)
{
int nCol1Offset = 20;
int nCol2Offset = nCol1Offset + 25 * nCharSpacing;
int nRowOffset = nRowNumber * nRowSpacing;
SetTextAlign(hDC, TA_LEFT | TA_TOP);
TextOut(hDC,
nCol1Offset,
nRowOffset,
pszDescription,
lstrlen(pszDescription));
SetTextAlign(hDC, TA_RIGHT | TA_TOP);
char szBuffer[16];
wsprintf(szBuffer, "%d", nValue);
TextOut(hDC,
nCol2Offset,
nRowOffset,
szBuffer,
lstrlen(szBuffer));
}
And the error is this:
Code:
error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
What is the fastest and easiest way to fix this sort of a problem. Also, word of the wise, don't try to learn from book!