Solved

Always on top

Posted on 1998-03-23
10
341 Views
Last Modified: 2013-12-03
ms visual c 4.1 :

In MDI application, how do I implement the always on top feature?
0
Comment
Question by:rich135
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1412227
Do you want a child to always be on top? Or do you mean the application?

0
 

Expert Comment

by:lbrucher
ID: 1412228
For the app to be always on top, look at the SetWindowsPos() Win32 API. The last param (flags) allows you to set/remove that feature.

If you want that for a child window (and I suppose relative to the other child windows), dunno (and don't remember having ever seen it).

L.

0
 

Author Comment

by:rich135
ID: 1412229
win 95    ms visual c++ 4.1 App.

trying to implement always on top feature for a MDI app. Want entire app to be on top (but at users command).

tried SetWindowPos as advised but dont undersatnd which of the flags to set. Tried to set the 1st parm to &wndTopMost, but then the module gave me wndTopMost= undefined! (even though spinctrl sample app uses same statement).

Have spent 4 hours trying to figure out why (esp. why the undefined).

Previous answer got me started, but still stuck..

Thanx...rich
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

by:rich135
ID: 1412230
also...how to I respond to Thui's "comment"
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1412231
In your response to making the application be on top, use

  AfxGetApp()->GetMainWnd()->ModifyStyleEx(0, WS_EX_TOPMOST);

and to turn it off

  AfxGetApp()->GetMainWnd()->ModifyStyleEx(WS_EX_TOPMOST, 0);

0
 

Author Comment

by:rich135
ID: 1412232
thui...tried the modify style fix, but it didnt work. MDI app wizard created app. vis c 4.1 ..name of app is opcal. here is code i put in opcal.doc to turn on "always on top" feature. And still, other apps, when run, would overlap/hide this app.

have spent all day on this.....

      // create main MDI Frame window
      CMainFrame* pMainFrame = new CMainFrame;
      if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
            return FALSE;
      pMainFrame->ShowWindow(m_nCmdShow);
      pMainFrame->UpdateWindow();
      AfxGetApp()->GetMainWnd()->ModifyStyleEx(0, WS_EX_TOPMOST);       
//      AfxGetApp()->GetMainWnd()->ModifyStyle(SWP_NOZORDER,0);       
      m_pMainWnd = pMainFrame;
i also tried the 2nd modify style to insure swp_nozorder turned off. i also put the modify style statement (the one you rec'd in opcaldoc. cpp, and opcaldlg.cpp (i use a formview, not a view).

still, other windowsapps would overlap this app.

why?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1412233
In this case, use
pMainFrame->ModifyStyleEx(0, WS_EX_TOPMOST);
or
m_pMainWnd = pMainFrame;
AfxGetApp()->GetMainWnd()->ModifyStyleEx(0, WS_EX_TOPMOST);

0
 

Author Comment

by:rich135
ID: 1412234
Chensu...still doesnt work...Did a brand new app with vis c++ 4.1...MDI...nothing fancy. here is code in alwaysontop.doc:

      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
            return FALSE;

      // The main window has been initialized, so show and update it.
      pMainFrame->ShowWindow(m_nCmdShow);
      pMainFrame->UpdateWindow();
      pMainFrame->ModifyStyleEx(0, WS_EX_TOPMOST);       
      return TRUE;

yet this app gets overlapped/hidden when i run other, different apps, under win 95...

allday i spent on this...

maybe someone should try to construct, using vis c++, similar app, abd see if iyt works...
0
 
LVL 23

Accepted Solution

by:
chensu earned 50 total points
ID: 1412235
First, m_pMainWnd = pMainFrame; is still needed in the above code.

Second, try overriding PreCreateWindow().

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
    cs.dwExStyle |= WS_EX_TOPMOST;

    return CFrameWnd::PreCreateWindow(cs);
}

Third, you can also try overriding OnCreate:

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    ...

    this->SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);

    return 0;
}

0
 

Author Comment

by:rich135
ID: 1412236
Chensu...finally got it to work...by putting setwindowpos(&wnd...etc) in mainfrm.h.

we conversed several times but i gave you a b cause you responded quickly and stayed with it. The other methods you suggested did not work for me. if int.., you can call me a thome (Boston).

rich
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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