Solved

non-mfc semi transparent control

Posted on 2006-07-13
5
303 Views
Last Modified: 2008-02-01
hi experts,

i'm trying to create semi-transparent slider control.
the parent is a window which draws a map and i want the control to be displayed on top of it upon long press.
i don't even know how to start, i thought maybe using OnCustomDraw like in MFC but i got nowhere.

cheers
0
Comment
Question by:sedgwick
  • 3
  • 2
5 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17098263
Use the following function SetWindowLong(...) and SetLayeredWindowAttributes(...)

Like this
SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hwnd, 0, 127.7, LWA_ALPHA);
0
 
LVL 42

Author Comment

by:sedgwick
ID: 17098908
i did it but i can't see the control at all.

let me explain the logic:
the control should be displayed upon long press on a button, after 2 seconds i create the control and on the Draw() function i show it.
when the user stop pressing the button, i count 3 seconds and hide the control.

here's my code:
void CDMainView::CreateVolumeSlider()
{
      CDButton* pBtn = m_MainScreen->GetButtonFromCtlID(IDC_MAINSCREEN_MUTE_BTN);

      RECT rcSlider, rc;
      pBtn->GetRect(rc);
      rcSlider = rc;
      rcSlider.bottom = rc.top+2;
      rcSlider.top = rcSlider.bottom+50;
      
//tell main screen to create the control
      m_MainScreen->CreateVolumeSlider(rcSlider);
}

void CNavMainScreen::CreateVolumeSlider(RECT& rcSlider)
{
      if(!VolumeSlider)
      {
            VolumeSlider = new CVolumeSlider();
            VolumeSlider->CreateWnd(this, rcSlider);

      }

      m_bShowVolumeSlider = true;
}

void CNavMainScreen::Draw()
{
.
.
.
//m_bShowVolumeSlider - wheather to show the control or not
//m_bVolumeSliderCountdown - wheather to start the 3 seconds countdown before hiding the control again

      if(m_bShowVolumeSlider)
      {
            if(m_bVolumeSliderCountdown)
            {
                  if(m_dwVolumeSliderTick == 0)
                        m_dwVolumeSliderTick = GetTickCount();
                  else
                  {
                        DWORD dw = GetTickCount();
                        if(dw-m_dwVolumeSliderTick > VOLUME_SLIDER_INTERVAL)
                        {
                              m_dwVolumeSliderTick = 0;
                              m_bShowVolumeSlider = false;
                              m_bVolumeSliderCountdown = false;
                        }
                  }
            }

            ShowVolumeSlider(m_bShowVolumeSlider);
      }

      RedrawWindow();
}

maybe the parent window doesn't get the message, i don't know why i can;t see it.

cheers
0
 
LVL 42

Author Comment

by:sedgwick
ID: 17099026
if i call CreateVolumeSlider() after user release the button (upon LButtonUp()) it works fine, but i want to display it while the user press the button for 2 seconds.
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 17100061
Create two message handlers:

One for Left  button down. Set a timer
void CNavMainScreen::OnLButtonDown(UINT nFlags, CPoint point)
{
      SetTimer(1, 2000, fnTimer); // fnTimer is the handler.
      CView::OnLButtonDown(nFlags, point);
}

void CALLBACK fnTimer(HWND, UINT, UINT, DWORD)
{
    // Do whatever you wnt to do
}

One for Left  button up . Set a timer
void CNavMainScreen::OnLButtonUp(UINT nFlags, CPoint point)
{
      KillTimer(1); // kill the timer if left button is released before 2 seconds
      CView::OnLButtonUp(nFlags, point);
}
0
 
LVL 12

Accepted Solution

by:
rajeev_devin earned 125 total points
ID: 17100069
>> One for Left  button up . Set a timer
Sorry, that would be kill the timer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

830 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