//发牌处理
bool CGameClientView::SendCard()
{
	//动画判断
	if (m_SendCardItemArray.GetCount()==0) return false;

	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//变量定义
	int nXExcursion[GAME_PLAYER]={-1,1,-1,-1,-1};
	int nYExcursion[GAME_PLAYER]={0,1,1,1,1};

	//设置位置
	tagSendCardItem * pSendCardItem=&m_SendCardItemArray[0];
	WORD bID=pSendCardItem->wChairID;
	BYTE bTimes;
	if(bID==0)bTimes=4;
	else if(bID==1)bTimes=3;
	else if(bID==2)bTimes=2;
	else if(bID>=3)bTimes=2;

	m_SendCardPos.x+=nXExcursion[bID]*(abs(m_ptUserCard[bID].x-m_KeepPos.x)/SPEED*bTimes);
	m_SendCardPos.y+=nYExcursion[bID]*(abs(m_ptUserCard[bID].y-m_KeepPos.y)/SPEED*bTimes);

	//更新界面
	UpdateGameView(&rcClient);

	//停止判断
	int bTempX=0,bTempY=0;
	bTempX=m_ptUserCard[bID].x;
	bTempY=m_ptUserCard[bID].y;
	if((pSendCardItem->wChairID==0 && m_SendCardPos.x<=bTempX)||(pSendCardItem->wChairID>=1 && m_SendCardPos.y>=bTempY))
	{
		//获取扑克
		BYTE cbCardData[MAX_COUNT];
		WORD wChairID=pSendCardItem->wChairID;
		BYTE cbCardCount=(BYTE)m_CardControl[wChairID].GetCardData(cbCardData,CountArray(cbCardData));

		//设置扑克&& pSendCardItem->cbCardData!=0
		if (cbCardCount<=MAX_COUNT)
		{
			cbCardData[cbCardCount++]=pSendCardItem->cbCardData;
			m_CardControl[wChairID].SetCardData(cbCardData,cbCardCount);
		}

		//删除动画
		m_SendCardItemArray.RemoveAt(0);

		//继续动画
		if (m_SendCardItemArray.GetCount()>0)
		{
			//设置位置 /2
			GetClientRect(&rcClient);
			m_SendCardPos.x=rcClient.Width()/2+200;
			m_SendCardPos.y=rcClient.Height()/2-308;

			//播放声音
			CGameClientDlg * pGameClientDlg=CONTAINING_RECORD(this,CGameClientDlg,m_GameClientView);
			pGameClientDlg->PlayGameSound(AfxGetInstanceHandle(),TEXT("SEND_CARD"));

			return true;
		}
		else
		{
			//完成处理
			AfxGetMainWnd()->PostMessage(IDM_SEND_CARD_FINISH,0,0);

			return false;
		}
	}

	return true;
}
Esempio n. 2
0
unsigned track_bar_impl::calculate_thumb_size() const
{
	RECT rc_client;
	GetClientRect(get_wnd(), &rc_client);
	return MulDiv(get_orientation() ? rc_client.right : rc_client.bottom,9,20);
}
Esempio n. 3
0
LRESULT track_bar::on_message(HWND wnd,UINT msg,WPARAM wp,LPARAM lp)
{
	switch(msg)
	{
	case WM_NCCREATE:
		break;
	case WM_CREATE:
		{
			if (IsThemeActive() && IsAppThemed())
			{
				m_theme = OpenThemeData(wnd, L"Trackbar");
			}
		}
		break;
	case WM_THEMECHANGED:
		{
			{
				if (m_theme)
				{
					CloseThemeData(m_theme);
					m_theme=0;
				}
				if (IsThemeActive() && IsAppThemed())
					m_theme = OpenThemeData(wnd, L"Trackbar");
			}
		}
		break;
	case WM_DESTROY:
		{
			if (m_hook_registered)
			{
				message_hook_manager::deregister_hook(message_hook_manager::type_keyboard, this);
				m_hook_registered=false;
			}
			{
				if (m_theme) CloseThemeData(m_theme);
				m_theme=0;
			}
		}
		break;
	case WM_NCDESTROY:
		break;
	case WM_SIZE:
		RedrawWindow(wnd, 0, 0, RDW_INVALIDATE|RDW_ERASE);
		break;
	case WM_MOUSEMOVE:
		{

			POINT pt = {GET_X_LPARAM(lp), GET_Y_LPARAM(lp)};
			if (m_dragging)
			{
				if (!m_last_mousemove.m_valid || wp != m_last_mousemove.m_wp || lp != m_last_mousemove.m_lp)
				{
					if (get_enabled()) 
					{
						unsigned pos = calculate_position_from_point(pt);
						set_position_internal(pos);
						if (m_wnd_tooltip && m_host)
						{
							POINT pts = pt;
							ClientToScreen(wnd, &pts);
							track_bar_string temp;
							m_host->get_tooltip_text(pos, temp);
							update_tooltip(pts, temp.data());
						}
						if (m_host)
							m_host->on_position_change(pos, true);
					}
				}
				m_last_mousemove.m_valid = true;
				m_last_mousemove.m_wp = wp;
				m_last_mousemove.m_lp = lp;
			}
			else
			{
				update_hot_status(pt);
			}
		}
		break;
	case WM_ENABLE:
		{
			RECT rc;
			get_thumb_rect(&rc);
			InvalidateRect(wnd, &rc, TRUE);
		}
		break;
	case WM_MBUTTONDOWN:
	case WM_RBUTTONDOWN:
	case WM_XBUTTONDOWN:
		{
			if (get_enabled() && get_auto_focus() && GetFocus() != wnd) 
				SetFocus(wnd);

			if (m_dragging)
			{
				destroy_tooltip();
				if (GetCapture() == wnd)
					ReleaseCapture();
				message_hook_manager::deregister_hook(message_hook_manager::type_keyboard, this);
				m_hook_registered=false;
				//SetFocus(IsWindow(m_wnd_prev) ? m_wnd_prev : uFindParentPopup(wnd));
				m_dragging = false;
				set_position_internal(m_position);
			}
		}
		break;
	case WM_LBUTTONDOWN:
		{
			if (get_enabled()) 
			{
				if (get_auto_focus() && GetFocus() != wnd) 
					SetFocus(wnd);

				POINT pt; 

				pt.x = GET_X_LPARAM(lp);
				pt.y = GET_Y_LPARAM(lp);

				RECT rc_client;
				GetClientRect(wnd, &rc_client);

				if (PtInRect(&rc_client, pt))
				{
					m_dragging = true;
					SetCapture(wnd);

					//SetFocus(wnd);
					message_hook_manager::register_hook(message_hook_manager::type_keyboard, this);
					m_hook_registered=true;

					unsigned pos = calculate_position_from_point(pt);
					set_position_internal(pos);
					POINT pts = pt;
					ClientToScreen(wnd, &pts);
					if (m_show_tooltips && m_host)
					{
						track_bar_string temp;
						m_host->get_tooltip_text(pos, temp);
						create_tooltip(temp.data(), pts);
					}
				}
				m_last_mousemove.m_valid = false;
			}
		}
		return 0;
	case WM_LBUTTONUP:
		{
			if (m_dragging)
			{
				destroy_tooltip();
				if (GetCapture() == wnd)
					ReleaseCapture();
				m_dragging = false;
				if (get_enabled()) 
				{
					POINT pt; 

					pt.x = GET_X_LPARAM(lp);
					pt.y = GET_Y_LPARAM(lp);

					unsigned pos = calculate_position_from_point(pt);
					set_position(pos);
				}
				//SetFocus(IsWindow(m_wnd_prev) ? m_wnd_prev : uFindParentPopup(wnd));
				message_hook_manager::deregister_hook(message_hook_manager::type_keyboard, this);
				m_hook_registered = false;
				if (m_host)
					m_host->on_position_change(m_display_position, false);

				m_last_mousemove.m_valid = false;
			}
		}
		return 0;
	case WM_KEYDOWN:
	case WM_KEYUP:
		{
			if ((wp == VK_ESCAPE || wp == VK_RETURN) && m_host && m_host->on_key(wp, lp))
				return 0;
			if ( !(lp & (1<<31)) && (wp == VK_LEFT || wp == VK_DOWN || wp == VK_RIGHT || wp == VK_UP))
			{
				bool down = (wp == VK_LEFT || wp == VK_UP) == false;//!get_direction();
				unsigned newpos = m_position;
				if (down && m_step > m_position)
					newpos = 0;
				else if (!down && m_step + m_position > m_range)
					newpos = m_range;
				else
					newpos += down ? -(int)m_step : m_step;
				if (newpos != m_position)
				{
					set_position(newpos);
					if (m_host)
						m_host->on_position_change(m_position, false);
				}
			}
			if ( !(lp & (1<<31)) && (wp == VK_HOME || wp == VK_END))
			{
				bool down = (wp == VK_END) == false;//!get_direction();
				unsigned newpos = m_position;
				if (down) newpos = m_range;
				else newpos = 0;
				if (newpos != m_position)
				{
					set_position(newpos);
					if (m_host)
						m_host->on_position_change(m_position, false);
				}
			}
		}
		break;
	case WM_MOUSEWHEEL:
		{
			UINT ucNumLines=3;  // 3 is the default
			SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ucNumLines, 0);
			unsigned short fwKeys = GET_KEYSTATE_WPARAM(wp);
			short zDelta = GET_WHEEL_DELTA_WPARAM(wp);
			int xPos = GET_X_LPARAM(lp); 
			int yPos = GET_Y_LPARAM(lp);
			if (ucNumLines == WHEEL_PAGESCROLL)
				ucNumLines = 3;
			int delta = MulDiv(m_step*zDelta, ucNumLines, WHEEL_DELTA);
			bool down = delta < 0;
			//if (get_direction()) down = down == false;
			if (!get_orientation()) down = down == false;
			if (m_mouse_wheel_reversed)
				 down = down == false;
			unsigned offset = abs(delta);

			unsigned newpos = m_position;
			if (down && offset > m_position)
				newpos = 0;
			else if (!down && offset + m_position > m_range)
				newpos = m_range;
			else
				newpos += down ? -(int)offset : offset;
			if (newpos != m_position)
			{
				set_position(newpos);
				if (m_host)
					m_host->on_position_change(m_position, false);
			}
		}
		return 0;
#if 0
	case WM_KEYDOWN:
		if (wp == VK_ESCAPE)
		{
			destroy_tooltip();
			if (GetCapture() == wnd)
				ReleaseCapture();
			SetFocus(IsWindow(m_wnd_prev) ? m_wnd_prev : uFindParentPopup(wnd));
			m_dragging = false;
			set_position_internal(m_position);
			return 0;
		}
		break;
	case WM_SETFOCUS:
		m_wnd_prev = (HWND)wp;
		break;
#endif
	case WM_MOVE:
		RedrawWindow(wnd, NULL, NULL, RDW_ERASE|RDW_INVALIDATE);
		break;
	case WM_ERASEBKGND:
		return FALSE;
	case WM_PAINT:
		{
			RECT rc_client;
			GetClientRect(wnd, &rc_client);

			PAINTSTRUCT ps;

			HDC dc = BeginPaint(wnd, &ps);

			RECT rc_thumb;

			get_thumb_rect(&rc_thumb);

			RECT rc_track; //channel
			get_channel_rect(&rc_track);

			//Offscreen rendering to eliminate flicker
			HDC dc_mem = CreateCompatibleDC(dc);

			//Create a rect same size of update rect
			HBITMAP bm_mem = CreateCompatibleBitmap(dc, rc_client.right, rc_client.bottom);

			HBITMAP bm_old = (HBITMAP)SelectObject(dc_mem, bm_mem);

			//we should always be erasing first, so shouldn't be needed
			BitBlt(dc_mem, 0, 0, rc_client.right, rc_client.bottom, dc, 0, 0, SRCCOPY);
			if (ps.fErase)
			{
				draw_background(dc_mem, &rc_client);
			}

			draw_channel(dc_mem, &rc_track);
			draw_thumb(dc_mem, &rc_thumb);

			BitBlt(dc, 0, 0, rc_client.right, rc_client.bottom, dc_mem, 0, 0, SRCCOPY);
			SelectObject(dc_mem, bm_old);
			DeleteObject(bm_mem);
			DeleteDC(dc_mem);
			EndPaint(wnd, &ps);
		}
		return 0;

	}
	return DefWindowProc(wnd, msg, wp, lp);
}
Esempio n. 4
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// Below we check what the user types in.  If they use the arrow keys
	// then we want to move the triangle around (LEFT RIGHT UP and DOWN keys)

	case WM_KEYDOWN:
		switch(wParam) 
		{
			case VK_ESCAPE:								// Check if we hit the ESCAPE key.
				PostQuitMessage(0);						// Tell windows we want to quit
				break;

			case VK_UP:									// Check if we hit the UP ARROW key.
				vTriangle[0].x += 0.01f;				// Move the left point of the triangle to the left
				vTriangle[1].x += 0.01f;				// Move the right point of the triangle to the left
				vTriangle[2].x += 0.01f;				// Move the top point of the triangle to the left
				break;

			case VK_DOWN:								// Check if we hit the DOWN ARROW key.
				vTriangle[0].x -= 0.01f;				// Move the left point of the triangle to the left
				vTriangle[1].x -= 0.01f;				// Move the right point of the triangle to the left
				vTriangle[2].x -= 0.01f;				// Move the top point of the triangle to the left
				break;


			case VK_LEFT:								// Check if we hit the LEFT ARROW key.
				vTriangle[0].z -= 0.01f;				// Move the left point of the triangle back
				vTriangle[1].z -= 0.01f;				// Move the right point of the triangle back
				vTriangle[2].z -= 0.01f;				// Move the top point of the triangle back
				break;

			case VK_RIGHT:								// Check if we hit the RIGHT ARROW key.
				vTriangle[0].z += 0.01f;				// Move the left point of the triangle forward
				vTriangle[1].z += 0.01f;				// Move the right point of the triangle forward
				vTriangle[2].z += 0.01f;				// Move the top point of the triangle forward
				break;
		}

		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
 
    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
