Click here to Skip to main content
14,981,456 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hi,
Based on user input i need to dynamically scroll vertical bar on a notepad. How do i trap message from output window to the program if the user has reached the end of the page to start scrolling vertically ?
Is my approach correct to achieve this ? please help.
Posted
Comments
   
What do you mean by "notepad"? Notepad already exists, you cannot modify its behavior. And why?
--SA
[no name] 6-Aug-11 16:23pm
   
i m sorry. i was preparing an application similar to notepad. When ever the user inputs any character I am displaying a message say like "key pressed is %c" and then move to next line. But if the user continues to press keys he reaches the end of the page and at this stage how do i scroll vertically down and how do i enable this feature.

Below is the program for your reference.

#include <windows.h>

LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow )
{
HWND hwnd;
MSG msg;
WNDCLASS wc;
TCHAR szClassName[] = TEXT("Sample");

wc.style = CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.lpfnWndProc = WndProc;
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = ( HBRUSH ) GetStockObject( WHITE_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = szClassName;
wc.hInstance = hInstance;

if( ! RegisterClass( &wc ) )
{
MessageBox( NULL, TEXT("Class Registration failed!"), szClassName, MB_ICONERROR );
return 1;
}

hwnd = CreateWindow( szClassName,
TEXT("Text Pad"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL );

ShowWindow( hwnd, iCmdShow );
UpdateWindow( hwnd );

while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}

return msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
static int cyChar, cyClient, iLines;
HDC hdc;
TCHAR szBuffer[50];
TEXTMETRIC tm;

switch( message )
{
case WM_CREATE:
hdc = GetDC( hwnd );
GetTextMetrics( hdc, &tm );
cyChar = tm.tmHeight;
ReleaseDC( hwnd, hdc );
break;

case WM_CHAR:
hdc = GetDC( hwnd );
wsprintf( szBuffer, TEXT("Key pressed %c"), wParam );
TextOut( hdc, 0, cyChar * iLines++, szBuffer, lstrlen( szBuffer ) );
ReleaseDC( hwnd, hdc );
break;

case WM_DESTROY:
PostQuitMessage(0);
break;
}

return DefWindowProc( hwnd, message, wParam, lParam );
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900