DevPinoy.org
A Filipino Developers Community

>>> First two to make 3 wins! <<<

I Wanna Be "Always on Top"

rated by 0 users
This post has 4 Replies | 0 Followers

Top 10 Contributor
Posts 751
Points 10,140
modchip Posted: 08-22-2008 12:25 AM

Hi all!

Is there an API or something that would make a DIALOGBOX stay always on top? I have tried searching but I have found none... (Maybe because of poor searching skils).

Thanks in advance!

Top 10 Contributor
Posts 498
Points 8,375

After you've secured the window's handler (HWND) of your dialog, just call the SetWindowPos function:

local rect: RECT

invoke GetWindowRect, m_hWnd, addr rect
invoke SetWindowPos, m_hWnd, HWND_TOPMOST, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW

Cheers,

-chris

Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 751
Points 10,140

Thanks for the quick reply!

local rect: RECT

invoke GetWindowRect, hWin, addr rect
; Gets the current teh screen coordinates of the dialog?

invoke SetWindowPos, hWin, HWND_TOPMOST, rect.left, rect.top, rect.right, rect.bottom, SWP_SHOWWINDOW
; Sets the coordinates gathered from the line above, makes dialog topmost even when deactivated, and shows the the dialog?


Yes my dialog stays on top.. but, I was wondering why it becomes larger than its original size...

Thanks again!

 

Top 10 Contributor
Posts 498
Points 8,375

Oops, sorry:

I was using SetWindowPos to reset the size as well. Add SWP_NOMOVE and SWP_NOSIZE to uFlags and set all size arguments to 0 if you want just the "top most" flag set (HWND_TOPMOST):

invoke SetWindowPos, hWin, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW or SWP_NOMOVE or SWP_NOSIZE

This will do it.

Note: HWND_TOPMOST is a window handle of the currently set on top most, and you are telling that SetWindowPost to "show the window on top of the current top most".

Other handles are: HWND_BOTTOM, HWND_NOTOPMOST, HWND_TOP

Enjoy,

-chris

Chris Vega This posting is provided "AS IS" with no warranties, and confers no rights My Weblog|Visit MSDN Community
  • | Post Points: 20
Top 10 Contributor
Posts 751
Points 10,140

Nice! I got it now...

I figured that the size and location was being replaced by the values gathered from the GetWindowRect! So, since now that we are literally defining the coords and dimensions, then I could omit the GetWindowRect function right? :D

Here's my code now;

DlgProc proc uses ebx esi edi hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
...

.elseif uMsg==WM_COMMAND
        .if wParam==IDC_BUTTON_MAIN_SET
            invoke SetWindowPos, hWin, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE

...

Now all i have to do is figure out how to correctly set it using checkboxes... pft!

Thanks a lot chris! This helped me a lot!

Page 1 of 1 (5 items) | RSS

Copyright DevPinoy 2005-2008