Esempio n. 5
0
void CDisAsmWnd::RefreshLayout()
{
	RECT rc = GetClientRect();
	m_disAsm->SetSize(rc.right, rc.bottom);
}
Esempio n. 6
0
static RECT * UpdateInsets(JNIEnv *env, HWND hwnd, jobject window)
{
    // being naughty here
    static RECT m_insets = { 0, 0, 0, 0 };
    RECT outside;
    RECT inside;

    if (IsIconic(hwnd)) {
        m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = -1;
        return FALSE;
    }

    m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = 0;

    GetClientRect(hwnd, &inside);
    GetWindowRect(hwnd, &outside);

    if (outside.right - outside.left > 0 && outside.bottom - outside.top > 0) {
        MapWindowPoints(hwnd, 0, (LPPOINT)&inside, 2);
        m_insets.top = inside.top - outside.top;
        m_insets.bottom = outside.bottom - inside.bottom;
        m_insets.left = inside.left - outside.left;
        m_insets.right = outside.right - inside.right;
    } else {
        m_insets.top = -1;
    }
    if (m_insets.left < 0 || m_insets.top < 0 ||
        m_insets.right < 0 || m_insets.bottom < 0)
    {
        LONG style = GetWindowLong(hwnd, GWL_STYLE);
        // TODO: TDV: better undecorated checking needed

        BOOL bIsUndecorated = (style & (WS_CHILD|WS_POPUP|WS_SYSMENU)) != 0;
        if (!bIsUndecorated) {
            /* Get outer frame sizes. */
            if (style & WS_THICKFRAME) {
                m_insets.left = m_insets.right =
                    GetSystemMetrics(SM_CXSIZEFRAME);
                m_insets.top = m_insets.bottom =
                    GetSystemMetrics(SM_CYSIZEFRAME);
            } else {
                m_insets.left = m_insets.right =
                    GetSystemMetrics(SM_CXDLGFRAME);
                m_insets.top = m_insets.bottom =
                    GetSystemMetrics(SM_CYDLGFRAME);
            }

            /* Add in title. */
            m_insets.top += GetSystemMetrics(SM_CYCAPTION);
        } else {
            /* undo the -1 set above */
            m_insets.left = m_insets.top = m_insets.right = m_insets.bottom = 0;
        }
    }

    DBG_PRINT("*** WindowsWindow: UpdateInsets window %p, %d/%d %dx%d\n", 
        (void*)hwnd, (int)m_insets.left, (int)m_insets.top, (int)(m_insets.right-m_insets.left), (int)(m_insets.top-m_insets.bottom));

    (*env)->CallVoidMethod(env, window, insetsChangedID,
                           m_insets.left, m_insets.top,
                           m_insets.right, m_insets.bottom);
    return &m_insets;
}
LRESULT VLCControlsWnd::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg){
        case WM_CREATE:{
            const int ControlsHeight = 21+3;
            const int ButtonsWidth = ControlsHeight;

            int HorizontalOffset = xControlsSpace;
            int ControlWidth = ButtonsWidth;
            hPlayPauseButton =
                CreateWindow(TEXT("BUTTON"), TEXT("Play/Pause"),
                             WS_CHILD|WS_VISIBLE|BS_BITMAP|BS_FLAT,
                             HorizontalOffset, xControlsSpace,
                             ControlWidth, ControlsHeight, hWnd(),
                             (HMENU)ID_FS_PLAY_PAUSE, 0, 0);
            SendMessage(hPlayPauseButton, BM_SETIMAGE,
                        (WPARAM)IMAGE_BITMAP, (LPARAM)RC().hPauseBitmap);
            HorizontalOffset+=ControlWidth+xControlsSpace;

            ControlWidth = 200;
            int VideoPosControlHeight = 10;
            hVideoPosScroll =
                CreateWindow(PROGRESS_CLASS, TEXT("Video Position"),
                             WS_CHILD|WS_DISABLED|WS_VISIBLE|SBS_HORZ|SBS_TOPALIGN|PBS_SMOOTH,
                             HorizontalOffset, xControlsSpace+(ControlsHeight-VideoPosControlHeight)/2,
                             ControlWidth, VideoPosControlHeight, hWnd(),
                             (HMENU)ID_FS_VIDEO_POS_SCROLL, 0, 0);
            HMODULE hThModule = LoadLibrary(TEXT("UxTheme.dll"));
            if(hThModule){
                FARPROC proc = GetProcAddress(hThModule, "SetWindowTheme");
                typedef HRESULT (WINAPI* SetWindowThemeProc)(HWND, LPCWSTR, LPCWSTR);
                if(proc){
                    ((SetWindowThemeProc)proc)(hVideoPosScroll, L"", L"");
                }
                FreeLibrary(hThModule);
            }
            HorizontalOffset+=ControlWidth+xControlsSpace;

            ControlWidth = ButtonsWidth;
            hMuteButton =
                CreateWindow(TEXT("BUTTON"), TEXT("Mute"),
                             WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX|BS_PUSHLIKE|BS_BITMAP, //BS_FLAT
                             HorizontalOffset, xControlsSpace,
                             ControlWidth, ControlsHeight,
                             hWnd(), (HMENU)ID_FS_MUTE, 0, 0);
            SendMessage(hMuteButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP,
                        (LPARAM)RC().hVolumeBitmap);
            HorizontalOffset+=ControlWidth+xControlsSpace;

            ControlWidth = 100;
            hVolumeSlider =
                CreateWindow(TRACKBAR_CLASS, TEXT("Volume"),
                             WS_CHILD|WS_VISIBLE|TBS_HORZ|TBS_BOTTOM|TBS_AUTOTICKS,
                             HorizontalOffset, xControlsSpace,
                             ControlWidth, ControlsHeight - 4, hWnd(),
                             (HMENU)ID_FS_VOLUME, 0, 0);
            HorizontalOffset+=ControlWidth+xControlsSpace;
            SendMessage(hVolumeSlider, TBM_SETRANGE, FALSE, (LPARAM) MAKELONG (0, 100));
            SendMessage(hVolumeSlider, TBM_SETTICFREQ, (WPARAM) 10, 0);

            ControlWidth = ButtonsWidth;
            DWORD dwFSBtnStyle = WS_CHILD|BS_BITMAP|BS_FLAT;
            if( !PO() || PO()->get_enable_fs() ){
                dwFSBtnStyle |= WS_VISIBLE;
            }
            hFSButton =
                CreateWindow(TEXT("BUTTON"), TEXT("Toggle fullscreen"),
                             dwFSBtnStyle,
                             HorizontalOffset, xControlsSpace,
                             ControlWidth, ControlsHeight, hWnd(),
                             (HMENU)ID_FS_SWITCH_FS, 0, 0);
            SendMessage(hFSButton, BM_SETIMAGE, (WPARAM)IMAGE_BITMAP,
                        (LPARAM)RC().hDeFullscreenBitmap);
            HorizontalOffset+=ControlWidth+xControlsSpace;

            RECT rect;
            GetClientRect(GetParent(hWnd()), &rect);

            int ControlWndWidth = HorizontalOffset;
            int ControlWndHeight = xControlsSpace+ControlsHeight+xControlsSpace;
            SetWindowPos(hWnd(), 0,
                         0, (rect.bottom - rect.top) - ControlWndWidth,
                         rect.right-rect.left, ControlWndHeight,
                         SWP_NOZORDER|SWP_NOOWNERZORDER|SWP_NOACTIVATE);

            //new message blinking timer
            SetTimer(hWnd(), 2, 500, NULL);

            CreateToolTip();

            break;
        }
        case WM_SHOWWINDOW:{
            if(FALSE!=wParam){ //showing
                UpdateButtons();
            }
            break;
        }
        case WM_LBUTTONUP:{
            POINT BtnUpPoint = {LOWORD(lParam), HIWORD(lParam)};
            RECT VideoPosRect;
            GetWindowRect(hVideoPosScroll, &VideoPosRect);
            ClientToScreen(hWnd(), &BtnUpPoint);
            if(PtInRect(&VideoPosRect, BtnUpPoint)){
                SetVideoPos(float(BtnUpPoint.x-VideoPosRect.left)/(VideoPosRect.right-VideoPosRect.left));
            }
            break;
        }
        case WM_TIMER:{
            switch(wParam){
                case 1:{
                    POINT MousePoint;
                    GetCursorPos(&MousePoint);
                    RECT ControlWndRect;
                    GetWindowRect(hWnd(), &ControlWndRect);
                    if(PtInRect(&ControlWndRect, MousePoint)||GetCapture()==hVolumeSlider){
                        //do not allow control window to close while mouse is within
                        NeedShowControls();
                    }
                    else{
                        NeedHideControls();
                    }
                    break;
                }
                case 2:{
                    UpdateButtons();
                    break;
                }
            }
            break;
        }
        case WM_SETCURSOR:{
            RECT VideoPosRect;
            GetWindowRect(hVideoPosScroll, &VideoPosRect);
            DWORD dwMsgPos = GetMessagePos();
            POINT MsgPosPoint = {LOWORD(dwMsgPos), HIWORD(dwMsgPos)};
            if(PtInRect(&VideoPosRect, MsgPosPoint)){
                SetCursor(LoadCursor(NULL, IDC_HAND));
                return TRUE;
            }
            else{
                return VLCWnd::WindowProc(uMsg, wParam, lParam);
            }
            break;
        }
        case WM_NCDESTROY:
            break;
        case WM_COMMAND:{
            WORD NCode = HIWORD(wParam);
            WORD Control = LOWORD(wParam);
            switch(NCode){
                case BN_CLICKED:{
                    switch(Control){
                        case ID_FS_SWITCH_FS:
                            WM().ToggleFullScreen();
                            break;
                        case ID_FS_PLAY_PAUSE:{
                            if( VP() ){
                                if( IsPlaying() )
                                    VP()->pause();
                                else
                                    VP()->play();
                            }
                            break;
                        }
                        case ID_FS_MUTE:{
                            if( VP() ){
                                VP()->set_mute( IsDlgButtonChecked(hWnd(), ID_FS_MUTE) != FALSE );
                                SyncVolumeSliderWithVLCVolume();
                            }
                            break;
                        }
                    }
                    break;
                }
            }
            break;
        }
        case WM_SIZE:{
            if( GetWindowLong(hWnd(), GWL_STYLE) & WS_VISIBLE &&
                !WM().IsFullScreen() &&
                ( !PO() || !PO()->get_show_toolbar() ) )
            {
                //hide controls when they are not allowed
                NeedHideControls();
            }

            const int new_client_width = LOWORD(lParam);

            bool isFSBtnVisible =
                (GetWindowLong(hFSButton, GWL_STYLE) & WS_VISIBLE) != 0;

            HDWP hDwp = BeginDeferWindowPos(4);

            int VideoScrollWidth = new_client_width;

            POINT pt = {0, 0};
            RECT rect;
            GetWindowRect(hPlayPauseButton, &rect);
            pt.x = rect.right;
            ScreenToClient(hWnd(), &pt);
            VideoScrollWidth -= pt.x;
            VideoScrollWidth -= xControlsSpace;

            RECT VideoSrcollRect;
            GetWindowRect(hVideoPosScroll, &VideoSrcollRect);

            RECT MuteRect;
            GetWindowRect(hMuteButton, &MuteRect);
            VideoScrollWidth -= xControlsSpace;
            VideoScrollWidth -= (MuteRect.right - MuteRect.left);

            RECT VolumeRect;
            GetWindowRect(hVolumeSlider, &VolumeRect);
            VideoScrollWidth -= xControlsSpace;
            VideoScrollWidth -= (VolumeRect.right - VolumeRect.left);

            RECT FSRect = {0, 0, 0, 0};
            if( isFSBtnVisible ) {
                GetWindowRect(hFSButton, &FSRect);
                VideoScrollWidth -= xControlsSpace;
                VideoScrollWidth -= (FSRect.right - FSRect.left);
                VideoScrollWidth -= xControlsSpace;
            }

            pt.x = VideoSrcollRect.left;
            pt.y = VideoSrcollRect.top;
            ScreenToClient(hWnd(), &pt);
            hDwp = DeferWindowPos(hDwp, hVideoPosScroll, 0, pt.x, pt.y,
                                  VideoScrollWidth,
                                  VideoSrcollRect.bottom - VideoSrcollRect.top,
                                  SWP_NOACTIVATE|SWP_NOOWNERZORDER);

            int HorizontalOffset =
                pt.x + VideoScrollWidth + xControlsSpace;
            pt.x = 0;
            pt.y = MuteRect.top;
            ScreenToClient(hWnd(), &pt);
            hDwp = DeferWindowPos(hDwp, hMuteButton, 0,
                                  HorizontalOffset, pt.y, 0, 0,
                                  SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER);
            HorizontalOffset +=
                MuteRect.right - MuteRect.left + xControlsSpace;

            pt.x = 0;
            pt.y = VolumeRect.top;
            ScreenToClient(hWnd(), &pt);
            hDwp = DeferWindowPos(hDwp, hVolumeSlider, 0,
                                  HorizontalOffset, pt.y, 0, 0,
                                  SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER);
            HorizontalOffset +=
                VolumeRect.right - VolumeRect.left + xControlsSpace;

            if( isFSBtnVisible ) {
                pt.x = 0;
                pt.y = FSRect.top;
                ScreenToClient(hWnd(), &pt);
                hDwp = DeferWindowPos(hDwp, hFSButton, 0,
                                      HorizontalOffset, pt.y, 0, 0,
                                      SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOOWNERZORDER);
            }

            EndDeferWindowPos(hDwp);
            break;
        }
        case WM_HSCROLL:
        case WM_VSCROLL: {
            if( VP() ){
                if(hVolumeSlider==(HWND)lParam){
                    LRESULT SliderPos = SendMessage(hVolumeSlider, (UINT) TBM_GETPOS, 0, 0);
                    SetVLCVolumeBySliderPos(SliderPos);
                }
            }
            break;
        }
        default:
            return VLCWnd::WindowProc(uMsg, wParam, lParam);
    }
    return 0L;
}
Esempio n. 8
0
void CTroubleShootDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	// Do not call CDialogEx::OnPaint() for painting messages
	CMemDC memDC(dc,this);
	CRect rcClient;
	GetClientRect(&rcClient);
	memDC.GetDC().FillSolidRect(&rcClient,RGB(230,230,230));
	//Graphics graphics(memDC.GetDC());
	SolidBrush *BlackBrush;
	SolidBrush *CharacterBlackBrush;
	
	Graphics *mygraphics;
	mygraphics = new Graphics(memDC.GetDC());
	mygraphics->SetSmoothingMode(SmoothingModeAntiAlias);
	BlackBrush =new  SolidBrush(MY_COLOR_RED) ;
	CharacterBlackBrush = new SolidBrush(MY_COLOR_BLACK_CHARACTER);


	mygraphics->FillRectangle(BlackBrush,0,0,rcClient.Width(),40);

	FontFamily  CharacterfontFamily(_T("Arial"));
	PointF     TitlepointF(0, 0);
	SolidBrush  TitleCharacterColor(Color(255,255,255,255));
	Gdiplus::Font  Scroll_font(&CharacterfontFamily, 28, FontStyleBold, UnitPixel);
	TitlepointF.X = 150;
	TitlepointF.Y = 5;
	mygraphics->DrawString(_T("Different Subnets Detected!"), -1, &Scroll_font, TitlepointF,&TitleCharacterColor);

	PointF      WarningMessagePoint(0, 0);
	WarningMessagePoint.X = 25;
	WarningMessagePoint.Y = 45;
	SolidBrush  WarningMessageColor(Color(255,0,0,0));
	Gdiplus::Font  WarningMessageFont(&CharacterfontFamily, 24, FontStyleRegular, UnitPixel);
	mygraphics->DrawString(_T("The subnet of your PC and the device must match."), -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);
	WarningMessagePoint.X = 25;
	WarningMessagePoint.Y = 75;
	mygraphics->DrawString(_T("Would you like to change the IP address of the device"), -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);
	WarningMessagePoint.X = 25;
	WarningMessagePoint.Y = 105;
	mygraphics->DrawString(_T("to match the IP address of your PC?"), -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);

	WarningMessagePoint.X = 170;
	WarningMessagePoint.Y = 160;
	mygraphics->DrawString(_T("Current"), -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);

	WarningMessagePoint.X = 500;
	WarningMessagePoint.Y = 160;
	mygraphics->DrawString(_T("Proposed"), -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);


	mygraphics->FillRectangle(CharacterBlackBrush,BLACK_GROUND_START_X,BLACK_GROUND_START_Y,BLACK_GROUND_WIDTH,BLACK_GROUND_HEIGHT);
	mygraphics->FillRectangle(CharacterBlackBrush,BLACK_2_GROUND_START_X,BLACK_2_GROUND_START_Y,BLACK_2_GROUND_WIDTH,BLACK_2_GROUND_HEIGHT);

	CString StrTempOrgDeviceIP;
	StrTempOrgDeviceIP.Format(_T("Device IP address:  %s"),m_net_product_node.BuildingInfo.strIp);
	WarningMessagePoint.X = BLACK_GROUND_START_X + 5;
	WarningMessagePoint.Y = BLACK_GROUND_START_Y + 5;
	mygraphics->DrawString(StrTempOrgDeviceIP, -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);

	mygraphics->FillRectangle(CharacterBlackBrush,BLACK_PC_GROUND_START_X,BLACK_PC_GROUND_START_Y,BLACK_PC_GROUND_WIDTH,BLACK_PC_GROUND_HEIGHT);
	CString StrTempPCIP;
	StrTempPCIP.Format(_T("PC's IP address:     %s"),m_net_product_node.NetworkCard_Address);
	WarningMessagePoint.X = BLACK_PC_GROUND_START_X + 5;
	WarningMessagePoint.Y = BLACK_PC_GROUND_START_Y + 5;
	mygraphics->DrawString(StrTempPCIP, -1, &WarningMessageFont, WarningMessagePoint,&WarningMessageColor);
	//Bitmap bitmap(hBitmap_login,NULL);
	//graphics.DrawImage(&bitmap,0 ,0,test_rect.Width(),test_rect.Height());
}
Esempio n. 9
0
bool CMainWindow::Initialize()
{
	CRegStdWORD pos(_T("Software\\TortoiseGit\\UDiffViewerPos"), 0);
	CRegStdWORD width(_T("Software\\TortoiseGit\\UDiffViewerWidth"), (DWORD)640);
	CRegStdWORD height(_T("Software\\TortoiseGit\\UDiffViewerHeight"), (DWORD)480);
	if (DWORD(pos) && DWORD(width) && DWORD(height))
	{
		RECT rc;
		rc.left = LOWORD(DWORD(pos));
		rc.top = HIWORD(DWORD(pos));
		rc.right = rc.left + DWORD(width);
		rc.bottom = rc.top + DWORD(height);
		HMONITOR hMon = MonitorFromRect(&rc, MONITOR_DEFAULTTONULL);
		if (hMon)
		{
			// only restore the window position if the monitor is valid
			MoveWindow(*this, LOWORD(DWORD(pos)), HIWORD(DWORD(pos)),
				DWORD(width), DWORD(height), FALSE);
		}
	}

	m_hWndEdit = ::CreateWindow(
		_T("Scintilla"),
		_T("Source"),
		WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_CLIPCHILDREN,
		CW_USEDEFAULT, CW_USEDEFAULT,
		CW_USEDEFAULT, CW_USEDEFAULT,
		*this,
		0,
		hResource,
		0);
	if (m_hWndEdit == NULL)
		return false;

	RECT rect;
	GetClientRect(*this, &rect);
	::SetWindowPos(m_hWndEdit, HWND_TOP, 
		rect.left, rect.top,
		rect.right-rect.left, rect.bottom-rect.top,
		SWP_SHOWWINDOW);

	m_directFunction = SendMessage(m_hWndEdit, SCI_GETDIRECTFUNCTION, 0, 0);
	m_directPointer = SendMessage(m_hWndEdit, SCI_GETDIRECTPOINTER, 0, 0);

	// Set up the global default style. These attributes are used wherever no explicit choices are made.
	SetAStyle(STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW),
		// Reusing TortoiseBlame's setting which already have an user friendly
		// pane in TortoiseSVN's Settings dialog, while there is no such
		// pane for TortoiseUDiff.
		CRegStdWORD(_T("Software\\TortoiseGit\\BlameFontSize"), 10),
		WideToMultibyte(CRegStdString(_T("Software\\TortoiseGit\\BlameFontName"), _T("Courier New"))).c_str());
	SendEditor(SCI_SETTABWIDTH, 4);
	SendEditor(SCI_SETREADONLY, TRUE);
	LRESULT pix = SendEditor(SCI_TEXTWIDTH, STYLE_LINENUMBER, (LPARAM)"_99999");
	SendEditor(SCI_SETMARGINWIDTHN, 0, pix);
	SendEditor(SCI_SETMARGINWIDTHN, 1);
	SendEditor(SCI_SETMARGINWIDTHN, 2);
	//Set the default windows colors for edit controls
	SendEditor(SCI_STYLESETFORE, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOWTEXT));
	SendEditor(SCI_STYLESETBACK, STYLE_DEFAULT, ::GetSysColor(COLOR_WINDOW));
	SendEditor(SCI_SETSELFORE, TRUE, ::GetSysColor(COLOR_HIGHLIGHTTEXT));
	SendEditor(SCI_SETSELBACK, TRUE, ::GetSysColor(COLOR_HIGHLIGHT));
	SendEditor(SCI_SETCARETFORE, ::GetSysColor(COLOR_WINDOWTEXT));

	return true;
}
Esempio n. 10
0
static void CB_Paint( HWND hwnd, HDC hDC, UINT action )
{
    RECT rbox, rtext, client;
    HBRUSH hBrush;
    int delta;
    UINT dtFlags;
    HFONT hFont;
    LONG state = get_button_state( hwnd );
    LONG style = GetWindowLongW( hwnd, GWL_STYLE );
    HWND parent;

    if (style & BS_PUSHLIKE)
    {
        PB_Paint( hwnd, hDC, action );
	return;
    }

    GetClientRect(hwnd, &client);
    rbox = rtext = client;

    if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );

    parent = GetParent(hwnd);
    if (!parent) parent = hwnd;
    hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
				  (WPARAM)hDC, (LPARAM)hwnd);
    if (!hBrush) /* did the app forget to call defwindowproc ? */
        hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
					(WPARAM)hDC, (LPARAM)hwnd );
    setup_clipping( hwnd, hDC );

    if (style & BS_LEFTTEXT)
    {
	/* magic +4 is what CTL3D expects */

        rtext.right -= checkBoxWidth + 4;
        rbox.left = rbox.right - checkBoxWidth;
    }
    else
    {
        rtext.left += checkBoxWidth + 4;
        rbox.right = checkBoxWidth;
    }

    /* Since WM_ERASEBKGND does nothing, first prepare background */
    if (action == ODA_SELECT) FillRect( hDC, &rbox, hBrush );
    if (action == ODA_DRAWENTIRE) FillRect( hDC, &client, hBrush );

    /* Draw label */
    client = rtext;
    dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &rtext);
    
    /* Only adjust rbox when rtext is valid */
    if (dtFlags != (UINT)-1L)
    {
	rbox.top = rtext.top;
	rbox.bottom = rtext.bottom;
    }

    /* Draw the check-box bitmap */
    if (action == ODA_DRAWENTIRE || action == ODA_SELECT)
    {
	UINT flags;

	if ((get_button_type(style) == BS_RADIOBUTTON) ||
	    (get_button_type(style) == BS_AUTORADIOBUTTON)) flags = DFCS_BUTTONRADIO;
	else if (state & BUTTON_3STATE) flags = DFCS_BUTTON3STATE;
	else flags = DFCS_BUTTONCHECK;

	if (state & (BUTTON_CHECKED | BUTTON_3STATE)) flags |= DFCS_CHECKED;
	if (state & BUTTON_HIGHLIGHTED) flags |= DFCS_PUSHED;

	if (style & WS_DISABLED) flags |= DFCS_INACTIVE;

	/* rbox must have the correct height */
	delta = rbox.bottom - rbox.top - checkBoxHeight;
	
	if (style & BS_TOP) {
	    if (delta > 0) {
		rbox.bottom = rbox.top + checkBoxHeight;
	    } else { 
		rbox.top -= -delta/2 + 1;
		rbox.bottom = rbox.top + checkBoxHeight;
	    }
	} else if (style & BS_BOTTOM) {
	    if (delta > 0) {
		rbox.top = rbox.bottom - checkBoxHeight;
	    } else {
		rbox.bottom += -delta/2 + 1;
		rbox.top = rbox.bottom - checkBoxHeight;
	    }
	} else { /* Default */
	    if (delta > 0) {
		int ofs = (delta / 2);
		rbox.bottom -= ofs + 1;
		rbox.top = rbox.bottom - checkBoxHeight;
	    } else if (delta < 0) {
		int ofs = (-delta / 2);
		rbox.top -= ofs + 1;
		rbox.bottom = rbox.top + checkBoxHeight;
	    }
	}

	DrawFrameControl( hDC, &rbox, DFC_BUTTON, flags );
    }

    if (dtFlags == (UINT)-1L) /* Noting to draw */
	return;

    if (action == ODA_DRAWENTIRE)
	BUTTON_DrawLabel(hwnd, hDC, dtFlags, &rtext);

    /* ... and focus */
    if ((action == ODA_FOCUS) ||
        ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS)))
    {
	rtext.left--;
	rtext.right++;
	IntersectRect(&rtext, &rtext, &client);
	DrawFocusRect( hDC, &rtext );
    }
}
Esempio n. 11
0
HRESULT BaseApp::createDeviceResources(HWND hWnd)
{

	HRESULT hr = S_OK;

	RECT rc;
	GetClientRect(hWnd, &rc);

	D2D1_SIZE_U size = D2D1::SizeU(
		rc.right - rc.left,
		rc.bottom - rc.top
		);

	hr = d2dFactory->CreateHwndRenderTarget(
		D2D1::RenderTargetProperties(),
		D2D1::HwndRenderTargetProperties(hWnd, size),
		&renderingTarget
		);

	size_t index{ 0 };

	// Brushes
	for (auto color : brushColor) {
		solidBrushes.push_back(NULL);
		hr = renderingTarget->CreateSolidColorBrush(
			color,
			&solidBrushes.at(index));
		++index;
	}

	// Text formats
	// Pasing in Font, font-size
	index = 0;
	for (auto font : fonts) {
		for (auto fontSize : fontSizes) {
			textFormats.push_back(NULL);
			hr = d2dDWriteFactory->CreateTextFormat(
				TUtils::toWSString(font).c_str(),
				NULL,
				DWRITE_FONT_WEIGHT_REGULAR,
				DWRITE_FONT_STYLE_NORMAL,
				DWRITE_FONT_STRETCH_NORMAL,
				fontSize,
				L"en-us",
				&textFormats.at(index)
				);
			// Center align (horizontally) the text.
			if (SUCCEEDED(hr))
			{
				hr = textFormats.at(index)->SetTextAlignment(DWRITE_TEXT_ALIGNMENT_LEADING);
				hr = textFormats.at(index)->SetParagraphAlignment(DWRITE_PARAGRAPH_ALIGNMENT_NEAR);
			}
			++index;
		}
	}

	//// Bitmaps

	IWICBitmapDecoder* wicBitmapDecoder = NULL;
	IWICFormatConverter* wicFormatConverter = NULL;
	IWICBitmapFrameDecode* wicBitmapFrameDecode = NULL;

	index = 0;

	for (auto spriteSheetFile : spriteSheetFiles) {

		hr = wicImaingFactory->CreateDecoderFromFilename(
			TUtils::toWSString(spriteSheetFile).c_str(),
			NULL,
			GENERIC_READ,
			WICDecodeMetadataCacheOnLoad,
			&wicBitmapDecoder);

		hr = wicImaingFactory->CreateFormatConverter(&wicFormatConverter);

		hr = wicBitmapDecoder->GetFrame(0, &wicBitmapFrameDecode);

		hr = wicFormatConverter->Initialize(
			wicBitmapFrameDecode,
			GUID_WICPixelFormat32bppPBGRA,
			WICBitmapDitherTypeNone,
			NULL, 0.f,
			WICBitmapPaletteTypeMedianCut
			);

		spriteSheets.push_back(NULL);

		hr = renderingTarget->CreateBitmapFromWicBitmap(
			wicFormatConverter,
			NULL,
			&spriteSheets.at(index)
			);

		++index;
	}


	return hr;
}
Esempio n. 12
0
/**********************************************************************
 *       Push Button Functions
 */
