Solved

non-mfc semi transparent control

Posted on 2006-07-13
5
300 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now