Пример #1
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT Message,
	WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	LPDCB lpDCB = &cc.dcb;
	static int  cxClient,cyClient;
	PAINTSTRUCT ps;
	static int iVertPos = 0;
	SCROLLINFO si;
	char buffer[128] = {0};
	DWORD bytesRead;
	DWORD bytesWritten;
	//OVERLAPPED ov = {0,0,0};
	std::fstream ifs;
	OPENFILENAME ofn;
	static TCHAR szFilter[] = TEXT ("All Files (*.*)\0*.*\0\0") ;
	static TCHAR szFileName[MAX_PATH], szTitleName[MAX_PATH] ;
	char packet[1024];
	char packet2[2];

	if (cxClient && cyClient) {
		/*text_area.left = 0;
		text_area.top = 0;
		text_area.right = cxClient;
		text_area.bottom = cyClient;
		areaset = true;*/
		topright.left = cxClient - cxClient/3 + 1;
		topright.top = 1;
		topright.right = cxClient;
		topright.bottom = cyClient - cyClient/3 - 1;
		topleft.left = 1;
		topleft.top = 1;
		topleft.right = cxClient - cxClient/3 - 1;
		topleft.bottom = cyClient - cyClient/3 - 1;
	}

	switch (Message)
	{
	case WM_CREATE:
		ov.Offset = 0;
		ov.OffsetHigh = 0;
		ov.Pointer = 0;
		ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

		global.hSem = (HANDLE*)malloc(sizeof(HANDLE));
		*global.hSem = CreateSemaphore(NULL, 0, 1, NULL);

		//global.hSem = &semm;

		global.ofs.open("file.txt");
		global.ofs.close();
		break;
	case WM_COMMAND:
		switch (LOWORD (wParam))
		{
		case IDM_COM1:
			cc.dwSize = sizeof(COMMCONFIG);
			cc.wVersion = 0x100;

			if (!CommConfigDialog (lpszCommName1, hwnd, &cc))
				break;
			else {
				comset = true;
				curCom = 1;
			}
			break;
		case IDM_COM2:
			cc.dwSize = sizeof(COMMCONFIG);
			cc.wVersion = 0x100;

			if (!CommConfigDialog (lpszCommName2, hwnd, &cc))
				break;
			else {
				comset = true;
				curCom = 2;
			}
			break;
		case IDM_COM3:
			cc.dwSize = sizeof(COMMCONFIG);
			cc.wVersion = 0x100;

			if (!CommConfigDialog (lpszCommName3, hwnd, &cc))
				break;
			else {
				comset = true;
				curCom = 3;
			}
			break;
		case IDM_COM4:
			cc.dwSize = sizeof(COMMCONFIG);
			cc.wVersion = 0x100;

			if (!CommConfigDialog (lpszCommName4, hwnd, &cc)) {
				break;
			}else {
				comset = true;
				curCom = 4;
			}
			break;
		case IDM_Connect:
			//WaitForSingleObject(ov.hEvent, INFINITE);
			//MessageBox(hwnd, TEXT(""), TEXT(""), MB_OK);
			if (comset) {
				if (curCom == 1) {
					if ((hComm = CreateFile (lpszCommName1, GENERIC_READ | GENERIC_WRITE, 0,
						NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))
						== INVALID_HANDLE_VALUE)
					{
						MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK);
						return FALSE;
					}
				} else if (curCom == 2) {
					if ((hComm = CreateFile (lpszCommName2, GENERIC_READ | GENERIC_WRITE, 0,
						NULL, OPEN_EXISTING, NULL, NULL))
						== INVALID_HANDLE_VALUE)
					{
						MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK);
						return FALSE;
					}
				} else if (curCom == 3) {
					if ((hComm = CreateFile (lpszCommName3, GENERIC_READ | GENERIC_WRITE, 0,
						NULL, OPEN_EXISTING, NULL, NULL))
						== INVALID_HANDLE_VALUE)
					{
						MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK);
						return FALSE;
					}
				} else if (curCom == 4) {
					if ((hComm = CreateFile (lpszCommName4, GENERIC_READ | GENERIC_WRITE, 0,
						NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))
						== INVALID_HANDLE_VALUE)
					{
						MessageBox (NULL, TEXT("Error opening COM port:"), TEXT(""), MB_OK);
						return FALSE;
					}
				}
				lpDCB = &cc.dcb;

				if (!SetCommState(hComm, lpDCB)) {
					MessageBox (NULL, TEXT("Error setting COM state"), TEXT(""), MB_OK);
					return false;
				}

				COMMTIMEOUTS timeouts;

				timeouts.ReadIntervalTimeout = MAXDWORD; 
				timeouts.ReadTotalTimeoutMultiplier	= 0;
				timeouts.ReadTotalTimeoutConstant = 0;
				timeouts.WriteTotalTimeoutMultiplier = 0;
				timeouts.WriteTotalTimeoutConstant = 0;

				if (!SetCommTimeouts(hComm, &timeouts)) {
					MessageBox (NULL, TEXT("Error setting COM timeouts"), TEXT(""), MB_OK);
					return false;
				}
				if (hComm) {
					global.hComm = &hComm;
					//global.ov = ov;
					//opThrd = CreateThread(NULL, 0, OutputThread, (LPVOID)hwnd, 0, &opThrdID );
					recvThread = CreateThread(NULL, 0, receiverThread, &global, NULL, &opThrdID);
					MessageBox(NULL, TEXT("connected"), TEXT(""), MB_OK);
				} else {
					MessageBox(NULL, TEXT("Please select a COM port."), TEXT(""), MB_OK);
				}
			} else {
				MessageBox(NULL, TEXT("Please select a COM port."), TEXT(""), MB_OK);
			}

			break;
		case IDM_Disconnect: //kills the reading thread and closes the com port if they are active
			if (KillReader == false && hComm) {
				KillReader = true;
				CloseHandle(hComm);
				MessageBox(NULL, TEXT("disconnected"), TEXT(""), MB_OK);
			}
			break;
		case IDM_OpenFile:

			ofn.lStructSize       = sizeof (OPENFILENAME) ;
			ofn.hwndOwner         = hwnd ;
			ofn.hInstance         = NULL ;
			ofn.lpstrFilter       = szFilter ;
			ofn.lpstrCustomFilter = NULL ;
			ofn.nMaxCustFilter    = 0 ;
			ofn.nFilterIndex      = 0 ;
			ofn.lpstrFile         = NULL ;          // Set in Open and Close functions
			ofn.nMaxFile          = MAX_PATH ;
			ofn.lpstrFileTitle    = NULL ;          // Set in Open and Close functions
			ofn.nMaxFileTitle     = MAX_PATH ;
			ofn.lpstrInitialDir   = NULL ;
			ofn.lpstrTitle        = NULL ;
			ofn.Flags             = 0 ;             // Set in Open and Close functions
			ofn.nFileOffset       = 0 ;
			ofn.nFileExtension    = 0 ;
			ofn.lpstrDefExt       = TEXT ("txt") ;
			ofn.lCustData         = 0L ;
			ofn.lpfnHook          = NULL ;
			ofn.lpTemplateName    = NULL ;

			ofn.hwndOwner         = hwnd ;
			ofn.lpstrFile         = szFileName ;
			ofn.lpstrFileTitle    = szTitleName ;
			ofn.Flags             = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;

			if (GetOpenFileName(&ofn)) {

				std::wstring wfilename(szFileName);
				std::string filename;

				for(int i = 0; i < wfilename.size(); i++) {
					filename += wfilename[i];
				}

				ifs = OpenFile(filename);

				readFile(ifs);

				DWORD threadID;
				DWORD exitStatus;

				if (sendThread == 0 || (GetExitCodeThread(sendThread, &exitStatus) && exitStatus != STILL_ACTIVE)) {
					sendThread = CreateThread(NULL, 0, sendBufferThread, &global, NULL, &threadID);
				}

			}
		}
		break;
	case WM_CHAR:	// Process keystroke
		break;
	case WM_LBUTTONDOWN:
		break;
	case WM_SIZE:
		cxClient = LOWORD(lParam);
		cyClient = HIWORD(lParam);

		si.cbSize = sizeof(si);
		si.fMask = SIF_ALL;
		si.nMin = 0;
		si.nMax = cyClient;
		si.nPos = 0;
		si.nPage = 50;
		SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
		break;
	case WM_VSCROLL:

		si.cbSize = sizeof(si);
		si.fMask = SIF_ALL;
		GetScrollInfo(hwnd, SB_VERT, &si);
		iVertPos = si.nPos;

		switch(LOWORD(wParam)){

		case SB_LINEUP:
			si.nPos -= 10;
			break;

		case SB_LINEDOWN:
			si.nPos += 10;
			break;

		case SB_PAGEUP:
			si.nPos -= si.nPage;
			break;

		case SB_PAGEDOWN:
			si.nPos += si.nPage;
			break;

		case SB_THUMBTRACK:
			si.nPos = si.nTrackPos;
			break;

		default:
			break;
		}

		si.fMask = SIF_POS;
		SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
		GetScrollInfo(hwnd, SB_VERT, &si);

		//if there was change in the vertical scroll bar, make adjustments to redraw
		if (si.nPos != iVertPos){
			//InvalidateRect(hwnd, &text_area, TRUE);
		}
		break;
	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);
		MoveToEx(hdc, cxClient - cxClient/3, 0, NULL);
		LineTo(hdc, cxClient - cxClient/3, cyClient);
		MoveToEx(hdc, 0, cyClient - cyClient/3, NULL);
		LineTo(hdc, cxClient, cyClient - cyClient/3);
		DisplayStatistics(topright, stats, hdc);
		DisplayReceivedFileData(topleft, lines, hdc);
		ReleaseDC(hwnd, hdc);
		break;
	case WM_DESTROY:	// Terminate program
		if (hComm) {
			//CloseHandle(hComm);
		}
		PostQuitMessage (0);
		break;
	default:
		return DefWindowProc (hwnd, Message, wParam, lParam);
	}
	return 0;
}
Пример #2
0
LRESULT CFilePreviewCtrl::OnHScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    SCROLLINFO info;
    int nHScrollInc = 0;
    int  nOldHScrollPos = m_nHScrollPos;

    switch (LOWORD(wParam))
    {
    case SB_LEFT:
        m_nHScrollPos = 0;
        break;

    case SB_RIGHT:
        m_nHScrollPos = m_nHScrollMax + 1;
        break;

    case SB_LINELEFT:
        if(m_nHScrollPos > 0) --m_nHScrollPos;
        break;

    case SB_LINERIGHT:
        m_nHScrollPos++;
        break;

    case SB_PAGELEFT:
        m_nHScrollPos -= m_nMaxColsPerPage;
        if(m_nHScrollPos > nOldHScrollPos)
            m_nHScrollPos = 0;
        break;

    case SB_PAGERIGHT:
        m_nHScrollPos += m_nMaxColsPerPage;
        break;

    case SB_THUMBPOSITION:
        info.cbSize = sizeof(SCROLLINFO);
        info.fMask = SIF_TRACKPOS;
        GetScrollInfo(SB_HORZ, &info);
        m_nHScrollPos = info.nTrackPos;
        break;

    case SB_THUMBTRACK:
        info.cbSize = sizeof(SCROLLINFO);
        info.fMask = SIF_TRACKPOS;
        GetScrollInfo(SB_HORZ, &info);
        m_nHScrollPos = info.nTrackPos;
        break;

    default:
        nHScrollInc = 0;
    }

    //keep scroll position in range
    if(m_nHScrollPos  > m_nHScrollMax - m_nMaxColsPerPage + 1)
        m_nHScrollPos = m_nHScrollMax - m_nMaxColsPerPage + 1;

    nHScrollInc = m_nHScrollPos - nOldHScrollPos;

    if (nHScrollInc)
    {

        //finally setup the actual scrollbar!
        info.cbSize = sizeof(SCROLLINFO);
        info.fMask = SIF_POS;
        info.nPos = m_nHScrollPos;
        SetScrollInfo(SB_HORZ, &info, TRUE);

        InvalidateRect(NULL);
    }

    return 0;
}
Пример #3
0
LRESULT CFilePreviewCtrl::OnVScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    // React to the various vertical scroll related actions.
    // CAUTION:
    // All sizes are in unsigned values, so be carefull
    // when testing for < 0 etc

    SCROLLINFO info;
    int nVScrollInc;
    int  nOldVScrollPos = m_nVScrollPos;

    switch (LOWORD(wParam))
    {
    case SB_TOP:
        m_nVScrollPos = 0;
        break;

    case SB_BOTTOM:
        m_nVScrollPos = m_nVScrollMax - m_nMaxLinesPerPage + 1;
        break;

    case SB_LINEUP:
        if(m_nVScrollPos > 0) --m_nVScrollPos;
        break;

    case SB_LINEDOWN:
        m_nVScrollPos++;
        break;

    case SB_PAGEUP:
        m_nVScrollPos -= max(1, m_nMaxLinesPerPage);
        if(m_nVScrollPos > nOldVScrollPos) m_nVScrollPos = 0;
        break;

    case SB_PAGEDOWN:
        m_nVScrollPos += max(1, m_nMaxLinesPerPage);
        break;

    case SB_THUMBPOSITION:
        info.cbSize = sizeof(SCROLLINFO);
        info.fMask = SIF_TRACKPOS;
        GetScrollInfo(SB_VERT, &info);
        m_nVScrollPos = info.nTrackPos;
        break;

    case SB_THUMBTRACK:
        info.cbSize = sizeof(SCROLLINFO);
        info.fMask = SIF_TRACKPOS;
        GetScrollInfo(SB_VERT, &info);
        m_nVScrollPos = info.nTrackPos;
        break;

    default:
        nVScrollInc = 0;
    }

    //keep scroll position in range
    if(m_nVScrollPos > m_nVScrollMax - m_nMaxLinesPerPage+1)
        m_nVScrollPos = m_nVScrollMax - m_nMaxLinesPerPage+1;

    if(m_nVScrollPos<0)
        m_nVScrollPos = 0;

    nVScrollInc = m_nVScrollPos - nOldVScrollPos;

    if (nVScrollInc)
    {

        //finally setup the actual scrollbar!
        info.cbSize = sizeof(SCROLLINFO);
        info.fMask = SIF_POS;
        info.nPos = m_nVScrollPos;
        SetScrollInfo(SB_VERT, &info, TRUE);

        InvalidateRect(NULL);
    }

    return 0;
}
Пример #4
0
LRESULT CView::OnWindowPosChanged(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(uMsg);
	UNREFERENCED_PARAMETER(wParam);
	UNREFERENCED_PARAMETER(lParam);

	if (m_pPicture)
	{
		CRect rcImage = GetImageRect();
		DWORD dwStyle = (DWORD)GetWindowLongPtr(GWL_STYLE);
		DWORD dwExStyle = (DWORD)GetWindowLongPtr(GWL_EXSTYLE);
		AdjustWindowRectEx(&rcImage, dwStyle, FALSE, dwExStyle);

		CRect rcView = GetClientRect();
		AdjustWindowRectEx(&rcView, dwStyle, FALSE, dwExStyle);

		SCROLLINFO si;
		ZeroMemory(&si, sizeof(SCROLLINFO));
		si.cbSize = sizeof(si);
		si.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
		si.nMin   = 0;

		if (rcView.Width()  >= rcImage.Width())
		{
			m_xCurrentScroll = 0;
			ShowScrollBar(SB_HORZ, FALSE);
		}
		else
		{
			si.nMax   = rcImage.Width();
			si.nPage  = rcView.Width();
			si.nPos   = m_xCurrentScroll;
			SetScrollInfo(SB_HORZ, si, TRUE);
			ShowScrollBar(SB_HORZ, TRUE);
		}

		if (rcView.Height() >= rcImage.Height())
		{
			m_yCurrentScroll = 0;
			ShowScrollBar(SB_VERT, FALSE);
		}
		else
		{
			si.nMax   = rcImage.Height();
			si.nPage  = rcView.Height();
			si.nPos   = m_yCurrentScroll;
			SetScrollInfo(SB_VERT, si, TRUE);
			ShowScrollBar(SB_VERT, TRUE);
		}

		int xNewPos = MIN(m_xCurrentScroll, rcImage.Width() - rcView.Width());
		m_xCurrentScroll = MAX(xNewPos, 0);
		int yNewPos = MIN(m_yCurrentScroll, rcImage.Height() - rcView.Height());
		m_yCurrentScroll = MAX(yNewPos, 0);

		// Paint the window directly to eliminate flicker
		CClientDC dcView(*this);
		Paint(dcView);
	}

	return 0L;
}
Пример #5
0
/**
 * @param nScrollBarType - scrollbar type.
 * @param nScrollCode - scroll code.
 */