static void PB_Paint( HWND hwnd, HDC hDC, UINT action )
{
    RECT     rc, focus_rect, r;
    UINT     dtFlags, uState;
    HPEN     hOldPen;
    HBRUSH   hOldBrush;
    INT      oldBkMode;
    COLORREF oldTxtColor;
    HFONT hFont;
    LONG state = get_button_state( hwnd );
    LONG style = GetWindowLongW( hwnd, GWL_STYLE );
    BOOL pushedState = (state & BUTTON_HIGHLIGHTED);
    HWND parent;

    GetClientRect( hwnd, &rc );

    /* Send WM_CTLCOLOR to allow changing the font (the colors are fixed) */
    if ((hFont = get_button_font( hwnd ))) SelectObject( hDC, hFont );
    parent = GetParent(hwnd);
    if (!parent) parent = hwnd;
    SendMessageW( parent, WM_CTLCOLORBTN, (WPARAM)hDC, (LPARAM)hwnd );

    setup_clipping( hwnd, hDC );

    hOldPen = SelectObject(hDC, SYSCOLOR_GetPen(COLOR_WINDOWFRAME));
    hOldBrush = SelectObject(hDC,GetSysColorBrush(COLOR_BTNFACE));
    oldBkMode = SetBkMode(hDC, TRANSPARENT);

    if (get_button_type(style) == BS_DEFPUSHBUTTON)
    {
        if (action != ODA_FOCUS)
            Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
	InflateRect( &rc, -1, -1 );
    }

    focus_rect = rc;

    /* completely skip the drawing if only focus has changed */
    if (action == ODA_FOCUS) goto draw_focus;

    uState = DFCS_BUTTONPUSH | DFCS_ADJUSTRECT;

    if (style & BS_FLAT)
        uState |= DFCS_MONO;
    else if (pushedState)
    {
	if (get_button_type(style) == BS_DEFPUSHBUTTON )
	    uState |= DFCS_FLAT;
	else
	    uState |= DFCS_PUSHED;
    }

    if (state & (BUTTON_CHECKED | BUTTON_3STATE))
        uState |= DFCS_CHECKED;

    DrawFrameControl( hDC, &rc, DFC_BUTTON, uState );

    /* draw button label */
    r = rc;
    dtFlags = BUTTON_CalcLabelRect(hwnd, hDC, &r);

    if (dtFlags == (UINT)-1L)
       goto cleanup;

    if (pushedState)
       OffsetRect(&r, 1, 1);

    IntersectClipRect(hDC, rc.left, rc.top, rc.right, rc.bottom);

    oldTxtColor = SetTextColor( hDC, GetSysColor(COLOR_BTNTEXT) );

    BUTTON_DrawLabel(hwnd, hDC, dtFlags, &r);

    SetTextColor( hDC, oldTxtColor );

draw_focus:
    if ((action == ODA_FOCUS) ||
        ((action == ODA_DRAWENTIRE) && (state & BUTTON_HASFOCUS)))
    {
        InflateRect( &focus_rect, -1, -1 );
        IntersectRect(&focus_rect, &focus_rect, &rc);
        DrawFocusRect( hDC, &focus_rect );
    }

 cleanup:
    SelectObject( hDC, hOldPen );
    SelectObject( hDC, hOldBrush );
    SetBkMode(hDC, oldBkMode);
}
Esempio n. 13
0
/***********************************************************************
 *           ButtonWndProc_common
 */
