PDA

Click to See Complete Forum and Search --> : What is wrong with this code.....??


CyberCarsten
Dec 9th, 2000, 05:00 PM
#define STRICT
#include <windows.h>

LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{ switch (iMsg)
{ case WM_LBUTTONDOWN:
MessageBox(hWnd, "Left-mousebutton pressed", "Info", MB_OK);
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd, "Right-mousebutton pressed", "Info", MB_OK);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, iMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
const char *const szAppName = "tradwin";
WNDCLASSEX wndclass;
HWND hWnd;
MSG msg;

wndclass.cbSize = sizeof(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;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

RegisterClassEx(&wndclass);

hWnd = CreateWindow(szAppName, "Tradwin: Press a mousekey.",
WS_OVERLAPPEDWINDOW, 0, 0, 640, 480,
NULL, NULL, hInstance, NULL);

ShowWindow(hWnd, iCmdShow);
UpdateWindow(hWnd);

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

I get 5 errors....

parksie
Dec 9th, 2000, 05:29 PM
What errors?

CyberCarsten
Dec 10th, 2000, 04:15 AM
NONAME.CPP 24: Undefined symbol 'WNDCLASSEX' in function pascal WinMain(const HINSTANCE__near*,const HINSTANCE__near*,char near*,int)

NONAME.CPP 24: Statement missing ; in function pascal WinMain(const HINSTANCE__near*,const HINSTANCE__near*,char near*,int)

NONAME.CPP 28: Undefined symbol 'wndclass' in function pascal WinMain(const HINSTANCE__near*,const HINSTANCE__near*,char near*,int)

NONAME.CPP 28: Not an allowed type in function pascal WinMain(const HINSTANCE__near*,const HINSTANCE__near*,char near*,int)

NONAME.CPP 41: Call to undefined function 'RegisterClassEx' in function pascal WinMain(const HINSTANCE__near*,const HINSTANCE__near*,char near*,int)

Dec 10th, 2000, 10:38 AM
Your code works fine for me. Using VC++ 6, I added it to a new Win32 project with 1 source file.

CyberCarsten
Dec 10th, 2000, 10:53 AM
I use Borland C++ 4.5, do you know why it doesn't work on mine????

I create a new Win32 Project, with no resource file or .def file.

I have also tried to use Borland's C++ Compiler 5.5.....no go!

[Edited by CyberCarsten on 12-10-2000 at 12:56 PM]