void CImageView::ScrollImageView(int nScrollBarType, int nScrollCode)
{
	_ASSERTE(nScrollBarType == SB_HORZ || nScrollBarType == SB_VERT);

	SCROLLINFO sinfo;
	ZeroMemory(&sinfo, sizeof(sinfo));
	sinfo.cbSize = sizeof(sinfo);
	sinfo.fMask = SIF_POS | SIF_PAGE | SIF_RANGE;
	if (nScrollCode == SB_THUMBTRACK)
		sinfo.fMask |= SIF_TRACKPOS;
	GetScrollInfo(m_hwnd, nScrollBarType, &sinfo);
	int nOldPos = sinfo.nPos;

	int nLineOffset = LOWORD(GetDialogBaseUnits());

	switch (nScrollCode)
	{
	case SB_LINEUP:
	//case SB_LINELEFT:
		sinfo.nPos -= nLineOffset;
		break;
	case SB_LINEDOWN:
	//case SB_LINERIGHT:
		sinfo.nPos += nLineOffset;
		break;
	case SB_PAGEUP:
	//case SB_PAGELEFT:
		sinfo.nPos -= sinfo.nPage;
		break;
	case SB_PAGEDOWN:
	//case SB_PAGERIGHT:
		sinfo.nPos += sinfo.nPage;
		break;
	case SB_THUMBTRACK:
		sinfo.nPos = sinfo.nTrackPos;
		break;
	case SB_TOP:
	//case SB_LEFT:
		sinfo.nPos = 0;
		break;
	case SB_BOTTOM:
	//case SB_RIGHT:
		sinfo.nPos = sinfo.nMax;
		break;
	default:
		return;
	}
	ValidateScrollInfo(&sinfo);
	sinfo.fMask = SIF_POS;
	SetScrollInfo(m_hwnd, nScrollBarType, &sinfo, TRUE);

	if (sinfo.nPos != nOldPos)
	{
		int nHorOffset, nVertOffset;
		if (nScrollBarType == SB_HORZ)
		{
			nHorOffset = nOldPos - sinfo.nPos;
			nVertOffset = 0;
		}
		else
		{
			nHorOffset = 0;
			nVertOffset = nOldPos - sinfo.nPos;
		}

		RECT rcClient;
		GetClientRect(m_hwnd, &rcClient);
		// Explicitly clip output to override style CS_PARENTDC.
		ScrollWindowEx(m_hwnd, nHorOffset, nVertOffset, &rcClient, &rcClient, NULL, NULL, SW_INVALIDATE);
		UpdateWindow(m_hwnd);
	}
}
Пример #6
0
Bool
winCreateBoundingWindowWindowed (ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  int			iWidth = pScreenInfo->dwUserWidth;
  int			iHeight = pScreenInfo->dwUserHeight;
  HWND			*phwnd = &pScreenPriv->hwndScreen;
  WNDCLASS		wc;
  RECT			rcClient, rcWorkArea;
  DWORD			dwWindowStyle;

#ifdef NXWIN_LOGO
  HANDLE nxIcon;

  nxIcon = LoadImage( GetModuleHandle(NULL),
                     MAKEINTRESOURCE(IDI_ICON2),
                     IMAGE_ICON,
                                         16,
                                         16,
                                         /*
                     GetSystemMetrics(SM_CXICON),
                     GetSystemMetrics(SM_CYICON),
                                         */
                     0
                    );

  if(nxIcon == NULL)
  {
     ErrorF ("cannot load icon\n");
  }

#endif

  

  ErrorF ("winCreateBoundingWindowWindowed - User w: %d h: %d\n",
	  pScreenInfo->dwUserWidth, pScreenInfo->dwUserHeight);
  ErrorF ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n",
	  pScreenInfo->dwWidth, pScreenInfo->dwHeight);
  /* Set the common window style flags */
  dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;

  /* Decorated or undecorated window */
  if (pScreenInfo->fDecoration
      && !pScreenInfo->fRootless
      && !pScreenInfo->fMultiWindow)
    {
      dwWindowStyle |= WS_CAPTION;
      if (pScreenInfo->fScrollbars)
	dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
    }
  else
    dwWindowStyle |= WS_POPUP;

  /* Setup our window class */
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = winWindowProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = g_hInstance;
#ifdef NXWIN_LOGO
  wc.hIcon = nxIcon;
#else
  wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
#endif
  wc.hCursor = 0;
  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = WINDOW_CLASS;
  RegisterClass (&wc);

  /* Get size of work area */
  winGetWorkArea (&rcWorkArea, pScreenInfo);

  /* Adjust for auto-hide taskbars */
  winAdjustForAutoHide (&rcWorkArea);

  /* Did the user specify a height and width? */
  if (pScreenInfo->fUserGaveHeightAndWidth)
    {
      /* User gave a desired height and width, try to accomodate */
#if CYGDEBUG
      ErrorF ("winCreateBoundingWindowWindowed - User gave height "
	      "and width\n");
#endif

      /* Adjust the window width and height for borders and title bar */
      if (pScreenInfo->fDecoration
	  && !pScreenInfo->fRootless
	  && !pScreenInfo->fMultiWindow)
	{
#if CYGDEBUG
	  ErrorF ("winCreateBoundingWindowWindowed - Window has decoration\n");
#endif
	  /* Are we using scrollbars? */
	  if (pScreenInfo->fScrollbars)
	    {
#if CYGDEBUG
	      ErrorF ("winCreateBoundingWindowWindowed - Window has "
		      "scrollbars\n");
#endif

	      iWidth += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
	      iHeight += 2 * GetSystemMetrics (SM_CYSIZEFRAME)
		+ GetSystemMetrics (SM_CYCAPTION);
	    }
	  else
	    {
#if CYGDEBUG
	      ErrorF ("winCreateBoundingWindowWindowed - Window does not have "
		      "scrollbars\n");
#endif

	      iWidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME);
	      iHeight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME)
		+ GetSystemMetrics (SM_CYCAPTION);
	    }
	}
      else
	{
	  /*
	   * User gave a width and height but also said no decoration.
	   * In this case we have to ignore the requested width and height
	   * and instead use the largest possible window that we can.
	   */
	  if (pScreenInfo->fMultipleMonitors)
	    {
	      iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
	      iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
	    }
	  else
	    {
	      iWidth = GetSystemMetrics (SM_CXSCREEN);
	      iHeight = GetSystemMetrics (SM_CYSCREEN);
	    }
	}
    }
  else
    {
      /* By default, we are creating a window that is as large as possible */
#if CYGDEBUG
      ErrorF ("winCreateBoundingWindowWindowed - User did not give "
	      "height and width\n");
#endif
      /* Defaults are wrong if we have multiple monitors */
      if (pScreenInfo->fMultipleMonitors)
	{
	  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
	  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
	}
    }

  /* Clean up the scrollbars flag, if necessary */
  if ((!pScreenInfo->fDecoration
       || pScreenInfo->fRootless
       || pScreenInfo->fMultiWindow)
      && pScreenInfo->fScrollbars)
    {
      /* We cannot have scrollbars if we do not have a window border */
      pScreenInfo->fScrollbars = FALSE;
    }

  /* Trim window width to fit work area */
  if (iWidth > (rcWorkArea.right - rcWorkArea.left))
    iWidth = rcWorkArea.right - rcWorkArea.left;

  /* Trim window height to fit work area */
  if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
    iHeight = rcWorkArea.bottom - rcWorkArea.top;

#if CYGDEBUG
  ErrorF ("winCreateBoundingWindowWindowed - Adjusted width: %d "\
	  "height: %d\n",
	  iWidth, iHeight);
#endif

  /* Create the window */
  *phwnd = CreateWindowExA (0,			/* Extended styles */
			    WINDOW_CLASS,	/* Class name */
			    WINDOW_TITLE,	/* Window name */
			    dwWindowStyle
#ifdef NXWIN_ICONIC
                                | (nxwinIconicMode?WS_ICONIC:0)
#endif
                                ,
			    rcWorkArea.left,	/* Horizontal position */
			    rcWorkArea.top,	/* Vertical position */
			    iWidth,		/* Right edge */
			    iHeight,		/* Bottom edge */
			    (HWND) NULL,	/* No parent or owner window */
			    (HMENU) NULL,	/* No menu */
			    GetModuleHandle (NULL),/* Instance handle */
			    pScreenPriv);	/* ScreenPrivates */
  if (*phwnd == NULL)
    {
      ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
      return FALSE;
    }

#if CYGDEBUG
  ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
#endif

  /* Get the client area coordinates */
  if (!GetClientRect (*phwnd, &rcClient))
    {
      ErrorF ("winCreateBoundingWindowWindowed - GetClientRect () "
	      "failed\n");
      return FALSE;
    }

  ErrorF ("winCreateBoundingWindowWindowed - WindowClient "
	  "w %ld h %ld r %ld l %ld b %ld t %ld\n",
	  rcClient.right - rcClient.left,
	  rcClient.bottom - rcClient.top,
	  rcClient.right, rcClient.left,
	  rcClient.bottom, rcClient.top);

  /* We adjust the visual size if the user did not specify it */
  if (!(pScreenInfo->fScrollbars && pScreenInfo->fUserGaveHeightAndWidth))
    {
      /*
       * User did not give a height and width with scrollbars enabled,
       * so we will resize the underlying visual to be as large as
       * the initial view port (page size).  This way scrollbars will
       * not appear until the user shrinks the window, if they ever do.
       *
       * NOTE: We have to store the viewport size here because
       * the user may have an autohide taskbar, which would
       * cause the viewport size to be one less in one dimension
       * than the viewport size that we calculated by subtracting
       * the size of the borders and caption.
       */
      pScreenInfo->dwWidth = rcClient.right - rcClient.left;
      pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
    }

#if 0
  /*
   * NOTE: For the uninitiated, the page size is the number of pixels
   * that we can display in the x or y direction at a time and the
   * range is the total number of pixels in the x or y direction that we
   * have available to display.  In other words, the page size is the
   * size of the window area minus the space the caption, borders, and
   * scrollbars (if any) occupy, and the range is the size of the
   * underlying X visual.  Notice that, contrary to what some of the
   * MSDN Library arcticles lead you to believe, the windows
   * ``client area'' size does not include the scrollbars.  In other words,
   * the whole client area size that is reported to you is drawable by
   * you; you do not have to subtract the size of the scrollbars from
   * the client area size, and if you did it would result in the size
   * of the scrollbars being double counted.
   */

  /* Setup scrollbar page and range, if scrollbars are enabled */
  if (pScreenInfo->fScrollbars)
    {
      SCROLLINFO		si;

      /* Initialize the scrollbar info structure */
      si.cbSize = sizeof (si);
      si.fMask = SIF_RANGE | SIF_PAGE;
      si.nMin = 0;

      /* Setup the width range and page size */
      si.nMax = pScreenInfo->dwWidth - 1;
      si.nPage = rcClient.right - rcClient.left;
      ErrorF ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n",
	      si.nMax, si.nPage);
      SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE);

      /* Setup the height range and page size */
      si.nMax = pScreenInfo->dwHeight - 1;
      si.nPage = rcClient.bottom - rcClient.top;
      ErrorF ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n",
	      si.nMax, si.nPage);
      SetScrollInfo (*phwnd, SB_VERT, &si, TRUE);
    }
