-
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:44 PM
#7
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
#8
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
#9
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
-
September 3rd, 2013, 03:54 PM
#10
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by VictorN
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?)
i don't know use the Spy++ but i have it
-
September 3rd, 2013, 04:12 PM
#11
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by Cambalinho
mouse, keyboard, paint, move, what is possible
whats why i wanted use that function for i get more easy the messages
But as I stated, you must take those messages you intercepted and give them to the original console window procedure when you are done with them. You can't just throw the messages away as your code is doing now.
Regards,
Paul McKenzie
-
September 3rd, 2013, 04:17 PM
#12
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by Paul McKenzie
But as I stated, you must take those messages you intercepted and give them to the original console window procedure when you are done with them. You can't just throw the messages away as your code is doing now.
Regards,
Paul McKenzie
Code:
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <string>
using namespace std;
LRESULT CALLBACK ConsoleWndProc(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 CallWindowProc((WNDPROC ) ConsoleWndProc, hWnd, msg, wParam, lParam);
}
int main()
{
string a;
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();
cin >> a;
return 0;
}
but how can i do it, if the SetWindowLong() function is give problems?
i have sure about the GetConsoleWindow(), because i get the HDC from it and works fine. i have used the HDC
-
September 3rd, 2013, 04:08 PM
#13
Re: how can i call LRESULT CALLBACK WindowProc() function?
Then learn how to use it and do use!
Victor Nijegorodov
-
September 3rd, 2013, 04:27 PM
#14
Re: how can i call LRESULT CALLBACK WindowProc() function?
but i get 1 error "Error code: 5 - Access is denied" on GetLastError()
can you advice me?
Yes - you can't do this with consoles! Windows won't let you subclass a console window.
What exactly are you trying to achieve?
Last edited by 2kaud; September 3rd, 2013 at 04:30 PM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
September 3rd, 2013, 04:36 PM
#15
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by 2kaud
Yes - you can't do this with consoles! Windows won't let you subclass a console window.
What exactly are you trying to achieve?
just get the messages for add events in my class
i'm trying another code but i don't know how works
Code:
MSG msg;
BOOL bRet;
//...
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
i belive these is the other way, but isn't working
can you advice?
i only need get the messages from console
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
|