Hello,
how to bring a wxFrame definitely to front. wx302 on windows.
Raise does it not. A click on titlebar or task icon does it.
Thank you
wxFrame bring to front Topic is solved
Re: wxFrame bring to front
Dunno if this works, but if the window you raise is a child window you might want to raise the app's main window first:
Would be nice with a wxApp::Raise(), though
Code: Select all
void RaiseFrame(wxFrame *someFrame)
{
wxWindow pw = (wxWindow*)someFrame;
while (pw->GetParent()) pw = pw->GetParent();
pw->Raise();
someFrame->Raise();
}
I have a bad habbit of not testing the code I post
Re: wxFrame bring to front
The frame is minimized.
When calling Raise, the task icon get's highlighted but not restored.
When pressing with the mouse on the task icon it is restored correctly.
When calling Raise, the task icon get's highlighted but not restored.
When pressing with the mouse on the task icon it is restored correctly.
Re: wxFrame bring to front
wxFrame::Restore
wxFrame::Raise
does the job.
(perhaps ::Raise is not needed)
wxFrame::Raise
does the job.
(perhaps ::Raise is not needed)
Re: wxFrame bring to front
Maybe giving the information that "the frame is minimized" would have been helpfull in the beginning.. But I'm not entirely sure....wxwxwx wrote:The frame is minimized.
When calling Raise, the task icon get's highlighted but not restored.
When pressing with the mouse on the task icon it is restored correctly.
I have a bad habbit of not testing the code I post
Re: wxFrame bring to front
yes.sorry
-
- Earned a small fee
- Posts: 21
- Joined: Wed Oct 30, 2013 9:22 am
Re: wxFrame bring to front
The following works fine on windows (tested extensively on XP, 7 and 8 / 8.1), not so sure how it is on Linux / other platforms. I'd like to claim the credit for writing it, but I can't - I've tried to acknowledge all those who contributed part of the solution ...
Code: Select all
bool CWindowUtilities::ForceWindowToForeground (wxTopLevelWindow* Window)
{
// Code from Thomas Stutz @ delphi3000.com
// Converted to Borland C++ Builder Code by Wolfgang Frisch
// Converted to a Borland independent version by Kai Schaeffer @ schaeffer-ag.de
// Converted to wxWindows version by me
bool Result = false;
#ifdef __WXMSW__
const HWND hwnd = Window->GetHWND ();
DWORD nullvalue = 0;
DWORD ForegroundThreadID;
DWORD ThisThreadID;
DWORD timeout;
// restore the window if currently iconised
if (IsIconic (hwnd))
{
ShowWindow (hwnd, SW_RESTORE);
}
// nothing more to do if already the fg window
if (GetForegroundWindow () == hwnd)
{
Result = true;
}
else
{
// Windows 98/2000 doesn't want to foreground a window when some other
// window has keyboard focus
OSVERSIONINFO VersionInfo;
VersionInfo.dwOSVersionInfoSize=sizeof (OSVERSIONINFO);
GetVersionEx (&VersionInfo);
int Win32Platform = VersionInfo.dwPlatformId;
int Win32MajorVersion = VersionInfo.dwMajorVersion;
int Win32MinorVersion = VersionInfo.dwMinorVersion;
if ( ((Win32Platform == VER_PLATFORM_WIN32_NT) && (Win32MajorVersion> 4))
|| ((Win32Platform == VER_PLATFORM_WIN32_WINDOWS)
&& ((Win32MajorVersion > 4) || ((Win32MajorVersion == 4) &&
(Win32MinorVersion > 0)))) )
{
// Code from Karl E. Peterson, www.mvps.org/vb/sample.htm
// Converted to Delphi by Ray Lischner
// Published in The Delphi Magazine 55, page 16
Result = false;
ForegroundThreadID = GetWindowThreadProcessId (GetForegroundWindow (), NULL);
ThisThreadID = GetWindowThreadProcessId (hwnd, NULL);
if (AttachThreadInput (ThisThreadID, ForegroundThreadID, true))
{
BringWindowToTop (hwnd); // IE 5.5 related hack
SetForegroundWindow (hwnd);
AttachThreadInput (ThisThreadID, ForegroundThreadID, false);
Result = (GetForegroundWindow () == hwnd);
}
if (!Result)
{
// Code by Daniel P. Stasinski
SystemParametersInfo (SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &timeout, 0);
SystemParametersInfo (SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &nullvalue, SPIF_SENDCHANGE);
BringWindowToTop (hwnd); // IE 5.5 related hack
SetForegroundWindow (hwnd);
SystemParametersInfo (SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &timeout, SPIF_SENDCHANGE);
}
}
else
{
BringWindowToTop (hwnd); // IE 5.5 related hack
SetForegroundWindow (hwnd);
}
Result = (GetForegroundWindow () == hwnd);
}
#else
Window->Iconize (false); // restore the window if minimized
Window->SetFocus (); // focus on my window
Window->Raise (); // bring window to front
Window->Show (true); // show the window
Result = true;
#endif
return Result;
}
Re: wxFrame bring to front
It worked.
ColinTaylor wrote: ↑Wed Mar 04, 2015 1:00 pm The following works fine on windows (tested extensively on XP, 7 and 8 / 8.1), not so sure how it is on Linux / other platforms. I'd like to claim the credit for writing it, but I can't - I've tried to acknowledge all those who contributed part of the solution ...
Code: Select all
bool CWindowUtilities::ForceWindowToForeground (wxTopLevelWindow* Window) { // Code from Thomas Stutz @ delphi3000.com // Converted to Borland C++ Builder Code by Wolfgang Frisch // Converted to a Borland independent version by Kai Schaeffer @ schaeffer-ag.de // Converted to wxWindows version by me bool Result = false; #ifdef __WXMSW__ const HWND hwnd = Window->GetHWND (); DWORD nullvalue = 0; DWORD ForegroundThreadID; DWORD ThisThreadID; DWORD timeout; // restore the window if currently iconised if (IsIconic (hwnd)) { ShowWindow (hwnd, SW_RESTORE); } // nothing more to do if already the fg window if (GetForegroundWindow () == hwnd) { Result = true; } else { // Windows 98/2000 doesn't want to foreground a window when some other // window has keyboard focus OSVERSIONINFO VersionInfo; VersionInfo.dwOSVersionInfoSize=sizeof (OSVERSIONINFO); GetVersionEx (&VersionInfo); int Win32Platform = VersionInfo.dwPlatformId; int Win32MajorVersion = VersionInfo.dwMajorVersion; int Win32MinorVersion = VersionInfo.dwMinorVersion; if ( ((Win32Platform == VER_PLATFORM_WIN32_NT) && (Win32MajorVersion> 4)) || ((Win32Platform == VER_PLATFORM_WIN32_WINDOWS) && ((Win32MajorVersion > 4) || ((Win32MajorVersion == 4) && (Win32MinorVersion > 0)))) ) { // Code from Karl E. Peterson, www.mvps.org/vb/sample.htm // Converted to Delphi by Ray Lischner // Published in The Delphi Magazine 55, page 16 Result = false; ForegroundThreadID = GetWindowThreadProcessId (GetForegroundWindow (), NULL); ThisThreadID = GetWindowThreadProcessId (hwnd, NULL); if (AttachThreadInput (ThisThreadID, ForegroundThreadID, true)) { BringWindowToTop (hwnd); // IE 5.5 related hack SetForegroundWindow (hwnd); AttachThreadInput (ThisThreadID, ForegroundThreadID, false); Result = (GetForegroundWindow () == hwnd); } if (!Result) { // Code by Daniel P. Stasinski SystemParametersInfo (SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &timeout, 0); SystemParametersInfo (SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &nullvalue, SPIF_SENDCHANGE); BringWindowToTop (hwnd); // IE 5.5 related hack SetForegroundWindow (hwnd); SystemParametersInfo (SPI_SETFOREGROUNDLOCKTIMEOUT, 0, &timeout, SPIF_SENDCHANGE); } } else { BringWindowToTop (hwnd); // IE 5.5 related hack SetForegroundWindow (hwnd); } Result = (GetForegroundWindow () == hwnd); } #else Window->Iconize (false); // restore the window if minimized Window->SetFocus (); // focus on my window Window->Raise (); // bring window to front Window->Show (true); // show the window Result = true; #endif return Result; }
Re: wxFrame bring to front
Hi,
Raise() is doing exactly what is suppose to - bring the application main window to the front.
If you start the application, then switch to another one and then call Raise() the application window will become "raised", i.e. becomes the first one in Z-order
When you talk about minimizing, you should call some other function.
Thank you.
Raise() is doing exactly what is suppose to - bring the application main window to the front.
If you start the application, then switch to another one and then call Raise() the application window will become "raised", i.e. becomes the first one in Z-order
When you talk about minimizing, you should call some other function.
Thank you.