-
September 3rd, 2013, 01:39 PM
#1
[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?
-
September 3rd, 2013, 02:00 PM
#2
Re: how can i call LRESULT CALLBACK WindowProc() function?
What for?
Victor Nijegorodov
-
September 3rd, 2013, 02:26 PM
#3
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by VictorN
What for?
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?
-
September 3rd, 2013, 02:38 PM
#4
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
Last edited by Paul McKenzie; September 3rd, 2013 at 02:41 PM.
-
September 3rd, 2013, 02:57 PM
#5
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
-
September 3rd, 2013, 03:11 PM
#6
Re: how can i call LRESULT CALLBACK WindowProc() function?
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?
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
-
September 3rd, 2013, 03:15 PM
#7
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
-
September 3rd, 2013, 03:20 PM
#8
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by Cambalinho
i read, but i don't understand
You didn't read.
Once again:
you should clear the last error information by calling SetLastError with 0 before calling SetWindowLong.
Your code is not doing this.
Regards,
Paul McKenzie
-
September 3rd, 2013, 03:27 PM
#9
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
-
September 3rd, 2013, 03:36 PM
#10
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
-
September 3rd, 2013, 03:37 PM
#11
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
-
September 3rd, 2013, 03:44 PM
#12
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
Last edited by Paul McKenzie; September 3rd, 2013 at 03:49 PM.
-
September 3rd, 2013, 03:44 PM
#13
Re: how can i call LRESULT CALLBACK WindowProc() function?
What "messages" would you like to get for your console window?
Victor Nijegorodov
-
September 3rd, 2013, 03:47 PM
#14
Re: how can i call LRESULT CALLBACK WindowProc() function?
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
-
September 3rd, 2013, 03:53 PM
#15
Re: how can i call LRESULT CALLBACK WindowProc() function?
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?)
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|