[RESOLVED] how can i call LRESULT CALLBACK WindowProc() function?
in these case, i'm using a console aplication, so i don't have the windows class. then how can i call the LRESULT CALLBACK WindowProc() function?
Re: how can i call LRESULT CALLBACK WindowProc() function?
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
VictorN
What for? :confused:
is 1 thing that i need;)
i have these code:
Code:
#include <iostream>
#include <windows.h>
#include <conio.h>
using namespace std;
LRESULT CALLBACK conProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
MessageBox(NULL, "The window was destroyed", "bye", MB_OK);
break;
case WM_CREATE:
MessageBox(NULL, "The window was created", "hello", MB_OK);
}
return DefWindowProc(hWnd, msg, wParam, lParam );
}
int main()
{
SetWindowLong(GetConsoleWindow(), GWL_WNDPROC, (LONG)conProc);
std::cout << GetLastError();
getch();
return 0;
}
but i get 1 error "Error code: 5 - Access is denied" on GetLastError()
can you advice me?
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Cambalinho
is 1 thing that i need;)
i have these code:
Why are you not checking the return value of GetConsoleWindow()?
Why are you not checking the SetWindowLong() return code? You are not supposed to call GetLastError() if the function is successful.
Please read the documentation about the return code:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Regards,
Paul McKenzie
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Paul McKenzie
Why are you not checking the return value of GetConsoleWindow()?
Why are you not checking the SetWindowLong() return code? You are not supposed to call GetLastError() if the function is successful.
Please read the documentation about the return code:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Regards,
Paul McKenzie
the give me a value diferent than NULL: 0x1f082e
and the SetWindowLong() give 0(zero). meaning that something isn't correct
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Cambalinho
the give me a value diferent than NULL: 0x1f082e
and the SetWindowLong() give 0(zero). meaning that something isn't correct
Did you read the documentation carefully?
Quote:
If the previous value of the specified 32-bit integer is zero, and the function succeeds, the return value is zero, but the function does not clear the last error information. This makes it difficult to determine success or failure.
To deal with this, you should clear the last error information by calling SetLastError with 0 before calling SetWindowLong. Then, function failure will be indicated by a return value of zero and a GetLastError result that is nonzero
You should post your current code, the code that checks for errors and return codes in the correct way. Your first code you posted is not correct.
Regards,
Paul McKenzie
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Paul McKenzie
Did you read the documentation carefully?
You should post your current code, the code that checks for errors and return codes in the correct way. Your first code you posted is not correct.
Regards,
Paul McKenzie
Code:
#include <iostream>#include <windows.h>
#include <conio.h>
using namespace std;
LRESULT CALLBACK ConsoleWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
cout<< "hi";
switch(msg)
{
case WM_DESTROY:
MessageBox(NULL, "The window was destroyed", "bye", MB_OK);
break;
case WM_CREATE:
MessageBox(NULL, "The window was created", "hello", MB_OK);
}
return DefWindowProc(hWnd, msg, wParam, lParam );
}
int main()
{
cout << GetConsoleWindow() << endl;//the value is diferent from 0(zero)\NULL
cout << SetWindowLong(GetConsoleWindow(), GWL_WNDPROC, (LONG)ConsoleWndProc);//here i recive 0(zero)
getch();
return 0;
}
i read, but i don't understand what they speak about the GWL_WNDPROC const:(
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Cambalinho
i read, but i don't understand
You didn't read.
Once again:
Quote:
you should clear the last error information by calling SetLastError with 0 before calling SetWindowLong.
Your code is not doing this.
Regards,
Paul McKenzie
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Paul McKenzie
You didn't read.
Once again:
Your code is not doing this.
Regards,
Paul McKenzie
Code:
int main()
{
cout << GetConsoleWindow() << endl;//the value is diferent from 0(zero)\NULL
SetLastError(0);
cout << SetWindowLong(GetConsoleWindow(), GWL_WNDPROC, (LONG)ConsoleWndProc);//here i recive 0(zero)
cout << GetLastError();
getch();
return 0;
}
i get the same results:(
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Cambalinho
i read, but i don't understand what they speak about the GWL_WNDPROC const:(
Why are you trying to override the console window's window procedure?
Regards,
Paul McKenzie
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Paul McKenzie
Why are you trying to override the console window's window procedure?
Regards,
Paul McKenzie
what i need is getting the messages nothing more;)
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Cambalinho
what i need is getting the messages nothing more;)
Even if the OS allowed you to overide the window procedure for capturing messages, you are not doing it correctly. Your code just takes over all control of the console window, thus the console window never has a chance to behave properly because it is not receiving its messages.
You're supposed to override the window, and then call the Console window's window procedure after you receive the message, not DefWindowProc. Otherwise, the console window will not operate correctly. And all of this is if you're allowed to override the console window's procedure.
You need to take a step back and learn about Windows' subclassing. You don't just replace the Window Proc, you must keep the original one so that the original window's behaviour is done.
Picture it this way -- you're the console window, and you receive messages and act OK. Then I am the custom window procedure and steps in front of you to receive messages. I get the message, and instead of handing the message to you (the console window) so that you can operate correctly, I throw it away. You never get the messages, and you're just sitting there doing nothing. That is exactly what your code snippet will do.
Regards,
Paul McKenzie
Re: how can i call LRESULT CALLBACK WindowProc() function?
What "messages" would you like to get for your console window?
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
VictorN
What "messages" would you like to get for your console window?
mouse, keyboard, paint, move, what is possible;)
whats why i wanted use that function for i get more easy the messages;)
Re: how can i call LRESULT CALLBACK WindowProc() function?
Quote:
Originally Posted by
Cambalinho
mouse, keyboard, paint, move, what is possible;)
Well, I never worked with console windows... Therefore I ask you: are you sure these messages come to console?
Did you check it (with Spy++ or some other tool?)