#endif

  /* Show the window */
  if (pScreenInfo->fMultiWindow)
    ShowWindow (*phwnd, nxwinHideStart?SW_HIDE:SW_SHOWMINNOACTIVE);
  else
    ShowWindow (*phwnd, nxwinHideStart?SW_HIDE:SW_SHOWNORMAL);

  SetWindowText(*phwnd, nxwinWinName);

 /* if (!UpdateWindow (*phwnd))
    {
      ErrorF ("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
      return FALSE;
    }

   Attempt to bring our window to the top of the display 
  if (!BringWindowToTop (*phwnd))
    {
      ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () "
	      "failed\n");
      return FALSE;
    }
    */

  /* Paint window background blue */
  if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
    winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF));

  ErrorF ("winCreateBoundingWindowWindowed -  Returning\n");

  return TRUE;
}
Пример #7
0
BOOL NEAR TV_CalcScrollBars(PTREE pTree)
{
    // UINT wMaxPos;
    BOOL fChange = FALSE;
    SCROLLINFO si;

    si.cbSize = sizeof(SCROLLINFO);

    if ((SHORT)pTree->cxMax > (SHORT)pTree->cxWnd)
    {
        if (!pTree->fHorz)
        {
            fChange = TRUE;
            pTree->fHorz = TRUE;
        }

        si.fMask = SIF_PAGE | SIF_RANGE;
        si.nMin = 0;
        si.nMax = pTree->cxMax - 1;
        si.nPage = pTree->cxWnd;

        TV_SetLeft(pTree, (UINT)SetScrollInfo(pTree->ci.hwnd, SB_HORZ, &si, TRUE));
    }
    else if (pTree->fHorz)
    {
        TV_SetLeft(pTree, 0);
        SetScrollRange(pTree->ci.hwnd, SB_HORZ, 0, 0, TRUE);

        pTree->fHorz = FALSE;
        fChange = TRUE;
    }

    if (pTree->cShowing > pTree->cFullVisible)
    {
        if (!pTree->fVert)
        {
            pTree->fVert = TRUE;
            fChange = TRUE;
        }

        si.fMask = SIF_PAGE | SIF_RANGE;
        si.nMin = 0;
        si.nMax = pTree->cShowing - 1;
        si.nPage = pTree->cFullVisible;

        TV_SetTopItem(pTree, (UINT)SetScrollInfo(pTree->ci.hwnd, SB_VERT, &si, TRUE));

    }
    else if (pTree->fVert)
    {
        TV_SetTopItem(pTree, 0);
        SetScrollRange(pTree->ci.hwnd, SB_VERT, 0, 0, TRUE);

        pTree->fVert = FALSE;
        fChange = TRUE;
    }

    if (fChange)
        TV_SizeWnd(pTree, 0, 0);

    return(TRUE);
}
Пример #8
0
void outwnd_paint(HWND hwnd)
{
	int i, n, x, y, len;
	int old_nrows, scroll_pos;
	HDC hdc;
	PAINTSTRUCT ps;	
	RECT client;
	TEXTMETRIC tm;
	HFONT newfont, oldfont;
	HBRUSH newbrush, oldbrush;

	Outwnd_changed = 0;

	hdc = BeginPaint(hwnd, &ps);
	GetClientRect(hOutputWnd, &client);
	newfont = (HFONT)GetStockObject(ANSI_FIXED_FONT);
	oldfont = (HFONT)SelectObject(hdc,newfont);
	
	GetTextMetrics(hdc, &tm);
	nTextHeight = tm.tmHeight + tm.tmExternalLeading;
	nTextWidth = tm.tmAveCharWidth;
	old_nrows = nCharRows;
	nCharRows = ((client.bottom-client.top)/nTextHeight)+1;

	newbrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
	oldbrush = (HBRUSH)SelectObject(hdc,newbrush);
	
	y = client.bottom - nTextHeight * nCharRows;  // starting y position at top
	client_top_yoffset = y - nTextHeight;
	scroll_pos = (max_scroll_pos - GetScrollPos( hOutputWnd, SB_VERT ));
	cur_line_index = x = mprintf_last_line - scroll_pos - nCharRows;
	if (x >= marked_top && x < marked_bottom)  // starting in marked area
		text_hilight(hdc);
	else
		text_normal(hdc);
	if (scroll_pos != old_scroll_pos) {
		if (!scroll_pos)	{
			char tmp[1024];
			sprintf( tmp, "Debug Spew");
			SetWindowText( hOutputWnd, tmp );

		} else {
			char tmp[1024];
			sprintf( tmp, "Debug Spew [Scrolled back %d lines]", scroll_pos );
			SetWindowText( hOutputWnd, tmp );
		}

		old_scroll_pos = scroll_pos;
	}

	i = nCharRows;
	while (i--)
	{
		n = mprintf_last_line - scroll_pos - i;
		if (n < 0)
			n += SCROLL_BUFFER_SIZE;
	
		if (n >= 0 && n < SCROLL_BUFFER_SIZE)
		{
			len = strlen(outtext[n]);
			if (marked)
			{
				if (n == marked_top && n == marked_bottom)  // special 1 line case
				{
					if (marked_left)
						TextOut(hdc, 0, y, outtext[n], marked_left);

					text_hilight(hdc);
					x = marked_left * nTextWidth;
					TextOut(hdc, x, y, outtext[n] + marked_left, marked_right -
						marked_left);

					text_normal(hdc);
					x = marked_right * nTextWidth;
					if (marked_right < len)
						TextOut(hdc, x, y, outtext[n] + marked_right, len - marked_right);

					x = len * nTextWidth;
					TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len);

				} else if (n == marked_top)	{  // start marked on this line
					if (marked_left)
						TextOut(hdc, 0, y, outtext[n], marked_left);

					text_hilight(hdc);
					x = marked_left * nTextWidth;

					TextOut(hdc, x, y, outtext[n] + marked_left, len - marked_left);

					x = len * nTextWidth;
					if (marked_left < MAX_LINE_WIDTH)
						TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - marked_left);

				} else if (n == marked_bottom)	{  // end marked on this line
					if (marked_right)
						TextOut(hdc, 0, y, outtext[n], marked_right);

					text_normal(hdc);
					x = marked_right * nTextWidth;
					if (marked_right < len)
						TextOut(hdc, x, y, outtext[n] + marked_right, len - marked_right);

					x = len * nTextWidth;
					TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len);

				} else	{  // whole line marked
					TextOut(hdc, 0, y, outtext[n], len);
					x = len * nTextWidth;
					TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len);
				}

			} else {
				TextOut(hdc, 0, y, outtext[n], len);
				x = len * nTextWidth;
				TextOut(hdc, x, y, spaces, MAX_LINE_WIDTH - len);
			}
		} else
			TextOut(hdc, 0, y, spaces, MAX_LINE_WIDTH);

		y += nTextHeight;
	}

	text_normal(hdc);
	SelectObject(hdc, oldfont);
	SelectObject(hdc, oldbrush);
	DeleteObject(newbrush);

	if ( old_nrows != nCharRows )	{
		SCROLLINFO si;
		max_scroll_pos = SCROLL_BUFFER_SIZE-nCharRows - 1;
		si.cbSize = sizeof(SCROLLINFO);
		si.fMask = SIF_RANGE;
		si.nMin = 0;
		si.nMax = max_scroll_pos;
		SetScrollInfo(hwnd, SB_VERT, &si, 1 );
	}

	EndPaint(hwnd, &ps);

}
Пример #9
0
Bool
winCreateBoundingWindowWindowed (ScreenPtr pScreen)
{
  winScreenPriv(pScreen);
  winScreenInfo		*pScreenInfo = pScreenPriv->pScreenInfo;
  int			iWidth = pScreenInfo->dwUserWidth;
  int			iHeight = pScreenInfo->dwUserHeight;
  int                   iPosX;
  int                   iPosY;
  HWND			*phwnd = &pScreenPriv->hwndScreen;
  WNDCLASSEX		wc;
  RECT			rcClient, rcWorkArea;
  DWORD			dwWindowStyle;
  BOOL			fForceShowWindow = FALSE;
  char			szTitle[256];
  
  winDebug ("winCreateBoundingWindowWindowed - User w: %d h: %d\n",
	  (int) pScreenInfo->dwUserWidth, (int) pScreenInfo->dwUserHeight);
  winDebug ("winCreateBoundingWindowWindowed - Current w: %d h: %d\n",
	  (int) pScreenInfo->dwWidth, (int) pScreenInfo->dwHeight);

  /* Set the common window style flags */
  dwWindowStyle = WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX;
  
  /* Decorated or undecorated window */
  if (pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
      && !pScreenInfo->fMWExtWM
#endif
      && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
      && !pScreenInfo->fMultiWindow
#endif
      )
    {
        /* Try to handle startup via run.exe. run.exe instructs Windows to 
         * hide all created windows. Detect this case and make sure the 
         * window is shown nevertheless */
        STARTUPINFO   startupInfo;
        GetStartupInfo(&startupInfo);
        if (startupInfo.dwFlags & STARTF_USESHOWWINDOW && 
                startupInfo.wShowWindow == SW_HIDE)
        {
          fForceShowWindow = TRUE;
        } 
        dwWindowStyle |= WS_CAPTION;
        if (pScreenInfo->iResizeMode != notAllowed)
            dwWindowStyle |= WS_THICKFRAME | WS_MAXIMIZEBOX;
    }
  else
    dwWindowStyle |= WS_POPUP;

  /* Setup our window class */
  wc.cbSize=sizeof(WNDCLASSEX);
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = winWindowProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = g_hInstance;
  wc.hIcon = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
		GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0);
  wc.hCursor = 0;
  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = WINDOW_CLASS;
  wc.hIconSm = (HICON)LoadImage (g_hInstance, MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
		GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTSIZE);
  RegisterClassEx (&wc);

  /* Get size of work area */
  winGetWorkArea (&rcWorkArea, pScreenInfo);

  /* Adjust for auto-hide taskbars */
  winAdjustForAutoHide (&rcWorkArea);

  /* Did the user specify a position? */
  if (pScreenInfo->fUserGavePosition)
    {
      iPosX = pScreenInfo->dwInitialX;
      iPosY = pScreenInfo->dwInitialY;
    }
  else
    {
      iPosX = rcWorkArea.left;
      iPosY = rcWorkArea.top;
    }

  /* Clean up the scrollbars flag, if necessary */
  if ((!pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
       || pScreenInfo->fMWExtWM
#endif
       || pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
       || pScreenInfo->fMultiWindow
#endif
       )
      && (pScreenInfo->iResizeMode == resizeWithScrollbars))
    {
      /* We cannot have scrollbars if we do not have a window border */
      pScreenInfo->iResizeMode = notAllowed;
    }

  /* Did the user specify a height and width? */
  if (pScreenInfo->fUserGaveHeightAndWidth)
    {
      /* User gave a desired height and width, try to accomodate */
#if CYGDEBUG
      winDebug ("winCreateBoundingWindowWindowed - User gave height "
	      "and width\n");
#endif
      
      /* Adjust the window width and height for borders and title bar */
      if (pScreenInfo->fDecoration
#ifdef XWIN_MULTIWINDOWEXTWM
	  && !pScreenInfo->fMWExtWM
#endif
	  && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
	  && !pScreenInfo->fMultiWindow
#endif
	  )
	{
#if CYGDEBUG
	  winDebug ("winCreateBoundingWindowWindowed - Window has decoration\n");
#endif

          /* Are we resizable */
          if (pScreenInfo->iResizeMode != notAllowed)
	    {
#if CYGDEBUG
	      winDebug ("winCreateBoundingWindowWindowed - Window is resizable\n");
#endif

	      iWidth += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
	      iHeight += 2 * GetSystemMetrics (SM_CYSIZEFRAME) 
		+ GetSystemMetrics (SM_CYCAPTION);
	    }
	  else
	    {
#if CYGDEBUG
	      winDebug ("winCreateBoundingWindowWindowed - Window is not resizable\n");
#endif

	      iWidth += 2 * GetSystemMetrics (SM_CXFIXEDFRAME);
	      iHeight += 2 * GetSystemMetrics (SM_CYFIXEDFRAME) 
		+ GetSystemMetrics (SM_CYCAPTION);
	    }
	}
    }
  else
    {
      /* By default, we are creating a window that is as large as possible */
#if CYGDEBUG
      winDebug ("winCreateBoundingWindowWindowed - User did not give "
	      "height and width\n");
#endif
      /* Defaults are wrong if we have multiple monitors */
      if (pScreenInfo->fMultipleMonitors)
	{
	  iWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
	  iHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
	}
    }

  /* Make sure window is no bigger than work area */
  if (TRUE 
#ifdef XWIN_MULTIWINDOWEXTWM
       && !pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
       && !pScreenInfo->fMultiWindow
#endif
     )
    {
      /* Trim window width to fit work area */
      if (iWidth > (rcWorkArea.right - rcWorkArea.left))
        iWidth = rcWorkArea.right - rcWorkArea.left;
  
      /* Trim window height to fit work area */
      if (iHeight >= (rcWorkArea.bottom - rcWorkArea.top))
        iHeight = rcWorkArea.bottom - rcWorkArea.top;
  
#if CYGDEBUG
      winDebug ("winCreateBoundingWindowWindowed - Adjusted width: %d "\
	      "height: %d\n",
    	  iWidth, iHeight);
#endif
    }

  /* Set display and screen-specific tooltip text */
  if (g_pszQueryHost != NULL)
    snprintf (szTitle,
	    sizeof (szTitle),
	    WINDOW_TITLE_XDMCP,
	    g_pszQueryHost,
	    display,
	    (int) pScreenInfo->dwScreen);
  else    
    snprintf (szTitle,
	    sizeof (szTitle),
	    WINDOW_TITLE,
	    display, 
	    (int) pScreenInfo->dwScreen);

  /* Create the window */
  *phwnd = CreateWindowExA (0,			/* Extended styles */
			    WINDOW_CLASS,	/* Class name */
			    szTitle,		/* Window name */
			    dwWindowStyle,
			    iPosX,	        /* Horizontal position */
			    iPosY,	        /* Vertical position */
			    iWidth,		/* Right edge */
			    iHeight,		/* Bottom edge */
			    (HWND) NULL,	/* No parent or owner window */
			    (HMENU) NULL,	/* No menu */
			    GetModuleHandle (NULL),/* Instance handle */
			    pScreenPriv);	/* ScreenPrivates */
  if (*phwnd == NULL)
    {
      ErrorF ("winCreateBoundingWindowWindowed - CreateWindowEx () failed\n");
      return FALSE;
    }

#if CYGDEBUG
  winDebug ("winCreateBoundingWindowWindowed - CreateWindowEx () returned\n");
#endif

  if (fForceShowWindow)
  {
      ErrorF("winCreateBoundingWindowWindowed - Setting normal windowstyle\n");
      ShowWindow(*phwnd, SW_SHOW);      
  }

  /* Get the client area coordinates */
  if (!GetClientRect (*phwnd, &rcClient))
    {
      ErrorF ("winCreateBoundingWindowWindowed - GetClientRect () "
	      "failed\n");
      return FALSE;
    }

  winDebug ("winCreateBoundingWindowWindowed - WindowClient "
	  "w %ld h %ld r %ld l %ld b %ld t %ld\n",
	  rcClient.right - rcClient.left,
	  rcClient.bottom - rcClient.top,
	  rcClient.right, rcClient.left,
	  rcClient.bottom, rcClient.top);
  
  /* We adjust the visual size if the user did not specify it */
  if (!((pScreenInfo->iResizeMode == resizeWithScrollbars) && pScreenInfo->fUserGaveHeightAndWidth))
    {
      /*
       * User did not give a height and width with scrollbars enabled,
       * so we will resize the underlying visual to be as large as
       * the initial view port (page size).  This way scrollbars will
       * not appear until the user shrinks the window, if they ever do.
       *
       * NOTE: We have to store the viewport size here because
       * the user may have an autohide taskbar, which would
       * cause the viewport size to be one less in one dimension
       * than the viewport size that we calculated by subtracting
       * the size of the borders and caption.
       */
      pScreenInfo->dwWidth = rcClient.right - rcClient.left;
      pScreenInfo->dwHeight = rcClient.bottom - rcClient.top;
    }

#if 0
  /*
   * NOTE: For the uninitiated, the page size is the number of pixels
   * that we can display in the x or y direction at a time and the
   * range is the total number of pixels in the x or y direction that we
   * have available to display.  In other words, the page size is the
   * size of the window area minus the space the caption, borders, and
   * scrollbars (if any) occupy, and the range is the size of the
   * underlying X visual.  Notice that, contrary to what some of the
   * MSDN Library arcticles lead you to believe, the windows
   * ``client area'' size does not include the scrollbars.  In other words,
   * the whole client area size that is reported to you is drawable by
   * you; you do not have to subtract the size of the scrollbars from
   * the client area size, and if you did it would result in the size
   * of the scrollbars being double counted.
   */

  /* Setup scrollbar page and range, if scrollbars are enabled */
  if (pScreenInfo->fScrollbars)
    {
      SCROLLINFO		si;
      
      /* Initialize the scrollbar info structure */
      si.cbSize = sizeof (si);
      si.fMask = SIF_RANGE | SIF_PAGE;
      si.nMin = 0;
      
      /* Setup the width range and page size */
      si.nMax = pScreenInfo->dwWidth - 1;
      si.nPage = rcClient.right - rcClient.left;
      winDebug ("winCreateBoundingWindowWindowed - HORZ nMax: %d nPage :%d\n",
	      si.nMax, si.nPage);
      SetScrollInfo (*phwnd, SB_HORZ, &si, TRUE);
      
      /* Setup the height range and page size */
      si.nMax = pScreenInfo->dwHeight - 1;
      si.nPage = rcClient.bottom - rcClient.top;
      winDebug ("winCreateBoundingWindowWindowed - VERT nMax: %d nPage :%d\n",
	      si.nMax, si.nPage);
      SetScrollInfo (*phwnd, SB_VERT, &si, TRUE);
    }