LRESULT ButtonWndProc_common(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL unicode )
{
    RECT rect;
    POINT pt;
    LONG style = GetWindowLongW( hWnd, GWL_STYLE );
    UINT btn_type = get_button_type( style );
    LONG state;
    HANDLE oldHbitmap;

    if (!IsWindow( hWnd )) return 0;

    pt.x = (short)LOWORD(lParam);
    pt.y = (short)HIWORD(lParam);

    switch (uMsg)
    {
    case WM_GETDLGCODE:
        switch(btn_type)
        {
        case BS_USERBUTTON:
        case BS_PUSHBUTTON:      return DLGC_BUTTON | DLGC_UNDEFPUSHBUTTON;
        case BS_DEFPUSHBUTTON:   return DLGC_BUTTON | DLGC_DEFPUSHBUTTON;
        case BS_RADIOBUTTON:
        case BS_AUTORADIOBUTTON: return DLGC_BUTTON | DLGC_RADIOBUTTON;
        case BS_GROUPBOX:        return DLGC_STATIC;
        default:                 return DLGC_BUTTON;
        }

    case WM_ENABLE:
        paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        break;

    case WM_CREATE:
        if (!hbitmapCheckBoxes)
        {
            BITMAP bmp;
            hbitmapCheckBoxes = LoadBitmapW(0, MAKEINTRESOURCEW(OBM_CHECKBOXES));
            GetObjectW( hbitmapCheckBoxes, sizeof(bmp), &bmp );
            checkBoxWidth  = bmp.bmWidth / 4;
            checkBoxHeight = bmp.bmHeight / 3;
        }
        if (btn_type >= MAX_BTN_TYPE)
            return -1; /* abort */

        /* XP turns a BS_USERBUTTON into BS_PUSHBUTTON */
        if (btn_type == BS_USERBUTTON )
        {
            style = (style & ~0x0f) | BS_PUSHBUTTON;
            WIN_SetStyle( hWnd, style, 0x0f & ~style );
        }
        set_button_state( hWnd, BUTTON_UNCHECKED );
        return 0;

    case WM_ERASEBKGND:
        if (btn_type == BS_OWNERDRAW)
        {
            HDC hdc = (HDC)wParam;
            RECT rc;
            HBRUSH hBrush;
            HWND parent = GetParent(hWnd);
            if (!parent) parent = hWnd;
            hBrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORBTN, (WPARAM)hdc, (LPARAM)hWnd);
            if (!hBrush) /* did the app forget to call defwindowproc ? */
                hBrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORBTN,
                                                (WPARAM)hdc, (LPARAM)hWnd);
            GetClientRect(hWnd, &rc);
            FillRect(hdc, &rc, hBrush);
        }
        return 1;

    case WM_PRINTCLIENT:
    case WM_PAINT:
        if (btnPaintFunc[btn_type])
        {
            PAINTSTRUCT ps;
            HDC hdc = wParam ? (HDC)wParam : BeginPaint( hWnd, &ps );
            int nOldMode = SetBkMode( hdc, OPAQUE );
            (btnPaintFunc[btn_type])( hWnd, hdc, ODA_DRAWENTIRE );
            SetBkMode(hdc, nOldMode); /*  reset painting mode */
            if( !wParam ) EndPaint( hWnd, &ps );
        }
        break;

    case WM_KEYDOWN:
	if (wParam == VK_SPACE)
	{
	    SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
            set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
            SetCapture( hWnd );
	}
	break;

    case WM_LBUTTONDBLCLK:
        if(style & BS_NOTIFY ||
           btn_type == BS_RADIOBUTTON ||
           btn_type == BS_USERBUTTON ||
           btn_type == BS_OWNERDRAW)
        {
            BUTTON_NOTIFY_PARENT(hWnd, BN_DOUBLECLICKED);
            break;
        }
        /* fall through */
    case WM_LBUTTONDOWN:
        SetCapture( hWnd );
        SetFocus( hWnd );
        set_button_state( hWnd, get_button_state( hWnd ) | BUTTON_BTNPRESSED );
        SendMessageW( hWnd, BM_SETSTATE, TRUE, 0 );
        break;

    case WM_KEYUP:
	if (wParam != VK_SPACE)
	    break;
	/* fall through */
    case WM_LBUTTONUP:
        state = get_button_state( hWnd );
        if (!(state & BUTTON_BTNPRESSED)) break;
        state &= BUTTON_NSTATES;
        set_button_state( hWnd, state );
        if (!(state & BUTTON_HIGHLIGHTED))
        {
            ReleaseCapture();
            break;
        }
        SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
        ReleaseCapture();
        GetClientRect( hWnd, &rect );
	if (uMsg == WM_KEYUP || PtInRect( &rect, pt ))
        {
            state = get_button_state( hWnd );
            switch(btn_type)
            {
            case BS_AUTOCHECKBOX:
                SendMessageW( hWnd, BM_SETCHECK, !(state & BUTTON_CHECKED), 0 );
                break;
            case BS_AUTORADIOBUTTON:
                SendMessageW( hWnd, BM_SETCHECK, TRUE, 0 );
                break;
            case BS_AUTO3STATE:
                SendMessageW( hWnd, BM_SETCHECK,
                                (state & BUTTON_3STATE) ? 0 : ((state & 3) + 1), 0 );
                break;
            }
            BUTTON_NOTIFY_PARENT(hWnd, BN_CLICKED);
        }
        break;

    case WM_CAPTURECHANGED:
        TRACE("WM_CAPTURECHANGED %p\n", hWnd);
        state = get_button_state( hWnd );
        if (state & BUTTON_BTNPRESSED)
        {
            state &= BUTTON_NSTATES;
            set_button_state( hWnd, state );
            if (state & BUTTON_HIGHLIGHTED) SendMessageW( hWnd, BM_SETSTATE, FALSE, 0 );
        }
        break;

    case WM_MOUSEMOVE:
        if ((wParam & MK_LBUTTON) && GetCapture() == hWnd)
        {
            GetClientRect( hWnd, &rect );
            SendMessageW( hWnd, BM_SETSTATE, PtInRect(&rect, pt), 0 );
        }
        break;

    case WM_SETTEXT:
    {
        /* Clear an old text here as Windows does */
        HDC hdc = GetDC(hWnd);
        HBRUSH hbrush;
        RECT client, rc;
        HWND parent = GetParent(hWnd);

        if (!parent) parent = hWnd;
        hbrush = (HBRUSH)SendMessageW(parent, WM_CTLCOLORSTATIC,
				      (WPARAM)hdc, (LPARAM)hWnd);
        if (!hbrush) /* did the app forget to call DefWindowProc ? */
            hbrush = (HBRUSH)DefWindowProcW(parent, WM_CTLCOLORSTATIC,
					    (WPARAM)hdc, (LPARAM)hWnd);

        GetClientRect(hWnd, &client);
        rc = client;
        BUTTON_CalcLabelRect(hWnd, hdc, &rc);
        /* Clip by client rect bounds */
        if (rc.right > client.right) rc.right = client.right;
        if (rc.bottom > client.bottom) rc.bottom = client.bottom;
        FillRect(hdc, &rc, hbrush);
        ReleaseDC(hWnd, hdc);

        if (unicode) DefWindowProcW( hWnd, WM_SETTEXT, wParam, lParam );
        else DefWindowProcA( hWnd, WM_SETTEXT, wParam, lParam );
        if (btn_type == BS_GROUPBOX) /* Yes, only for BS_GROUPBOX */
            InvalidateRect( hWnd, NULL, TRUE );
        else
            paint_button( hWnd, btn_type, ODA_DRAWENTIRE );
        return 1; /* success. FIXME: check text length */
    }

    case WM_SETFONT:
        set_button_font( hWnd, (HFONT)wParam );
        if (lParam) InvalidateRect(hWnd, NULL, TRUE);
        break;

    case WM_GETFONT:
        return (LRESULT)get_button_font( hWnd );

    case WM_SETFOCUS:
        TRACE("WM_SETFOCUS %p\n",hWnd);
        set_button_state( hWnd, get_button_state(hWnd) | BUTTON_HASFOCUS );
        paint_button( hWnd, btn_type, ODA_FOCUS );
        if (style & BS_NOTIFY)
            BUTTON_NOTIFY_PARENT(hWnd, BN_SETFOCUS);
        break;

    case WM_KILLFOCUS:
        TRACE("WM_KILLFOCUS %p\n",hWnd);
        state = get_button_state( hWnd );
        set_button_state( hWnd, state & ~BUTTON_HASFOCUS );
	paint_button( hWnd, btn_type, ODA_FOCUS );

        if ((state & BUTTON_BTNPRESSED) && GetCapture() == hWnd)
            ReleaseCapture();
        if (style & BS_NOTIFY)
            BUTTON_NOTIFY_PARENT(hWnd, BN_KILLFOCUS);

        InvalidateRect( hWnd, NULL, FALSE );
        break;

    case WM_SYSCOLORCHANGE:
        InvalidateRect( hWnd, NULL, FALSE );
        break;

    case BM_SETSTYLE:
        if ((wParam & 0x0f) >= MAX_BTN_TYPE) break;
        btn_type = wParam & 0x0f;
        style = (style & ~0x0f) | btn_type;
        WIN_SetStyle( hWnd, style, 0x0f & ~style );

        /* Only redraw if lParam flag is set.*/
        if (lParam)
            InvalidateRect( hWnd, NULL, TRUE );

        break;

    case BM_CLICK:
	SendMessageW( hWnd, WM_LBUTTONDOWN, 0, 0 );
	SendMessageW( hWnd, WM_LBUTTONUP, 0, 0 );
	break;

    case BM_SETIMAGE:
        /* Check that image format matches button style */
        switch (style & (BS_BITMAP|BS_ICON))
        {
        case BS_BITMAP:
            if (wParam != IMAGE_BITMAP) return 0;
            break;
        case BS_ICON:
            if (wParam != IMAGE_ICON) return 0;
            break;
        default:
            return 0;
        }
        oldHbitmap = (HBITMAP)SetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET, lParam );
	InvalidateRect( hWnd, NULL, FALSE );
	return (LRESULT)oldHbitmap;

    case BM_GETIMAGE:
        return GetWindowLongPtrW( hWnd, HIMAGE_GWL_OFFSET );

    case BM_GETCHECK:
        return get_button_state( hWnd ) & 3;

    case BM_SETCHECK:
        if (wParam > maxCheckState[btn_type]) wParam = maxCheckState[btn_type];
        state = get_button_state( hWnd );
        if ((btn_type == BS_RADIOBUTTON) || (btn_type == BS_AUTORADIOBUTTON))
        {
            if (wParam) style |= WS_TABSTOP;
            else style &= ~WS_TABSTOP;
            SetWindowLongW( hWnd, GWL_STYLE, style );
        }
        if ((state & 3) != wParam)
        {
            set_button_state( hWnd, (state & ~3) | wParam );
            paint_button( hWnd, btn_type, ODA_SELECT );
        }
        if ((btn_type == BS_AUTORADIOBUTTON) && (wParam == BUTTON_CHECKED) && (style & WS_CHILD))
            BUTTON_CheckAutoRadioButton( hWnd );
        break;

    case BM_GETSTATE:
        return get_button_state( hWnd );

    case BM_SETSTATE:
        state = get_button_state( hWnd );
        if (wParam)
        {
            if (state & BUTTON_HIGHLIGHTED) break;
            set_button_state( hWnd, state | BUTTON_HIGHLIGHTED );
        }
        else
        {
            if (!(state & BUTTON_HIGHLIGHTED)) break;
            set_button_state( hWnd, state & ~BUTTON_HIGHLIGHTED );
        }
        paint_button( hWnd, btn_type, ODA_SELECT );
        break;

    case WM_NCHITTEST:
        if(btn_type == BS_GROUPBOX) return HTTRANSPARENT;
        /* fall through */
    default:
        return unicode ? DefWindowProcW(hWnd, uMsg, wParam, lParam) :
                         DefWindowProcA(hWnd, uMsg, wParam, lParam);
    }
    return 0;
}
Esempio n. 14
0
static GLUTwindow *
processWindowWorkList(GLUTwindow * window)
{
  int workMask;

  if (window->prevWorkWin) {
    window->prevWorkWin = processWindowWorkList(window->prevWorkWin);
	if (beforeEnd == 0)
      beforeEnd = &window->prevWorkWin;
  } else {
    beforeEnd = &window->prevWorkWin;
  }

  /* Capture work mask for work that needs to be done to this
     window, then clear the window's work mask (excepting the
     dummy work bit, see below).  Then, process the captured
     work mask.  This allows callbacks in the processing the
     captured work mask to set the window's work mask for
     subsequent processing. */

  workMask = window->workMask;
  assert((workMask & GLUT_DUMMY_WORK) == 0);

  /* Set the dummy work bit, clearing all other bits, to
     indicate that the window is currently on the window work
     list _and_ that the window's work mask is currently being
     processed.  This convinces __glutPutOnWorkList that this
     window is on the work list still. */
  window->workMask = GLUT_DUMMY_WORK;

  /* Optimization: most of the time, the work to do is a
     redisplay and not these other types of work.  Check for
     the following cases as a group to before checking each one
     individually one by one. This saves about 25 MIPS
     instructions in the common redisplay only case. */
  if (workMask & (GLUT_EVENT_MASK_WORK | GLUT_DEVICE_MASK_WORK |
      GLUT_CONFIGURE_WORK | GLUT_COLORMAP_WORK | GLUT_MAP_WORK)) {
#if !defined(_WIN32)
    /* Be sure to set event mask BEFORE map window is done. */
    if (workMask & GLUT_EVENT_MASK_WORK) {
      long eventMask;

      /* Make sure children are not propogating events this
         window is selecting for.  Be sure to do this before
         enabling events on the children's parent. */
      if (window->children) {
        GLUTwindow *child = window->children;
        unsigned long attribMask = CWDontPropagate;
        XSetWindowAttributes wa;

        wa.do_not_propagate_mask = window->eventMask & GLUT_DONT_PROPAGATE_FILTER_MASK;
        if (window->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK) {
          wa.event_mask = child->eventMask | (window->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK);
          attribMask |= CWEventMask;
        }
        do {
          XChangeWindowAttributes(__glutDisplay, child->win,
            attribMask, &wa);
          child = child->siblings;
        } while (child);
      }
      eventMask = window->eventMask;
      if (window->parent && window->parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK)
        eventMask |= (window->parent->eventMask & GLUT_HACK_STOP_PROPAGATE_MASK);
      XSelectInput(__glutDisplay, window->win, eventMask);
      if (window->overlay)
        XSelectInput(__glutDisplay, window->overlay->win,
          window->eventMask & GLUT_OVERLAY_EVENT_FILTER_MASK);
    }
#endif /* !_WIN32 */
    /* Be sure to set device mask BEFORE map window is done. */
    if (workMask & GLUT_DEVICE_MASK_WORK) {
      __glutUpdateInputDeviceMaskFunc(window);
    }
    /* Be sure to configure window BEFORE map window is done. */
    if (workMask & GLUT_CONFIGURE_WORK) {
#if defined(_WIN32)
        if ( workMask & GLUT_FULL_SCREEN_WORK ) {
            DWORD s;
            RECT r;

            GetWindowRect(GetDesktopWindow(), &r);
            s = GetWindowLong(window->win, GWL_STYLE);
            s &= ~WS_OVERLAPPEDWINDOW;
            s |= WS_POPUP;
            SetWindowLong(window->win, GWL_STYLE, s);
            SetWindowPos(window->win, 
                HWND_TOP, /* safer - a lot of people use windows atop a fullscreen GLUT window. */
				//HWND_TOPMOST, /* is better, but no windows atop it */
                r.left, r.top, 
                r.right-r.left, r.bottom-r.top, 
                SWP_FRAMECHANGED);
            
            /* This hack causes the window to go back to the right position
            when it is taken out of fullscreen mode. */
            {
                POINT p;

                p.x = 0;
                p.y = 0;
                ClientToScreen(window->win, &p);
                window->desiredConfMask |= CWX | CWY;
                window->desiredX = p.x;
                window->desiredY = p.y;
            }
        } else {
            RECT changes;
            POINT point;
            UINT flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER;
            DWORD style;
			
            GetClientRect(window->win, &changes);
            style = GetWindowLong(window->win, GWL_STYLE);
            
            /* Get rid of fullscreen mode, if it exists */
            if ( style & WS_POPUP ) {
                style &= ~WS_POPUP;
                style |= WS_OVERLAPPEDWINDOW;
                SetWindowLong(window->win, GWL_STYLE, style);
                flags |= SWP_FRAMECHANGED;
            }

            /* If this window is a toplevel window, translate the 0,0 client
            coordinate into a screen coordinate for proper placement. */
            if (!window->parent) {
                point.x = 0;
                point.y = 0;
                ClientToScreen(window->win, &point);
                changes.left = point.x;
                changes.top = point.y;
            }
            if (window->desiredConfMask & (CWX | CWY)) {
                changes.left = window->desiredX;
                changes.top = window->desiredY;
                flags &= ~SWP_NOMOVE;
            }
            if (window->desiredConfMask & (CWWidth | CWHeight)) {
                changes.right = changes.left + window->desiredWidth;
                changes.bottom = changes.top + window->desiredHeight;
                flags &= ~SWP_NOSIZE;
                /* XXX If overlay exists, resize the overlay here, ie.
                if (window->overlay) ... */
            }
            if (window->desiredConfMask & CWStackMode) {
                flags &= ~SWP_NOZORDER;
                /* XXX Overlay support might require something special here. */
            }
            
            /* Adjust the window rectangle because Win32 thinks that the x, y,
            width & height are the WHOLE window (including decorations),
            whereas GLUT treats the x, y, width & height as only the CLIENT
            area of the window.  Only do this to top level windows
            that are not in game mode (since game mode windows do
            not have any decorations). */
            if (!window->parent && window != __glutGameModeWindow) {
                AdjustWindowRect(&changes, style, FALSE);
            }
            
            /* Do the repositioning, moving, and push/pop. */
            SetWindowPos(window->win,
                window->desiredStack == Above ? HWND_TOP : HWND_BOTTOM,
                changes.left, changes.top,
                changes.right - changes.left, changes.bottom - changes.top,
                flags);
            
            /* Zero out the mask. */
            window->desiredConfMask = 0;
        }
#else /* !_WIN32 */
      XWindowChanges changes;

      changes.x = window->desiredX;
      changes.y = window->desiredY;
      if (window->desiredConfMask & (CWWidth | CWHeight)) {
        changes.width = window->desiredWidth;
        changes.height = window->desiredHeight;
        if (window->overlay)
          XResizeWindow(__glutDisplay, window->overlay->win,
            window->desiredWidth, window->desiredHeight);
        if (__glutMotifHints != None) {
          if (workMask & GLUT_FULL_SCREEN_WORK) {
            MotifWmHints hints;

            hints.flags = MWM_HINTS_DECORATIONS;
            hints.decorations = 0;  /* Absolutely no
                                       decorations. */
            XChangeProperty(__glutDisplay, window->win,
              __glutMotifHints, __glutMotifHints, 32,
              PropModeReplace, (unsigned char *) &hints, 4);
            if (workMask & GLUT_MAP_WORK) {
              /* Handle case where glutFullScreen is called
                 before the first time that the window is
                 mapped. Some window managers will randomly or
                 interactively position the window the first
                 time it is mapped if the window's
                 WM_NORMAL_HINTS property does not request an
                 explicit position. We don't want any such
                 window manager interaction when going
                 fullscreen.  Overwrite the WM_NORMAL_HINTS
                 property installed by glutCreateWindow's
                 XSetWMProperties property with one explicitly
                 requesting a fullscreen window. */
              XSizeHints hints;

              hints.flags = USPosition | USSize;
              hints.x = 0;
              hints.y = 0;
              hints.width = window->desiredWidth;
              hints.height = window->desiredHeight;
              XSetWMNormalHints(__glutDisplay, window->win, &hints);
            }
          } else {
            XDeleteProperty(__glutDisplay, window->win, __glutMotifHints);
          }
        }
      }
      if (window->desiredConfMask & CWStackMode) {
        changes.stack_mode = window->desiredStack;
        /* Do not let glutPushWindow push window beneath the
           underlay. */
        if (window->parent && window->parent->overlay
          && window->desiredStack == Below) {
          changes.stack_mode = Above;
          changes.sibling = window->parent->overlay->win;
          window->desiredConfMask |= CWSibling;
        }
      }
      XConfigureWindow(__glutDisplay, window->win,
        window->desiredConfMask, &changes);
      window->desiredConfMask = 0;
#endif
    }
#if !defined(_WIN32)
    /* Be sure to establish the colormaps BEFORE map window is
       done. */
    if (workMask & GLUT_COLORMAP_WORK) {
      __glutEstablishColormapsProperty(window);
    }
#endif
    if (workMask & GLUT_MAP_WORK) {
      switch (window->desiredMapState) {
      case WithdrawnState:
        if (window->parent) {
          XUnmapWindow(__glutDisplay, window->win);
        } else {
          XWithdrawWindow(__glutDisplay, window->win,
            __glutScreen);
        }
        window->shownState = 0;
        break;
      case NormalState:
        XMapWindow(__glutDisplay, window->win);
        window->shownState = 1;
        break;
#ifdef _WIN32
      case GameModeState:  /* Not an Xlib value. */
        ShowWindow(window->win, SW_SHOW);
        window->shownState = 1;
        break;
#endif
      case IconicState:
        XIconifyWindow(__glutDisplay, window->win, __glutScreen);
        window->shownState = 0;
        break;
      }
    }
  }
  if (workMask & (GLUT_REDISPLAY_WORK | GLUT_OVERLAY_REDISPLAY_WORK | GLUT_REPAIR_WORK | GLUT_OVERLAY_REPAIR_WORK)) {
    if (window->forceReshape) {
      /* Guarantee that before a display callback is generated
         for a window, a reshape callback must be generated. */
      __glutSetWindow(window);
      window->reshape(window->width, window->height);
      window->forceReshape = False;

      /* Setting the redisplay bit on the first reshape is
         necessary to make the "Mesa glXSwapBuffers to repair
         damage" hack operate correctly.  Without indicating a
         redisplay is necessary, there's not an initial back
         buffer render from which to blit from when damage
         happens to the window. */
      workMask |= GLUT_REDISPLAY_WORK;
    }
    /* The code below is more involved than otherwise necessary
       because it is paranoid about the overlay or entire window
       being removed or destroyed in the course of the callbacks.
       Notice how the global __glutWindowDamaged is used to record
       the layers' damage status.  See the code in glutLayerGet for
       how __glutWindowDamaged is used. The  point is to not have to
       update the "damaged" field after  the callback since the
       window (or overlay) may be destroyed (or removed) when the
       callback returns. */

    if (window->overlay && window->overlay->display) {
      int num = window->num;
      Window xid = window->overlay ? window->overlay->win : None;

      /* If an overlay display callback is registered, we
         differentiate between a redisplay needed for the
         overlay and/or normal plane.  If there is no overlay
         display callback registered, we simply use the
         standard display callback. */

      if (workMask & (GLUT_REDISPLAY_WORK | GLUT_REPAIR_WORK)) {
        if (__glutMesaSwapHackSupport) {
          if (window->usedSwapBuffers) {
            if ((workMask & (GLUT_REPAIR_WORK | GLUT_REDISPLAY_WORK)) == GLUT_REPAIR_WORK) {
	      SWAP_BUFFERS_WINDOW(window);
              goto skippedDisplayCallback1;
            }
          }
        }
        /* Render to normal plane. */
#ifdef _WIN32
        window->renderDc = window->hdc;
#endif
        window->renderWin = window->win;
        window->renderCtx = window->ctx;
        __glutWindowDamaged = (workMask & GLUT_REPAIR_WORK);
        __glutSetWindow(window);
        window->usedSwapBuffers = 0;
        window->display();
        __glutWindowDamaged = 0;

      skippedDisplayCallback1:;
      }
      if (workMask & (GLUT_OVERLAY_REDISPLAY_WORK | GLUT_OVERLAY_REPAIR_WORK)) {
        window = __glutWindowList[num];
        if (window && window->overlay &&
          window->overlay->win == xid && window->overlay->display) {

          /* Render to overlay. */
#ifdef _WIN32
          window->renderDc = window->overlay->hdc;
#endif
          window->renderWin = window->overlay->win;
          window->renderCtx = window->overlay->ctx;
          __glutWindowDamaged = (workMask & GLUT_OVERLAY_REPAIR_WORK);
          __glutSetWindow(window);
          window->overlay->display();
          __glutWindowDamaged = 0;
        } else {
          /* Overlay may have since been destroyed or the
             overlay callback may have been disabled during
             normal display callback. */
        }
      }
    } else {
      if (__glutMesaSwapHackSupport) {
        if (!window->overlay && window->usedSwapBuffers) {
          if ((workMask & (GLUT_REPAIR_WORK | GLUT_REDISPLAY_WORK)) == GLUT_REPAIR_WORK) {
	    SWAP_BUFFERS_WINDOW(window);
            goto skippedDisplayCallback2;
          }
        }
      }
      /* Render to normal plane (and possibly overlay). */
      __glutWindowDamaged = (workMask & (GLUT_OVERLAY_REPAIR_WORK | GLUT_REPAIR_WORK));
      __glutSetWindow(window);
      window->usedSwapBuffers = 0;
      window->display();
      __glutWindowDamaged = 0;

    skippedDisplayCallback2:;
    }
  }
  /* Combine workMask with window->workMask to determine what
     finish and debug work there is. */
  workMask |= window->workMask;

  if (workMask & GLUT_FINISH_WORK) {
    /* Finish work makes sure a glFinish gets done to indirect
       rendering contexts.  Indirect contexts tend to have much 
       longer latency because lots of OpenGL extension requests 
       can queue up in the X protocol stream. __glutSetWindow
       is where the finish works gets queued for indirect
       contexts. */
    __glutSetWindow(window);
    glFinish();
  }
  if (workMask & GLUT_DEBUG_WORK) {
    __glutSetWindow(window);
    glutReportErrors();
  }
  /* Strip out dummy, finish, and debug work bits. */
  window->workMask &= ~(GLUT_DUMMY_WORK | GLUT_FINISH_WORK | GLUT_DEBUG_WORK);
  if (window->workMask) {
    /* Leave on work list. */
    return window;
  } else {
	if (beforeEnd == &window->prevWorkWin)
	  beforeEnd = 0;
    /* Remove current window from work list. */
    return window->prevWorkWin;
  }
}
Esempio n. 15
0
//Yeah this truly turned into a mess with the latest additions.. but it sure looks nice ;)
void CtrlRegisterList::onPaint(WPARAM wParam, LPARAM lParam)
{
	if (!cpu) 
		return;

	GetClientRect(wnd, &rect);
	PAINTSTRUCT ps;
	HDC hdc;
	
	hdc = BeginPaint(wnd, &ps);
	// TODO: Add any drawing code here...
	int width = rect.right;
	//numRows=(numRows&(~1)) + 1;
	SetBkMode(hdc, TRANSPARENT);
	DWORD bgColor = 0xffffff;
	HPEN nullPen=CreatePen(0,0,bgColor);
	HPEN currentPen=CreatePen(0,0,0);
	HPEN selPen=CreatePen(0,0,0x808080);

	LOGBRUSH lbr;
	lbr.lbHatch=0; lbr.lbStyle=0; 
	lbr.lbColor=bgColor;
	HBRUSH nullBrush=CreateBrushIndirect(&lbr);
	lbr.lbColor=0xFFEfE8;
	HBRUSH currentBrush=CreateBrushIndirect(&lbr);
	lbr.lbColor=0x70FF70;
	HBRUSH pcBrush=CreateBrushIndirect(&lbr);

	HPEN oldPen=(HPEN)SelectObject(hdc,nullPen);
	HBRUSH oldBrush=(HBRUSH)SelectObject(hdc,nullBrush);

   
	HFONT oldFont = (HFONT)SelectObject(hdc,(HGDIOBJ)font);
//	HICON breakPoint = (HICON)LoadIcon(GetModuleHandle(0),(LPCSTR)IDI_STOP);
//	HICON breakPointDisable = (HICON)LoadIcon(GetModuleHandle(0),(LPCSTR)IDI_STOPDISABLE);

	int nc = cpu->GetNumCategories();
	for (int i=0; i<nc; i++)
	{
		SelectObject(hdc,i==category?currentPen:nullPen);
		SelectObject(hdc,i==category?pcBrush:nullBrush);
		Rectangle(hdc,width*i/nc,0,width*(i+1)/nc,rowHeight);
		const TCHAR *name = cpu->GetCategoryName(i);
		TextOut(hdc,width*i/nc,1,name,(int)strlen(name));
	}

	int numRows=rect.bottom/rowHeight;

	for (int i=0; i<numRows; i++)
	{
		int rowY1 = rowHeight*(i+1);
		int rowY2 = rowHeight*(i+2);


		lbr.lbColor = i==selection?0xffeee0:0xffffff;

		SelectObject(hdc,currentBrush);
		SelectObject(hdc,nullPen);
		Rectangle(hdc,0,rowY1,16,rowY2);

		if (selecting && i == selection)
			SelectObject(hdc,selPen);
		else
			SelectObject(hdc,nullPen);

		HBRUSH mojsBrush=CreateBrushIndirect(&lbr);
		SelectObject(hdc,mojsBrush);

		//else
		//	SelectObject(hdc,i==0 ? currentBrush : nullBrush);

		Rectangle(hdc,16,rowY1,width,rowY2);

		// Check for any changes in the registers.
		if (lastPC != cpu->GetPC())
		{
			for (int j = 0, n = cpu->GetNumRegsInCategory(0); j < n; ++j)
			{
				u32 v = cpu->GetRegValue(0, j);
				changedCat0Regs[j] = v != lastCat0Values[j];
				lastCat0Values[j] = v;
			}
			
			changedCat0Regs[REGISTER_PC] = cpu->GetPC() != lastCat0Values[REGISTER_PC];
			lastCat0Values[REGISTER_PC] = cpu->GetPC();
			changedCat0Regs[REGISTER_HI] = cpu->GetHi() != lastCat0Values[REGISTER_HI];
			lastCat0Values[REGISTER_HI] = cpu->GetHi();
			changedCat0Regs[REGISTER_LO] = cpu->GetLo() != lastCat0Values[REGISTER_LO];
			lastCat0Values[REGISTER_LO] = cpu->GetLo();

			lastPC = cpu->GetPC();
		}

		SelectObject(hdc,currentBrush);
		DeleteObject(mojsBrush);
		if (i<cpu->GetNumRegsInCategory(category))
		{
			char temp[256];
			int temp_len = sprintf(temp,"%s",cpu->GetRegName(category,i));
			SetTextColor(hdc,0x600000);
			TextOut(hdc,17,rowY1,temp,temp_len);
			SetTextColor(hdc,0x000000);

			cpu->PrintRegValue(category,i,temp);
			if (category == 0 && changedCat0Regs[i])
				SetTextColor(hdc, 0x0000FF);
			else
				SetTextColor(hdc,0x004000);
			TextOut(hdc,77,rowY1,temp,(int)strlen(temp));
		} else if (category == 0 && i < REGISTERS_END)
		{
			char temp[256];
			int len;
			u32 value;

			switch (i)
			{
			case REGISTER_PC:
				value = cpu->GetPC();
				len = sprintf(temp,"pc");
				break;
			case REGISTER_HI:
				value = cpu->GetHi();
				len = sprintf(temp,"hi");
				break;
			case REGISTER_LO:
				value = cpu->GetLo();
				len = sprintf(temp,"lo");
				break;
			}

			SetTextColor(hdc,0x600000);
			TextOut(hdc,17,rowY1,temp,len);
			len = sprintf(temp,"%08X",value);
			if (changedCat0Regs[i])
				SetTextColor(hdc, 0x0000FF);
			else
				SetTextColor(hdc,0x004000);
			TextOut(hdc,77,rowY1,temp,(int)strlen(temp));
		}

		/*
			}
			SetTextColor(hdc,0x007000);

			TextOut(hdc,70,rowY1,dis,strlen(dis));
			if (desc[0]==0)
				strcpy(desc,debugger->getDescription(address));
			SetTextColor(hdc,0x0000FF);
			//char temp[256];
			//UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE);
			if (strlen(desc))
				TextOut(hdc,280,rowY1,desc,strlen(desc));
			if (debugger->isBreakpoint(address))
			{
				DrawIconEx(hdc,2,rowY1,breakPoint,32,32,0,0,DI_NORMAL);
			}
		}*/
	}

	SelectObject(hdc,oldFont);
	SelectObject(hdc,oldPen);
	SelectObject(hdc,oldBrush);
	
	DeleteObject(nullPen);
	DeleteObject(currentPen);
	DeleteObject(selPen);

	DeleteObject(nullBrush);
	DeleteObject(pcBrush);
	DeleteObject(currentBrush);
	
//	DestroyIcon(breakPoint);
//	DestroyIcon(breakPointDisable);
	
	EndPaint(wnd, &ps);
}
Esempio n. 16
0
LRESULT CALLBACK CMainWindow::WinMsgHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
	case WM_CREATE:
		{
			m_hwnd = hwnd;
			Initialize();
		}
		break;
	case WM_COMMAND:
		{
			return DoCommand(LOWORD(wParam));
		}
		break;
	case WM_MOUSEWHEEL:
		{
			if (GET_KEYSTATE_WPARAM(wParam) == MK_SHIFT)
			{
				// scroll sideways
				SendEditor(SCI_LINESCROLL, -GET_WHEEL_DELTA_WPARAM(wParam)/40, 0);
			}
			else
				return DefWindowProc(hwnd, uMsg, wParam, lParam);
		}
		break;
	case WM_SIZE:
		{
			RECT rect;
			GetClientRect(*this, &rect);
			if (m_bShowFindBar)
			{
				::SetWindowPos(m_hWndEdit, HWND_TOP, 
					rect.left, rect.top,
					rect.right-rect.left, rect.bottom-rect.top-30,
					SWP_SHOWWINDOW);
				::SetWindowPos(m_FindBar, HWND_TOP,
					rect.left, rect.bottom-30,
					rect.right-rect.left, 30,
					SWP_SHOWWINDOW);
			}
			else
			{
				::SetWindowPos(m_hWndEdit, HWND_TOP, 
					rect.left, rect.top,
					rect.right-rect.left, rect.bottom-rect.top,
					SWP_SHOWWINDOW);
				::ShowWindow(m_FindBar, SW_HIDE);
			}
		}
		break;
	case WM_GETMINMAXINFO:
		{
			MINMAXINFO * mmi = (MINMAXINFO*)lParam;
			mmi->ptMinTrackSize.x = 100;
			mmi->ptMinTrackSize.y = 100;
			return 0;
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_CLOSE:
		{
			CRegStdWORD w = CRegStdWORD(_T("Software\\TortoiseGit\\UDiffViewerWidth"), (DWORD)CW_USEDEFAULT);
			CRegStdWORD h = CRegStdWORD(_T("Software\\TortoiseGit\\UDiffViewerHeight"), (DWORD)CW_USEDEFAULT);
			CRegStdWORD p = CRegStdWORD(_T("Software\\TortoiseGit\\UDiffViewerPos"), 0);

			RECT rect;
			::GetWindowRect(*this, &rect);
			w = rect.right-rect.left;
			h = rect.bottom-rect.top;
			p = MAKELONG(rect.left, rect.top);
		}
		::DestroyWindow(m_hwnd);
		break;
	case WM_SETFOCUS:
		SetFocus(m_hWndEdit);
		break;
	case COMMITMONITOR_FINDMSGNEXT:
		{
			SendEditor(SCI_CHARRIGHT);
			SendEditor(SCI_SEARCHANCHOR);
			m_bMatchCase = !!wParam;
			m_findtext = (LPCTSTR)lParam;
			SendEditor(SCI_SEARCHNEXT, m_bMatchCase ? SCFIND_MATCHCASE : 0, (LPARAM)CUnicodeUtils::StdGetUTF8(m_findtext).c_str());
			SendEditor(SCI_SCROLLCARET);
		}
		break;
	case COMMITMONITOR_FINDMSGPREV:
		{
			SendEditor(SCI_SEARCHANCHOR);
			m_bMatchCase = !!wParam;
			m_findtext = (LPCTSTR)lParam;
			SendEditor(SCI_SEARCHPREV, m_bMatchCase ? SCFIND_MATCHCASE : 0, (LPARAM)CUnicodeUtils::StdGetUTF8(m_findtext).c_str());
			SendEditor(SCI_SCROLLCARET);
		}
		break;
	case COMMITMONITOR_FINDEXIT:
		{
			RECT rect;
			GetClientRect(*this, &rect);
			m_bShowFindBar = false;
			::ShowWindow(m_FindBar, SW_HIDE);
			::SetWindowPos(m_hWndEdit, HWND_TOP, 
				rect.left, rect.top,
				rect.right-rect.left, rect.bottom-rect.top,
				SWP_SHOWWINDOW);
		}
		break;
	case COMMITMONITOR_FINDRESET:
		SendEditor(SCI_SETSELECTIONSTART, 0);
		SendEditor(SCI_SETSELECTIONEND, 0);
		SendEditor(SCI_SEARCHANCHOR);
		break;
	default:
		return DefWindowProc(hwnd, uMsg, wParam, lParam);
	}

	return 0;
};
Esempio n. 17
0
void OpenGLDisplayDevice::do_reposition_window(int xpos, int ypos) {
  RECT rcClient, rcWindow;
  GetClientRect(glwsrv.hWnd, &rcClient);
  GetWindowRect(glwsrv.hWnd, &rcWindow);
  MoveWindow(glwsrv.hWnd, xpos, ypos, rcWindow.right-rcWindow.left, rcWindow.bottom-rcWindow.top, TRUE);
}
Esempio n. 18
0
static int winDialogBaseProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
  if (iupwinBaseContainerProc(ih, msg, wp, lp, result))
    return 1;

  iupwinMenuDialogProc(ih, msg, wp, lp);

  switch (msg)
  {
  case WM_GETDLGCODE:
    *result = DLGC_WANTALLKEYS;
    return 1;
  case WM_GETMINMAXINFO:
    {
      if (winDialogCheckMinMaxInfo(ih, (MINMAXINFO*)lp))
      {
        *result = 0;
        return 1;
      }
      break;
    }
  case WM_SIZE:
    {
      if (ih->data->ignore_resize)
        break;

      switch(wp)
      {
      case SIZE_MINIMIZED:
        {
          if (ih->data->show_state != IUP_MINIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            if (show_cb && show_cb(ih, IUP_MINIMIZE) == IUP_CLOSE)
              IupExitLoop();
            ih->data->show_state = IUP_MINIMIZE;
          }
          break;
        }
      case SIZE_MAXIMIZED:
        {
          if (ih->data->show_state != IUP_MAXIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            if (show_cb && show_cb(ih, IUP_MAXIMIZE) == IUP_CLOSE)
              IupExitLoop();
            ih->data->show_state = IUP_MAXIMIZE;
          }

          winDialogResize(ih, LOWORD(lp), HIWORD(lp));
          break;
        }
      case SIZE_RESTORED:
        {
          if (ih->data->show_state == IUP_MAXIMIZE || ih->data->show_state == IUP_MINIMIZE)
          {
            IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
            if (show_cb && show_cb(ih, IUP_RESTORE) == IUP_CLOSE)
              IupExitLoop();
            ih->data->show_state = IUP_RESTORE;
          }

          winDialogResize(ih, LOWORD(lp), HIWORD(lp));
          break;
        }
      }

      break;
    }
  case WM_USER+IWIN_TRAY_NOTIFICATION:
    {
      int dclick  = 0;
      int button  = 0;
      int pressed = 0;

      switch (lp)
      {
      case WM_LBUTTONDOWN:
        pressed = 1;
        button  = 1;
        break;
      case WM_MBUTTONDOWN:
        pressed = 1;
        button  = 2;
        break;
      case WM_RBUTTONDOWN:
        pressed = 1;
        button  = 3;
        break;
      case WM_LBUTTONDBLCLK:
        dclick = 1;
        button = 1;
        break;
      case WM_MBUTTONDBLCLK:
        dclick = 1;
        button = 2;
        break;
      case WM_RBUTTONDBLCLK:
        dclick = 1;
        button = 3;
        break;
      case WM_LBUTTONUP:
        button = 1;
        break;
      case WM_MBUTTONUP:
        button = 2;
        break;
      case WM_RBUTTONUP:
        button = 3;
        break;
      }

      if (button != 0)
      {
        IFniii cb = (IFniii)IupGetCallback(ih, "TRAYCLICK_CB");
        if (cb && cb(ih, button, pressed, dclick) == IUP_CLOSE)
          IupExitLoop();
      }

      break;
    }
  case WM_CLOSE:
    {
      Icallback cb = IupGetCallback(ih, "CLOSE_CB");
      if (cb)
      {
        int ret = cb(ih);
        if (ret == IUP_IGNORE)
        {
          *result = 0;
          return 1;
        }
        if (ret == IUP_CLOSE)
          IupExitLoop();
      }

      /* child mdi is automatically destroyed */
      if (iupAttribGetInt(ih, "MDICHILD"))
        IupDestroy(ih);
      else
      {
        if (!winDialogMDICloseChildren(ih))
        {
          *result = 0;
          return 1;
        }

        IupHide(ih); /* IUP default processing */
      }

      *result = 0;
      return 1;
    }
  case WM_SETCURSOR: 
    { 
      if (ih->handle == (HWND)wp && LOWORD(lp)==HTCLIENT)
      {
        HCURSOR hCur = (HCURSOR)iupAttribGet(ih, "_IUPWIN_HCURSOR");
        if (hCur)
        {
          SetCursor(hCur); 
          *result = 1;
          return 1;
        }
        else if (iupAttribGet(ih, "CURSOR"))
        {
          SetCursor(NULL); 
          *result = 1;
          return 1;
        }
      }
      break; 
    } 
  case WM_ERASEBKGND:
    {
      HBITMAP hBitmap = (HBITMAP)iupAttribGet(ih, "_IUPWIN_BACKGROUND_BITMAP");
      if (hBitmap) 
      {
        RECT rect;
        HDC hdc = (HDC)wp;

        HBRUSH hBrush = CreatePatternBrush(hBitmap);
        GetClientRect(ih->handle, &rect); 
        FillRect(hdc, &rect, hBrush); 
        DeleteObject(hBrush);

        /* return non zero value */
        *result = 1;
        return 1; 
      }
      else
      {
        unsigned char r, g, b;
        char* color = iupAttribGet(ih, "_IUPWIN_BACKGROUND_COLOR");
        if (iupStrToRGB(color, &r, &g, &b))
        {
          RECT rect;
          HDC hdc = (HDC)wp;

          SetDCBrushColor(hdc, RGB(r,g,b));
          GetClientRect(ih->handle, &rect); 
          FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH)); 

          /* return non zero value */
          *result = 1;
          return 1;
        }
      }
      break;
    }
  case WM_DESTROY:
    {
      /* Since WM_CLOSE changed the Windows default processing                            */
      /* WM_DESTROY is NOT received by IupDialogs                                         */
      /* Except when they are children of other IupDialogs and the parent is destroyed.   */
      /* So we have to destroy the child dialog.                                          */
      /* The application is responsable for destroying the children before this happen.   */
      IupDestroy(ih);
      break;
    }
  }

  if (msg == (UINT)WM_HELPMSG)
  {
    Ihandle* child = NULL;
    DWORD* struct_ptr = (DWORD*)lp;
    if (*struct_ptr == sizeof(CHOOSECOLOR))
    {
      CHOOSECOLOR* choosecolor = (CHOOSECOLOR*)lp;
      child = (Ihandle*)choosecolor->lCustData;
    }
    if (*struct_ptr == sizeof(CHOOSEFONT))
    {
      CHOOSEFONT* choosefont = (CHOOSEFONT*)lp;
      child = (Ihandle*)choosefont->lCustData;
    }

    if (child)
    {
      Icallback cb = IupGetCallback(child, "HELP_CB");
      if (cb && cb(child) == IUP_CLOSE)
        EndDialog((HWND)iupAttribGet(child, "HWND"), IDCANCEL);
    }
  }

  return 0;
}
Esempio n. 19
0
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
  switch (uMessage)
    {
    case WM_PAINT:
      {
	PAINTSTRUCT ps;
	BeginPaint(hwnd, &ps);
	SetMapMode(ps.hdc, MM_ANISOTROPIC);
	/* Set the window extent to a sane value in case the metafile doesn't */
	SetWindowExtEx(ps.hdc, width, height, NULL);
	SetViewportExtEx(ps.hdc, width, height, NULL);
	SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
       if (isEnhanced && enhmf)
       {
           RECT r;
           GetClientRect(hwnd, &r);
           PlayEnhMetaFile(ps.hdc, enhmf, &r);
       }
       else if (hmf)
           PlayMetaFile(ps.hdc, hmf);
	EndPaint(hwnd, &ps);
      }
      break;

    case WM_COMMAND: /* message: command from application menu */
        switch (LOWORD(wparam))
	{
	case IDM_OPEN:
	  {
              WCHAR filename[MAX_PATH];
              if (FileOpen(hwnd, filename, sizeof(filename)/sizeof(WCHAR)))
              {
                  szFileTitle[0] = 0;
                  GetFileTitleW(filename, szFileTitle, sizeof(szFileTitle)/sizeof(WCHAR));
                  DoOpenFile(filename);
                  UpdateWindowCaption();
              }
	  }
	  break;

	case IDM_SET_EXT_TO_WIN:
	  {
	    RECT r;
	    GetClientRect(hwnd, &r);
	    width = r.right - r.left;
	    height = r.bottom - r.top;
	    deltax = deltay = 0;
	    InvalidateRect( hwnd, NULL, TRUE );
	  }
	  break;


	case IDM_LEFT:
	  deltax += 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;
	case IDM_RIGHT:
	  deltax -= 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;
	case IDM_UP:
	  deltay += 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;
	case IDM_DOWN:
	  deltay -= 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;

	case IDM_EXIT:
	  DestroyWindow(hwnd);
	  break;

	default:
	  return DefWindowProcW(hwnd, uMessage, wparam, lparam);
	}
      break;

    case WM_DESTROY:  /* message: window being destroyed */
      PostQuitMessage(0);
      break;

    default:          /* Passes it on if unprocessed */
      return DefWindowProcW(hwnd, uMessage, wparam, lparam);
    }
    return 0;
}
Esempio n. 20
0
BOOL CPopupList::OnMouseMove(CPoint point)
{
	CRect rcClient;
	GetClientRect(&rcClient);
	BOOL bDraw = FALSE;
	if(rcClient.PtInRect(point))
	{	
		int nHoverItem = m_nHoverItem;
		
		if(m_nHoverItem != -1)
		{
			EditListItem &editListItem = m_vecItem.at(m_nHoverItem);
			if(editListItem.rcItem.PtInRect(point))
			{
				if((m_pImageClose != NULL) && m_rcClose.PtInRect(point))
				{
					bDraw = m_buttonState != enBSHover;
					m_buttonState = enBSHover;
				}
				else
				{
					bDraw = m_buttonState == enBSHover;
					m_buttonState = enBSNormal;
				}
			}
			else
			{
				nHoverItem = -1;	
				bDraw = TRUE;
			}
		}

		if(m_nHoverItem != nHoverItem)
		{
			int nItemCount =  m_vecItem.size();
			for (int i = 0; i < nItemCount; i++)
			{
				EditListItem &editListItem = m_vecItem.at(i);
				if(editListItem.rcItem.PtInRect(point))
				{
					m_nHoverItem = i;
					bDraw = TRUE;
					break;
				}
			}
			if(m_nHoverItem != -1)
			{
				SetItemPoint();
			}
			if((m_pImageClose != NULL) && m_rcClose.PtInRect(point))
			{
				m_buttonState = enBSHover;
			}
			else
			{
				m_buttonState = enBSNormal;
			}
			bDraw = TRUE;
		}
	}
	else
	{
		m_buttonState = enBSNormal;
		bDraw = TRUE;
	}
	
	return bDraw;
}
Esempio n. 21
0
static int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
	AllocConsole(); //create a console
	freopen( "conin$","r",stdin );
	freopen( "conout$","w",stdout );
	freopen( "conout$","w",stderr );
	printf( "Program Started, console initialized\n" );

	const char WindowName[] = "Wet Clay";

	int64 mSecsPerFrame = 16; //60FPS
	System system = { };
	system.windowHeight = 680;
	system.windowWidth = 1080;
	system.ReadWholeFile = &ReadWholeFile;
	system.GetMostRecentMatchingFile = &GetMostRecentMatchingFile;
	system.TrackFileUpdates = &TrackFileUpdates;
	system.DidFileUpdate = &DidFileUpdate;
	system.WriteFile = &WriteFile;
	system.HasFocus = &HasFocus;

	//Center position of window
	uint16 fullScreenWidth = GetSystemMetrics( SM_CXSCREEN );
	uint16 fullScreenHeight = GetSystemMetrics( SM_CYSCREEN );
	uint16 windowPosX = ( fullScreenWidth / 2 ) - (system.windowWidth / 2 );
	uint16 windowPosY = ( fullScreenHeight / 2 ) - (system.windowHeight / 2 );

	WNDCLASSEX wc = { };
	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpszMenuName = NULL;
	wc.lpszClassName = WindowName;
	wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if( !RegisterClassEx( &wc ) ) {
		printf( "Failed to register class\n" );
		return -1;
	}

	EnableCrashingOnCrashes();
 
	// at this point WM_CREATE message is sent/received
	// the WM_CREATE branch inside WinProc function will execute here
	HWND hwnd = CreateWindowEx(
		0, 
		WindowName, 
		"Wet Clay App", 
		WS_BORDER, 
		windowPosX, 
		windowPosY, 
		system.windowWidth, 
		system.windowHeight,
		NULL, 
		NULL, 
		hInstance, 
		NULL
	);

	RECT windowRect = { };
	GetClientRect( hwnd, &windowRect );

	SetWindowLong( hwnd, GWL_STYLE, 0 );
	ShowWindow ( hwnd, SW_SHOWNORMAL );
	UpdateWindow( hwnd );

	LARGE_INTEGER timerResolution;
	BOOL canSupportHiResTimer = QueryPerformanceFrequency( &timerResolution );
	assert( canSupportHiResTimer );

	size_t systemsMemorySize = MEGABYTES( 8 );
	Stack gameSlab;
	gameSlab.size = SIZEOF_GLOBAL_HEAP + systemsMemorySize;
	gameSlab.start = VirtualAlloc( 
		NULL, 
		gameSlab.size, 
		MEM_COMMIT | MEM_RESERVE, 
		PAGE_EXECUTE_READWRITE 
	);
	gameSlab.current = gameSlab.start;
	assert( gameSlab.start != NULL );

	Stack systemsMemory = AllocateNewStackFromStack( &gameSlab, systemsMemorySize );

	InitWin32WorkerThread( &systemsMemory );

	GLRendererGlobalState glRendererStorage = { };
	globalGLRendererStorageRef = &glRendererStorage;
	GLRenderDriver glDriver = Win32InitGLRenderer( hwnd, &system, globalGLRendererStorageRef );
	Win32Sound win32Sound = Win32InitSound( hwnd, 60, &systemsMemory );

	void* imguistate = InitImGui_LimeStone(	&systemsMemory,	(RenderDriver*)&glDriver, system.windowWidth, system.windowHeight );

	printf( "Remaining System Memory: %Id\n", SPACE_IN_STACK( (&gameSlab) ) );

	LoadGameCode( &gameapp );
	assert( gameapp.GameInit != NULL );

	fileTracking = { };
	fileTracking.writeHead = &fileTracking.stringBuffer[0];

	int dllTrackingIndex = TrackFileUpdates( GAME_CODE_FILEPATH );
	assert( dllTrackingIndex != -1 );

	void* gameMemoryPtr = gameapp.GameInit( 
		&gameSlab, 
		(RenderDriver*)&glDriver,
		&win32Sound.driver,
		&system
	);

	appIsRunning = true;

	InputState inputSnapshot1 = { };
	InputState inputSnapshot2 = { };
	inputSnapshot1.prevState = &inputSnapshot2;
	inputSnapshot2.prevState = &inputSnapshot1;
	InputState* currentSnapshotStorage = &inputSnapshot1;

	MSG Msg;
	while( appIsRunning ) {
		if( DidFileUpdate( dllTrackingIndex ) ) {
			LoadGameCode( &gameapp );
		}

		static LARGE_INTEGER startTime;
		LARGE_INTEGER elapsedTime;
		LARGE_INTEGER lastTime = startTime;
		QueryPerformanceCounter( &startTime );

		elapsedTime.QuadPart = startTime.QuadPart - lastTime.QuadPart;
		elapsedTime.QuadPart *= 1000;
		elapsedTime.QuadPart /= timerResolution.QuadPart;

		//GAME LOOP
		if(	gameapp.UpdateAndRender != NULL && gameapp.MixSound != NULL ) {

			currentSnapshotStorage = currentSnapshotStorage->prevState;
		    QueryInput( 
		    	system.windowWidth, 
		    	system.windowHeight,
		    	windowPosX,
		    	windowPosY,
		    	currentSnapshotStorage
		    );
		    keypressHistoryIndex = 0;

		    UpdateImgui( currentSnapshotStorage, imguistate, system.windowWidth, system.windowHeight );

			appIsRunning = gameapp.UpdateAndRender( 
				gameMemoryPtr, 
				(float)elapsedTime.QuadPart, 
				currentSnapshotStorage,
				&win32Sound.driver,
				(RenderDriver*)&glDriver,
				&system,
				imguistate
			);

		    PushAudioToSoundCard( &gameapp, &win32Sound );

		    ImGui::Render();

			BOOL swapBufferSuccess = SwapBuffers( deviceContext );
			glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
		} else {
			printf( "Game code was not loaded...\n" );
		}

		//Windows Message pump is here, so if there is a system level Close or
		//Destory command, the UpdateAndRender method does not reset the appIsRunning
		//flag to true
		while( PeekMessage( &Msg, NULL, 0, 0, PM_REMOVE ) ) {
			TranslateMessage( &Msg );
			DispatchMessage( &Msg );
		}

		//End loop timer query
		LARGE_INTEGER endTime, computeTime;
		{
			QueryPerformanceCounter( &endTime );
			computeTime.QuadPart = endTime.QuadPart - startTime.QuadPart;
			computeTime.QuadPart *= 1000;
			computeTime.QuadPart /= timerResolution.QuadPart;
		}

		if( computeTime.QuadPart <= mSecsPerFrame ) {
			Sleep(mSecsPerFrame - computeTime.QuadPart );
		} else {
			printf("Didn't sleep, compute was %ld\n", computeTime.QuadPart );
		}
	};

	FreeConsole();

	return Msg.wParam;
}
// Used to update the tracking info to account for a change in the top-level menu
HRESULT CMenuFocusManager::UpdateFocus()
{
    HRESULT hr;
    StackEntry * old = m_current;

    TRACE("UpdateFocus\n");

    // Assign the new current item
    if (m_bandCount > 0)
        m_current = &(m_bandStack[m_bandCount - 1]);
    else
        m_current = NULL;

    // Remove the menu capture if necesary
    if (!m_current || m_current->type != MenuPopupEntry)
    {
        SetMenuCapture(NULL);
        if (old && old->type == MenuPopupEntry && m_PreviousForeground)
        {
            ::SetForegroundWindow(m_PreviousForeground);
            m_PreviousForeground = NULL;
        }
    }

    // Obtain the top-level window for the new active menu
    if (m_current && m_current->type != TrackedMenuEntry)
    {
        hr = m_current->mb->_GetTopLevelWindow(&(m_current->hwnd));
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;
    }

    // Refresh the parent pointer
    if (m_bandCount >= 2)
    {
        m_parent = &(m_bandStack[m_bandCount - 2]);
        _ASSERT(m_parent->type != TrackedMenuEntry);
    }
    else
    {
        m_parent = NULL;
    }

    // Refresh the menubar pointer, if applicable
    if (m_bandCount >= 1 && m_bandStack[0].type == MenuBarEntry)
    {
        m_menuBar = &(m_bandStack[0]);
    }
    else
    {
        m_menuBar = NULL;
    }

    // Remove the old hooks if the menu type changed, or we don't have a menu anymore
    if (old && (!m_current || old->type != m_current->type))
    {
        if (m_current && m_current->type != TrackedMenuEntry)
        {
            DisableMouseTrack(m_current->hwnd, FALSE);
        }

        hr = RemoveHooks();
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;
    }

    // And place new ones if necessary
    if (m_current && (!old || old->type != m_current->type))
    {
        hr = PlaceHooks();
        if (FAILED_UNEXPECTEDLY(hr))
            return hr;
    }

    // Give the user a chance to move the mouse to the new menu
    if (m_parent)
    {
        DisableMouseTrack(m_parent->hwnd, TRUE);
    }

    if (m_current && m_current->type == MenuPopupEntry)
    {
        if (m_captureHwnd == NULL)
        {
            // We need to restore the capture after a non-shell submenu or context menu is shown
            StackEntry * topMenu = m_bandStack;
            if (topMenu->type == MenuBarEntry)
                topMenu++;

            // Get the top-level window from the top popup
            CComPtr<IServiceProvider> bandSite;
            CComPtr<IOleWindow> deskBar;
            hr = topMenu->mb->GetSite(IID_PPV_ARG(IServiceProvider, &bandSite));
            hr = bandSite->QueryService(SID_SMenuPopup, IID_PPV_ARG(IOleWindow, &deskBar));

            CComPtr<IOleWindow> deskBarSite;
            hr = IUnknown_GetSite(deskBar, IID_PPV_ARG(IOleWindow, &deskBarSite));

            // FIXME: Find the correct place for this
            HWND hWndOwner;
            deskBarSite->GetWindow(&hWndOwner);

            m_PreviousForeground = ::GetForegroundWindow();
            if (m_PreviousForeground != hWndOwner)
                ::SetForegroundWindow(hWndOwner);
            else
                m_PreviousForeground = NULL;

            // Get the HWND of the top-level window
            HWND hWndSite;
            hr = deskBar->GetWindow(&hWndSite);
            SetMenuCapture(hWndSite);

        }

        if (!m_parent || m_parent->type == MenuBarEntry)
        {
            if (old && old->type == TrackedMenuEntry)
            {
                // FIXME: Debugging code, probably not right
                POINT pt2;
                RECT rc2;
                GetCursorPos(&pt2);
                ScreenToClient(m_current->hwnd, &pt2);
                GetClientRect(m_current->hwnd, &rc2);
                if (PtInRect(&rc2, pt2))
                    SendMessage(m_current->hwnd, WM_MOUSEMOVE, 0, MAKELPARAM(pt2.x, pt2.y));
                else
                    SendMessage(m_current->hwnd, WM_MOUSELEAVE, 0, 0);
            }
        }
    }

    _ASSERT(!m_parent || m_parent->type != TrackedMenuEntry);

    return S_OK;
}
Esempio n. 23
0
static  u32 win_proc(MSG *pMsg)
{
    HWND hwnd;
    HDC hdc;
    RECT rc,rc0;
    u32 i;

    hwnd =pMsg->hwnd;

    switch(pMsg->Code)
    {
        case    MSG_CREATE:


                GetClientRect(hwnd,&rc0);
                CreateWindow(BUTTON,"关闭",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,RectW(&rc0)-64,RectH(&rc0)-28,60,24,hwnd,ID_CLOSE,NULL);

                SetRect(&rc,4,8,120,100);
                hwndLB1=CreateWindow(LISTBOX,"列表框1",WS_CHILD|WS_BORDER|WS_VISIBLE,rc.left,rc.top,RectW(&rc),RectH(&rc),hwnd,ID_LISTBOX1,NULL);
                OffsetRect(&rc,RectW(&rc)+8,0);
                hwndLB2=CreateWindow(LISTBOX,"列表框2",WS_CHILD|WS_BORDER|WS_VISIBLE,rc.left,rc.top,RectW(&rc),RectH(&rc),hwnd,ID_LISTBOX2,NULL);

                GetWindowRect(hwndLB1,&rc);
                OffsetRect(&rc,0,RectH(&rc)+4);
                ScreenToClient(hwnd,(POINT*)&rc,2);
                CreateWindow(BUTTON,"-->",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,rc.right-50,rc.top,50,20,hwnd,ID_RIGHT,NULL);

                GetWindowRect(hwndLB2,&rc);
                OffsetRect(&rc,0,RectH(&rc)+4);
                ScreenToClient(hwnd,(POINT*)&rc,2);
                CreateWindow(BUTTON,"<--",WS_CHILD|BS_NORMAL|WS_BORDER|WS_VISIBLE,rc.left,rc.top,50,20,hwnd,ID_LEFT,NULL);


                SendMessage(hwndLB1,LBM_ADDSTRING,0,(u32)"ListItem-0");
                SendMessage(hwndLB1,LBM_ADDSTRING,1,(u32)"ListItem-1");
                SendMessage(hwndLB1,LBM_ADDSTRING,2,(u32)"ListItem-2");
                SendMessage(hwndLB1,LBM_ADDSTRING,3,(u32)"ListItem-3");
                SendMessage(hwndLB1,LBM_ADDSTRING,4,(u32)"ListItem-4");
                SendMessage(hwndLB1,LBM_ADDSTRING,5,(u32)"ListItem-5");
                SendMessage(hwndLB1,LBM_ADDSTRING,6,(u32)"ListItem-6");
                SendMessage(hwndLB1,LBM_ADDSTRING,7,(u32)"ListItem-7");
                SendMessage(hwndLB1,LBM_ADDSTRING,8,(u32)"ListItem-8");
                SendMessage(hwndLB1,LBM_ADDSTRING,9,(u32)"ListItem-9");
                SendMessage(hwndLB1,LBM_SETTOPINDEX,0,0);
                SendMessage(hwndLB1,LBM_SETCURSEL,3,0);

                SendMessage(hwndLB2,LBM_ADDSTRING,0,(u32)"ListItem-10");
                SendMessage(hwndLB2,LBM_ADDSTRING,1,(u32)"ListItem-11");
                SendMessage(hwndLB2,LBM_ADDSTRING,2,(u32)"ListItem-12");
                SendMessage(hwndLB2,LBM_ADDSTRING,3,(u32)"ListItem-13");
                SendMessage(hwndLB2,LBM_ADDSTRING,4,(u32)"ListItem-14");
                SendMessage(hwndLB2,LBM_ADDSTRING,5,(u32)"ListItem-15");
                SendMessage(hwndLB2,LBM_ADDSTRING,6,(u32)"ListItem-16");
                SendMessage(hwndLB2,LBM_ADDSTRING,7,(u32)"ListItem-17");
                SendMessage(hwndLB2,LBM_ADDSTRING,8,(u32)"ListItem-18");
                SendMessage(hwndLB2,LBM_ADDSTRING,9,(u32)"ListItem-19");
                SendMessage(hwndLB2,LBM_SETTOPINDEX,0,0);
                SendMessage(hwndLB2,LBM_SETCURSEL,3,0);

                GDD_CreateTimer(hwnd,1,3000,TMR_START);
                GDD_CreateTimer(hwnd,2,100,TMR_START);

                break;
                ////
        case    MSG_TIMER:
                {
                    switch(pMsg->Param1)
                    {
                        case    1:
                        		{

                        		}
                                break;
                                /////
                        case    2:
                                {

                                }
                                break;
                                /////
                    }
                }
                break;

        case    MSG_NOTIFY:
                {
                    u16 event,id;

                    event =HI16(pMsg->Param1);
                    id =LO16(pMsg->Param1);

                    if(event==BTN_UP && id==ID_CLOSE)
                    {
                    	PostMessage(hwnd,MSG_CLOSE,0,0);
                    }////


                    if(event==BTN_UP && id==ID_RIGHT)
                    {
                    	char *buf;
                    	int i;
                    	i =SendMessage(hwndLB1,LBM_GETCURSEL,0,0);

                    	if(i>=0)
                    	{
                    	     buf =(char*)malloc(SendMessage(hwndLB1,LBM_GETTEXTLEN,i,0));
                    	     if(buf!=NULL)
                    	     {
                    	         SendMessage(hwndLB1,LBM_GETTEXT,i,(u32)buf);
                    	         SendMessage(hwndLB1,LBM_DELSTRING,i,0);

                    	         SendMessage(hwndLB2,LBM_ADDSTRING,-1,(u32)buf);
                    	         i=SendMessage(hwndLB2,LBM_GETCOUNT,0,0)-1;
                    	         SendMessage(hwndLB2,LBM_SETTOPINDEX,i-3,0);
                    	         SendMessage(hwndLB2,LBM_SETCURSEL,-1,0);

                    	         free(buf);
                    	      }
                    	}
                    }////

                    if(event==BTN_UP && id==ID_LEFT)
                    {
                    	char *buf;
                        int i;
                        i =SendMessage(hwndLB2,LBM_GETCURSEL,0,0);
                        if(i>=0)
                        {
                    		buf =(char*)malloc(SendMessage(hwndLB2,LBM_GETTEXTLEN,i,0));
                    		if(buf!=NULL)
                    		{
                    			SendMessage(hwndLB2,LBM_GETTEXT,i,(u32)buf);
                    			SendMessage(hwndLB2,LBM_DELSTRING,i,0);

                    			SendMessage(hwndLB1,LBM_ADDSTRING,-1,(u32)buf);
                    			i=SendMessage(hwndLB1,LBM_GETCOUNT,0,0)-1;
                    			SendMessage(hwndLB1,LBM_SETTOPINDEX,i-3,0);
                    			SendMessage(hwndLB1,LBM_SETCURSEL,-1,0);

                    			free(buf);
                    		}
                         }
                    }////

                    if(event==LBN_SELCHANGE && id==ID_LISTBOX1)
                    {
                    	printf("listbox1 sel change.\r\n");
                    }////

                    if(event==LBN_SELCHANGE && id==ID_LISTBOX2)
                    {
                    	printf("listbox2 sel change.\r\n");
                    }////
                }
                break;
                ////

        case    MSG_PAINT:
                {
                    hdc =BeginPaint(hwnd);

                    GetClientRect(hwnd,&rc0);
                    SetFillColor(hdc,RGB(200,200,200));
                    FillRect(hdc,&rc0);

                    EndPaint(hwnd,hdc);

                }
                break;
                ////

        default:
                return  DefWindowProc(pMsg);


    }
    return  0;
}
Esempio n. 24
0
static VOID
InitUserGroupsList(HWND hwndDlg)
{
    HWND hwndLV;
    LV_COLUMN column;
    RECT rect;
    TCHAR szStr[32];

    NET_API_STATUS netStatus;
    PLOCALGROUP_INFO_1 pBuffer;
    DWORD entriesread;
    DWORD totalentries;
    DWORD_PTR resume_handle = 0;
    DWORD i;
    LV_ITEM lvi;
    INT iItem;

    HIMAGELIST hImgList;
    HICON hIcon;

    hwndLV = GetDlgItem(hwndDlg, IDC_USER_ADD_MEMBERSHIP_LIST);
    GetClientRect(hwndLV, &rect);

    hImgList = ImageList_Create(16,16,ILC_COLOR8 | ILC_MASK,5,5);
    hIcon = LoadImage(hApplet,MAKEINTRESOURCE(IDI_GROUP),IMAGE_ICON,16,16,LR_DEFAULTCOLOR);
    ImageList_AddIcon(hImgList,hIcon);
    DestroyIcon(hIcon);

    (void)ListView_SetImageList(hwndLV, hImgList, LVSIL_SMALL);
    (void)ListView_SetExtendedListViewStyle(hwndLV, LVS_EX_FULLROWSELECT);

    memset(&column, 0x00, sizeof(column));
    column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT;
    column.fmt = LVCFMT_LEFT;
    column.cx = (INT)((rect.right - rect.left) * 0.40);
    column.iSubItem = 0;
    LoadString(hApplet, IDS_NAME, szStr, sizeof(szStr) / sizeof(szStr[0]));
    column.pszText = szStr;
    (void)ListView_InsertColumn(hwndLV, 0, &column);

    column.cx = (INT)((rect.right - rect.left) * 0.60);
    column.iSubItem = 1;
    LoadString(hApplet, IDS_DESCRIPTION, szStr, sizeof(szStr) / sizeof(szStr[0]));
    column.pszText = szStr;
    (void)ListView_InsertColumn(hwndLV, 1, &column);

    for (;;)
    {
        netStatus = NetLocalGroupEnum(NULL, 1, (LPBYTE*)&pBuffer,
                                      1024, &entriesread,
                                      &totalentries, &resume_handle);
        if (netStatus != NERR_Success && netStatus != ERROR_MORE_DATA)
            break;

        for (i = 0; i < entriesread; i++)
        {
           memset(&lvi, 0x00, sizeof(lvi));
           lvi.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
           lvi.pszText = pBuffer[i].lgrpi1_name;
           lvi.state = 0;
           lvi.iImage = 0;
           iItem = ListView_InsertItem(hwndLV, &lvi);

           ListView_SetItemText(hwndLV, iItem, 1,
                                pBuffer[i].lgrpi1_comment);
        }

        NetApiBufferFree(pBuffer);

        /* No more data left */
        if (netStatus != ERROR_MORE_DATA)
            break;
    }
}
Esempio n. 25
0
void CPropTreeList::OnLButtonDown(UINT, CPoint point) 
{
	ASSERT(m_pProp!=NULL);

	if (m_pProp->IsDisableInput())
		return;

	m_pProp->SendNotify(NM_CLICK);

	if (!m_pProp->IsWindowEnabled())
		return;

	SetFocus();

	LONG nHit = m_pProp->HitTest(point);

	CPropTreeItem* pItem;
	CRect rc;
	CDC* pDC;

	switch (nHit)
	{
		case HTCOLUMN:
			if (m_pProp->SendNotify(PTN_COLUMNCLICK))
				break;

			m_bColDrag = TRUE;
			SetCapture();

			m_nPrevCol = m_pProp->GetOrigin().x;

			// paint drag line
			pDC = GetDC();
			GetClientRect(rc);
			pDC->PatBlt(m_nPrevCol - PROPTREEITEM_COLRNG/2, 0, PROPTREEITEM_COLRNG, rc.bottom, PATINVERT);
			ReleaseDC(pDC);
			break;

		case HTCHECKBOX:
			if ((pItem = m_pProp->FindItem(point))!=NULL)
			{
				pItem->Check(!pItem->IsChecked());
				m_pProp->SendNotify(PTN_CHECKCLICK, pItem);
				Invalidate();
			}
			break;
		case HTBUTTON:
			if ((pItem = m_pProp->FindItem(point))!=NULL)
			{
				pItem->Check();
				m_pProp->SendNotify(PTN_ITEMBUTTONCLICK, pItem);
				Invalidate();
			}
			break;
		case HTEXPAND:
			if ((pItem = m_pProp->FindItem(point))!=NULL)
			{
				if (pItem->GetChild() && !m_pProp->SendNotify(PTN_ITEMEXPANDING, pItem))
				{
					pItem->Expand(!pItem->IsExpanded());

					UpdateResize();
					Invalidate();
					UpdateWindow();
					CheckVisibleFocus();
				}
			}
			break;

		default:
			if ((pItem = m_pProp->FindItem(point))!=NULL)
			{
				CPropTreeItem* pOldFocus = m_pProp->GetFocusedItem();

				m_pProp->SelectItems(NULL, FALSE);
				m_pProp->SetFocusedItem(pItem);

				pItem->Select();

				Invalidate();

				if (pItem!=pOldFocus)
					m_pProp->SendNotify(PTN_SELCHANGE, pItem);

				if (nHit==HTATTRIBUTE && !pItem->IsRootLevel())
				{
					if (!m_pProp->SendNotify(PTN_PROPCLICK, pItem) && !pItem->IsReadOnly())
						pItem->Activate(CPropTreeItem::ACTIVATE_TYPE_MOUSE, point);
				}
			}
			else
			{
				m_pProp->SelectItems(NULL, FALSE);
				m_pProp->SetFocusedItem(NULL);
				m_pProp->SendNotify(PTN_SELCHANGE);
				Invalidate();
			}
			break;
	}
}
Esempio n. 26
0
// Все параметры могут быть NULL - вызов из GuiMacro
bool CConEmuCtrl::key_ShowTabsList(DWORD VkMod, bool TestOnly, const ConEmuHotKey* hk, CRealConsole* pRCon)
{
	// 120820 - не будем требовать наличия плагина для F12 в Far
	if (pRCon && pRCon->GetFarPID(false))
	{
		// Для Far Manager - не обрабатывать.
		// Если юзеру нужно ConEmu-шное меню для списка табов - есть vkShowTabsList2 и GuiMacro "Tabs(8)"
		return false;
	}
	else
	{
		if (TestOnly)
			return true;

		//HMENU hPopup = gpConEmu->CreateVConListPopupMenu(NULL, FALSE);

		RECT rcWnd = {};
		if (pRCon)
		{
			GetWindowRect(pRCon->GetView(), &rcWnd);
		}
		else
		{
			GetClientRect(ghWnd, &rcWnd);
			MapWindowPoints(ghWnd, NULL, (LPPOINT)&rcWnd, 2);
		}

		POINT pt = {(rcWnd.left+rcWnd.right)/2, (rcWnd.top+rcWnd.bottom)/2};

		ChooseTabFromMenu(FALSE, pt, TPM_CENTERALIGN|TPM_VCENTERALIGN);

		//int nTab = gpConEmu->trackPopupMenu(tmp_TabsList, hPopup, TPM_CENTERALIGN|TPM_VCENTERALIGN|TPM_RETURNCMD,
		//	x, y, 0, ghWnd, NULL);
		//if (nTab >= IDM_VCON_FIRST && nTab <= IDM_VCON_LAST)
		//{
		//	int nNewV = ((int)HIWORD(nTab))-1;
		//	int nNewR = ((int)LOWORD(nTab))-1;
		//	
		//	CVirtualConsole* pVCon = gpConEmu->GetVCon(nNewV);
		//	if (pVCon)
		//	{
		//		CRealConsole* pRCon = pVCon->RCon();
		//		if (pRCon)
		//		{
		//			pRCon->ActivateFarWindow(nNewR);
		//		}
		//		if (!gpConEmu->isActive(pVCon))
		//			gpConEmu->Activate(pVCon);
		//	}
		//}

		//CESERVER_REQ_GETALLTABS::TabInfo* pTabs = NULL;
		//int Count = (int)CConEmuCtrl::GetOpenedTabs(pTabs);
		//if ((Count < 1) || !pTabs)
		//{
		//	SafeFree(pTabs);
		//	return false;
		//}

		//WARNING("должна быть подобная функция для DropDown у тулбара");
		//HMENU hPopup = CreatePopupMenu();

		//int nLastConsole = 0;
		//for (int i = 0, k = 0; i < Count; i++, k++)
		//{
		//	if (nLastConsole != pTabs[i].ConsoleIdx)
		//	{
		//		AppendMenu(hPopup, MIF_SEPARATOR, 0, NULL);
		//		nLastConsole = pTabs[i].ConsoleIdx;
		//	}
		//	DWORD nFlags = 0
		//		| (pTabs[i].Disabled ? (MF_GRAYED|MF_DISABLED) : MF_ENABLED)
		//		| 
		//	pItems[k].Selected = (pOut->GetAllTabs.Tabs[i].ActiveConsole && pOut->GetAllTabs.Tabs[i].ActiveTab);
		//	pItems[k].Checked = pOut->GetAllTabs.Tabs[i].ActiveTab;
		//	pItems[k].Disabled = pOut->GetAllTabs.Tabs[i].Disabled;
		//	pItems[k].MsgText = pOut->GetAllTabs.Tabs[i].Title;
		//	pItems[k].UserData = i;
		//}
		//DestroyMenu(hPopup);
	}

	//int AllCount = Count + pTabs[Count-1].ConsoleIdx;
	//if (pItems)
	//{
	//}

	return true;
}
Esempio n. 27
0
/*------------------------------------------------
  paint StartMenu (BaseBar) of IE 4 or later
--------------------------------------------------*/
void OnPaintStartmenuIE4(HWND hwnd, HDC hdc, BOOL bPrint)
{
	RECT rc, rcWin, rcChild;
	POINT pt;
	COLORREF col;
	HBRUSH hbr;
	BITMAP bmp;
	int hClient, wClient;
	
	GetWindowRect(GetWindow(hwnd, GW_CHILD), &rcChild);
	GetWindowRect(hwnd, &rcWin);
	GetClientRect(hwnd, &rc);
	pt.x = 0; pt.y = 0;
	ClientToScreen(hwnd, &pt);
	if(pt.x == rcChild.left) return;
	
	rc.right = 21;
	wClient = rc.right; hClient = rc.bottom;
	if(bPrint)
	{
		int dx, dy;
		dx = pt.x - rcWin.left; dy = pt.y - rcWin.top;
		rc.left += dx; rc.right += dx;
		rc.top += dy; rc.bottom += dy;
	}
	
	// fill with color
	col = m_colMenu;
	if(col & 0x80000000) col = GetSysColor(col & 0x00ffffff);
	hbr = CreateSolidBrush(col);
	FillRect(hdc, &rc, hbr);
	DeleteObject(hbr);
	
	// draw bitmap
	if(m_hbmpMenu)
	{
		int i, j;
		GetObject(m_hbmpMenu, sizeof(BITMAP), &bmp);
		
		for(i = 0; ; i++)
		{
			int y, ysrc, h, x, w;
			for(j = 0; ; j++)
			{
				y = hClient - ((i + 1) * bmp.bmHeight);
				ysrc = 0;
				h = bmp.bmHeight;
				if(y < 0)
				{
					y = 0;
					ysrc = ((i + 1) * bmp.bmHeight) - hClient;
					h -= ysrc;
				}
				x = j * bmp.bmWidth; w = bmp.bmWidth;
				if(x + w > wClient)
				{
					w -= ((j + 1) * bmp.bmWidth) - wClient;
				}
				if(w > 0 && h > 0)
					BitBlt(hdc, rc.left + x, rc.top + y, w, h,
						m_hdcMemMenu, 0, ysrc, SRCCOPY);
				if(!m_bTile || w < bmp.bmWidth) break;
			}
			if(!m_bTile || y == 0) break;
		}
	}
}
Esempio n. 28
0
void HandleGLSceneUpdate(HDC hDC)
{
    if(!bTargetAcquired && hdcAcquiredDC == NULL)
    {
        logOutput << CurrentTimeString() << "setting up gl data" << endl;
        PIXELFORMATDESCRIPTOR pfd;

        hwndTarget = WindowFromDC(hDC);

        int pixFormat = GetPixelFormat(hDC);
        DescribePixelFormat(hDC, pixFormat, sizeof(pfd), &pfd);

        if(pfd.cColorBits == 32 && hwndTarget)
        {
            bTargetAcquired = true;
            hdcAcquiredDC = hDC;
            glcaptureInfo.format = GS_BGR;
        }

        OSInitializeTimer();
    }

    if(hDC == hdcAcquiredDC)
    {
        if(bCapturing && WaitForSingleObject(hSignalEnd, 0) == WAIT_OBJECT_0)
            bStopRequested = true;

        if(bCapturing && !IsWindow(hwndOBS))
        {
            hwndOBS = NULL;
            bStopRequested = true;
        }

        if(bCapturing && bStopRequested)
        {
            RUNEVERYRESET logOutput << CurrentTimeString() << "stop requested, terminating gl capture" << endl;

            ClearGLData();
            bCapturing = false;
            bStopRequested = false;
            bReacquiring = false;
        }

        if(!bCapturing && WaitForSingleObject(hSignalRestart, 0) == WAIT_OBJECT_0)
        {
            hwndOBS = FindWindow(OBS_WINDOW_CLASS, NULL);
            if(hwndOBS)
                bCapturing = true;
        }

        RECT rc;
        GetClientRect(hwndTarget, &rc);

        if(bCapturing && bReacquiring)
        {
            if(lastCX != rc.right || lastCY != rc.bottom) //reset if continuing to size within the 3 seconds
            {
                reacquireStart = OSGetTimeMicroseconds();
                lastCX = rc.right;
                lastCY = rc.bottom;
            }

            if(OSGetTimeMicroseconds()-reacquireTime >= 3000000) { //3 second to reacquire
                RUNEVERYRESET logOutput << CurrentTimeString() << "reacquiring gl due to resize..." << endl;
                bReacquiring = false;
            } else {
                return;
            }
        }

        if(bCapturing && (!bHasTextures || rc.right != glcaptureInfo.cx || rc.bottom != glcaptureInfo.cy))
        {
            if (!rc.right || !rc.bottom)
                return;

            if(bHasTextures) //resizing
            {
                ClearGLData();
                bReacquiring = true;
                reacquireStart = OSGetTimeMicroseconds();
                lastCX = rc.right;
                lastCY = rc.bottom;
                return;
            }
            else
            {
                if(hwndOBS)
                    DoGLCPUHook(rc);
                else
                    ClearGLData();
            }
        }

        LONGLONG timeVal = OSGetTimeMicroseconds();

        //check keep alive state, dumb but effective
        if(bCapturing)
        {
            if (!keepAliveTime)
                keepAliveTime = timeVal;

            if((timeVal-keepAliveTime) > 5000000)
            {
                HANDLE hKeepAlive = OpenEvent(EVENT_ALL_ACCESS, FALSE, strKeepAlive.c_str());
                if (hKeepAlive) {
                    CloseHandle(hKeepAlive);
                } else {
                    ClearGLData();
                    logOutput << CurrentTimeString() << "Keepalive no longer found on gl, freeing capture data" << endl;
                    bCapturing = false;
                }

                keepAliveTime = timeVal;
            }
        }

        if(bHasTextures)
        {
            LONGLONG frameTime;
            if(bCapturing)
            {
                if(copyData)
                {
                    if(frameTime = copyData->frameTime)
                    {
                        LONGLONG timeElapsed = timeVal-lastTime;

                        if(timeElapsed >= frameTime)
                        {
                            lastTime += frameTime;
                            if(timeElapsed > frameTime*2)
                                lastTime = timeVal;

                            GLuint texture = gltextures[curCapture];
                            DWORD nextCapture = (curCapture == NUM_BUFFERS-1) ? 0 : (curCapture+1);

                            glReadBuffer(GL_BACK);
                            glBindBuffer(GL_PIXEL_PACK_BUFFER, texture);

                            if(glLockedTextures[curCapture])
                            {
                                OSEnterMutex(glDataMutexes[curCapture]);

                                glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
                                glLockedTextures[curCapture] = false;

                                OSLeaveMutex(glDataMutexes[curCapture]);
                            }

                            glReadPixels(0, 0, glcaptureInfo.cx, glcaptureInfo.cy, GL_BGRA, GL_UNSIGNED_BYTE, 0);

                            //----------------------------------

                            glBindBuffer(GL_PIXEL_PACK_BUFFER, gltextures[nextCapture]);
                            pCopyData = (void*)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
                            if(pCopyData)
                            {
                                curCPUTexture = nextCapture;
                                glLockedTextures[nextCapture] = true;

                                RUNEVERYRESET logOutput << CurrentTimeString() << "successfully capturing gl frames via RAM" << endl;

                                SetEvent(hCopyEvent);
                            } else {
                                RUNEVERYRESET logOutput << CurrentTimeString() << "one or more gl frames failed to capture for some reason" << endl;
                            }

                            //----------------------------------

                            glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);

                            curCapture = nextCapture;
                        }
                    }
                }
            }
            else {
                RUNEVERYRESET logOutput << CurrentTimeString() << "no longer capturing, terminating gl capture" << endl;
                ClearGLData();
            }
        }
    }
}
Esempio n. 29
0
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message){
	    case WM_DESTROY:
			PostQuitMessage(0);
			return 0;
	    case WM_CLOSE:
			mplayer_put_key(KEY_CLOSE_WIN);
			break;
		case WM_WINDOWPOSCHANGED:
           {
                int tmpheight=0;
                /*calculate new window rect*/
                 if(!vo_fs){
                 RECT rd;
                 POINT point_window;
                 if(!hWnd)hWnd=hwnd;
                 ShowCursor(TRUE);
                 point_window.x = 0;
                 point_window.y = 0;
                 ClientToScreen(hWnd,&point_window);
                 GetClientRect(hWnd,&rd);

                 vo_dwidth=rd.right - rd.left;
                 vo_dheight=rd.bottom - rd.top;
                 vo_dx =point_window.x;
                 vo_dy =point_window.y;
          //       aspect(&vo_dwidth, &vo_dheight, A_NOZOOM);

                 /* keep aspect on resize, borrowed from vo_directx.c */
                 tmpheight = ((float)vo_dwidth/window_aspect);
                 tmpheight += tmpheight % 2;
                 if(tmpheight > vo_dheight)
                 {
                     vo_dwidth = ((float)vo_dheight*window_aspect);
                     vo_dwidth += vo_dwidth % 2;
                 }
                 else vo_dheight = tmpheight;
                 rd.right = rd.left + vo_dwidth;
                 rd.bottom = rd.top + vo_dheight;

                 if(rd.left < 0) rd.left = 0;
                 if(rd.right > vo_screenwidth) rd.right = vo_screenwidth;
                 if(rd.top < 0) rd.top = 0;
                 if(rd.bottom > vo_screenheight) rd.bottom = vo_screenheight;

                 AdjustWindowRect(&rd, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, 0);
                 SetWindowPos(hWnd, HWND_TOPMOST, vo_dx+rd.left, vo_dy+rd.top, rd.right-rd.left, rd.bottom-rd.top, SWP_NOOWNERZORDER);
               }
               else {
                 if(ShowCursor(FALSE)>=0)while(ShowCursor(FALSE)>=0){}
                 aspect(&vo_dwidth, &vo_dheight, A_ZOOM);
                 vo_dx = (vo_screenwidth - vo_dwidth)/2;
                 vo_dy = (vo_screenheight - vo_dheight)/2;
               }
               /*update vidix*/
               /* FIXME: implement runtime resize/move if possible, this way is very ugly! */
	           vidix_stop();
	           if(vidix_init(image_width, image_height, vo_dx, vo_dy, vo_dwidth, vo_dheight, image_format, vo_depthonscreen, vo_screenwidth, vo_screenheight) != 0)
	               mp_msg(MSGT_VO, MSGL_FATAL, "Can't initialize VIDIX driver: %s\n", strerror(errno));
               /*set colorkey*/
               vidix_start();
               mp_msg(MSGT_VO, MSGL_V, "[winvidix] window properties: pos: %dx%d, size: %dx%d\n",vo_dx, vo_dy, vo_dwidth, vo_dheight);
               if(vidix_grkey_support()){
                 vidix_grkey_get(&gr_key);
	             gr_key.key_op = KEYS_PUT;
	             gr_key.ckey.op = CKEY_TRUE;
	             if(vo_fs)gr_key.ckey.red = gr_key.ckey.green = gr_key.ckey.blue = 0;
                 else {
                   gr_key.ckey.red = gr_key.ckey.blue = 255;
                   gr_key.ckey.green = 0;
	             }
                 vidix_grkey_set(&gr_key);
               }

           }
           break;
        case WM_SYSCOMMAND:
	        switch (wParam){
                case SC_SCREENSAVE:
		        case SC_MONITORPOWER:
                    return 0;
			 }
             break;
        case WM_KEYDOWN:
			switch (wParam){
				case VK_LEFT:
					{mplayer_put_key(KEY_LEFT);break;}
                case VK_UP:
					{mplayer_put_key(KEY_UP);break;}
                case VK_RIGHT:
					{mplayer_put_key(KEY_RIGHT);break;}
	            case VK_DOWN:
					{mplayer_put_key(KEY_DOWN);break;}
	            case VK_TAB:
					{mplayer_put_key(KEY_TAB);break;}
		        case VK_CONTROL:
					{mplayer_put_key(KEY_CTRL);break;}
		        case VK_DELETE:
					{mplayer_put_key(KEY_DELETE);break;}
		        case VK_INSERT:
					{mplayer_put_key(KEY_INSERT);break;}
		        case VK_HOME:
					{mplayer_put_key(KEY_HOME);break;}
		        case VK_END:
					{mplayer_put_key(KEY_END);break;}
		        case VK_PRIOR:
			        {mplayer_put_key(KEY_PAGE_UP);break;}
		        case VK_NEXT:
			        {mplayer_put_key(KEY_PAGE_DOWN);break;}
		        case VK_ESCAPE:
					{mplayer_put_key(KEY_ESC);break;}
			}
            break;
        case WM_CHAR:
			mplayer_put_key(wParam);
			break;
    }
	return DefWindowProc(hwnd, message, wParam, lParam);
}
Esempio n. 30
-1
/**
 * name:	Button_WndProc
 * desc:	window procedure for the button class
 * param:	hwndBtn		- window handle to the button
 *			uMsg		- message to handle
 *			wParam		- message specific parameter
 *			lParam		- message specific parameter
 * return:	message specific
 **/
