LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_LBUTTONDOWN:
SetWindowText(hwndStatic, "You clicked the left mouse button!");
break;
case WM_RBUTTONDOWN:
SetWindowText(hwndStatic, "You clicked the right mouse button!");
break;
}
return 0;
}
And I get these errors:
In function 'LRESULT WndProc(HWND_*,UINT,WPARAM,LPARAM)':
'hwndStatic' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
bitshifter420
August 19th, 2008, 03:09 PM
What its saying is that 'hwndStatic' has not been defined.
Indeed, it does not exist in your code.
If you mean to write the text into the window that was passed into the procedure, use 'hwnd, in place of 'hwndStatic'.
This is obviously a cut and paste code sample...
You should also call 'DefWindowProc' for unhandled messages.
{
switch(Msg)
{
case WM_LBUTTONDOWN:
SetWindowText(hwnd, "You clicked the left mouse button!");
break;
case WM_RBUTTONDOWN:
SetWindowText(hwnd, "You clicked the right mouse button!");
break;
}
return 0;
}
[Linker error] undefined reference to 'WinMain@16'
Id returned 1 exit status
Paul McKenzie
August 20th, 2008, 10:26 AM
What do you mean call 'DefWindowProc'?You always call DefWindowProc() for any unhandled Windows messages, otherwise your program will exhibit erratic behaviour.
This should have been clearly documented in whatever reference you're using to create the code you created.
I fixed it this way but now i get these errors:
[Linker error] undefined reference to 'WinMain@16'
Id returned 1 exit statusThis is a linker error not a compiler error. Your project settings for whatever IDE you're using must not be correct.
Regards,
Paul McKenzie
Pitufo
August 20th, 2008, 10:31 AM
Thanks I fixed it...The code that i have now changes the title when I click a mouse button...how can I make it send info to notepad...for example, if i click on the right button it will send a 1 to notepad or if i click on left button it will send a 2?
// Step 2: Creating the Window
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"The title of my window",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
NULL, NULL, hInstance, NULL);
You should also implement some error testing to verify the file handle is valid.
Notice the file is opened when the window is created and closed when the window is destroyed.
It would be wasteful to open the file write some data and close the file every time you clicked the mouse.
Pitufo
August 26th, 2008, 01:37 PM
What exactly do i put in the (...) because I tried different things and i just kept on getting errors?
bitshifter420
August 26th, 2008, 09:34 PM
You must never guess what parameters a function expects.
If you are unsure of what to use, look it up at msdn or google.