Robert, I'm probably stating the obvious, but besides Matt changes I guess icon loading implementation for each of the platforms except windows will be required too.
Guy. Hi Matt, Could you post the whole modified files, I can then review then with a view to merging them or something similar. Cheers, Robert. On Tue, Mar 10, 2009 at 6:43 PM, Matt McPheeters <[email protected]> wrote: > Awesome, it worked. The icon I was talking about is the one in the > upper left hand corner of the window. But it also appears in the > taskbar and the > alt-tab popup menu. > > This is a Windows platform so the solution I came up with is not > platform independent, but I believe I implemented it in the same generic > way that > GraphicsWindow::setWindowName() is done. > > In GraphicsWindow (header file, line 121): > > /** Set the icons the window uses */ > virtual void setWindowIcons(const std::string& /*iconPath*/) { > osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowIcons(..) not > implemented."<<std::endl; } > > /** Set the name of the window */ > virtual void setWindowName(const std::string& /*name*/) { > osg::notify(osg::NOTICE)<<"GraphicsWindow::setWindowName(..) not > implemented."<<std::endl; } > > > In GraphicsWindowWin32 (header file, line 85): > > /** Set the icons for the window */ > virtual void setWindowIcons(const std::string& /*iconPath*/); > > /** Set the name of the window */ > virtual void setWindowName(const std::string& /*name*/); > > (and on line 151, the member variables): > > HWND _hwnd; > HDC _hdc; > HGLRC _hglrc; > HCURSOR _currentCursor; > HICON _currentIcon; > > > In GraphicsWindowWin32.cpp (source file, line 959, the constructor): > > GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* > traits ) > : _hwnd(0), > _hdc(0), > _hglrc(0), > _currentCursor(0), > _currentIcon(0), > > (and on line 1006, the destructor): > > GraphicsWindowWin32::~GraphicsWindowWin32() > { > if (_currentIcon != NULL) > { > DestroyIcon(_currentIcon); > } > > close(); > destroyWindow(); > } > > (and on line 1878, the Windows implementation of the new function): > > void GraphicsWindowWin32::setWindowIcons( const std::string & iconPath ) > { > HINSTANCE hinst = ::GetModuleHandle(NULL); > _currentIcon = ExtractIcon(hinst, iconPath.c_str(), 0 ); > > if (_currentIcon != NULL) > { > SendMessage(_hwnd, WM_SETICON, ICON_SMALL, (LPARAM)_currentIcon > ); > SendMessage(_hwnd, WM_SETICON, ICON_BIG, (LPARAM)_currentIcon ); > } > } > > void GraphicsWindowWin32::setWindowName( const std::string & name ) > { > _traits->windowName = name; > SetWindowText(_hwnd, name.c_str()); > } > > > > Here is the code from my ::osgViewer application. Names have been > changed > to protect the innocent (haha): > > viewer.realize(); > > osgViewer::Viewer::Windows windows; > viewer.getWindows( windows ); > std::string windowName; > windowName.assign( "fooViewer" ); > windows[0]->setWindowName( windowName ); > windows[0]->setWindowIcons( "barney.ico" ); > > All that is required is that "barney.ico" exists in the same directory > that > the executable is run from and contains a valid icon. However, I > verified that this code works even if the iconPath parameter contains > full path information. I did a test: > > windows[0]->( "C:\\WINDOWS\\nvidia icons\\Portal_32x32.ico" ); > > And it worked like a charm. If the file doesn't exist or exists but > doesn't actually contain a valid icon, the viewer doesn't crash. You > just get the same default icon from before. > > Thanks for the great hints, > -Matt > > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Guy > Sent: Monday, March 09, 2009 11:24 PM > To: OpenSceneGraph Users > Subject: Re: [osg-users] Simple question: How to set the icon that will > beused when a viewer is realized? > > Hi, > I guess it depends on your platform. I haven't seen generic > implementation for it but I guess it could be added to display settings > or something like that (maybe GraphicsContext::Traits). > > Anyway, on windows platform, in the file > "\osgViewer\GraphicsWindowWin32.cpp", > In the function "void Win32WindowingSystem::registerWindowClasses()" > The code register a window class and set it's icon to > wc.hIcon = ::LoadIcon(hinst, "OSG_ICON"); > > so you can change it there (Hard coded). > > It of course will be much more usefull to pass the file in a generic way > that each platform implementation will call the specific platform calls > to load the icon. > > Guy. > > > > > I don't know if there is a platform independent way of setting this. > What OS are you using? which icon are you talking about exactly? The one > in the top right corner? > > Cory > > Matt McPheeters wrote: >> Hi guys, >> >> I found of an old way of doing this using Producer. I want the icon > of >> the viewer window to be custom, not the plain white application icon > it >> defaults to. How do you set the icon now in OpenSceneGraph-2.7.4? >> >> Sorry if this question gets asked a lot. >> _______________________________________________ >> osg-users mailing list >> [email protected] >> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or > g >> >> > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or > g > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or > g > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

