Exemple #1
0
int SelectComboText( HWND hDlg, long id, const char *szString )
{
	long count = GetPopupTot( id );
	while( count > 0 )
	{
		char lString[255];
		GetPopupText( id, 255, lString );
		if ( strstr( lString, szString ) )
		{
			SetPopupNum( id, count );
			return count;
		}
		count--;
	}
}
void ToasterBoxWindow::DrawText()
{
	DCType dc(this);
	//width and height of text
	wxCoord w = 0, h = 0;
	//where we will set the text
	wxCoord x = 0, y = 0;
	//border from sides and top to text (in pixels)
	int border_right = 7;
	int border_left = 102;
	if (sbm.GetBitmap().IsOk()) {
		border_left += sbm.GetBitmap().GetWidth();
	}
	//how much space between text lines
	int textPadding = 4;
	//how much can we have on a line?
	int textColumns = 0;
	//how many lines can we fit vertically
	float textLines = 1;
	//the popupText after our transformations (if we do any)
	wxString pText = GetPopupText();
	wxFont outFont(9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD);
	dc.SetFont(outFont);

	dc.GetMultiLineTextExtent(pText, &w, &h);

	//shrink the text to fit in the popup box
	if (shrink) {
		while ((w + (border_right + border_left)) > GetSize().GetWidth()) {
			pText = pText.Left(pText.Length() - 1);
			dc.GetMultiLineTextExtent(pText, &w, &h);
		}
		textColumns = pText.Length();
		//figure out how many lines of text we have
		textLines = (GetPopupText().Length() / textColumns) + .9;
	}

	bool haveHeader = false;
	if (popupHeaderText.IsEmpty() == false) {
		textLines++;
		haveHeader = true;
	}
	//center the text
	//  if(w < GetSize().GetWidth())
	//    x = (GetSize().GetWidth() - w) / 2;
	//  if(h < GetSize().GetHeight())
	//    y = (GetSize().GetHeight() - h) / 2;


	//  //if we have multiple lines
	if (textLines > 1) {
		if (haveHeader) {
			//Draw header text with a shadow effect
			dc.SetTextForeground(*wxGREEN);
			//Try to center header text
			auto textSize = dc.GetTextExtent(popupHeaderText);
			int headerX = (GetSize().GetWidth() / 2) - (textSize.GetWidth() / 2);
			const int headerY = 3;
			dc.DrawText(popupHeaderText, headerX, headerY);
			dc.SetTextForeground(headerTextColor);
			dc.DrawText(popupHeaderText, headerX + 1, headerY + 1); //This makes "shadow" effect
		}
		dc.SetTextForeground(textColor);
		//how many lines we can fit in the height available
		float howManyLinesFit = GetSize().GetHeight() / (h + textPadding);
		if (textLines < howManyLinesFit)
			howManyLinesFit = textLines;
		y = (GetSize().GetHeight() - ((h + textPadding) * howManyLinesFit)) / 2;
		//Move text down a bit to get place for header
		if (haveHeader) {
			y += 15;
		}
		for (int i = 0; i < howManyLinesFit; i++) {
			dc.DrawText(GetPopupText().Mid((i * textColumns), textColumns), x + border_left, y);
			//move the text down a line
			y += h + textPadding;
		}
	} else {
		dc.SetTextForeground(textColor);
		dc.DrawText(pText, x, y);
	}
}
Exemple #3
0
LONG APIENTRY MainDialogProc(HWND hWnd, UINT msg, DWORD dwParam, LONG lParam)
{
	short	wParam = (short)dwParam;
	PAINTSTRUCT ps;
	HDC hdc;
	HWND hDlg = hWnd;

    switch (msg) {
        case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			EndPaint(hWnd, &ps);
            break;

		case WM_CLOSE:
			EndDialog(hWnd, TRUE);
			return (TRUE);
			break;

		case WM_DESTROY:
			break;

        case WM_INITDIALOG:
			{
			FillComboWithWindowNames( hWnd, IDC_COMBO1 );
			FillComboWithWindowNames( hWnd, IDC_COMBO2 );

			if ( sourceWindowName1[0] )
				SelectComboText( hWnd, IDC_COMBO1, sourceWindowName1 );

			if ( sourceWindowName2[0] )
				SelectComboText( hWnd, IDC_COMBO2, sourceWindowName2 );

			//SetDlgItemText( hWnd, IDC_WINDOWNAME, "Type window's title here" );
			return TRUE;
			}
			break;

		case WM_TIMER:
			switch (wParam){
				case MYWAIT_EVENT:
					//DoMirrorProcess( hWnd );
					break;
			}
			break;

	case WM_COMMAND: 
            switch (dwParam) {
				case IDC_START:
					char szString[256];
					HWND hDlg = hWnd;
					// get search string
					GetDlgItemText( hDlg, IDC_WINDOWNAME, szString , sizeof(szString) );
					if( szString[0] )
					{
						SelectComboText( hDlg, IDC_COMBO1, szString );
						hWndSourceWindow1 = FindSourceWindow( hWnd, szString );
						strcpy( sourceWindowName1, szString );
					} else
					{
						int selA = GetPopupNum( IDC_COMBO1 );
						GetPopupText( IDC_COMBO1, selA, szString );
						if( szString[0] ){
							hWndSourceWindow1 = FindSourceWindow( hWnd, szString );
							strcpy( sourceWindowName1, szString );
						}

						int selB = GetPopupNum( IDC_COMBO2 );
						GetPopupText( IDC_COMBO2, selB, szString );
						if( szString[0] ){
							hWndSourceWindow2 = FindSourceWindow( hWnd, szString );
							strcpy( sourceWindowName2, szString );
						}

						hWndSourceWindow = hWndSourceWindow1;
						
						SetForegroundWindow( hWndSourceWindow );

					}

					if( hWndSourceWindow )
					{
						DialogBox( hInst, (LPCTSTR)IDD_MIRROR, hWnd, (DLGPROC)MirrorProc);
						FillComboWithWindowNames( hWnd, IDC_COMBO1 );
						FillComboWithWindowNames( hWnd, IDC_COMBO2 );
					} else {
						MessageBox( GetFocus(), "Cannot find source window", "Error", MB_OK|MB_ICONQUESTION );
					}
					break;
			}
	}
	return FALSE;
}
void ToasterBoxWindow::DrawText()
{
	DCType dc( this );
#ifdef __WXMSW__
//	dc.SetBackground( *wxBLACK_BRUSH );
//	dc.Clear();
	dc.DrawBitmap(charArr2wxBitmap( notif_bg_png, sizeof(notif_bg_png) ), 0, 0, false);
#endif
  //width and height of text
  wxCoord w = 0, h = 0;
  //where we will set the text
  wxCoord x = 0, y = 0;
  //border from sides and top to text (in pixels)
  int border_right = 7;
  int border_left = sbm.GetBitmap().GetWidth() + 102;
  //how much space between text lines
  int textPadding = 4;
  //how much can we have on a line?
  int textColumns = 0;
  //how many lines can we fit vertically
  float textLines = 1;
  //the popupText after our transformations (if we do any)
  wxString pText = GetPopupText();
	wxFont outFont( 9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD );
	dc.SetFont( outFont );

  dc.GetTextExtent(pText, &w, &h);

  //shrink the text to fit in the popup box
  if(shrink)
  {
	while((w +(border_right + border_left))> GetSize().GetWidth())
    {
      pText = pText.Left(pText.Length()-1);
      dc.GetTextExtent(pText, &w, &h);
    }
    textColumns = pText.Length();
    //figure out how many lines of text we have
    textLines = (GetPopupText().Length() / textColumns) +.9;
  }

  //center the text
//  if(w < GetSize().GetWidth())
//    x = (GetSize().GetWidth() - w) / 2;
//  if(h < GetSize().GetHeight())
//    y = (GetSize().GetHeight() - h) / 2;

  dc.SetTextForeground(textColor);

//  //if we have multiple lines
  if(textLines > 1)
  {
    //how many lines we can fit in the height available
    float howManyLinesFit = GetSize().GetHeight() / (h+textPadding);
    if(textLines < howManyLinesFit)
      howManyLinesFit = textLines;
    y = (GetSize().GetHeight() - ((h+textPadding) * howManyLinesFit)) / 2;
    for(int i = 0; i < howManyLinesFit; i++)
    {
	  dc.DrawText(GetPopupText().Mid((i*textColumns), textColumns), x + border_left,y);
      //move the text down a line
      y += h+textPadding;
    }
  }
  else
    dc.DrawText(pText, x,y);

}