Win32 scrolling (Map Editor)

Started by
7 comments, last by Evil Steve 19 years, 8 months ago
Hey, I'm currently working on a map editor for my game. The map editor is within a maximized window, the drawing is done with OpenGL. Not all of the window is covered by the map graphics, a part is left out for buttons/combobox, etc.. To achieve this, I created a "STATIC" control within my main window and I used its HDC for OpenGL. I also passed (WS_VSCROLL | WS_HSCROLL) to the control style, so now I have on the bottom and on the right of the map two scrolling bars. The problem is that, I can't find any good info on how would I be able to modify the length of those scroll bars and to make them movable according to the length I would specify. Those scrolling bars should naturally be used for scrolling within some text, but since I don't use text at all in this control, I need a way to manually modify the possible scrolling length. Anyone could provide me with some info about that? Thanks a lot.
Advertisement
If pure Win32 API send SBM_SETRANGE to the scrollbar.

wParam
Specifies the minimum scrolling position.
lParam
Specifies the maximum scrolling position.

When you set the range, take care to exclude the visible area from the scrolling range.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Thanks a lot, after googling for SBM_SETRANGE, I found SetScrollInfo function and now everything works great :)
Coding a full-fledged editor for your game in Win32 probably isn't the best idea. Using pre-existing code such as WTL is a better idea, since you won't waste time on the Windows code, and you'll get straight to the editor instead. Even MFC is a viable option, since editors (usually) aren't realtime.
Quote:Original post by psykr
Coding a full-fledged editor for your game in Win32 probably isn't the best idea. Using pre-existing code such as WTL is a better idea, since you won't waste time on the Windows code, and you'll get straight to the editor instead. Even MFC is a viable option, since editors (usually) aren't realtime.


I will second this... map editors take a lot of time out, and if you chose to do W32 as your base... it can really burn you out after working on engine for a month, and know the level of work required to port it in right into W32.
Quote:Original post by psykr
Coding a full-fledged editor for your game in Win32 probably isn't the best idea. Using pre-existing code such as WTL is a better idea, since you won't waste time on the Windows code, and you'll get straight to the editor instead. Even MFC is a viable option, since editors (usually) aren't realtime.

An alternate view - I just finished writing a map editor in Win32. I decided to use Win32 over MFC because I prefer to have lower level access to what I'm doing, and I know Win32 slightly better than MFC. I didn't have any problems with it, and I got it done pretty quickly. I could copy all the window setup and message pump code from other apps, so I got something set up quickly.

Heres the code I used for setting the scrollbar range (inside my WM_SIZE handler):
SCROLLINFO si;si.cbSize = sizeof(si);si.fMask = SIF_POS | SIF_RANGE;si.nMin = 0;si.nPos = m_nXScroll;si.nMax = m_nMaxWidth-m_nScreenWidth;SetScrollInfo(m_hWnd,SB_HORZ,&si,TRUE);si.nPos = m_nYScroll;si.nMax = m_nMaxHeight-m_nScreenHeight;SetScrollInfo(m_hWnd,SB_VERT,&si,TRUE);

m_nXScroll and m_nYScroll are the current scrollbar positions, m_nScreenWidth and m_nScreenHeight is the size of the client area and m_nMaxWidth and m_nMaxHeight is the size of the 'canvas' (20000x20000 initially).

Theres an MSDN tutorial on using scrollbars, which I basically copied for handling my scrolling, since its exactly what I needed. Heres a link: Here. You can strip out the stuff you don't need obviously.
That's pretty much the samething I've done Evil Steve, it works fine ;)

I gotta say I'm tempted to go for MFC or something else than pure Win32.. Actually doing some things is starting to be painful, it takes too long to find the information I'm looking for.
For exemple, I just made a toolbar with buttons, using some code from theForger's webiste..
I wanted to add a tooltip text when the mouse is over the button for 1 second.. but first, it's hard to find the documentation on MSDN and once you've found it, it's not always clear enought..

I think I'm gonna take a look at this WTL, I've been losing way too much time on Win32 :/
there are much better alternatives to win32 and win32 based toolkits. these things will mega boost your productivity:

Qt http://trolltech.com - an excellent C++ GUI toolkit library. very nice design, very easy to use, very powerful, very fast. Free Software [GPL]

FOX http://fox-toolkit.com - another great C++ GUI toolkit, uses a nice design for events. It's also very easy to use, and very powerful. Free Software [LPGL]

Gtk+ http://gtk.org - it's pretty good, it has loads of language bindings. it's simple in a way, but it offers most of the functionality that you need.

wxWidgets http://wxwidgets.org - supposed to be good. i've never really used it. lot's of people love it though

Also, you may want to consider using a language other then C++. An editor application isn't as demanding as a realtime game. A language like Python or Ruby will boost your productivity even more on top of using one of the above GUI toolkits. pretty much all of them have loads of language bindings.

I really think you should look into these. they will save you lots of time and headache. they were all designed in order to provide the developer the best development experience. win32 on the other hand is just this ugly mutant that evolved from the windows 3.1 days, and is still trying to stay compatible with it.
Scrollbars in Win32 aren't that bad. Well, once you get the basics done ;)
	// Fill in TBBUTTON struct //	for(i=0; i<m_vToolbarButtons.size(); ++i)	{		ZeroMemory(&theButton,sizeof(theButton));		if(!m_vToolbarButtons.bSeperator)		{			theButton.iBitmap = m_vToolbarButtons.nBmpIndex;			theButton.idCommand = m_vToolbarButtons.dwID;			theButton.fsState = TBSTATE_ENABLED;			theButton.fsStyle = TBSTYLE_BUTTON;			if(m_vToolbarButtons.bCheckbox) 				theButton.fsStyle |= TBSTYLE_CHECK;		}		else			theButton.fsStyle = TBSTYLE_SEP;		vButtons.push_back(theButton);	}	// Create image list for toolbar //	if(!m_hImageList)		m_hImageList = ImageList_Create(16,16,ILC_COLOR32|ILC_MASK,0,64);	if(!m_hImageList)	{		m_strError = "Failed to create image list";		Release();		return false;	}	// Create toolbar //	m_hWndToolbar = CreateToolbarEx(m_hWnd,WS_CHILD|WS_VISIBLE|CCS_ADJUSTABLE|		TBSTYLE_TOOLTIPS|TBSTYLE_FLAT,0,vButtons.size(),NULL,NULL,		&vButtons[0],vButtons.size(),24,24,16,16,sizeof(TBBUTTON));	if(!m_hWndToolbar)	{		m_strError = "Failed to create toolbar";		Release();		return false;		}	SendMessage(m_hWndToolbar,TB_SETIMAGELIST,0,(LPARAM)m_hImageList);

In my code, you call SetToolbarImage() which will create m_hImageList if it doesn't exist, and will add an image to it. Thats usually called several times before the function above.

This topic is closed to new replies.

Advertisement