AlwaysOnTop form and hook

Posted on 2007-04-11
Last Modified: 2010-04-05

I have a problem, but i didn't find any solution on the Internet.
The problem is the following. I have a stayontop window (created by me) and i want to keep it
always on top over other desktop windows but !!! not over popup menus (like right click context menus), file menus (e.g. File-Edit-Settings...), and dropdown lists. If a window is created with WS_POPUP or WS_POPUPWINDOW style flag then my window can't stay on top. I tried to use a hook but wont work...because i don't know how can i draw a distinction between a real popup window and a standard window created with WS_POPUP or WS_POPUPWINDOW flag...


//stayontopform is my window
if PCWP^.hwnd<>FindWindow(nil,'stayontopform') then
      if (GetWindowLong(PCWP.hwnd, GWL_EXSTYLE) and WS_EX_TOPMOST) <> 0 then
      Style:=GetWindowLong(PCWP^.hwnd, GWL_STYLE);

      //if not WS_POPUP
      if ((Style and WS_POPUP or WS_POPUPWINDOW or WS_SYSMENU)=0) then
      SetWindowPos(PCWP^.hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE + SWP_NOMOVE);

      //if has menu
      if ((HMenu(GetMenu(PCWP^.hwnd))<>0) and (SendMessage(PCWP^.hwnd,LB_SETCOUNT,0,0)=0)) then
      SetWindowPos(PCWP^.hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE + SWP_NOMOVE);

      //if has system menu
      if (HMenu(GetSystemMenu(PCWP^.hwnd,false))<>0) then
      SetWindowPos(PCWP^.hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE + SWP_NOMOVE);

      //if has captionbar
      if ((Style and WS_CAPTION)=WS_CAPTION) then
      SetWindowPos(PCWP^.hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE + SWP_NOMOVE);


    Result:=CallNextHookEx(MyHook, pCode, pHandle, pWindow);

Is there any difference between these windows? For example a system message that's applicable for a
real popup (right click menus, file menus, dropdown lists) and not for a standard desktop window?
(or vice versa)

Thanks in advance!
Question by:rogerrr
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

xr1140 earned 125 total points
ID: 18893669

maybe i haven`t understood your problem but .... by default popup menus are drawn over onTop windows
LVL 16

Assisted Solution

CodedK earned 125 total points
ID: 18897938
I have a problem like that with a custom ontop form.
I've noticed the following :

In my form i have a pop up menu.
When i pop up my form menu and close it...
Then EVERY other pop up menu sit above my form without a problem !

So if you don't find something to work with just fire up a Pop-up menu once, when the form loads.
Hope this will help.

Expert Comment

ID: 21156552
Forced accept.

EE Admin

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 81
Convert GUI app into console app for Win32 Env 5 126
Dev Express grid collapse 2 48
Tvertscrollbox like a whatsapp layout delete messages 1 39
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question