#endif

  /* Show the window */
  if (FALSE
#ifdef XWIN_MULTIWINDOWEXTWM
      || pScreenInfo->fMWExtWM
#endif
#ifdef XWIN_MULTIWINDOW
      || pScreenInfo->fMultiWindow
#endif
      )
    {
#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
      pScreenPriv->fRootWindowShown = FALSE;
#endif
      ShowWindow (*phwnd, SW_HIDE);
    }
  else
    ShowWindow (*phwnd, SW_SHOWNORMAL);
  if (!UpdateWindow (*phwnd))
    {
      ErrorF ("winCreateBoundingWindowWindowed - UpdateWindow () failed\n");
      return FALSE;
    }
  
  /* Attempt to bring our window to the top of the display */
  if (TRUE
#ifdef XWIN_MULTIWINDOWEXTWM
      && !pScreenInfo->fMWExtWM
#endif
      && !pScreenInfo->fRootless
#ifdef XWIN_MULTIWINDOW
      && !pScreenInfo->fMultiWindow
#endif
      )
    {
      if (!BringWindowToTop (*phwnd))
	{
	  ErrorF ("winCreateBoundingWindowWindowed - BringWindowToTop () "
		  "failed\n");
	  return FALSE;
	}
    }

#ifdef XWIN_NATIVEGDI
  /* Paint window background blue */
  if (pScreenInfo->dwEngine == WIN_SERVER_NATIVE_GDI)
    winPaintBackground (*phwnd, RGB (0x00, 0x00, 0xFF));
