Windows on top error

QML on Windows: make the window to stay on top

I do really need to make my window to stay on top on Windows, but Windows itself does not seem willing to allow me to do this.

I cannot use the workaround with setting registry values because I am not able to ask the user to log-out/log-in.

Besides, I use QML and the solution with QWidget::raise() and QApplication::setActiveWindow() does not seem to work also because I have not managed to get the QML root object as a QWidget pointer with the following code:

I have also tried to make the window active right from the QML:

but with no luck also.

Is there, either way to bring the window on top on Windows without changing the registry and, preferably, from the QML purely?

Edit: currently used window flags are:

I am deploying Qt 5.7 app on the Windows 10 x64 machine. I have found this two bugfixes:

from which I can conclude that QWidget::activateWindow() and QWindow::requestActive() should work on Windows XP and Windows 7.

Here is my mcve, as @derM asked:

It was compiled under Windows 10 x64 with MinGW x32.

Easier way to reproduce: run in the command prompt

where debug\Test.exe is a path to the mcve binary, then open File Explorer and navigate somewhere. When the window opens, it won`t be in the foreground.

Harder way: If you just run it, the window will stay on top as it should. But if you press Run button in the Qt Creator and switch the focus (I suppose, mouse focus should be changed, just pressing Alt+Tab won`t help) to another process (in my case — File Explorer), the window is displayed under the current active File Explorer window, and even if I will bring it up by clicking, it will go background as soon as I choose any other application.

