PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : Warum dieser Fehler!!


Ich
2003-04-17, 14:24:02
Hallo,

warum spuckt VC++6 bei diesem Code an der Stelle

WndClass.lpfnWndProc = MsgProc;

den folgenden Fehler aus:

Compiling...
Win32.cpp
J:\BaseWnd\Win32.cpp(46) : error C2440: '=' : cannot convert from 'long (__stdcall *)(struct HWND__ *,unsigned int,long,unsigned int)' to 'long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.

Window.exe - 1 error(s), 0 warning(s)


#include <windows.h>

LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam);

HWND WndHandle = NULL;
BOOL Keys[256];
BOOL AppActive = FALSE;

#define WND_X 0
#define WND_Y 0
#define WND_WIDTH 800
#define WND_HEIGHT 600


LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, LPARAM lParam, WPARAM wParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
case WM_KEYDOWN:
{
Keys[wParam] = TRUE;
return 0;
}
case WM_KEYUP:
{
Keys[wParam] = FALSE;
return 0;
}
}

return DefWindowProc(hWnd, msg, wParam, lParam);
}

INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, INT ShowCmd)
{
WNDCLASS WndClass;

WndClass.cbClsExtra = 0;
WndClass.lpfnWndProc = MsgProc;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor = 0;
WndClass.hIcon = 0;
WndClass.hInstance = hInst;
WndClass.lpszClassName = "AppClass";
WndClass.lpszMenuName = 0;
WndClass.style = 0;

RegisterClass(&WndClass);

RECT WndRect;
SetRect(&WndRect, 0, 0, WND_WIDTH, WND_HEIGHT);
AdjustWindowRect(&WndRect, 0, 0);

WndHandle = CreateWindowEx(NULL, "AppClass", "The App", WS_OVERLAPPEDWINDOW, WND_X, WND_Y,
(WndRect.right - WndRect.left),
(WndRect.bottom - WndRect.top),
GetDesktopWindow(), NULL, WndClass.hInstance, NULL);

if(WndHandle != NULL)
AppActive = TRUE;
else
AppActive = FALSE;

if(AppActive)
{
ShowWindow(WndHandle, SW_SHOWDEFAULT);
UpdateWindow(WndHandle);

MSG msg;

while((msg.message != WM_QUIT) && (!Keys[VK_ESCAPE]))
{
if(PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}

return 0;

}

Abe Ghiran
2003-04-17, 15:23:43
Hi!
Sieht auf den ersten Blick so aus, als hättest du die Reihenfolge von lParam und wParam bei deiner window procedure vertauscht. Richtig ist

LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

Grüße, Jan

Ich
2003-04-17, 16:03:10
Oh, danke das wars :)