Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 309
  • Last Modified:

non-mfc semi transparent control

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
Meir Rivkin
Asked:
Meir Rivkin
  • 3
  • 2
1 Solution
 
rajeev_devinCommented:
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
 
Meir RivkinFull stack Software EngineerAuthor Commented:
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
 
Meir RivkinFull stack Software EngineerAuthor Commented:
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
 
rajeev_devinCommented:
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
 
rajeev_devinCommented:
>> One for Left  button up . Set a timer
Sorry, that would be kill the timer
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now