The real application is started from a service, so there often will be an app holding mouse focus when my app is started. I suppose that Qt ability to bring the window to foreground is implemented using SetForegroundWindow API call, which notes the following restrictions in it`s remarks:

  • The process is the foreground process.
  • The process was started by the foreground process.
  • The process received the last input event.
  • There is no foreground process.
  • The process is being debugged.
  • The foreground process is not a Modern Application or the Start Screen.
  • The foreground is not locked (see LockSetForegroundWindow).
  • The foreground lock time-out has expired (see — SPI_GETFOREGROUNDLOCKTIMEOUT in SystemParametersInfo).
  • No menus are active.

So I wonder is it possible at all to bring the window to foreground if the process has been started by a service, not a user (i. e. the process has not been an active process during startup).

How to Fix the Most Annoying Things in Windows 10

Windows 10 is great, but it has its issues, from unpredictable reboots to aggravating notifications. Here’s how to fix some of the more irritating quirks with Microsoft’s latest operating system.

Windows 10 is probably the best edition of Microsoft’s venerable operating system. But Redmond has never made an entirely perfect OS. As much as we like Windows 10—and we really do like it a lot—it’s got problems. Just check the comments below to see how much our readers hate the tracking and lack of privacy. (For that, read How to Protect Your Privacy in Windows 10.)

Thankfully, many of the OS’s problems are easily corrected. Here are the steps you can take, so version 10 doesn’t drive you up the Windows wallpaper.

Читайте также:  Как включить углы windows 10

Stop Auto Reboots

Windows 10 updates are regular and seemingly never-ending, and pretty much out of the user’s control (unless you turn off updates altogether, which is a bad idea). What’s worse: if you don’t reboot your PC after an update, Windows 10 eventually takes it upon itself to reboot for you. That’s a good way to lose data in open apps.

Take advantage of a feature called Active Hours, which lets you schedule a time for updates and reboots. Navigate to Settings > Update & Security > Windows Update > Change active hours. To select your own timeframe, click Change and choose a start and end time.

Starting with the May 2019 Update (version 1903), meanwhile, you can also opt to have Windows automatically adjust active hours based on your device’s activity. Navigate to Settings > Update & Security > Windows Update > Change active hours and toggle on the option for Automatically adjust active hours for this device based on activity.

Prevent Sticky Keys

If you hit the Shift key five times in a row in Windows, you activate Sticky Keys, a Windows feature that allows for keyboard shortcuts where you hit one key at a time instead of simultaneously (so it works with any combo that includes the Shift, Ctrl, Alt, or Windows keys).

If you activate it without knowing—by hitting «yes» in a dialog box without thinking, for example—it can be seriously annoying. Prevent it from ever happening by hitting the Shift five times rapidly to bring up that very dialog box. Click the Disable this keyboard shortcut in Ease of Access Keyboard Settings and uncheck the box next to Turn on Sticky Keys when SHIFT is pressed five times.

Calm the UAC Down

Ever since Windows Vista, User Account Control (UAC) has been there to protect users so they can quickly grant administrative rights to software programs that need it—specifically when installing or uninstalling software. In the old days, when you went to do an install, the screen would suddenly dim and everything seemed to come to a halt, causing several (anecdotal, probably fictional) heart attacks amid the populace. UAC is still there in Windows and will still dim the desktop, but you have the option to turn it off, or at least prevent the screen dimming.

Type UAC into the Windows 10 search box to get Change User Account Control Settings. The screen presents a slider with four levels of security, from never notify (bad) to always notify (annoying—it’ll warn you when you make your own changes). Pick one of the middle options; the second from the bottom notifies you without the dimming scare tactic. With that option, you’ll still get a dialog box confirmation with a yes/no option when you install things.

Delete Unused Apps

Did you know you have a program in Windows 10 called Groove Music? Probably not, because the world uses other services. Thankfully, a few pre-installed Windows apps can finally be deleted. Navigate to Settings > Apps > Apps & Features, where you can ditch Mail and Calendar, Groove Music, Weather, and Maps.

If your uninstall option is grayed out, you could go the DOS route, but it gets a little complicated and you should be 100% sure of what you’re doing.

Type PowerShell in the Windows search box—when you see it, right-click and launch it via Run as Administrator.

Type in «Get-AppxPackage –AllUsers» without the quotes. A giant list of all the stuff you’ve got installed that came from Microsoft’s Store, plus some other stuff, will appear.

It’s hard to find those apps in there, but the last one will probably clearly read Microsoft.ZuneMusic—that’s actually Groove Music. Copy everything it says on the line next to PackageFullName.

You’ll then type in a command and paste that line, so it reads something like «remove-AppxPackage Microsoft.ZuneMusic10.16122.10271.0x64__8wekyb3d8bbwe» (yours will be different after the first underscore character).

Читайте также:  Windows find files starting with

Execute it with a stroke of the return key. If you don’t get any errors, the Groove Music app should be gone. Be careful using this on other apps—be sure you’ve picked the right one.

Use a Local Account

Microsoft really wants you to sign in to Windows 10 with your Microsoft account—the one attached to all things Microsoft, be it your Xbox, Office 365, or OneDrive account, buying apps or music or video in the Windows Store, even talking on Skype, to name just a few. When you set up Windows, Microsoft specifically asks you to sign in using that account.

But you don’t have to. During setup, just click Skip this step. If you already signed in with the Microsoft account, go to Settings > Accounts > Your info. Click Sign in with a local account instead. Enter a local account name and new password (with a hint for when you forget it).

The downside is that when you end up on a service or site that requires Microsoft credentials, you’ll have to enter your Microsoft login each time; it won’t automatically sign you in as it does if you log into Windows with a Microsoft account.

Use a PIN, Not a Password

If you’re okay using the Microsoft account, but hate how long it takes to type in your super secure password, reset it to a short personal identification number (PIN) used only on the PC. The PIN, which is only numerals—no mixed case letters or special characters—might not sound secure. But it’s PC-only, hopefully you’re the only user, and it doesn’t compromise the security of your Microsoft account anywhere else. Plus, the PIN can be as many digits as you desire.

Go to Settings > Accounts > Sign-in options, and click the Add button under PIN. Enter the PIN you want and restart to try it. If you’ve already got a PIN, you’ll see options to change it, remove it, or click «I forgot my PIN» to recover it.

Skip the Password Login

Are you the only person who ever—and I mean ever—uses your PC? Then you can probably skip the password login screen that appears after every reboot or sometimes even when you come back from the screensaver.

Go to the User Accounts control panel by typing «netplwiz» in the search bar. Select the account, uncheck the box next to Users must enter a username and password to use this computer. You’ll get a confirmation box that asks you to enter that very password—twice. Click okay. Reboot the PC, and it should roll smoothly into the desktop without requesting a password. Don’t do this if it’s shared PC. Remember, you’ll still need to know the password if you’re logging into the PC remotely. (Or, you could use TeamViewer.)

Refresh Instead of Reset

Windows 10 has a fantastic feature that lets you essentially reinstall Windows 10 on your computer from the ground up, like new—with the option to not delete any of your data (though you will have to reinstall software and drivers). When your PC is beyond repair, you access it at Settings > Update & Security > Recovery. Click Get Started under Reset this PC, pick settings like «Keep My Files» or «Remove Everything,» and let it rip. You don’t need any separate media, like a copy of Windows 10 on a disc or USB flash drive.

However, that can be overkill. Sometimes, Windows just needs a reset that does not eradicate your software and drivers. This is also easy to do, but it does require a copy of Windows 10 on separate media. Don’t have the media? Get it here. Run it and install the included ISO file onto a 4GB or larger USB drive to use in the reset now and in the future. Or you can just mount it as a virtual drive in Windows 10.

Читайте также:  Что такое драйверы устройств линукс

Double-click the setup on that media/drive’s Setup option, ask to download updates and check Keep personal files and apps when it appears. After a few more prompts and waiting, your Windows 10 system will get the refresh it needs.

Hide or Disable Cortana

Master Chief would never let this happen. Windows 10 took out the switch to turn off Cortana, Microsoft’s answer to Siri and Alexa. But Cortana searches more than your computer; it searches the entire internet. You can still turn her off, however.

First, there is the option to hide Cortana: just right-click the Taskbar and select Show Cortana Button. The Cortana halo ring disappears. She’s still active and easily accessible, however: tap the Windows key on your keyboard and start typing.

If you want to really take her out, so all searches are local, you need to edit the registry. Don’t do this if you’re not feeling like a Windows expert. Make a system restore point before you do it, just in case. This only applies to Windows 10 Home version.

Open the Registry Editor: Type +R, then type regedit and hit Enter. In Windows 10 Home, navigate to HKEYLOCALMACHINE\SOFTWARE\Policies\Microsoft\Windows\Windows Search. If it’s not there, create it. Right-click it to create a DWORD value and call it AllowCortana. Set that value to 0 (zero). Once you sign out and come back, the search box will now read «Search Windows.» You can put Cortana back by doing all this again and setting the value to 1 (one).

If you have Windows 10 Pro or Enterprise, you can use the Group Policy Editor to turn her off, but for that, you should first check with your IT admin. Type Windows Key+R, type in gpedit.msc to bring up the Group Policy Editor, then navigate to Computer Configuration > Administrative Templates > Windows Components > Search. Double-click on Allow Cortana, check the button next to Disabled. Close the window and restart Windows 10.

If you’re killing Cortana for privacy reasons, don’t forget to visit your Microsoft account online and delete everything Cortana collected about you. Under Cortana’s Notebook, click the Clear Cortana Data button.

Win32: Bring a window to top

I have a Windows program which has two 2 windows in it:

When I double click on hwnd, I need hwnd2 to pop up and show some data, so I use this function to bring hwnd2 to top:

hwnd2 is brought to top, but there is one thing odd. When I click on hwnd2 again, hwnd (main interface) pops itself up again automatically. I tried to use the following function to solve this problem, but non of them works.

How could I solve this problem? Thanks in advance.

(for replying to aJ, hwnd2 doesn’t have parent because it needs to be a toplevel window so it can be in front/back of other windows)

(hwnd2 is a media player which is composed of several windows, one of the windows is for video dispaly, two other trackbar controls for progress bar and volume bar, one Toolbar control for control panel.)

(There is one this might help, no matter which window I click on hwnd2, hwnd pops up automatically as loong as «the mouse is on top of hwnd in Z-order», including menu bar and non-client area, etc.)

(This media player is writen in Direct Show. I use IVideoWindow::put_Owner to put video window as the video owner, Direct Show internally creates a sub-video window as a child of the video window. Except for this sub-video window which I can’t see the source code, I don’t see any thing suspicious in hwnd2.)

I found the reason, which is because of Direct Show. I use multithread to execute it, and then the problem’s solved. But. why??

This problem can be resolved by using PostMessage (rather than SendMessage).

Оцените статью