static LRESULT CALLBACK Button_WndProc(HWND hwndBtn, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	LPBTNCTRL bct = (LPBTNCTRL)GetWindowLongPtr(hwndBtn, 0);
	
	switch (uMsg) {
	case WM_NCCREATE:
		{
			LPCREATESTRUCT cs = (LPCREATESTRUCT)lParam;

			cs->style |= BS_OWNERDRAW;
			if (!(bct = (LPBTNCTRL)mir_alloc(sizeof(BTNCTRL))))
				return FALSE;
			ZeroMemory(bct, sizeof(BTNCTRL));
			bct->hwnd = hwndBtn;
			bct->stateId = PBS_NORMAL;
			bct->hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
			bct->dwStyle = cs->style;
			if (cs->style & MBS_DOWNARROW)
				bct->arrow = Skin_GetIcon(ICO_BTN_DOWNARROW);
			LoadTheme(bct);
			SetWindowLongPtr(hwndBtn, 0, (LONG_PTR)bct);
			if (cs->lpszName) SetWindowText(hwndBtn, cs->lpszName);
			return TRUE;
		}
	case WM_DESTROY:
		if (bct) {
			EnterCriticalSection(&csTips);
			if (hwndToolTips) {
				TOOLINFO ti;

				ZeroMemory(&ti, sizeof(ti));
				ti.cbSize = sizeof(ti);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) {
					SendMessage(hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
				}
				if (SendMessage(hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0) {
					DestroyWindow(hwndToolTips);
					hwndToolTips = NULL;
				}
			}
			LeaveCriticalSection(&csTips);
			DestroyTheme(bct);
			mir_free(bct);
		}
		SetWindowLongPtr(hwndBtn, 0, NULL);
		break;
	case WM_SETTEXT:
		bct->cHot = 0;
		if ((LPTSTR)lParam) {
			LPTSTR tmp = (LPTSTR)lParam;

			while (*tmp) {
				if (*tmp == '&' && *(tmp + 1)) {
					bct->cHot = _totlower(*(tmp + 1));
					break;
				}
				tmp++;
			}
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_SYSKEYUP:
		if (bct->stateId != PBS_DISABLED && bct->cHot && bct->cHot == _totlower((TCHAR)wParam)) {
			if (bct->dwStyle & MBS_PUSHBUTTON) {
				if (bct->pbState) bct->pbState = 0;
				else bct->pbState = 1;
				InvalidateRect(bct->hwnd, NULL, TRUE);
			}
			else
				SetFocus(hwndBtn);
			SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn);
			return 0;
		}
		break;
	case WM_THEMECHANGED: 
		// themed changed, reload theme object
		LoadTheme(bct);
		InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
		break;
	case WM_SETFONT: // remember the font so we can use it later
		bct->hFont = (HFONT)wParam; // maybe we should redraw?
		break;
	case WM_NCPAINT:
	case WM_PAINT:
		{
			PAINTSTRUCT ps;
			HDC hdcPaint;
			HDC hdcMem;
			HBITMAP hbmMem;
			HDC hOld;
			RECT rcClient;
			
			if (hdcPaint = BeginPaint(hwndBtn, &ps)) {
				GetClientRect(bct->hwnd, &rcClient);
				hdcMem = CreateCompatibleDC(hdcPaint);
				hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);
				hOld = (HDC)SelectObject(hdcMem, hbmMem);

				// If its a push button, check to see if it should stay pressed
				if ((bct->dwStyle & MBS_PUSHBUTTON) && bct->pbState) bct->stateId = PBS_PRESSED;

				if ((bct->dwStyle & MBS_FLAT) && bct->hThemeToolbar || bct->hThemeButton)
					PaintThemeButton(bct, hdcMem, &rcClient);
				else
					PaintButton(bct, hdcMem, &rcClient);

				BitBlt(hdcPaint, 0, 0, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top, hdcMem, 0, 0, SRCCOPY);
				SelectObject(hdcMem, hOld);
				DeleteObject(hbmMem);
				DeleteDC(hdcMem);				
				EndPaint(hwndBtn, &ps);
			}
		}
		return 0;
	case BM_SETIMAGE:
		if (wParam == IMAGE_ICON) {
			bct->hIcon = (HICON)lParam;
			bct->hBitmap = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		else if (wParam == IMAGE_BITMAP) {
			bct->hIcon = NULL;
			bct->hBitmap = (HBITMAP)lParam;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		else if (wParam == NULL && lParam == NULL) {
			bct->hIcon = NULL;
			bct->hBitmap = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case BM_SETCHECK:
		if (!(bct->dwStyle & MBS_PUSHBUTTON)) break;
		if (wParam == BST_CHECKED) {
			bct->pbState = 1;
			bct->stateId = PBS_PRESSED;
		}
		else if (wParam == BST_UNCHECKED) {
			bct->pbState = 0;
			bct->stateId = PBS_NORMAL;
		}
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BM_GETCHECK:
		if (bct->dwStyle & MBS_PUSHBUTTON) return bct->pbState ? BST_CHECKED : BST_UNCHECKED;
		return 0;
	case BUTTONSETDEFAULT:
		bct->defbutton = (wParam != 0);
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONADDTOOLTIP:
		if (wParam) {			
			EnterCriticalSection(&csTips);
			if (!hwndToolTips)
				hwndToolTips = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP, 0, 0, 0, 0, NULL, NULL, GetModuleHandle(NULL), NULL);

			if (lParam == MBBF_UNICODE) {
				TOOLINFOW ti;

				ZeroMemory(&ti, sizeof(TOOLINFOW));
				ti.cbSize = sizeof(TOOLINFOW);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(hwndToolTips, TTM_GETTOOLINFOW, 0, (LPARAM)&ti)) {
					SendMessage(hwndToolTips, TTM_DELTOOLW, 0, (LPARAM)&ti);
				}
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
				ti.uId = (UINT_PTR)bct->hwnd;
				ti.lpszText=(LPWSTR)wParam;
				SendMessage(hwndToolTips, TTM_ADDTOOLW, 0, (LPARAM)&ti);
			}
			else {
				TOOLINFOA ti;

				ZeroMemory(&ti, sizeof(TOOLINFOA));
				ti.cbSize = sizeof(TOOLINFOA);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(hwndToolTips, TTM_GETTOOLINFOA, 0, (LPARAM)&ti)) {
					SendMessage(hwndToolTips, TTM_DELTOOLA, 0, (LPARAM)&ti);
				}
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
				ti.uId = (UINT_PTR)bct->hwnd;
				ti.lpszText=(LPSTR)wParam;
				SendMessage(hwndToolTips, TTM_ADDTOOLA, 0, (LPARAM)&ti);
			}
			LeaveCriticalSection(&csTips);
		}
		break;
	case BUTTONTRANSLATE:
		{
			TCHAR szButton[MAX_PATH];
			GetWindowText(bct->hwnd, szButton, MAX_PATH);
			SetWindowText(bct->hwnd, TranslateTS(szButton));
		}
		break;
	case WM_SETFOCUS: // set keybord bFocus and redraw
		bct->bFocus = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_KILLFOCUS: // kill bFocus and redraw
		bct->bFocus = 0;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_WINDOWPOSCHANGED:
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_ENABLE: // windows tells us to enable/disable
		bct->stateId = wParam ? PBS_NORMAL : PBS_DISABLED;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case WM_MOUSELEAVE: // faked by the WM_TIMER
		if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_NORMAL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_LBUTTONDOWN:
		if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_PRESSED;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_LBUTTONUP:
		if (bct->stateId != PBS_DISABLED) { // don't change states if disabled
			BYTE bPressed = bct->stateId == PBS_PRESSED;

			if (bct->dwStyle & MBS_PUSHBUTTON) {
				if (bct->pbState) bct->pbState = 0;
				else bct->pbState = 1;
			}
			bct->stateId = PBS_HOT;

			// Tell your daddy you got clicked, if mouse is still over the button.
			if ((bct->dwStyle & MBS_PUSHBUTTON) || bPressed)
				SendMessage(GetParent(hwndBtn), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndBtn), BN_CLICKED), (LPARAM)hwndBtn);
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;
	case WM_MOUSEMOVE:
		if (bct->stateId == PBS_NORMAL) {
			bct->stateId = PBS_HOT;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		// Call timer, used to start cheesy TrackMouseEvent faker
		SetTimer(hwndBtn, BUTTON_POLLID, BUTTON_POLLDELAY, NULL);
		break;
	case WM_TIMER: // use a timer to check if they have did a mouseout
		if (wParam == BUTTON_POLLID) {
			RECT rc;
			POINT pt;

			GetWindowRect(hwndBtn, &rc);
			GetCursorPos(&pt);
			if (!PtInRect(&rc, pt)) { // mouse must be gone, trigger mouse leave
				PostMessage(hwndBtn, WM_MOUSELEAVE, 0, 0L);
				KillTimer(hwndBtn, BUTTON_POLLID);
			}
		}
		break;
	case WM_ERASEBKGND:
		return 1;
	}
	return DefWindowProc(hwndBtn, uMsg, wParam, lParam);
}