window always on top

Is there a nice way to set an oF window to be “always on top?” Namely in Windows. I call another app from within a fullscreen oF app and it briefly shows a small window on screen and exposes the taskbar, yuck.

i looked here: http://forum.openframeworks.cc/t/alwaysontop/5400/0
and i do that:

  • copy this code into ofAppGlutWindow.cpp
  
void ofAppGlutWindow::setWindowAlwaysOnTop(){    
	#ifdef TARGET_WIN32    
		//get its handle "GLUT" = class name "ogl" = window     
		HWND hwnd = FindWindowA( "GLUT", "" );     
		//set the window always-on-top    
		::SetWindowPos(hwnd, HWND_TOPMOST, NULL, NULL, NULL, NULL, SWP_NOREPOSITION | SWP_NOSIZE );    
	#endif    
}    

  • copy this code into ofAppRunner.cpp
  
void ofSetWindowAlwaysOnTop(){  
	window->setWindowAlwaysOnTop();  
}  

  • and copy into ofAppBaseWindow.h
  
virtual void	setWindowAlwaysOnTop(){}  

The path for all file is: of_preRelease_v0062_vs2010_FAT\libs\openFrameworks\app

  • in the end, write ofSetWindowAlwaysOnTop() in testApp.cpp

i don’t know if it’s correct way… but works.

Ciao

Hi,

it will be nice to find code how to implement in Mac too and Linux, to add this useful method as native in OF.

I found some code in cocoa, but did find way to integrate to OF:
http://whomwah.com/2009/04/11/using-cocoa-to-keep-an-app-window-always-on-top/

  
  
  // It's always nicer if the user has a choice  
  if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAlwaysOnTop"] == YES) {  
    [[self window] setLevel:NSFloatingWindowLevel];  
  } else {  
    [[self window] setLevel:NSNormalWindowLevel];  
  }  
  

At the moment in mac as alternative non code base, I used an application that allow any application to convert it in “Window on top”: http://infinite-labs.net/afloat/

this is what i do on OSx

string myAppName = "yourAppNameHere";

char myScript[255];
sprintf(myScript, “osascript -e ‘tell app “System Events”’ -e ‘set theApps to every process whose name contains “%s”’ -e ‘set theApp to item 1 of theApps’ -e ‘set frontmost of theApp to true’ -e ‘end tell’”,myAppName.c_str());
std::system(myScript);

2 Likes