How can get my form to be on top of everything all the time?

后端 未结 5 990
梦如初夏
梦如初夏 2021-01-21 03:46

I have these little cursor shaped forms that I need to be on Top of everything, all the time...
FormStyle is already fsStayOnTop
I use this cod

相关标签:
5条回答
  • 2021-01-21 04:24

    or instead of the SetWindowPos command - try this:

    if visible then form1.SetFocus;
    
    0 讨论(0)
  • 2021-01-21 04:25

    Quick, slightly hacky fix: Call this from an Timer, 10 times a second:

    BringWindowToTop(Handle)
    

    Just tried it and it works! Maybe you can find a way to make it less "brute force", but I'm not sure how.

    0 讨论(0)
  • 2021-01-21 04:29

    I think that's as good as you're going to get. If your form stayed on top of menus, then users wouldn't be able to see a menu when they opened it. Doing something like that, especially when the system doesn't make it available through any easy means, borders on the malicious, or at least feels that way. You don't want your users to think that your program is malicious, so my advice would be to not try to do this in the first place.

    0 讨论(0)
  • 2021-01-21 04:38

    I think that you can look into DirectX. I believe that it allows overlays over primary image. You can open it in non-exlusive mode and draw overlay over desktop. But I'm NOT sure about it. Just a guess.

    0 讨论(0)
  • 2021-01-21 04:39

    This has to be the ultimate, or worst, piece of hackery I'll publish.

    1. Set your FormStyle to be fsStayOnTop (This step may not actually be necessary)
    2. Drop a TTimer on your form and set it's interval to 100
    3. In the OnTimer event place the following code:

      if visible then SetWindowPos(Self.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_NOACTIVATE);

    I'm using this in one of my projects and it seems to work alright.

    0 讨论(0)
提交回复
热议问题