   [win32] syncing 2 scrolling 2 textboxes
  Im having trouble trying to implement this. Basically i have a rich text box that  displays code, and I want to incorporate line numbers. So along side the  code rich text box I have another rich text box, which simply displays incrementing numbers line by line. Now i want to same scrolling actions to occur on both when the user causes a scroll to occur through using the scrollbars or other shortcuts.At the moment I have the line numbers being updated whenever an EN_CHANGE notification is recieved, ie when text is edited in the code window. And I've managed to get some of the functionality I want by capturing the messages created by the code window and sending them to the line number text box. These being WM_MOUSEWHEEL, WM_VSCROLL and keyboard presses. But these dont handle the case where more text is added, which would change things, and another issue is that for the above to work, the line numbers text box needs a scroll bar, which i dont want visbible.Any suggestions?   
  Sorry, it's not quite clear what you are doing.Could you past code? I don't understand why you need vscroll bar for the other text box.BTW the vscroll bar is a funny thing. I implemented one in my own GUI, and there were so many issues/things to handle that after all, I simply redirected every messages to the textbox (so actually the text box was controlled), then updated the vscroll bar. So it was more a decoration than a widget. It received messages and translated them do the text box. I have no idea what does that have to do with your problem, but anyways...   ;  This might seem too obvious but I have done something similar to what you want.  When you get an update on the first window (displaying the code/text/whatever) use SendMessage() to send the same message to the other window also.  They stay in sync then easily.Hope that works, its been 4-5 years since I did it.   ;  Thats what I've been doing, but with selected messages. But the main problem is that for the window with the numbers to scroll ( by sending the other windows messages to it) I have to have its scrollbar enabled, and I dont want that. So Im looking for ways around it.Basically, I believe I need both windows ScrollWindow() functions to be in sync, but this function is handled internally in the richtextbox class.   ;  Post code please!   ;  You don't even have to scroll the line number text-box:Just start printing the line numbers starting with the appropriate number. Don't scroll at all.I hope it's clear.   ;  Well heres something I quickly threw togeather from a Charles Petzold example.#include <windows.h>#include <sstream>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;LRESULT CALLBACK RichTextWndProc (HWND, UINT, WPARAM, LPARAM) ;WNDPROC OLDPROC;HWND MainWindow, LineNumbers, Code;void UpdateLineNumbers(){int n = SendMessage( Code, EM_GETLINECOUNT, 0, 0 );std::wstringstream sstr;for( int i = 0; i < n; ++i ){sstr << i << L"\r\n";}SetWindowText( LineNumbers, sstr.str().c_str() );}int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow){static TCHAR szAppName[] = TEXT ("HelloWin") ;HWND    hwnd ;MSGmsg ;WNDCLASSwndclass ;wndclass.style    = CS_HREDRAW | CS_VREDRAW ;wndclass.lpfnWndProc   = WndProc ;wndclass.cbClsExtra    = 0 ;wndclass.cbWndExtra    = 0 ;wndclass.hInstance= hInstance ;wndclass.hIcon    = LoadIcon (NULL, IDI_APPLICATION) ;wndclass.hCursor  = LoadCursor (NULL, IDC_ARROW) ;wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;wndclass.lpszMenuName  = NULL ;wndclass.lpszClassName = szAppName ;if (!RegisterClass (&wndclass)){MessageBox (NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR) ;return 0 ;}MainWindow = CreateWindow (szAppName,  // window class name TEXT ("The Hello Program"), // window caption WS_OVERLAPPEDWINDOW,   // window style CW_USEDEFAULT,    // initial x position CW_USEDEFAULT,    // initial y position CW_USEDEFAULT,    // initial x size CW_USEDEFAULT,    // initial y size NULL,   // parent window handle NULL,   // window menu handle hInstance,   // program instance handle NULL) ; // creation parametersShowWindow (MainWindow, iCmdShow) ;UpdateWindow (MainWindow) ; RECT R; GetClientRect( MainWindow, &R );  LineNumbers = CreateWindow (L"EDIT",   L"",   WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER | ES_MULTILINE | WS_VSCROLL | ES_READONLY,    0, // initial x position 0, // initial y position 60,// initial x size  R.bottom - R.top, // initial y size MainWindow,  // parent window handle NULL,   // window menu handle hInstance,   // program instance handle NULL) ; // creation parameters std::wstringstream sstr; for( int i = 0; i < 300; ++i ){ sstr << "Line : " << i << L"\r\n"; } Code = CreateWindow (L"EDIT",   sstr.str().c_str(),  WS_CHILDWINDOW | WS_VISIBLE | WS_BORDER | WS_VSCROLL | ES_MULTILINE,    60,   // initial x position 0,    // initial y position  (R.right - R.left) - 60,  // initial x size  R.bottom - R.top,    // initial y size MainWindow,// parent window handle NULL, // window menu handle hInstance, // program instance handle NULL) ;    // creation parameters OLDPROC = (WNDPROC) SetWindowLong( Code, GWL_WNDPROC, (LONG)RichTextWndProc ); UpdateLineNumbers();while (GetMessage (&msg, NULL, 0, 0)){TranslateMessage (&msg) ;DispatchMessage (&msg) ;}return msg.wParam ;}LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){switch (message){ case WM_COMMAND: switch( HIWORD(wParam) ) {   case EN_CHANGE: UpdateLineNumbers(); break; } break;case WM_DESTROY:PostQuitMessage (0) ;return 0 ;}return DefWindowProc (hwnd, message, wParam, lParam) ;}LRESULT CALLBACK RichTextWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){if( message == WM_MOUSEWHEEL || message == WM_VSCROLL || message == WM_CHAR || message == WM_KEYDOWN )SendMessage( LineNumbers, message, wParam, lParam );return CallWindowProc( OLDPROC, hwnd, message, wParam, lParam) ;}http://pastebin.com/DnrLSS6qI had thought about not even scrolling and just working out the line numbers based on Scroll position and font size, but was hoping there was an easier way. Anyway I'll try it now.;  I think working out the numbers is actually simpler.You only have to "know" how many lines is scrolled in the main box. I think (at first) recalculate the number-box on every event affecting the main box.So let the number box be just decoration.   ;  Heh, worked fine for Text boxes, but not for rich text boxes, as they seem to be able to scroll less than a line.Just need to find a way to get the rich text box to only scroll line by line nowEDIT: I guess I really need to read the docs more. Stumbled upon this and it works like a charmPOINT p;SendMessage( Code, EM_GETSCROLLPOS, 0, (LPARAM)&p );SendMessage( LineNumbers, EM_SETSCROLLPOS, 0, (LPARAM)&p ); [Edited by - wforl on June 9, 2010 6:17:21 AM]