#endif

  winDebug ("winCreateBoundingWindowWindowed -  Returning\n");

  return TRUE;
}
Пример #10
0
void outwnd_print(char *id, char *tmp)
{
	char *sptr;
	char *dptr;
	int i, nrows, ccol;
	outwnd_filter_struct *temp;

	if(gr_screen.mode == GR_DIRECT3D){
		return;
	}

	if (!outwnd_inited)
		return;

	if ( Outwnd_no_filter_file == 1 )	{
		Outwnd_no_filter_file = 2;

		outwnd_print( "general", "==========================================================================\n" );
		outwnd_print( "general", "DEBUG SPEW: No debug_filter.cfg found, so only general, error, and warning\n" );
		outwnd_print( "general", "categories can be shown and no debug_filter.cfg info will be saved.\n" );
		outwnd_print( "general", "==========================================================================\n" );
	}

	if (!id)
		id = "General";

	for (i=0; i<outwnd_filter_count; i++)
		if (!stricmp(id, outwnd_filter[i]->name))
			break;


	if (i == outwnd_filter_count)  // new id found that's not yet in filter list
	{
		// Only create new filters if there was a filter file
		if ( Outwnd_no_filter_file )	{
			return;
		}

		if (outwnd_filter_count >= MAX_FILTERS) {
			Assert(outwnd_filter_count == MAX_FILTERS);  // how did it get over the max?  Very bad..
			outwnd_printf("General", "Outwnd filter limit reached.  Recycling \"%s\" to add \"%s\"",
				outwnd_filter[MAX_FILTERS - 1]->name, id);

			i--;  // overwrite the last element (oldest used filter in the list)
		}

		Assert(strlen(id) < FILTER_NAME_LENGTH);
		outwnd_filter[i] = &real_outwnd_filter[i];  // note: this assumes the list doesn't have gaps (from deleting an element for example)
		strcpy(outwnd_filter[i]->name, id);
		outwnd_filter[i]->state = 1;
		outwnd_filter_count = i + 1;
		save_filter_info();
	}

	// sort the filters from most recently used to oldest, so oldest ones will get recycled first
	temp = outwnd_filter[i];
	while (i--)
		outwnd_filter[i + 1] = outwnd_filter[i];

	i++;
	outwnd_filter[i] = temp;

	if (!outwnd_filter[i]->state)
		return;

	if (mprintf_last_line == -1 )	{
		for (i=0; i<SCROLL_BUFFER_SIZE;i++)	{
			outtext[i][0] = 0;
		}

		mprintf_last_line = 0;
	}

	// printf out to the monochrome screen first
	if ( mono_driver != ((HANDLE)-1) ) {
		DWORD   cbReturned;

		DeviceIoControl (mono_driver, (DWORD)IOCTL_MONO_PRINT, tmp, strlen(tmp), NULL, 0, &cbReturned, 0 );
	} else {
		mono_print(tmp, strlen(tmp) );
	}

	sptr = tmp;
	ccol = strlen(outtext[mprintf_last_line] );
	dptr = &outtext[mprintf_last_line][ccol];
	nrows = 0;

#ifndef NDEBUG

	if ( Log_debug_output_to_file ) {
		if ( Log_fp != NULL ) {
			fputs(tmp, Log_fp);	
			fflush(Log_fp);
		}
	}

#endif

	while(*sptr) {
		if ( (*sptr == '\n') || (ccol >= MAX_LINE_WIDTH-1 ) )	{
			nrows++;
			mprintf_last_line++;
			if (mprintf_last_line >= SCROLL_BUFFER_SIZE )
				mprintf_last_line = 0;
			ccol = 0;
			if ( *sptr != '\n' )	{
				outtext[mprintf_last_line][ccol]	= *sptr;
				ccol++;
			}
			outtext[mprintf_last_line][ccol] = '\0';
			dptr = &outtext[mprintf_last_line][ccol];
		} else {
			*dptr++ = *sptr;
			*dptr = '\0';
			ccol++;
		}
		sptr++;
	} 

	if(gr_screen.mode == GR_DIRECT3D){
		return;
	}
//	if ( D3D_enabled )	{
//		return;		// Direct3D seems to hang sometimes printing to window
//	}

	if ( outwnd_disabled ){
		return;
	}

	if ( !OutputActive )	{
		int oldpos = GetScrollPos( hOutputWnd, SB_VERT );
		if ( oldpos != max_scroll_pos )	{
			SCROLLINFO si;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_POS;
			si.nPos = max_scroll_pos;
			SetScrollInfo(hOutputWnd, SB_VERT, &si, 1 );
			InvalidateRect(hOutputWnd,NULL,0);
			UpdateWindow(hOutputWnd);
		} else {
			if ( nrows )	{
				RECT client;
				ScrollWindow(hOutputWnd,0,-nTextHeight*nrows,NULL,NULL);
				GetClientRect(hOutputWnd, &client);
				client.top = client.bottom - nTextHeight*(nrows+1);
				InvalidateRect(hOutputWnd,&client,0);

				UpdateWindow(hOutputWnd);
			} else {
				Outwnd_changed++;
			}
		}
	}
}
Пример #11
0
LRESULT CALLBACK outwnd_handler(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam)
{
	
	switch(msg)	{
	case WM_ACTIVATEAPP:
		// The application z-ordering has change
		// foreground application wParm will be
		OutputActive = (BOOL)wParam;
		break;

	case WM_CREATE:	{
			SCROLLINFO si;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_RANGE | SIF_POS;
			si.nMin = 0;
			si.nMax = max_scroll_pos;
			si.nPos = max_scroll_pos;
			SetScrollInfo(hwnd, SB_VERT, &si, 1 );
		}
		break;

	case WM_TIMER:
		if (scroll_wait)
			PostMessage(hwnd, WM_MOUSEMOVE, 0, last_mousemove);

		if ( Outwnd_changed )	{
			RECT client;
			GetClientRect(hOutputWnd, &client);
			client.top = client.bottom - nTextHeight;
			InvalidateRect(hOutputWnd,&client,0);
		}

		scroll_wait = 0;
		break;

	case WM_COMMAND:	{
		int z;

		z = LOWORD(wParam);
		if (z >= ID_FILTER && z < ID_FILTER + outwnd_filter_count)
		{
			z -= ID_FILTER;
			outwnd_filter[z]->state = !outwnd_filter[z]->state;

			if ( !stricmp( outwnd_filter[z]->name, "error" ) )	{
				outwnd_filter[z]->state = 1;
			} else if ( !stricmp( outwnd_filter[z]->name, "general" ) )	{
				outwnd_filter[z]->state = 1;
			} else if ( !stricmp( outwnd_filter[z]->name, "warning" ) )	{
				outwnd_filter[z]->state = 1;
			}
			save_filter_info();
			break;
		}

		switch (z)
		{
			case ID_COPY:
				outwnd_copy_marked_selection(hwnd);
				break;

			/*
			case ID_FIND:
				if (DialogBox(GetModuleHandle(NULL), "FIND_DIALOG", hOutputWnd,
					(int (__stdcall *)(void)) find_dlg_handler) == IDOK)
				{
					find_text_in_outwindow(mprintf_last_line, 0);
				}

				break;
				*/
		}
		break;
	}

	case WM_RBUTTONDOWN:	{
			HMENU h_menu = CreatePopupMenu();
			HMENU h_sub_menu = CreatePopupMenu();
			POINT pt;
			int i;

			for (i=0; i<outwnd_filter_count; i++)
			{
				UINT flags = MFT_STRING;	//MF_GRAYED;

				if ( !stricmp( outwnd_filter[i]->name, "error" ) )	{
					flags |= MF_GRAYED;
				} else if ( !stricmp( outwnd_filter[i]->name, "general" ) )	{
					flags |= MF_GRAYED;
				} else if ( !stricmp( outwnd_filter[i]->name, "warning" ) )	{
					flags |= MF_GRAYED;
				}

				if (outwnd_filter[i]->state)
					AppendMenu(h_sub_menu, flags | MF_CHECKED, ID_FILTER + i, outwnd_filter[i]->name);
				else
					AppendMenu(h_sub_menu, flags, ID_FILTER + i, outwnd_filter[i]->name);
			}

			AppendMenu(h_menu, MFT_STRING, ID_COPY, "&Copy\tEnter");
			AppendMenu(h_menu, MFT_STRING, ID_FIND, "&Find Text");
			AppendMenu(h_menu, MF_POPUP, (unsigned int) h_sub_menu, "Filter &Messages");
			pt.x = LOWORD(lParam);
			pt.y = HIWORD(lParam);
			ClientToScreen(hwnd, &pt);

			TrackPopupMenu(h_menu, 0, pt.x, pt.y, 0, hwnd, NULL);
			DestroyMenu(h_menu);
			break;
		}
		
	case WM_LBUTTONDOWN:
		fix_marking_coords(marking_started_x, marking_started_y, lParam);
		SetCapture(hwnd);  // monopolize mouse
		marking_active = 1;
		outwnd_update_marking(lParam, hwnd);
		break;

	case WM_MOUSEMOVE:
		last_mousemove = lParam;
		if (marking_active){
			outwnd_update_marking(lParam, hwnd);
		}
		break;

	case WM_LBUTTONUP:
		if (marking_active)
		{
			ReleaseCapture();
			marking_active = 0;
			outwnd_update_marking(lParam, hwnd);
		}
		break;
	
	case WM_VSCROLL:	{
			SCROLLINFO si;
			int vpos = GetScrollPos( hwnd, SB_VERT );
			int old_vpos=vpos;
			switch (LOWORD(wParam))	{
			case SB_LINEDOWN:
				vpos++;
				break;
			case SB_LINEUP:
				vpos--;
				break;
			case SB_THUMBPOSITION:
				vpos = HIWORD(wParam);
				break;
			case SB_THUMBTRACK:
				vpos = HIWORD(wParam);
				break;
			case SB_PAGEDOWN:
				vpos += nCharRows;
				break;
			case SB_PAGEUP:
				vpos -= nCharRows;
				break;
			}
			if ( vpos < 0 ) vpos = 0;
			else if ( vpos > max_scroll_pos ) vpos = max_scroll_pos;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_POS;
			si.nPos = vpos;
			SetScrollInfo(hwnd, SB_VERT, &si, 1 );
			ScrollWindow(hwnd,0,(old_vpos-vpos)*nTextHeight,NULL,NULL);
			UpdateWindow(hOutputWnd);
			//InvalidateRect(hOutputWnd,NULL,0);
		}
		break;

	case WM_KEYDOWN:	{
			SCROLLINFO si;
			int vpos = GetScrollPos( hwnd, SB_VERT );
			int old_vpos=vpos;
			int nVirtKey = (int) wParam;  // virtual-key code
			switch(nVirtKey)	{
			case VK_DOWN:
			case VK_RIGHT:
				vpos++;
				break;
			case VK_UP:
			case VK_LEFT:
				vpos--;
				break;
			case VK_NEXT:
				vpos += nCharRows;
				break;
			case VK_PRIOR:
				vpos -= nCharRows;
				break;
			case VK_END:
				vpos = 0;
				break;
			case VK_HOME:
				vpos = max_scroll_pos;
				break;
			case VK_RETURN:
				outwnd_copy_marked_selection(hwnd);
				break;
			case UP_FAST:  // special value we define
				vpos -= 5;
				break;
			case DOWN_FAST:  // special value we define
				vpos += 5;
				break;
			}
			
			if ( vpos < 0 ) vpos = 0;
			else if ( vpos > max_scroll_pos ) vpos = max_scroll_pos;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_POS;
			si.nPos = vpos;
			SetScrollInfo(hwnd, SB_VERT, &si, 1 );
			ScrollWindow(hwnd, 0, (old_vpos-vpos)*nTextHeight, NULL, NULL);
			UpdateWindow(hOutputWnd);
			//InvalidateRect(hOutputWnd,NULL,0);
		}
		break;

	case WM_SIZE:
		InvalidateRect(hOutputWnd,NULL,0);
		break;

	case WM_PAINT:
		outwnd_paint(hwnd);
		break;

	case WM_DESTROY:
		outwnd_disabled = 1;
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
		break;
	}

	return 0;
}
Пример #12
0
void find_text_in_outwindow(int n, int p)
{
	char *ptr, *str;

	str = outtext[n] + p;
	while (1)
	{
		ptr = strstr(str, find_text);
		if (ptr)
		{
			int scroll_pos, pos;

			find_pos = ptr - str;
			find_line = n;
			marked = 1;
			marked_top = marked_bottom = find_line;
			marked_left = find_pos;
			marked_right = find_pos + strlen(find_text);

			scroll_pos = (max_scroll_pos - GetScrollPos(hOutputWnd, SB_VERT));
			pos = mprintf_last_line - scroll_pos;
			if (pos < 0)
				pos += SCROLL_BUFFER_SIZE;

			pos -= n;
			if (pos < 0)
				pos += SCROLL_BUFFER_SIZE;

			Assert(pos >= 0);
			if (pos >= nCharRows - 1)  // outside of window viewport, so scroll
			{
				SCROLLINFO si;

				pos = mprintf_last_line - n - nCharRows / 2;
				if (pos < 0)
					pos += SCROLL_BUFFER_SIZE;

				if (pos > max_scroll_pos)
					pos = max_scroll_pos;

				scroll_pos = max_scroll_pos - GetScrollPos(hOutputWnd, SB_VERT);
				si.cbSize = sizeof(SCROLLINFO);
				si.fMask = SIF_POS;
				si.nPos = max_scroll_pos - pos;
				SetScrollInfo(hOutputWnd, SB_VERT, &si, 1);
				ScrollWindow(hOutputWnd, 0, (scroll_pos - pos) * nTextHeight, NULL, NULL);
			}

			InvalidateRect(hOutputWnd, NULL, 0);
			UpdateWindow(hOutputWnd);
			return;
		}

		n--;
		if (n < 0)
			n += SCROLL_BUFFER_SIZE;

		if (n == mprintf_last_line)
		{
			MessageBox(hOutputWnd, "Search text not found", "Find Error", MB_OK | MB_ICONERROR);
			find_line = -1;
			return;
		}

		str = outtext[n];
	}
}
Пример #13
0
static INT_PTR CALLBACK FtMgrPageDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	struct TFtPageData *dat = (struct TFtPageData *)GetWindowLongPtr(hwnd, GWLP_USERDATA);
	int i;

	switch (msg) {
	case WM_INITDIALOG:
		{
			// Force scrollbar visibility
			SCROLLINFO si = {0};
			si.cbSize = sizeof(si);
			si.fMask = SIF_DISABLENOSCROLL;
			SetScrollInfo(hwnd, SB_VERT, &si, TRUE);

			dat = (struct TFtPageData *)mir_alloc(sizeof(struct TFtPageData));
			dat->wnds = (struct TLayoutWindowList *)List_Create(0, 1);
			dat->scrollPos = 0;
			dat->runningCount = 0;
			SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat);
		}
		break;

	case WM_FT_ADD:
		{
			TLayoutWindowInfo *wnd = (struct TLayoutWindowInfo *)mir_alloc(sizeof(struct TLayoutWindowInfo));
			wnd->hwnd = (HWND)lParam;
			GetWindowRect(wnd->hwnd, &wnd->rc);
			List_Insert((SortedList *)dat->wnds, wnd, dat->wnds->realCount);
			LayoutTransfers(hwnd, dat);
			dat->runningCount++;
			PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL);
		}
		break;

	case WM_FT_RESIZE:
		for (i=0; i < dat->wnds->realCount; ++i)
			if (dat->wnds->items[i]->hwnd == (HWND)lParam) {
				GetWindowRect(dat->wnds->items[i]->hwnd, &dat->wnds->items[i]->rc);
				break;
			}
		LayoutTransfers(hwnd, dat);
		break;

	case WM_FT_REMOVE:
		for (i=0; i < dat->wnds->realCount; ++i)
			if (dat->wnds->items[i]->hwnd == (HWND)lParam) {
				mir_free(dat->wnds->items[i]);
				List_Remove((SortedList *)dat->wnds, i);
				break;
			}
		LayoutTransfers(hwnd, dat);
		break;

	case WM_FT_COMPLETED:
		//wParam: { ACKRESULT_SUCCESS | ACKRESULT_FAILED | ACKRESULT_DENIED }
		dat->runningCount--;
		for (i=0; i < dat->wnds->realCount; i++) {
			// no error when canceling (WM_FT_REMOVE is send first, check if hwnd is still registered)
			if (dat->wnds->items[i]->hwnd == (HWND)lParam) {
				SendMessage(GetParent(hwnd), WM_TIMER, 1, (LPARAM)wParam);
				break;
			}
		}
		if (i == dat->wnds->realCount)
			PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL);

		if(dat->runningCount == 0 && (int)wParam == ACKRESULT_SUCCESS && db_get_b(NULL, "SRFile", "AutoClose", 0))
			ShowWindow(hwndFtMgr, SW_HIDE);
		break;

	case WM_FT_CLEANUP:
		for (i=0; i < dat->wnds->realCount; ++i)
			SendMessage(dat->wnds->items[i]->hwnd, WM_FT_CLEANUP, wParam, lParam);
		break;

	case WM_SIZE:
		LayoutTransfers(hwnd, dat);
		break;

	case WM_MOUSEWHEEL:
		{
			int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
			if (zDelta) {
				int nScrollLines = 0;
				SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, (void*)&nScrollLines, 0);
				for (i=0; i < (nScrollLines + 1) / 2; i++)
					SendMessage(hwnd, WM_VSCROLL, (zDelta < 0) ? SB_LINEDOWN : SB_LINEUP, 0);
			}

			SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0);
			return TRUE;
		}

	case WM_VSCROLL:
		{
			int pos = dat->scrollPos;
			switch (LOWORD(wParam)) {
			case SB_LINEDOWN:
				pos += 15;
				break;
			case SB_LINEUP:
				pos -= 15;
				break;
			case SB_PAGEDOWN:
				pos += dat->height - 10;
				break;
			case SB_PAGEUP:
				pos -= dat->height - 10;
				break;
			case SB_THUMBTRACK:
				pos = HIWORD(wParam);
				break;
			}

			if (pos > dat->dataHeight - dat->height) pos = dat->dataHeight - dat->height;
			if (pos < 0) pos = 0;

			if (dat->scrollPos != pos) {
				ScrollWindow(hwnd, 0, dat->scrollPos - pos, NULL, NULL);
				SetScrollPos(hwnd, SB_VERT, pos, TRUE);
				dat->scrollPos = pos;
			}
			break;
		}

	case M_PRESHUTDOWN:
		for (i=0; i < dat->wnds->realCount; ++i)
			PostMessage(dat->wnds->items[i]->hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), 0);
		break;

	case M_CALCPROGRESS:
		{
			TFtProgressData *prg = (TFtProgressData *)wParam;
			for (i=0; i < dat->wnds->realCount; ++i) {
				struct FileDlgData *trdat = (struct FileDlgData *)GetWindowLongPtr(dat->wnds->items[i]->hwnd, GWLP_USERDATA);
				if (trdat->transferStatus.totalBytes && trdat->fs && !trdat->send && (trdat->transferStatus.totalBytes == trdat->transferStatus.totalProgress))
					prg->scan++;
				else if (trdat->transferStatus.totalBytes && trdat->fs) { // in progress
					prg->run++;
					prg->totalBytes += trdat->transferStatus.totalBytes;
					prg->totalProgress += trdat->transferStatus.totalProgress;
				}
				else if (trdat->fs) // starting
					prg->init++;
			}
		}
		break;

	case WM_DESTROY:
		for (i=0; i < dat->wnds->realCount; ++i)
			mir_free(dat->wnds->items[i]);
		List_Destroy((SortedList *)dat->wnds);
		mir_free(dat->wnds);
		mir_free(dat);
		break;
	}

	return FALSE;
}
Пример #14
0
void EPropWnd::SetScrollPage()
{
	CSize PageSize = GetScrollPageSize();

	if( PageSize.cx==0 && PageSize.cy==0 )
	{
		SetScrollPos ( SB_HORZ , 0     );
		SetScrollPos ( SB_VERT , 0     );
		ShowScrollBar( SB_BOTH , FALSE );
	}
	else
	{
		CRect wr;
		GetWindowRect(&wr);
		CSize ClientSize = wr.Size();

		bool bEnableH = false;
		bool bEnableV = false;

		if( PageSize.cx > ClientSize.cx )
		{
			ClientSize.cy -= GetSystemMetrics(SM_CYHSCROLL);
			bEnableH = true;
		}

		if( PageSize.cy > ClientSize.cy )
		{
			ClientSize.cx -= GetSystemMetrics(SM_CXVSCROLL);
			bEnableV = true;

			if( bEnableH == false )
			{
				if( PageSize.cx > ClientSize.cx )
				{
					ClientSize.cy -= GetSystemMetrics(SM_CYHSCROLL);
					bEnableH = true;
				}
			}
		}

		SCROLLINFO si;
		si.cbSize = sizeof(si);
		si.fMask  = SIF_PAGE | SIF_POS | SIF_RANGE;

		if( bEnableH )
		{
			si.nPage  = ClientSize.cx;			//size of scrolltab
			si.nMin   = 0;
			si.nMax   = PageSize.cx-1;
			si.nPos   = GetScrollPos(SB_HORZ);
			ShowScrollBar( SB_HORZ , TRUE );
			SetScrollInfo( SB_HORZ , &si );
		}
		else
		{
			ShowScrollBar( SB_HORZ , FALSE );
			SetScrollPos( SB_HORZ , 0 );
		}

		if( bEnableV )
		{
			si.nPage  = ClientSize.cy;			//size of scrolltab
			si.nMin   = 0;
			si.nMax   = PageSize.cy-1;
			si.nPos   = GetScrollPos(SB_VERT);
			ShowScrollBar( SB_VERT , TRUE );
			SetScrollInfo( SB_VERT , &si );
		}
		else
		{
			ShowScrollBar( SB_VERT , FALSE );
			SetScrollPos( SB_VERT , 0 );
		}

	}
}
Пример #15
0
/***************************************************
Moved
	Updates vertical scrolbar's position and redraws the grid.
Params:
	<none>
Returns:
	<none>
*****************************************************/
void CUGVScroll::Moved()
{
	if ( m_GI->m_paintMode == FALSE )
		return;

	BOOL bScrolled = FALSE;

	//set the scroll range
	if(	m_lastMaxTopRow != m_GI->m_maxTopRow ||
		m_lastScrollMode != m_GI->m_vScrollMode ||
		m_lastNumLockRow != m_GI->m_numLockRows)
	{
		//set the last value vars
		m_lastMaxTopRow = m_GI->m_maxTopRow;
		m_lastScrollMode = m_GI->m_vScrollMode;
		m_lastNumLockRow = m_GI->m_numLockRows;

		//set up the scrollbar if the number of rows is less than 1000
		if(m_GI->m_maxTopRow <=1000)
		{
			if(UG_SCROLLJOYSTICK == m_GI->m_vScrollMode)
			{
				SCROLLINFO ScrollInfo;
				ScrollInfo.cbSize =sizeof(SCROLLINFO);
				ScrollInfo.fMask = SIF_PAGE | SIF_RANGE |SIF_POS;
				ScrollInfo.nPage = 0;
				ScrollInfo.nMin = 0;
				ScrollInfo.nMax = 2;
				ScrollInfo.nPos = 1;
				SetScrollInfo(&ScrollInfo,FALSE);
				Invalidate();
			}
			else
			{
				SCROLLINFO ScrollInfo;

				ScrollInfo.cbSize =sizeof(SCROLLINFO);
				ScrollInfo.fMask = SIF_PAGE | SIF_RANGE;

				if( m_GI->m_defRowHeight < 1 )
					m_GI->m_defRowHeight =  1;

				ScrollInfo.nPage = m_GI->m_gridHeight / m_GI->m_defRowHeight;

				ScrollInfo.nMin = m_GI->m_numLockRows;
				ScrollInfo.nMax = m_GI->m_maxTopRow + ScrollInfo.nPage -1;
				SetScrollInfo(&ScrollInfo,FALSE);
				Invalidate();
			}
			bScrolled = TRUE;
			m_multiRange = 1;
			m_multiPos	= 1;			
		}
		//set up the scrollbar if the number of rows is greater than 1000
		else
		{
			m_multiRange = (double)1000 / (double)m_GI->m_maxTopRow;
			m_multiPos   = (double)m_GI->m_maxTopRow / (double)1000;
			if(UG_SCROLLJOYSTICK==m_GI->m_vScrollMode)
			{
				SetScrollRange(0,2,FALSE);
				m_multiRange = 1;
				m_multiPos	= 1;
			}
			else
			{
				SCROLLINFO ScrollInfo;
				ScrollInfo.cbSize =sizeof(SCROLLINFO);
				ScrollInfo.fMask = SIF_PAGE | SIF_RANGE;
				ScrollInfo.nPage = 1;
				ScrollInfo.nMin = 0;//m_GI->m_numLockRows;
				ScrollInfo.nMax = 1000;
				SetScrollInfo(&ScrollInfo,FALSE);
			}
			bScrolled = TRUE;
		}
	}

	//set the scroll pos
	if( m_GI->m_lastTopRow != m_GI->m_topRow || bScrolled == TRUE )
	{
		if(UG_SCROLLJOYSTICK == m_GI->m_vScrollMode)
			SetScrollPos(1,TRUE);
		else
			SetScrollPos((int)(m_GI->m_topRow * m_multiRange),TRUE);

		m_ctrl->OnViewMoved( UG_VSCROLL, m_GI->m_lastTopRow, m_GI->m_topRow );
	}
}
Пример #16
0
uint32 HeroChart::onMessage(uint32 message, uint32 wParam, uint32 lParam)
{
    switch (message)
    {
    case WM_ERASEBKGND:
    {
        HDC hDC = (HDC) wParam;
        SetBkColor(hDC, 0x000000);
        RECT rc;
        GetClientRect(hWnd, &rc);
        ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
    }
    return TRUE;
    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        HDC hDC = BeginPaint(hWnd, &ps);

        HDC hBitmapDC = CreateCompatibleDC(hDC);

        SetBkColor(hDC, 0x000000);
        SetBkMode(hDC, OPAQUE);
        for (int i = 0; i < numTags; i++)
        {
            SelectObject(hDC, textTags[i].hFont);
            SetTextColor(hDC, textTags[i].color);
            RECT rc = textTags[i].rc;
            rc.top -= scrollPos;
            rc.bottom -= scrollPos;
            DrawText(hDC, textTags[i].text, -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
        }

        ImageLibrary* ilib = getApp()->getImageLibrary();
        SelectObject(hDC, counterFont);
        SetTextColor(hDC, 0xFFFFFF);
        for (int i = 0; i < numTaverns; i++)
        {
            if (i == curTavern)
            {
                RECT rc = taverns[i].rc;
                rc.top -= scrollPos + 3;
                rc.bottom -= scrollPos - 3;
                rc.left -= 3;
                rc.right += 3;
                SetBkColor(hDC, taverns[i].color);
                ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
                SetBkColor(hDC, 0x000000);
                rc = taverns[i].rc;
                rc.top -= scrollPos;
                rc.bottom -= scrollPos;
                ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
            }
            for (int h = 0; h < 12; h++)
            {
                Dota::Hero* hero = taverns[i].heroes[h];
                if (hero)
                {
                    int x = taverns[i].rc.left + (32 + 2) * (h % 4);
                    int y = taverns[i].rc.top + (32 + 2) * (h / 4);
                    HBITMAP hBitmap = ilib->getBitmap(String::format("big%s", hero->icon));
                    if (hBitmap)
                    {
                        SelectObject(hBitmapDC, hBitmap);
                        BitBlt(hDC, x, y - scrollPos, 32, 32, hBitmapDC, 0, 0, SRCCOPY);
                        RECT tipRc = {x, y - scrollPos, x + 32, y + 32 - scrollPos};
                        DrawText(hDC, String::format(" %d ", heroCounter[hero->point]),
                                 -1, &tipRc, DT_SINGLELINE | DT_RIGHT | DT_BOTTOM);
                    }
                }
            }
        }

        DeleteDC(hBitmapDC);

        EndPaint(hWnd, &ps);
    }
    break;
    case WM_SIZE:
    {
        SCROLLINFO si;
        memset(&si, 0, sizeof si);
        si.cbSize = sizeof si;
        si.fMask = SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
        si.nPage = height();
        si.nMin = 0;
        si.nMax = contentHeight;
        SetScrollInfo(hWnd, SB_VERT, &si, TRUE);
    }
    break;
    case WM_LBUTTONDOWN:
    {
        SetFocus(hWnd);
        int x = GET_X_LPARAM(lParam);
        int y = GET_Y_LPARAM(lParam) + scrollPos;
        for (int i = 0; i < numTaverns; i++)
        {
            if (x >= taverns[i].rc.left && y >= taverns[i].rc.top &&
                    x < taverns[i].rc.right && y < taverns[i].rc.bottom)
            {
                if (curTavern >= 0)
                {
                    RECT rc = taverns[curTavern].rc;
                    rc.left -= 3;
                    rc.top -= scrollPos + 3;
                    rc.right += 3;
                    rc.bottom -= scrollPos - 3;
                    curTavern = i;
                    InvalidateRect(hWnd, &rc, TRUE);
                }
                curTavern = i;
                RECT rc = taverns[i].rc;
                rc.left -= 3;
                rc.top -= scrollPos + 3;
                rc.right += 3;
                rc.bottom -= scrollPos - 3;
                InvalidateRect(hWnd, &rc, TRUE);

                notify(WM_SETTAVERN, i, 0);

                int hx = (x - taverns[i].rc.left) / (32 + 2);
                int hy = (y - taverns[i].rc.top) / (32 + 2);
                int h = hx + hy * 4;
                if (h >= 0 && h < 12 && taverns[i].heroes[h])
                    notify(WM_SETHERO, taverns[i].heroes[h]->point, 0);

                break;
            }
        }
    }
    return 0;
    case WM_MOUSEWHEEL:
        doScroll(scrollPos - GET_WHEEL_DELTA_WPARAM(wParam) * 30 / WHEEL_DELTA);
        break;
    case WM_VSCROLL:
    {
        SCROLLINFO si;
        memset(&si, 0, sizeof si);
        si.cbSize = sizeof si;
        si.fMask = SIF_ALL;
        GetScrollInfo(hWnd, SB_VERT, &si);
        switch (LOWORD(wParam))
        {
        case SB_TOP:
            si.nPos = si.nMin;
            break;
        case SB_BOTTOM:
            si.nPos = si.nMax;
            break;
        case SB_LINEUP:
            si.nPos--;
            break;
        case SB_LINEDOWN:
            si.nPos++;
            break;
        case SB_PAGEUP:
            si.nPos -= si.nPage;
            break;
        case SB_PAGEDOWN:
            si.nPos += si.nPage;
            break;
        case SB_THUMBTRACK:
            si.nPos = si.nTrackPos;
            break;
        }
        doScroll(si.nPos);
    }
    break;
    default:
        return M_UNHANDLED;
    }
    return 0;
}
Пример #17
0
/***********************************************************************
 *		FlatSB_SetScrollInfo (COMCTL32.@)
 *
 * See SetScrollInfo.
 */
