Solved

non-mfc semi transparent control

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

910 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

21 Experts available now in Live!

Get 1:1 Help Now