Sign in to follow this  
ouraqt

Win32 API Question - Goto Line Number

Recommended Posts

ouraqt    236
I'm developing an IDE for a scripting language I wrote, and I need some help regarding edit boxes. I have it so that (like in Visual Studio) when you double-click on an error message at the bottom, the IDE will highlight the error in the source file (which is displayed in a normal edit box above the error window). It highlights the error correctly, but if the error is off the screen (i.e. you need to scroll to see it) then I need some way to make the edit box automatically scroll to a certain line number. I'm using plain old Windows API, no MFC, in unmanaged C++. This is the code I use to create the window: hCompOutput = CreateWindowEx(WS_EX_CLIENTEDGE, "LISTBOX", "", WS_CHILD|WS_VISIBLE|WS_VSCROLL|LBS_DISABLENOSCROLL|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY, 0, 0, 0, 0, hWnd, NULL, hInst, NULL); So basically, I need to implement a feature similar to Ctrl+G (goto line) in notepad. I tried using this: SCROLLINFO lpsi; lpsi.cbSize = sizeof(SCROLLINFO); lpsi.fMask = SIF_RANGE; GetScrollInfo(hEdit, SB_VERT, &lpsi); lpsi.cbSize = sizeof(SCROLLINFO); lpsi.fMask = SIF_PAGE|SIF_POS; lpsi.nPage = 10; lpsi.nPos = (Line-1)*(lpsi.nMax-9)/lpsi.nMax; SetScrollInfo(hEdit, SB_VERT, &lpsi, TRUE); lpsi.cbSize = sizeof(SCROLLINFO); lpsi.fMask = SIF_PAGE|SIF_POS; lpsi.nPage = 10; lpsi.nPos = 0; SetScrollInfo(hEdit, SB_HORZ, &lpsi, TRUE); ...the scrollbar moved to the correct spot, but the text in the edit box didn't move. And If I use the mousewheel to scroll from there, the scrollbar jumps back to where it was before. Any help is greatly appreciated.

Share this post


Link to post
Share on other sites
Omega147    536
You probably want the EM_LINESCROLL message, which will let you scroll the edit control vertically and horizontally by the amounts specified in the provided LPARAM and WPARAM. EM_SCROLL will also do it, but only one line or page at a time. For a full list of messages that can be sent to a Win32 Edit Control, go to this link (scroll down to "Messages").

Share this post


Link to post
Share on other sites
ouraqt    236
Thanks. A little further down that page I found what I was looking for:

SendMessage(hEdit, EM_SCROLLCARET, 0, 0);

Such a simple solution...that makes me happy.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this