INT WINAPI
FlatSB_SetScrollInfo(HWND hwnd, int nBar, LPSCROLLINFO info, BOOL bRedraw)
{
    return SetScrollInfo(hwnd, nBar, info, bRedraw);
}
Пример #18
0
void CDropScrollBar::VScroll(UINT nSBCode, UINT nPos) 
{
	if( !m_pListBox )
		return;

	SCROLLINFO info;

	info.cbSize = sizeof(SCROLLINFO);
	if( !GetScrollInfo( &info, SIF_ALL|SIF_DISABLENOSCROLL ) )
		return;

	switch( nSBCode )
	{
	case SB_BOTTOM: // Scroll to bottom.
		break;

	case SB_ENDSCROLL: // End scroll.
		//+++
		ReleaseCapture();
		GetParent()->PostMessage( WM_VRC_SETCAPTURE );
		break;

	case SB_LINEDOWN: // Scroll one line down.
		info.nPos++;
		if( info.nPos > info.nMax )
			info.nPos = info.nMax;
		m_pListBox->SetTopIdx( info.nPos );
		break;

	case SB_LINEUP: // Scroll one line up.
		info.nPos--;
		if( info.nPos < info.nMin )
			info.nPos = info.nMin;
		m_pListBox->SetTopIdx( info.nPos );
		break;

	case SB_PAGEDOWN: // Scroll one page down.
		info.nPos += info.nPage;
		if( info.nPos > info.nMax )
			info.nPos = info.nMax;
		m_pListBox->SetTopIdx( info.nPos );
		break;

	case SB_PAGEUP: // Scroll one page up.
		info.nPos -= info.nPage;
		if( info.nPos < info.nMin )
			info.nPos = info.nMin;
		m_pListBox->SetTopIdx( info.nPos );
		break;

	case SB_THUMBPOSITION: // Scroll to the absolute position. The current position is provided in nPos.
		info.nPos = nPos;
		m_pListBox->SetTopIdx( info.nPos );
		break;

	case SB_THUMBTRACK: // Drag scroll box to specified position. The current position is provided in nPos.
		info.nPos = nPos;
		m_pListBox->SetTopIdx( info.nPos );
		break;

	case SB_TOP: // Scroll to top. 
		break;

	}
	SetScrollInfo( &info );
			
}
void AwtScrollPane::RecalcSizes(int parentWidth, int parentHeight,
                                int childWidth, int childHeight)
{
    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    if (env->EnsureLocalCapacity(2) < 0) {
        return;
    }

    /* Determine border width without scrollbars. */
    int horzBorder;
    int vertBorder;
    if (IS_WIN4X) {
        horzBorder = ::GetSystemMetrics(SM_CXEDGE);
        vertBorder = ::GetSystemMetrics(SM_CYEDGE);
    } else {
        horzBorder = ::GetSystemMetrics(SM_CXBORDER);
        vertBorder = ::GetSystemMetrics(SM_CYBORDER);
    }

    parentWidth -= (horzBorder * 2);
    parentHeight -= (vertBorder * 2);

    /* Enable each scrollbar as needed. */
    jobject target = AwtObject::GetTarget(env);
    jint policy = env->GetIntField(target,
                                   AwtScrollPane::scrollbarDisplayPolicyID);

    BOOL needsHorz=(policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS ||
                    (policy == java_awt_ScrollPane_SCROLLBARS_AS_NEEDED &&
                     childWidth > parentWidth));
    if (needsHorz) {
        parentHeight -= ::GetSystemMetrics(SM_CYHSCROLL);
    }
    BOOL needsVert=(policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS ||
                    (policy ==java_awt_ScrollPane_SCROLLBARS_AS_NEEDED &&
                     childHeight > parentHeight));
    if (needsVert) {
        parentWidth -= ::GetSystemMetrics(SM_CXVSCROLL);
    }
    /*
     * Since the vertical scrollbar may have reduced the parent width
     * enough to now require a horizontal scrollbar, we need to
     * recalculate the horizontal metrics and scrollbar boolean.
     */
    if (!needsHorz) {
        needsHorz = (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS ||
                     (policy == java_awt_ScrollPane_SCROLLBARS_AS_NEEDED &&
                      childWidth > parentWidth));
        if (needsHorz) {
            parentHeight -= ::GetSystemMetrics(SM_CYHSCROLL);
        }
    }

    /* Now set ranges -- setting the min and max the same disables them. */
    if (needsHorz) {
        jobject hAdj =
            env->GetObjectField(target, AwtScrollPane::hAdjustableID);
        env->SetIntField(hAdj, AwtScrollPane::blockIncrementID, parentWidth);
        SetScrollInfo(SB_HORZ, childWidth - 1, parentWidth,
                      (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS));
        env->DeleteLocalRef(hAdj);
    } else {
        SetScrollInfo(SB_HORZ, 0, 0,
                      (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS));
    }

    if (needsVert) {
        jobject vAdj =
            env->GetObjectField(target, AwtScrollPane::vAdjustableID);
        env->SetIntField(vAdj, AwtScrollPane::blockIncrementID, parentHeight);
        SetScrollInfo(SB_VERT, childHeight - 1, parentHeight,
                      (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS));
        env->DeleteLocalRef(vAdj);
    } else {
        SetScrollInfo(SB_VERT, 0, 0,
                      (policy == java_awt_ScrollPane_SCROLLBARS_ALWAYS));
    }

    env->DeleteLocalRef(target);
}
        void OnScroll(int code, HWND source, bool is_horizontal)
        {
            int pos;

            if(code == SB_ENDSCROLL)
            {
                return;
            }

            // If we receive an event from the scrollbar, make the view
            // component focused so we actually get mousewheel events.
            if(source != NULL)
            {
                Widget* widget = parent_->GetWidget();
                if(widget && widget->GetNativeView()!=GetFocus())
                {
                    parent_->RequestFocus();
                }
            }

            SCROLLINFO si;
            si.cbSize = sizeof(si);
            si.fMask = SIF_POS | SIF_TRACKPOS;
            GetScrollInfo(scrollbar_, SB_CTL, &si);
            pos = si.nPos;

            ScrollBarController* sbc = parent_->GetController();

            switch(code)
            {
            case SB_BOTTOM:  // case SB_RIGHT:
                pos = parent_->GetMaxPosition();
                break;
            case SB_TOP:  // case SB_LEFT:
                pos = parent_->GetMinPosition();
                break;
            case SB_LINEDOWN:  //  case SB_LINERIGHT:
                pos += sbc->GetScrollIncrement(parent_, false, true);
                pos = std::min(parent_->GetMaxPosition(), pos);
                break;
            case SB_LINEUP:  //  case SB_LINELEFT:
                pos -= sbc->GetScrollIncrement(parent_, false, false);
                pos = std::max(parent_->GetMinPosition(), pos);
                break;
            case SB_PAGEDOWN:  //  case SB_PAGERIGHT:
                pos += sbc->GetScrollIncrement(parent_, true, true);
                pos = std::min(parent_->GetMaxPosition(), pos);
                break;
            case SB_PAGEUP:  // case SB_PAGELEFT:
                pos -= sbc->GetScrollIncrement(parent_, true, false);
                pos = std::max(parent_->GetMinPosition(), pos);
                break;
            case SB_THUMBPOSITION:
            case SB_THUMBTRACK:
                pos = si.nTrackPos;
                if(pos < parent_->GetMinPosition())
                {
                    pos = parent_->GetMinPosition();
                }
                else if(pos > parent_->GetMaxPosition())
                {
                    pos = parent_->GetMaxPosition();
                }
                break;
            default:
                break;
            }

            sbc->ScrollToPosition(parent_, pos);

            si.nPos = pos;
            si.fMask = SIF_POS;
            SetScrollInfo(scrollbar_, SB_CTL, &si, TRUE);

            // Note: the system scrollbar modal loop doesn't give a chance
            // to our message_loop so we need to call DidProcessMessage()
            // manually.
            //
            // Sadly, we don't know what message has been processed. We may
            // want to remove the message from DidProcessMessage()
            MSG dummy;
            dummy.hwnd = NULL;
            dummy.message = 0;
            MessageLoopForUI::current()->DidProcessMessage(dummy);
        }
