-
September 3rd, 2013, 03:54 PM
#16
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:08 PM
#17
Re: how can i call LRESULT CALLBACK WindowProc() function?
Then learn how to use it and do use!
Victor Nijegorodov
-
September 3rd, 2013, 04:12 PM
#18
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
#19
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:27 PM
#20
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
#21
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
-
September 3rd, 2013, 05:02 PM
#22
Re: how can i call LRESULT CALLBACK WindowProc() function?
i only need get the messages from console
Just because you need them, doesn't mean the console is going to give them! As far as I am aware, you don't get access to the console messages. A console is not like other windows and can't be treated as such.
Again, why do you want them? What are you going to use them for?
Have a look at PeekConsoleInput and ReadConsoleInput
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
These functions give you access to certain console events - mouse move etc.
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 4th, 2013, 04:03 AM
#23
Re: how can i call LRESULT CALLBACK WindowProc() function?
-
September 4th, 2013, 04:39 AM
#24
Re: how can i call LRESULT CALLBACK WindowProc() function?
i belive the MOUSE_EVENT_RECORD struture isn't completed.
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
why? because when i release the mouse button, the message is "button press"
Code:
VOID MouseEventProc(MOUSE_EVENT_RECORD mer)
{
#ifndef MOUSE_HWHEELED
#define MOUSE_HWHEELED 0x0008
#endif
printf("Mouse event: ");
switch(mer.dwEventFlags)
{
case 0:
if(mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
printf("left button press \n");
}
else if(mer.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
printf("right button press \n");
}
else
{
printf("button press\n");
}
break;
case DOUBLE_CLICK:
printf("double click\n");
break;
case MOUSE_HWHEELED:
printf("horizontal mouse wheel\n");
break;
case MOUSE_MOVED:
printf("mouse moved\n");
break;
case MOUSE_WHEELED:
printf("vertical mouse wheel\n");
break;
default:
printf("unknown\n");
break;
}
}
so what is the const for release?
(edit i mistake 1 thing: i mean the:
Code:
else
{
printf("button press\n");
}
is activated
Last edited by Cambalinho; September 4th, 2013 at 04:46 AM.
-
September 4th, 2013, 04:56 AM
#25
Re: [RESOLVED] how can i call LRESULT CALLBACK WindowProc() function?
fiz 2 alteraƧoes necessarias no codigo:
Code:
VOID MouseEventProc(MOUSE_EVENT_RECORD mer){
#ifndef MOUSE_HWHEELED
#define MOUSE_HWHEELED 0x0008
#endif
printf("Mouse event: ");
switch(mer.dwEventFlags)
{
case 0:
if(mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
printf("left button press \n");
}
else if(mer.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
printf("right button press \n");
}
else if(mer.dwButtonState == 4)
{
printf("middle button press \n");
}
else if(mer.dwButtonState !=0)
{
printf("another button press \n");
}
else
{
printf("button release\n"); //see these line. is release and not press;)
}
break;
case DOUBLE_CLICK:
printf("double click\n");
break;
case MOUSE_HWHEELED:
printf("horizontal mouse wheel\n");
break;
case MOUSE_MOVED:
printf("mouse moved\n");
break;
case MOUSE_WHEELED:
printf("vertical mouse wheel\n");
break;
default:
printf("unknown\n");
break;
}
}
see the comment and the back 'else if', now the middle button is detected. and is release button and not press button
thanks for all
-
September 4th, 2013, 04:58 AM
#26
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by Cambalinho
From the article you refer to:
Remarks
Mouse events are placed in the input buffer when the console is in mouse mode ( ENABLE_MOUSE_INPUT).
Mouse events are generated whenever the user moves the mouse, or presses or releases one of the mouse buttons. Mouse events are placed in a console's input buffer only when the console group has the keyboard focus and the cursor is within the borders of the console's window.
So it looks like there is no any const for "release"
Victor Nijegorodov
-
September 4th, 2013, 05:01 AM
#27
Re: how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by VictorN
From the article you refer to:So it looks like there is no any const for "release"
but if i relase the button, i recive '0'(zero)
-
September 4th, 2013, 05:07 AM
#28
Re: [RESOLVED] how can i call LRESULT CALLBACK WindowProc() function?
dwButtonState of 0 indicates that the last button pressed has been released. So you need to keep a record of which button has been pressed and then when you get 0 you know that button has been released!
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 4th, 2013, 05:14 AM
#29
Re: [RESOLVED] how can i call LRESULT CALLBACK WindowProc() function?
Originally Posted by 2kaud
dwButtonState of 0 indicates that the last button pressed has been released. So you need to keep a record of which button has been pressed and then when you get 0 you know that button has been released!
that's why i update it again
i update the code again:
Code:
VOID MouseEventProc(MOUSE_EVENT_RECORD mer)
{
#ifndef MOUSE_HWHEELED
#define MOUSE_HWHEELED 0x0008
#endif
printf("Mouse event: ");
switch(mer.dwEventFlags)
{
case 0:
if(mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
printf("left button press \n");
}
else if(mer.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
printf("right button press \n");
}
else if(mer.dwButtonState == 4)
{
printf("middle button press \n");
}
else if(mer.dwButtonState !=0)
{
printf("another button press \n");
}
else if (mer.dwButtonState ==0)
{
printf("button release\n");
}
else
{
printf("another event detected\n");
}
break;
case DOUBLE_CLICK:
printf("double click\n");
break;
case MOUSE_HWHEELED:
printf("horizontal mouse wheel\n");
break;
case MOUSE_MOVED:
printf("mouse moved\n");
break;
case MOUSE_WHEELED:
printf("vertical mouse wheel\n");
break;
default:
printf("unknown\n");
break;
}
}
thanks for all
-
September 5th, 2013, 04:35 PM
#30
Re: [RESOLVED] how can i call LRESULT CALLBACK WindowProc() function?
Code:
else
{
printf("another event detected\n");
}
You do realise that this code will never execute? Previously you have a test for a non-zero value, then you have a test for a zero value so one of those conditions must be true!
You can therefore simplify the tests slightly
Code:
#define BUTTON_RELEASE 0
if(mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
printf("left button press \n");
}
else if(mer.dwButtonState == RIGHTMOST_BUTTON_PRESSED)
{
printf("right button press \n");
}
else if(mer.dwButtonState == FROM_LEFT_2ND_BUTTON_PRESSED)
{
printf("middle button press \n");
}
else if(mer.dwButtonState == BUTTON_RELEASE)
{
printf("button release\n");
}
else
{
printf("another event detected\n");
}
IMO I prefer not to have nested if statements like this and would code this as
Code:
#define BUTTON_RELEASE 0
switch (mer.dwButtonState) {
case BUTTON_RELEASE:
puts("button release");
break;
case FROM_LEFT_1ST_BUTTON_PRESSED:
puts("left button press");
break;
case RIGHTMOST_BUTTON_PRESSED:
puts("right button press");
break;
case FROM_LEFT_2ND_BUTTON_PRESSED:
puts("middle button press");
break;
default:
puts("another button press");
break;
}
I would also use a #define (or a const int as appropriate) to define constants (such as the 0 for the button release test) to make the program more readable and more easily maintainable in the future.
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)
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
|