Ok two questions in one, cant do horizontal scroll; cant get LPRECT = anything

1st question
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
void Auto_Scroll (LONG pGT_X, LONG pGT_Y, long pScreen_Res_X, long pScreen_Res_Y)
{
	int Vscroll_type;
	int Hscroll_type;
	int App_win_tX, App_win_bX, App_win_tY, App_win_bY;

	int *pVscroll_type = &Vscroll_type;
	int *pHscroll_type = &Hscroll_type;
	int *pApp_win_tX = &App_win_tX;
	int *pApp_win_bX = &App_win_bX;
	int *pApp_win_tY = &App_win_tY;
	int *pApp_win_bY = &App_win_bY;

//check	cout << "Screen size x-axis: " << pScreen_Res_X << endl;		//Prints x-axis size
//check	cout << "Screen size y-axis: " << pScreen_Res_Y << endl;		//Prints y-axis size

//call function in the code below for 2nd question
	app_size(pApp_win_tX, pApp_win_bX, pApp_win_tY, pApp_win_bY);

	printf ("screen top x coordinates: %d, screen bottom x coordinates: %d, screen top y coordinates: %d, screen bottom y coordinates: %d\n"
		, *pApp_win_tX, *pApp_win_bX, *pApp_win_tY, *pApp_win_bY );

	//+ for up scroll; - for down scroll
	if ((Activate_Vscroll(pGT_Y, pScreen_Res_Y, pVscroll_type)) == TRUE)
	{
		DWORD GTEvent = MOUSEEVENTF_WHEEL;	//sets mouse event to vertical wheel
		switch (*pVscroll_type)
		{
			case 1:
				mouse_event ( GTEvent, pGT_X, pGT_Y, +10, 0);	//scrolls up
//check				cout << "Scrolled up\n";
				break;
			case 2:
				mouse_event ( GTEvent, pGT_X, pGT_Y, +30, 0);	//scrolls up fast
//check				cout << "Scrolled fast up\n";
				break;
			case 3:
				mouse_event ( GTEvent, pGT_X, pGT_Y, -10, 0);	//scrolls down
//check				cout << "Scrolled down\n";
				break;
			case 4:
				mouse_event ( GTEvent, pGT_X, pGT_Y, -30, 0);	//scrolls down fast
//check				cout << "Scrolled fast down\n";
				break;
			default:
				cout << "ERROR in auto vertical scroll: " << GetLastError () << endl;
				break;
		}
	}	//end vertical if

	//+ for right scroll; - for left scroll
	if ((Activate_Hscroll(pGT_X, pScreen_Res_X, pHscroll_type)) == TRUE)
	{
		DWORD GTEvent = MOUSEEVENTF_HWHEEL;	//set mouse event to horizontal wheel
		switch (*pHscroll_type)
		{
			case 1:
				mouse_event ( GTEvent, pGT_X, pGT_Y, +10, 0);	//scrolls right
//check				cout << "Scrolled right\n";
				break;
			case 2:
				mouse_event ( GTEvent, pGT_X, pGT_Y, +30, 0);	//scrolls right fast
//check				cout << "Scrolled fast right\n";
				break;
			case 3:
				mouse_event ( GTEvent, pGT_X, pGT_Y, -10, 0);	//scrolls left
//check				cout << "Scrolled left\n";
				break;
			case 4:
				mouse_event ( GTEvent, pGT_X, pGT_Y, -30, 0);	//scrolls left fast
//check				cout << "Scrolled fast left\n";
				break;
			default:
				cout << "ERROR in auto Horizontal scroll: " << GetLastError () << endl;
				break;
		}
	}	//end horizontal if
	
//check	cout << "**************************************************************************\n\n";	//print to specify this function has come to an end
	return;
}


the second switch is the horizontal scroll simulation action controls

2nd question's code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void app_size(int *pApp_win_tX, int *pApp_win_bX, int *pApp_win_tY, int *pApp_win_bY)
{

#define Buffer 1024

	//DECLARE variables
	char WindowTitle [Buffer];
	RECT CurrentWindowSize;
	HWND CurrentConsoleHwnd;
	
	if (!(CurrentConsoleHwnd = (HWND)GetConsoleTitle ( (LPWSTR)WindowTitle, Buffer)))
	{
		cout << "Error occured at get \"get console title\": " << GetLastError() << endl;
	}

	if ( GetClientRect (CurrentConsoleHwnd, CurrentWindowSize) == FALSE )
	{
		cout << "Error occured at get client window coordinates: " << GetLastError() << endl;
	}


	*pApp_win_tX = CurrentWindowSize.left;
	*pApp_win_bX = CurrentWindowSize.right;
	*pApp_win_tY = CurrentWindowSize.top;
	*pApp_win_bY = CurrentWindowSize.bottom;

	return;
}

I've tried everything with RECT to LPRECT. compiler doesnt like it, doing (LPRECT) to it doesnt help. In MSDN it says:Any variable of that user-defined type what does that mean???
Why did you assign the result of GetConsoleTitle call to CurrentConsoleHwnd?

DWORD GetConsoleTitle(LPTSTR lpConsoleTitle, DWORD nSize);

GetConsoleTitle retrieves current console window title(on the title bar)
to application supplied buffer(lpConsoleTitle).

Return value is the length of the string copied to the buffer, not HWND.
GetConsoleWindow function retrieves the console window's HWND.

hmm.. GetConsoleWindow requires...

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Header: Declared in Wincon.h; include Windows.h.
Library: Use Kernel32.lib.







GetClientRect (CurrentConsoleHwnd, &CurrentWindowSize)
You must pass CurrentWindowSize's address(LPRECT means long pointer to RECT).
fixed the 2nd problem by using get foreground window to get the hwnd

thanks.

how about the first question? horizontal scroll?
oh, sorry.

I tried below code and it seems to work well..
(under MS Win XP professional)

--------------------------------------------------------------------------------------------------
HWND hw = GetConsoleWindow();

// scroll to left...(one line.)
int NewPos = GetScrollPos(hw, SB_HORZ);
if (NewPos > 0) NewPos--;
SetScrollPos(hw, SB_HORZ, NewPos, TRUE);
SendMessage(hw, WM_HSCROLL, SB_LINELEFT, 0);

// scroll to right...(one line)
int NewPos = GetScrollPos(hw, SB_HORZ);
if (NewPos < 2147483647) NewPos++;
SetScrollPos(hw, SB_HORZ, NewPos, TRUE);
SendMessage(hw, WM_HSCROLL, SB_LINERIGHT, 0);
---------------------------------------------------------------------------------------------------

I recommend you to replace 2147483647 to INT_MAX or std::numeric_limits<int>::max().
You need to include limits.h to use INT_MAX constant.
You need to include <numeric_limits> to use std::numeric_limits.



p.s. Using GetForegroundWindow() is not good method to get console window's HWND.
If your console window is not foreground window,
and your GetForegroundWindow() call is being executed,
you may not be able to get your console window's handle...

(I'm not good at English.. Please pardon for grammatical errors.)

You need to predefine _WIN32_NT to 0x500 or later to use GetConsoleWindow().
Predefine before you include windows.h

Of course you need to install PSDK if you're using old version of VC++.
(If compile errors occur even though you predefined _WIN32_NT, you may need to install PSDK.)



#define _WIN32_NT 0x500
#include <windows.h>
Last edited on
Topic archived. No new replies allowed.