LRESULT CALLBACK MainWindow::MainWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HDC hdc_mem;
	static HDC hdc;
	static PAINTSTRUCT ps;
	static SCROLLINFO si;
	static TEXTMETRIC tm;
	static HPEN strokePen = CreatePen(PS_SOLID, 1, RGB(255,0,0));

	//Static variables for drawing
	static bool isDrawing = FALSE;
	static int StartX, StartY;
	static int EndX, EndY;
	static UINT iButtonState;

	//Static variables for mouse Co-ordinates
	static int xMouse, yMouse;
	xMouse = GET_X_LPARAM(lParam);
	yMouse = GET_Y_LPARAM(lParam);
	static HBRUSH newbrush;

	//Child Window Handles
	MainWindow create;
	RECT rect;

	// Size and position variables
	static int iSysWidth;
	static int iSysHeight;
	static int iWinWidth;
	static int iWinHeight;
	static int cxChar;
	static int cyChar;

	static int iWidth  = 60;   // Button width
	static int iHeight = 30;   // Button height

	static int iListBoxWidth = 300;
	static int iListBoxHeight = 360;

	// Size and position variables
	static int x, y;

	hdc = GetDC(hwnd);
	GetTextMetrics(hdc, &tm);
	cxChar = tm.tmAveCharWidth;
	cyChar = tm.tmHeight;
	ReleaseDC(hwnd, hdc);

	//for Bezier
	static POINT apt[4];

	//bool variables
	bool white = false;
	bool green = false;
	bool red = false;
	bool black = false;

	hProgramInstance = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);

	HBITMAP logo = NULL;
	BITMAP  bitmap;
	logo = (HBITMAP)LoadImage(hProgramInstance, L"standard.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
	GetObject(logo, sizeof(bitmap), &bitmap);

	switch (msg)
	{
	case WM_CREATE:
		{
			create.Create(hProgramInstance,hwnd,lParam,logo);
			Exo.CreateStandardToolbar(hwnd, Exo.m_hInstance);
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDC_MAINCURSOR, TBSTATE_CHECKED | TBSTATE_ENABLED);	
		}
		break;

	case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO pInfo = (LPMINMAXINFO) lParam;
			pInfo -> ptMaxTrackSize.x = 450;
			pInfo -> ptMaxTrackSize.y = 650;	
		}
		break;

	case WM_SIZE:

		iWidth  = LOWORD(lParam);
		iHeight = HIWORD(lParam);

		// Set vertical scroll bar range and page size
		si.cbSize = sizeof(si);
		si.fMask = SIF_RANGE | SIF_PAGE;
		si.nMin = 0;
		si.nMax = ((iMinWindowHeight - 70) / cyChar);
		si.nPage = iHeight / cyChar;
		SetScrollInfo(hwnd, SB_VERT, &si, TRUE);

		// Set horizontal scroll bar range and page size
		si.cbSize = sizeof(si);
		si.fMask = SIF_RANGE | SIF_PAGE;
		si.nMin = 0;
		si.nMax = ((iMinWindowWidth - 20) / cxChar);
		si.nPage = iWidth / cxChar;
		SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);

		//Child window reposition
		MoveWindow(hwndButton,20,510,iListBoxWidth+90, iListBoxHeight-335, TRUE);
		MoveWindow(hwndWidthSlider, 20, 35, iListBoxWidth - 150, 10, TRUE);
		MoveWindow(hwndFillColor, 260, 35, iListBoxWidth - 150, 10, TRUE);
		GetWindowRect(hwnd, &rect);
		iWinWidth = rect.right - rect.left;
		iWinHeight = rect.bottom - rect.top;
		iSysWidth = GetSystemMetrics(SM_CXSCREEN);
		iSysHeight = GetSystemMetrics(SM_CYSCREEN);

		apt[0].x = iWidth / 7 ;
		apt[0].y = iHeight / 2 ;

		apt[1].x = iWidth / 5;
		apt[1].y = iHeight / 7 ;

		apt[2].x =     iWidth / 2 ;
		apt[2].y = 3 * iHeight / 4 ;

		apt[3].x = 3 * iWidth / 4 ;
		apt[3].y =     iHeight / 2 ;

		break;

	case WM_VSCROLL:
		// Get all the vertical scroll bar information
		si.cbSize = sizeof(si);
		si.fMask = SIF_ALL;
		GetScrollInfo(hwnd, SB_VERT, &si);

		// Save the position for later comparison
		y = si.nPos;

		switch(LOWORD(wParam))
		{
		case SB_TOP:
			si.nPos = si.nMin;
			break;

		case SB_BOTTOM:
			si.nPos = si.nMax;
			break;

		case SB_LINEUP:
			si.nPos -= 1;
			break;

		case SB_LINEDOWN:
			si.nPos += 1;
			break;

		case SB_PAGEUP:
			si.nPos -= si.nPage;
			break;

		case SB_PAGEDOWN:
			si.nPos += si.nPage;
			break;

		case SB_THUMBTRACK:
			si.nPos = si.nTrackPos;
			break;

		default:
			break;
		}

		// Set the position and then retrieve it
		si.fMask = SIF_POS;
		SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
		GetScrollInfo(hwnd, SB_VERT, &si);

		// If the position has changed, scroll the window and update it
		if(si.nPos != y) 
		{
			ScrollWindow(hwnd, 0, cyChar * (y - si.nPos), NULL, NULL);
			UpdateWindow(hwnd);
		}
		break;

	case WM_CTLCOLORSTATIC:

		SetTextColor((HDC)wParam, RGB(150, 100, 255));
		SetBkMode((HDC)wParam, TRANSPARENT);
		newbrush = (HBRUSH)GetStockObject(NULL_BRUSH);
		DeleteObject(newbrush);
		return (LRESULT)newbrush;
		break;

	case WM_HSCROLL:
		GetWindowRect(hwnd, &rect);
		iWinWidth = rect.right - rect.left;
		iWinHeight = rect.bottom - rect.top;
		iSysWidth = GetSystemMetrics(SM_CXSCREEN);
		iSysHeight = GetSystemMetrics(SM_CYSCREEN);

		// Get all the vertical scroll bar information
		si.cbSize = sizeof(si);
		si.fMask = SIF_ALL;
		GetScrollInfo(hwnd, SB_HORZ, &si);

		// Save the position for later comparison
		x = si.nPos;

		if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_BACKGROUND_SCROLL)
		{
			switch(LOWORD(wParam))
			{
			case SB_PAGEDOWN:
				alfa += DELTA_COLOR;
				break;

			case SB_LINEDOWN:
				alfa = min(255, alfa+1);
				break;

			case SB_PAGEUP:
				alfa -= DELTA_COLOR;
				break;

			case SB_LINEUP:
				alfa = max(0, alfa-1);
				break;

			case SB_TOP:
				alfa = 0;
				break;

			case SB_BOTTOM:
				alfa = 255;
				break;

			case SB_THUMBPOSITION:
				break;

			case SB_THUMBTRACK:
				alfa = HIWORD(wParam);
				break;

			default: break;
			}
			SetScrollPos(hwndWidthSlider, SB_CTL, alfa, TRUE);
		}

		if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_FILL_COLOR)
		{
			switch(LOWORD(wParam))
			{
			case SB_PAGEDOWN:
				fill += DELTA_COLOR;
				break;

			case SB_LINEDOWN:
				fill = min(255, fill+1);
				break;

			case SB_PAGEUP:
				fill -= DELTA_COLOR;
				break;

			case SB_LINEUP:
				fill = max(0, fill-1);
				break;

			case SB_TOP:
				fill = 0;
				break;

			case SB_BOTTOM:
				fill = 255;
				break;

			case SB_THUMBPOSITION:
				break;

			case SB_THUMBTRACK:
				fill = HIWORD(wParam);
				break;

			default: break;
			}
			SetScrollPos(hwndFillColor, SB_CTL, fill, TRUE);
		}

		switch(LOWORD(wParam)) 
		{
			case SB_LINELEFT:
				si.nPos -= 1;
				break;

			case SB_LINERIGHT:
				si.nPos += 1;
				break;

			case SB_PAGELEFT:
				si.nPos -= si.nPage;
				break;

			case SB_PAGERIGHT:
				si.nPos += si.nPage;
				break;

			case SB_THUMBPOSITION:
				si.nPos = si.nTrackPos;
				break;

		default:break;
		}

		// Set the position and then retrieve it
		si.fMask = SIF_POS;
		SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
		GetScrollInfo(hwnd, SB_HORZ, &si);
		// If the position has changed, scroll the window and update it
		if(si.nPos != x)
		{
			ScrollWindow(hwnd, cxChar * (x - si.nPos), 0, NULL, 0);
			UpdateWindow(hwnd);
		}
		break;

	case WM_COMMAND:

		//Initialazing OnCommand Function
		HANDLE_WM_COMMAND(hwnd, wParam, lParam, OnCommand);

		switch(LOWORD(wParam))
		{
		case IDC_CLEAR:
			{
				//Cleaning the working area
				InvalidateRect(hwnd, &Recto, FALSE);
				InvalidateRect(hwnd, &Recto, TRUE);
			}
			break;

		case IDM_FILE_NEW:

			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_FILE_NEW, TBSTATE_CHECKED | TBSTATE_ENABLED);
			white = TRUE;
			break;

		case IDM_FILE_OPEN:

			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_FILE_OPEN, TBSTATE_CHECKED | TBSTATE_ENABLED);
			green = TRUE;
			break;

		case IDM_FILE_SAVE:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_FILE_SAVE, TBSTATE_CHECKED | TBSTATE_ENABLED);
			black = TRUE;
			break;

		case IDM_FILE_PRINT:
			red = TRUE;
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_FILE_PRINT, TBSTATE_CHECKED | TBSTATE_ENABLED);

			break;

		case IDM_FILE_EXIT:
			PostQuitMessage(WM_QUIT);
			break;

		case IDM_DRAW_FREEHAND:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_DRAW_FREEHAND, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_FREEHAND));
			break;
		case IDM_DRAW_LINE:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_DRAW_LINE, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_FREEHAND));
			break;

		case IDM_DRAW_POLYLINE:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_DRAW_POLYLINE, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_FREEHAND));
			break;
		case IDM_DRAW_RECTANGLE:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_DRAW_RECTANGLE, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_RECTANGLE));
			break;

		case IDM_DRAW_CIRCLE:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_DRAW_CIRCLE, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_CIRCLE));
			break;

		case IDM_DRAW_BEZIER:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_DRAW_BEZIER, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_CIRCLE));
			myBezier.DrawBezier(hdc, apt);
			break;

		case IDM_ERAZER:
			SendMessage(Exo.hWndToolbar, TB_SETSTATE, IDM_ERAZER, TBSTATE_CHECKED | TBSTATE_ENABLED);
			Exo.ChangeCurrentCursor(hwnd, MAKEINTRESOURCE(IDC_ERAZER));
			break;
		}
		break;

		//The following 3 cases are for drawing lines in my drawing area
	case WM_LBUTTONDOWN:


		if (xMouse > 20 && xMouse < 410 && yMouse > 50 && yMouse < 500 )
		{
			//Draw freehand
			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_FREEHAND, 0) & TBSTATE_CHECKED )
			{
				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen,RGB(0,0,255), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

				hdc = GetDC(hwnd);
				StartX = LOWORD(lParam);
				StartY = HIWORD(lParam);

				EndX = LOWORD(lParam);
				EndY = HIWORD(lParam);

				SetROP2(hdc, R2_XORPEN);

				MoveToEx(hdc, StartX, StartY, NULL);
				LineTo(hdc, EndX, EndY);
				isDrawing = TRUE;
				ReleaseDC(hwnd, hdc);
				Exo.DeleteObjectHPEN(strokePen);
			}

			// If the Line button is down, draw with it
			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_LINE, 0) & TBSTATE_CHECKED )
			{
				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

				hdc = GetDC(hwnd);
				StartX = LOWORD(lParam);
				StartY = HIWORD(lParam);

				EndX = LOWORD(lParam);
				EndY = HIWORD(lParam);
				MoveToEx(hdc, StartX, StartY, NULL);
				LineTo(hdc, EndX, EndY);
			}

			//Draw PolyLines
			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_POLYLINE, 0) & TBSTATE_CHECKED )
			{
				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

				hdc = GetDC(hwnd);
				StartX = LOWORD(lParam);
				StartY = HIWORD(lParam);

				EndX = LOWORD(lParam);
				EndY = HIWORD(lParam);
				MoveToEx(hdc, StartX, StartY, NULL);
				LineTo(hdc, EndX, EndY);
			}

			//Draw Rectangle
			if((SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_RECTANGLE, 0) & TBSTATE_CHECKED))
			{
				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

				hdc = GetDC(hwnd);
				StartX = LOWORD(lParam);
				StartY = HIWORD(lParam);
				SetBkMode(hdc,TRANSPARENT);
				EndX = LOWORD(lParam);
				EndY = HIWORD(lParam);
				SetROP2(hdc, R2_NOP);

				MoveToEx(hdc, StartX, StartY, NULL);
				Rectangle(hdc, StartX, StartY, EndX, EndY);
				ReleaseDC(hwnd, hdc);
			}

			//Draw Circle
			if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_CIRCLE, 0) & TBSTATE_CHECKED)
			{
				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
					Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

				hdc = GetDC(hwnd);
				StartX = LOWORD(lParam);
				StartY = HIWORD(lParam);
				SetBkMode(hdc,TRANSPARENT);
				EndX = LOWORD(lParam);
				EndY = HIWORD(lParam);
				SetROP2(hdc, R2_NOP);

				MoveToEx(hdc, StartX, StartY, NULL);
				Ellipse(hdc, StartX, StartY, EndX, EndY);
				ReleaseDC(hwnd, hdc);
			}

			//Eraser
			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_ERAZER, 0) & TBSTATE_CHECKED )
			{
				strokePen = CreatePen(PS_SOLID, alfa, RGB(246, 245, 243));
				SelectObject(hdc, strokePen);
				hdc = GetDC(hwnd);
				StartX = LOWORD(lParam);
				StartY = HIWORD(lParam);

				EndX = LOWORD(lParam);
				EndY = HIWORD(lParam);

				SetROP2(hdc, R2_XORPEN);

				MoveToEx(hdc, StartX, StartY, NULL);
				LineTo(hdc, EndX, EndY);
				isDrawing = TRUE;
				ReleaseDC(hwnd, hdc);
				DeleteObject(strokePen);
			}
			isDrawing = TRUE;
			ReleaseDC(hwnd, hdc);
		}
		break;

	case WM_MOUSEMOVE:

		if (xMouse > 20 && xMouse < 410 && yMouse > 50 && yMouse < 500 )
		{
			hdc = GetDC(hwnd);
			if(isDrawing == TRUE )
			{
				if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_LINE, 0) & TBSTATE_CHECKED )
				{
					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

					SetROP2(hdc, R2_NOTXORPEN);
					MoveToEx(hdc, StartX, StartY, NULL);
					LineTo(hdc, EndX, EndY);
					EndX = LOWORD(lParam);
					EndY = HIWORD(lParam);
					MoveToEx(hdc, StartX, StartY, NULL);
					LineTo(hdc, EndX, EndY);						
				}				

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_FREEHAND, 0) & TBSTATE_CHECKED )
				{
					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

					MoveToEx(hdc, EndX, EndY, NULL);
					EndX = LOWORD(lParam);
					EndY = HIWORD(lParam);
					LineTo(hdc, EndX, EndY);
				}

				if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_POLYLINE, 0) & TBSTATE_CHECKED )

				{
					if(wParam & MK_RBUTTON)
						isDrawing = false;

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

					EndX = LOWORD(lParam);
					EndY = HIWORD(lParam);

					MoveToEx(hdc, StartX, StartY, NULL);
					LineTo(hdc, EndX, EndY);;
				}

				if((SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_RECTANGLE, 0) & TBSTATE_CHECKED))
				{

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);

					HBRUSH brush = CreateSolidBrush(RGB(fill,fill-100,145));
					SelectObject(hdc, brush);

					SetROP2(hdc, R2_NOTXORPEN);
					SetBkMode(hdc,TRANSPARENT);
					MoveToEx(hdc, StartX, StartY, NULL);
					Rectangle(hdc, StartX, StartY, EndX, EndY);
					EndX = LOWORD(lParam);
					EndY = HIWORD(lParam);
					MoveToEx(hdc, StartX, StartY, NULL);
					Rectangle(hdc, StartX, StartY, EndX, EndY);
					DeleteObject(brush);
				}

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_CIRCLE, 0) & TBSTATE_CHECKED)
				{
					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,255), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,255,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(0,0,0), alfa);

					if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED)
						Exo.ChangeCurrentColor(hdc,strokePen, RGB(255,0,0), alfa);


					HBRUSH brush = CreateSolidBrush(RGB(fill,fill-100,145));
					SelectObject(hdc, brush);

					SetROP2(hdc, R2_NOTXORPEN);
					MoveToEx(hdc, StartX, StartY, NULL);
					Ellipse(hdc, StartX, StartY, EndX, EndY);
					EndX = LOWORD(lParam);
					EndY = HIWORD(lParam);
					MoveToEx(hdc, StartX, StartY, NULL);
					Ellipse(hdc, StartX, StartY, EndX, EndY);
					DeleteObject(brush);
				}

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_BEZIER, 0) & TBSTATE_CHECKED)
				{
					if (wParam & MK_LBUTTON || wParam & MK_RBUTTON)
					{
						HGDIOBJ original = NULL;

						//Saving the original object
						original = SelectObject(hdc,GetStockObject(DC_PEN));
						SelectObject(hdc, GetStockObject(DC_PEN));
						SetDCPenColor(hdc, RGB(246, 245, 243));
						myBezier.DrawBezier (hdc, apt) ;

						if (wParam & MK_LBUTTON)
						{
							apt[1].x = LOWORD (lParam) ;
							apt[1].y = HIWORD (lParam) ;
						}

						else  if (wParam & MK_RBUTTON)
						{
							apt[2].x = LOWORD (lParam) ;
							apt[2].y = HIWORD (lParam) ;
						}

						SelectObject (hdc, GetStockObject(BLACK_PEN)) ;
						myBezier.DrawBezier (hdc, apt) ;
						ReleaseDC (hwnd, hdc) ;
						DeleteObject(original);
					}
				}

				if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_ERAZER, 0) & TBSTATE_CHECKED )
				{
					strokePen = CreatePen(PS_SOLID, alfa, RGB(246, 245, 243));
					SelectObject(hdc, strokePen);
					MoveToEx(hdc, EndX, EndY, NULL);
					EndX = LOWORD(lParam);
					EndY = HIWORD(lParam);
					LineTo(hdc, EndX, EndY);
					Exo.DeleteObjectHPEN(strokePen);
				}
			}
			ReleaseDC(hwnd, hdc);
		}
		break;

	case WM_LBUTTONUP:

		if (xMouse > 20 && xMouse < 410 && yMouse > 50 && yMouse < 500 )
		{
			hdc = GetDC(hwnd);
			EndX = LOWORD(lParam);
			EndY = HIWORD(lParam);
			SetROP2(hdc, R2_XORPEN);
			MoveToEx(hdc, StartX, StartY, NULL);
			LineTo(hdc, EndX, EndY);

			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_NEW, 0) & TBSTATE_CHECKED )
			{
				isDrawing = FALSE;
				white = FALSE;
			}

			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_OPEN, 0) & TBSTATE_CHECKED )
			{
				isDrawing = FALSE;
				green = FALSE;
			}

			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_SAVE, 0) & TBSTATE_CHECKED )
			{
				isDrawing = FALSE;
				black = FALSE;
			}

			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_FILE_PRINT, 0) & TBSTATE_CHECKED )
			{
				isDrawing = FALSE;
				red = FALSE;
			}


			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_LINE, 0) & TBSTATE_CHECKED )
			{
				isDrawing = FALSE;
			}

			if( SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_POLYLINE, 0) & TBSTATE_CHECKED)
			{
				isDrawing = FALSE;
			}

			if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_FREEHAND, 0) & TBSTATE_CHECKED )
			{
				isDrawing = FALSE;
			}

			if((SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_RECTANGLE, 0) & TBSTATE_CHECKED))
			{
				SetBkMode(hdc,TRANSPARENT);
				Rectangle(hdc, StartX, StartY, EndX, EndY);
				isDrawing = FALSE;
			}

			if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_CIRCLE, 0) & TBSTATE_CHECKED)
			{
				isDrawing = FALSE;
			}

			if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_DRAW_BEZIER, 0) & TBSTATE_CHECKED)
			{
				isDrawing = FALSE;
			}

			if(SendMessage(Exo.hWndToolbar, TB_GETSTATE, IDM_ERAZER, 0) & TBSTATE_CHECKED)
			{
				isDrawing = FALSE;
			}

			ReleaseDC(hwnd, hdc);
		}
		break;

	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);
		GetClientRect(hwnd , &rect);
		hdc_mem = CreateCompatibleDC(hdc);
		SelectObject(hdc_mem, logo);
		BitBlt(hdc, 15, 540, bitmap.bmWidth, bitmap.bmHeight, hdc_mem, 0, 0, SRCCOPY);

		DeleteObject(hdc_mem);
		//Creating Draw Area
		DrawEdge(hdc, &Recto, BDR_RAISEDOUTER | BDR_SUNKENINNER, BF_RECT);

		EndPaint(hwnd, &ps);
		break;

		//Handle the combinations from the keyboard input
	case WM_KEYDOWN:
		{
			switch(wParam)
			{
			case KEY_S:
				isDrawing = FALSE;
				break;
			case KEY_Q:
				{
					if(GetAsyncKeyState(VK_LCONTROL))
					{
						//If Q + LCTRL then Exit
						PostQuitMessage(0);
					}
				}
				break;

			case KEY_C:
				{
					if(GetAsyncKeyState(VK_LSHIFT))
					{
						//If C + LShift then cleaning the drawingarea
						InvalidateRect(hwnd, &Recto, FALSE);
						InvalidateRect(hwnd, &Recto, TRUE);

					}
				}
				break;
			}
		}
		break;

	case WM_DESTROY:
		PostQuitMessage (0);
		DeleteObject(logo);
		DeleteObject(strokePen);
		break;

	default:
		return DefWindowProc (hwnd, msg, wParam, lParam);
	}

	return 0;
}
Пример #22
0
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    // Child windows' handles
    static HWND hwndListBox, hwndNewItem, hwndAddButton, hwndRemoveButton, hwndClearButton, hwndHeightScroll, hwndWidthScroll;
    static HINSTANCE hInstance;

    // Size and position variables
    int iSysWidth;
    int iSysHeight;
    int iWinWidth;
    int iWinHeight;

    int iWidth  = 60;   // Button width
    int iHeight = 30;   // Button height
    int x;
    int y;

    int i, cxChar, cyChar;

    // Menu & menu items
    HMENU hMenu;
    HMENU hSubMenu;

    // String
    char* szText;
    int iTextLength;

    // Paint and size structs
    TEXTMETRIC tm;
    SCROLLINFO si;
    HBRUSH brush;
    RECT rect, rct;
    int color;
    HDC hdc;


    hdc = GetDC(hwnd);
    GetTextMetrics(hdc, &tm);
    cxChar = tm.tmAveCharWidth;
    cyChar = tm.tmHeight;
    ReleaseDC(hwnd, hdc);

    switch(message) {

        case WM_CREATE:
            hwndListBox = CreateWindowEx(
                (DWORD)NULL,
                TEXT("ListBox"),
                NULL,
                WS_CHILD | WS_VISIBLE | WS_BORDER | LBS_NOTIFY | LBS_WANTKEYBOARDINPUT,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_LIST_BOX,
                hProgramInstance,
                NULL);

            hwndNewItem = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Edit"),
                TEXT("Input candidates"),
                WS_CHILD | WS_VISIBLE | WS_BORDER |ES_AUTOVSCROLL | ES_AUTOHSCROLL,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_NEW_ITEM,
                hProgramInstance,
                NULL);

            hwndWidthScroll = CreateWindow(
                "Scrollbar",
                NULL,
                WS_CHILD | WS_VISIBLE | SBS_HORZ | SBS_BOTTOMALIGN,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_WIDTH_SCROLL,
                hProgramInstance,
                NULL);
            SetScrollRange(hwndWidthScroll, SB_CTL, 0, 100, FALSE);
            SetScrollPos(hwndWidthScroll, SB_CTL, 0, FALSE);

            hwndHeightScroll = CreateWindow(
                "Scrollbar",
                NULL,
                WS_CHILD | WS_VISIBLE | SBS_VERT | SBS_BOTTOMALIGN,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_HEIGHT_SCROLL,
                hProgramInstance,
                NULL);
            SetScrollRange(hwndHeightScroll, SB_CTL, 0, 100, TRUE);
            SetScrollPos(hwndHeightScroll, SB_CTL, 0, FALSE);

            hwndAddButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Add"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_ADD_BUTTON,
                hProgramInstance,
                NULL);

            hwndRemoveButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Remove"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_REMOVE_BUTTON,
                hProgramInstance,
                NULL);

            hwndClearButton = CreateWindowEx(
                (DWORD)NULL,
                TEXT("Button"),
                TEXT("Clear"),
                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                0, 0, 0, 0, hwnd,
                (HMENU)IDC_CLEAR_BUTTON,
                hProgramInstance,
                NULL);


            // Create menu
            hMenu = CreateMenu();

            // Add "File" menu, with "Exit" submenu
            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
            AppendMenu(hSubMenu, MF_STRING, IDC_FILE_EXIT, "&Exit");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Edit");
            AppendMenu(hSubMenu, MF_STRING, IDC_MOVE, "&Jump around");

            hSubMenu = CreatePopupMenu();
            AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");
            AppendMenu(hSubMenu, MF_STRING, IDC_HELP_ABOUT, "&About");

            // Set the menu
            SetMenu(hwnd, hMenu);
            break;

        case WM_SIZE:
            iWidth  = LOWORD(lParam);
            iHeight = HIWORD(lParam);

            // Set vertical scroll bar range and page size
            si.cbSize = sizeof(si);
            si.fMask = SIF_RANGE | SIF_PAGE;
            si.nMin = 0;
            si.nMax = ((iMinWindowHeight - 70) / cyChar);
            si.nPage = iHeight / cyChar;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);

            // Set horizontal scroll bar range and page size
            si.cbSize = sizeof(si);
            si.fMask = SIF_RANGE | SIF_PAGE;
            si.nMin = 0;
            si.nMax = ((iMinWindowWidth - 20) / cxChar);
            si.nPage = iWidth / cxChar;
            SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);

            // CHILD WINDOWS REPOSITION BEGIN

            MoveWindow(hwndListBox, iWidth/2 - 210, iHeight/2 - 150, 300, 350, TRUE);
            MoveWindow(hwndNewItem, iWidth/2 - 210, iHeight/2 - 220, 300, 50, TRUE);
            MoveWindow(hwndWidthScroll, iWidth/2 - 210, iHeight/2 + 200, 410, 20, TRUE);
            MoveWindow(hwndHeightScroll, iWidth/2 + 180, iHeight/2 - 220, 20, 410, TRUE);
            MoveWindow(hwndAddButton, iWidth/2 + 100, iHeight/2 - 210, 60, 30, TRUE);
            MoveWindow(hwndRemoveButton, iWidth/2 + 100, iHeight/2 - 140, 60, 30, TRUE);
            MoveWindow(hwndClearButton, iWidth/2 + 100 , iHeight/2- 100, 60, 30, TRUE);

            // CHILD WINDOWS REPOSITION END
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            // Set width scrollbar position
            SetScrollPos(hwndWidthScroll, SB_CTL, (iWinWidth * 100 / iSysWidth), TRUE);

            // Set height scrollbar position
            SetScrollPos(hwndHeightScroll, SB_CTL, (iWinHeight * 100 / iSysHeight), TRUE);
            break;

        case WM_VSCROLL:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_HEIGHT_SCROLL) {
                si.cbSize = sizeof(si);
                si.fMask = SIF_ALL;
                GetScrollInfo(hwndHeightScroll, SB_CTL, &si);
                y = si.nPos;
                switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        si.nPos -= 1;
                        break;
                    case SB_LINERIGHT:
                        si.nPos += 1;
                        break;
                    case SB_THUMBPOSITION:
                        si.nPos = si.nTrackPos;
                        break;
                    default:
                        break;
                }
                si.fMask = SIF_POS;
                SetScrollInfo(hwndHeightScroll, SB_CTL, &si, TRUE);
                GetScrollInfo(hwndHeightScroll, SB_CTL, &si);
                if(si.nPos != y) {
                    SetScrollPos(hwndHeightScroll, SB_CTL, si.nPos, TRUE);
                }
                // Set window height
                MoveWindow(hwnd, rect.left, rect.top, iWinWidth, (si.nPos * iSysHeight / 100), TRUE);
                break;
            }


            // Get all the vertical scroll bar information
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_VERT, &si);

            // Save the position for later comparison
            x = si.nPos;


            switch(LOWORD(wParam)) {
                case SB_TOP:
                    si.nPos = si.nMin;
                    break;

                case SB_BOTTOM:
                    si.nPos = si.nMax;
                    break;

                case SB_LINEUP:
                    si.nPos -= 1;
                    break;

                case SB_LINEDOWN:
                    si.nPos += 1;
                    break;

                case SB_PAGEUP:
                    si.nPos -= si.nPage;
                    break;

                case SB_PAGEDOWN:
                    si.nPos += si.nPage;
                    break;

                case SB_THUMBTRACK:
                    si.nPos = si.nTrackPos;
                    break;

                default:
                    break;
            }

            // Set the position and then retrieve it
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
            GetScrollInfo(hwnd, SB_VERT, &si);

            // If the position has changed, scroll the window and update it
            if(si.nPos != x) {
                ScrollWindow(hwnd, 0, cyChar * (y - si.nPos), NULL, NULL);
                UpdateWindow(hwnd);
            }
            break;

        case WM_HSCROLL:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            if(GetWindowLong((HWND)lParam, GWL_ID) == IDC_WIDTH_SCROLL) {
                si.cbSize = sizeof(si);
                si.fMask = SIF_ALL;
                GetScrollInfo(hwndWidthScroll, SB_CTL, &si);
                x = si.nPos;
                switch(LOWORD(wParam)) {
                    case SB_LINELEFT:
                        si.nPos -= 1;
                        break;
                    case SB_LINERIGHT:
                        si.nPos += 1;
                        break;
                    case SB_THUMBPOSITION:
                        si.nPos = si.nTrackPos;
                        break;
                    default:
                        break;
                }
                si.fMask = SIF_POS;
                SetScrollInfo(hwndWidthScroll, SB_CTL, &si, TRUE);
                GetScrollInfo(hwndWidthScroll, SB_CTL, &si);
                if(si.nPos != x) {
                    SetScrollPos(hwndWidthScroll, SB_CTL, si.nPos, TRUE);
                }
                // Set window width
                MoveWindow(hwnd, rect.left, rect.top, (si.nPos * iSysWidth / 100), iWinHeight, TRUE);
                break;
            }

           // Get all the vertical scroll bar information
            si.cbSize = sizeof(si);
            si.fMask = SIF_ALL;
            GetScrollInfo(hwnd, SB_HORZ, &si);
            // Save the position for later comparison
            x = si.nPos;
            switch(LOWORD(wParam)) {
                case SB_LINELEFT:
                    si.nPos -= 1;
                    break;

                case SB_LINERIGHT:
                    si.nPos += 1;
                    break;

                case SB_PAGELEFT:
                    si.nPos -= si.nPage;
                    break;

                case SB_PAGERIGHT:
                    si.nPos += si.nPage;
                    break;

                case SB_THUMBPOSITION:
                    si.nPos = si.nTrackPos;
                    break;

                default:
                    break;
            }
            // Set the position and then retrieve it
            si.fMask = SIF_POS;
            SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
            GetScrollInfo(hwnd, SB_HORZ, &si);

            // If the position has changed, scroll the window and update it
            if(si.nPos != x) {
                ScrollWindow(hwnd, cxChar * (x - si.nPos), 0, NULL, 0);
                UpdateWindow(hwnd);
            }
            break;

        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                case IDC_LIST_BOX:
                    switch (HIWORD(wParam)) {
                        case LBN_DBLCLK:
                            MessageBox(NULL, TEXT("Candidate Selected!"), TEXT("Congrats!"), MB_OK);
                            break;
                    }
                    break;

                case IDC_ADD_BUTTON:
                    iTextLength = SendMessage(hwndNewItem, WM_GETTEXTLENGTH, 0, 0);
                    szText = (char*)malloc(iTextLength+1);
                    SendMessage(hwndNewItem, WM_GETTEXT, iTextLength+1, (LPARAM)szText);
                    SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)szText);
                    SendMessage(hwndNewItem, WM_SETTEXT, 0, (LPARAM)"");
                    free(szText);
                    break;

                case IDC_REMOVE_BUTTON:
                    i = SendMessage(hwndListBox, LB_GETCURSEL, 0, 0);
                    if(i != LB_ERR) {
                        SendMessage(hwndListBox, LB_DELETESTRING, i, 0);
                    }
                    break;

                case IDC_CLEAR_BUTTON:
                    SendMessage(hwndListBox, LB_RESETCONTENT, 0, 0);
                    break;

                case IDC_FILE_EXIT:
                    SendMessage(hwnd, WM_DESTROY, 0, 0);
                    break;

                case IDC_MOVE:
                            int xPos, yPos;
                            xPos = rand() % 1000;
                            yPos = rand() % 800;
                            SetWindowPos(hwnd, HWND_TOP, xPos, yPos, 0, 0, SWP_NOSIZE);
                            break;

                case IDC_HELP_ABOUT:
                    return DialogBox(hProgramInstance, MAKEINTRESOURCE(IDD_ABOUT), NULL, (DLGPROC)DialogProcedure);
                    break;

                default:
                    DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
                    break;
            }
            break;

        case WM_KEYDOWN:
            GetWindowRect(hwnd, &rect);
            iWinWidth = rect.right - rect.left;
            iWinHeight = rect.bottom - rect.top;
            iSysWidth = GetSystemMetrics(SM_CXSCREEN);
            iSysHeight = GetSystemMetrics(SM_CYSCREEN);

            // Move window right on Shift + Arrow Right
            if((wParam == VK_RIGHT)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.left >= iSysWidth - iWinWidth) {
                    MoveWindow(hwnd, iSysWidth - iWinWidth, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left + 5, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window left on Shift + Arrow Left
            if((wParam == VK_LEFT)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.left <= 0) {
                    MoveWindow(hwnd, 0, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left - 5, rect.top, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window down on Shift + Arrow Down
            if((wParam == VK_DOWN)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.top >= iSysHeight - iWinHeight) {
                    MoveWindow(hwnd, rect.left, iSysHeight - iWinHeight, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left, rect.top + 5, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            // Move window up on Shift + Arrow Up
            if((wParam == VK_UP)&&(HIBYTE(GetKeyState(VK_SHIFT)) > 1)) {
                if(rect.top <= 0) {
                    MoveWindow(hwnd, rect.left, 0, iWinWidth, iWinHeight, TRUE);
                }
                else {
                    MoveWindow(hwnd, rect.left, rect.top - 5, iWinWidth, iWinHeight, TRUE);
                }
                break;
            }
            return DefWindowProc (hwnd, WM_PAINT, wParam, lParam);


        case WM_PAINT:
            return DefWindowProc (hwnd, WM_PAINT, wParam, lParam);
            break;

        case WM_DESTROY:
            PostQuitMessage (0);
            break;

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}