Exemple #1
0
//#include "debugprint.h"
WinFontStruct *WinFontCreate(char* fontname, char style, char size) {
	HFONT	font;						// Windows Font ID
	GLuint	base;
	GLYPHMETRICSFLOAT gmf[256];
	base = glGenLists(256);					// Storage For 256 Characters


	// Height
	//By putting a minus, we're telling windows to find us a font based on the CHARACTER height.
	//If we use a positive number we match the font based on the CELL height.

	// Width
	//Then we specify the cell width. You'll notice I have it set to 0.
	//By setting values to 0, windows will use the default value.
	//You can play around with this value if you want. Make the font wide, etc.

	// Angle
	//Angle of Escapement will rotate the font. Orientation Angle quoted from MSDN help
	//Specifies the angle, in tenths of degrees, between each character's base line and
	//the x-axis of the device.
	//Unfortunately I have no idea what that means :(

	// Weight
	//Font weight is a great parameter. You can put a number from 0 - 1000 or you can use
	//one of the predefined values. FW_DONTCARE is 0, FW_NORMAL is 400, FW_BOLD is 700
	//and FW_BLACK is 900. There are alot more predefined values, but those 4 give some
	//good variety. The higher the value, the thicker the font (more bold).

	// Style
	//Italic, Underline and Strikeout can be either TRUE or FALSE. Basically if underline
	//is TRUE, the font will be underlined. If it's FALSE it wont be. Pretty simple :)

	// Charset
	//Character set Identifier describes the type of Character set you wish to use.
	//There are too many types to explain. CHINESEBIG5_CHARSET, GREEK_CHARSET, RUSSIAN_CHARSET,
	//DEFAULT_CHARSET, etc. ANSI is the one I use, although DEFAULT would probably work
	//just as well.
	//If you're interested in using a font such as Webdings or Wingdings, you need to use
	//SYMBOL_CHARSET instead of ANSI_CHARSET.

	// Precision
	//Output Precision is very important. It tells Windows what type of character set
	//to use if there is more than one type available. OUT_TT_PRECIS tells Windows that
	//if there is more than one type of font to choose from with the same name, select
	//the TRUETYPE version of the font. Truetype fonts always look better, especially
	//when you make them large. You can also use OUT_TT_ONLY_PRECIS, which ALWAYS trys
	//to use a TRUETYPE Font.

	// Clipping Precision
	//is the type of clipping to do on the font if it goes outside the clipping region.
	//Not much to say about this, just leave it set to default.

	// Output Quality
	//is very important.you can have PROOF, DRAFT, NONANTIALIASED, DEFAULT or ANTIALIASED.
	//We all know that ANTIALIASED fonts look good :) Antialiasing a font is the same effect
	//you get when you turn on font smoothing in Windows. It makes everything look less jagged.

	// Family and Pitch
	//Next we have the Family and Pitch settings. For pitch you can have DEFAULT_PITCH,
	//FIXED_PITCH and VARIABLE_PITCH, and for family you can have FF_DECORATIVE, FF_MODERN,
	//FF_ROMAN, FF_SCRIPT, FF_SWISS, FF_DONTCARE. Play around with them to find out what
	//they do. I just set them both to default.

	// Font name
	//Finally... We have the actual name of the font. Boot up Microsoft Word or some other
	//text editor. Click on the font drop down menu, and find a font you like. To use the
	//font, replace 'Comic Sans MS' with the name of the font you'd rather use.

	font = CreateFont(	-12,												// Height Of Font
						0,													// Width Of Font
						0,													// Angle Of Escapement
						0,													// Orientation Angle
						(style & WINFONT_BOLD) ? FW_BOLD : FW_DONTCARE,		// Font Weight
						style & WINFONT_ITALIC,								// Italic
						style & WINFONT_UNDERLINE,							// Underline
						style & WINFONT_STRIKEOUT,							// Strikeout
						ANSI_CHARSET,										// Character Set Identifier
						OUT_TT_PRECIS,										// Output Precision
						CLIP_DEFAULT_PRECIS,								// Clipping Precision
						ANTIALIASED_QUALITY,								// Output Quality
						FF_DONTCARE|DEFAULT_PITCH,							// Family And Pitch
						fontname);											// Font Name

	if (!font) {
		MessageBox(HWND_DESKTOP, "Failed to create font.", 0,0);
		return NULL;
	}

	HDC hDC = CreateCompatibleDC(GetDC(HWND_DESKTOP)); //"DISPLAY", NULL, NULL, NULL);
	if (!hDC) {
		MessageBox(HWND_DESKTOP, "Failed to create font.", 0,0);
		return NULL;
	}
	SelectObject(hDC, font);				// Selects The Font We Created

	//Now for the new code. We build our Outline font using a new command wglUseFontOutlines.
	//We select our DC, the starting character, the number of characters to create and the
	//'base' display list value. All very similar to the way we built our Bitmap font.


	//That's not all however. We then set the deviation level. The closer to 0.0f, the
	//smooth the font will look. After we set the deviation, we get to set the font
	//thickness. This describes how thick the font is on the Z axis. 0.0f will produce
	//a flat 2D looking font and 1.0f will produce a font with some depth.

	//The parameter WGL_FONT_POLYGONS tells OpenGL to create a solid font using polygons.
	//If we use WGL_FONT_LINES instead, the font will be wireframe (made of lines).
	//It's also important to note that if you use GL_FONT_LINES, normals will not be
	//generated so lighting will not work properly.

	//The last parameter gmf points to the address buffer for the display list data.


	wglUseFontOutlines(	hDC,				// Select The Current DC
						0,					// Starting Character
						255,				// Number Of Display Lists To Build
						base,				// Starting Display Lists
						1.0f,				// Deviation From The True Outlines
						0.0f,				// Font Thickness In The Z Direction
						WGL_FONT_POLYGONS,	// Use Polygons, Not Lines
						gmf);				// Address Of Buffer To Recieve Data

	//wglUseFontBitmaps (hDC, 0, 255, base);
	DeleteObject(font);
	DeleteDC(hDC);

	WinFontStruct *font_struct;
	font_struct = (WinFontStruct*)malloc(sizeof(WinFontStruct));
	font_struct->base = base;
	memcpy(font_struct->gmf, gmf, sizeof(gmf[0])*256);
	return font_struct;
}
void CKSImportGUIPane::Init()
{
    mpPane = ge::IPane::Create();
    mpPane->SetSize(ge::SSize(424,424));
    CreateBitmap(ge::IControl::giNoID, IDB_Back_Import, ge::SPos(0, 0));

    mpPop = NULL;

    //-------------------------------------------------
    // Scroll pane viewing the content in a "Folder"
    mpImport_File_Browser = new CKS_Import_File_Browser(this, GetGUI());
    mpImport_File_Browser->SetInfo();
    mpImport_File_Browser->Init();
    mpPane->AddControl(mpImport_File_Browser->GetPane(), ge::SPos(8, 39));
    Create_File_Browser_ScrollBar();

    //-------------------------------------------------
    // Scroll pane viewing a list of files to add to te project
    mpImport_Files = new CKS_Import_Files(this, GetGUI());
    mpImport_Files->SetInfo();
    mpImport_Files->Init();
    mpPane->AddControl(mpImport_Files->GetPane(), ge::SPos(216, 39));
    Create_File_ScrollBar();


    CreateButton(giCtrl_Remove_Import, IDB_Button_Move, ge::SPos(195, 345), false);
    CreateButton(giCtrl_Add_Import, IDB_Button_Add, ge::SPos(195, 369), false);
    // Stop
    CreateButton(giCtrl_Stop_Import, IDB_Button_Stop, ge::SPos(195, 369+24), false);
    // Play
    Create2StateButton(giCtrl_Play_Import, IDB_Button_Play, ge::SPos(195+28, 369+24), true);


    // Cancel / Export
    CreateButton(giCtrl_Cancel_Import, IDB_Button_Cancel, ge::SPos(292, 400), false);
    CreateButton(giCtrl_Import, IDB_Button_Import, ge::SPos(292 + 64, 400), false);

    tchar psz[1024];
    CKSPlugIn* pPlugIn = dynamic_cast<CKSPlugIn*>(GetPlugIn());
    //IFile::GetSystemDirectory(IFile::SystemDirDesktop, psz);
    pPlugIn->GetDefaultProjectFolder(psz);
    BrowseToDir(std::string(psz));

    dynamic_cast<CKSPlugIn*>(GetGUI()->GetPlugIn())->SetPreviewCallback(dynamic_cast<CPreviewCallback*>(this));

    ge::IText* pText = CreateDisplay(giControlType, ge::SPos(96, 333+22), ge::SSize(100, 12), CreateFont(Generic128, IDB_Minix_Tight, ge::SRGB(10, 10, 10)), false);
    pText->SetHorzAlignment(ge::IText::HorzAlignLeft);
    pText = CreateDisplay(giControlBitDepth, ge::SPos(96, 347+22), ge::SSize(100, 12), CreateFont(Generic128, IDB_Minix_Tight, ge::SRGB(10, 10, 10)), false);
    pText->SetHorzAlignment(ge::IText::HorzAlignLeft);
    pText = CreateDisplay(giControlSampleRate, ge::SPos(96, 361+22), ge::SSize(100, 12), CreateFont(Generic128, IDB_Minix_Tight, ge::SRGB(10, 10, 10)), false);
    pText->SetHorzAlignment(ge::IText::HorzAlignLeft);
    pText = CreateDisplay(giControlChannels, ge::SPos(96, 375+22), ge::SSize(100, 12), CreateFont(Generic128, IDB_Minix_Tight, ge::SRGB(10, 10, 10)), false);
    pText->SetHorzAlignment(ge::IText::HorzAlignLeft);
} // Init
// subclass for dialog item
LRESULT CALLBACK InternalEmulatorInputDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) {
	auto d = (DialogData *)dwRefData;
	switch (uMsg) {
	case WM_PAINT: {
		HDC				hdc;
		PAINTSTRUCT		ps;
		HANDLE			hOldFont;
		TCHAR			szText[200];
		RECT			rect;
		SIZE			sz;
		int				x, y;

		// Get a device context for this window
		hdc = BeginPaint(hWnd, &ps);

		auto hFont = CreateFont(14, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
			CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, TEXT("Arial"));
		SelectObject(hdc, hFont);

		// Set the text colours
		SetTextColor(hdc, d->fgColor);
		SetBkColor(hdc, d->bgColor);

		// Find the text to draw
		GetWindowText(hWnd, szText, sizeof(szText));

		// Work out where to draw
		GetClientRect(hWnd, &rect);

		// Find out how big the text will be
		GetTextExtentPoint32(hdc, szText, lstrlen(szText), &sz);

		// Center the text
		x = (rect.right - sz.cx) / 2;
		y = (rect.bottom - sz.cy) / 2;

		// Draw the text
		ExtTextOut(hdc, x, y, ETO_OPAQUE, &rect, szText, lstrlen(szText), 0);

		DeleteObject(hFont);

		EndPaint(hWnd, &ps);

		break;
	}
	case WM_KEYDOWN: {
		if (LOWORD(wParam) == VK_DELETE) {
			d->setting.type = InternalEmulatorInputType::KEY;
			d->setting.value = 0;

			d->fgColor = RGB(255, 0, 0);
			d->bgColor = RGB(0, 255, 0);

			auto s = GetButtonText(d);
			SetWindowText(hWnd, s.c_str());
		}
		else if (IsValidKey(LOWORD(wParam))) {
			//d->fgColor = GetSysColor(COLOR_WINDOWTEXT);
			//d->bgColor = GetSysColor(COLOR_WINDOW);

			d->setting.type = InternalEmulatorInputType::KEY;
			d->setting.value = lParam;

			d->fgColor = RGB(255, 0, 0);
			d->bgColor = RGB(0, 255, 0);

			auto s = GetButtonText(d);
			SetWindowText(hWnd, s.c_str());
		}
		else {
			d->fgColor = RGB(0, 255, 0);
			d->bgColor = RGB(255, 0, 0);
		}
		InvalidateRect(GetParent(hWnd), NULL, false);

		break;
	}
	case WM_TIMER: {
		if (hWnd == GetFocus()) {
			if (JoystickPoll(GetParent(hWnd), d)) {
				//d->fgColor = GetSysColor(COLOR_WINDOWTEXT);
				//d->bgColor = GetSysColor(COLOR_WINDOW);

				auto s = GetButtonText(d);
				SetWindowText(hWnd, s.c_str());
				InvalidateRect(GetParent(hWnd), NULL, false);
			}
		}
		SetTimer(hWnd, 747, 125, NULL);
		break;
	}
	case WM_CHAR: {
		break;
	}
	case WM_SETFOCUS: {
		if (!d->timerActive) {
			SetTimer(hWnd, 777, 125, NULL);
			d->timerActive = true;
		}
		d->fgColor = RGB(255, 0, 0);
		d->bgColor = RGB(0, 255, 0);
		InvalidateRect(GetParent(hWnd), NULL, false);
		break;
	}
	case WM_KILLFOCUS: {
		d->fgColor = GetSysColor(COLOR_WINDOWTEXT);
		d->bgColor = GetSysColor(COLOR_WINDOW);
		InvalidateRect(GetParent(hWnd), NULL, false);
		break;
	}
	default:
		return DefSubclassProc(hWnd, uMsg, wParam, lParam);
	}
	return 0;
}
Exemple #4
0
static void
windows_init(void *output)
{
  struct lstopo_windows_output *woutput = output;
  WNDCLASS wndclass;
  HWND toplevel, faketoplevel;
  unsigned width, height;
  HFONT font;

  /* make sure WM_DESTROY on the faketoplevel won't kill the program */
  woutput->toplevel = NULL;

  /* create the toplevel window, with random size for now */
  memset(&wndclass, 0, sizeof(wndclass));
  wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  wndclass.hCursor = LoadCursor(NULL, IDC_SIZEALL);
  wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wndclass.lpfnWndProc = WndProc;
  wndclass.lpszClassName = "lstopo";

  RegisterClass(&wndclass);

  /* compute the maximal needed size, this may require the toplevel window in the future */
  woutput->max_x = 0;
  woutput->max_y = 0;
  woutput->drawing = 0;
  faketoplevel = CreateWindow("lstopo", "lstopo", WS_OVERLAPPEDWINDOW,
			      CW_USEDEFAULT, CW_USEDEFAULT,
			      10, 10, NULL, NULL, NULL, NULL);
  BeginPaint(faketoplevel, &woutput->ps);
  font = CreateFont(fontsize, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL);
  SelectObject(woutput->ps.hdc, (HGDIOBJ) font);
  output_draw(&woutput->loutput);
  DeleteObject(font);
  EndPaint(faketoplevel, &woutput->ps);
  DestroyWindow(faketoplevel);
  woutput->drawing = 1;

  /* now create the actual toplevel with the sizes */
  width = woutput->max_x;
  height = woutput->max_y;

  win_width = width + 2*GetSystemMetrics(SM_CXSIZEFRAME);
  win_height = height + 2*GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION);

  if (win_width > GetSystemMetrics(SM_CXFULLSCREEN))
    win_width = GetSystemMetrics(SM_CXFULLSCREEN);

  if (win_height > GetSystemMetrics(SM_CYFULLSCREEN))
    win_height = GetSystemMetrics(SM_CYFULLSCREEN);

  toplevel = CreateWindow("lstopo", "lstopo", WS_OVERLAPPEDWINDOW,
		  CW_USEDEFAULT, CW_USEDEFAULT,
		  win_width, win_height, NULL, NULL, NULL, NULL);
  woutput->toplevel = toplevel;

  the_width = width;
  the_height = height;

  the_scale = 1.0f;

  the_fontsize = fontsize;
  the_gridsize = gridsize;

  /* and display the window */
  ShowWindow(toplevel, SW_SHOWDEFAULT);

  printf("\n");
  printf("Keyboard shortcuts:\n");
  printf(" Zoom-in or out .................... + -\n");
  printf(" Try to fit scale to window ........ f F\n");
  printf(" Reset scale to default ............ 1\n");
  printf(" Scroll vertically ................. Up Down PageUp PageDown\n");
  printf(" Scroll horizontally ............... Left Right Ctrl+PageUp/Down\n");
  printf(" Scroll to the top-left corner ..... Home\n");
  printf(" Scroll to the bottom-right corner . End\n");
  printf(" Exit .............................. q Q Esc\n");
  printf("\n\n");
}
Exemple #5
0
/**
 * @brief Handle dialog messages.
 * @param [in] hDlg Handle to the dialog.
 * @param [in] iMsg The message.
 * @param [in] wParam The command in the message.
 * @param [in] lParam The optional parameter for the command.
 * @return TRUE if the message was handled, FALSE otherwise.
 */
INT_PTR FillWithDialog::DlgProc(HWindow* pDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
	switch (iMsg)
	{
	case WM_INITDIALOG:
		{
			HEdit* pEditt = static_cast<HEdit *>(pDlg->GetDlgItem(IDC_HEX));//get the handle to the hex edit box
			pEditt->LimitText(FW_MAX);//limit the amount of text the user can enter
			pEditt->SetWindowText(pcFWText);//init hex text
			pEditt->SetFocus();//give the hex box focus
			pEditt->EnableWindow(!curtyp);
			oldproc = static_cast<LONG_PTR>(pEditt->SetWindowLongPtr(GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(HexProc)));//override the old proc to be HexProc
			EnableDlgItem(pDlg, IDC_HEXSTAT, !curtyp);

			HComboBox* typ = static_cast<HComboBox *>(pDlg->GetDlgItem(IDC_TYPE));
			typ->AddString(_T("Input"));
			typ->AddString(_T("File"));
			typ->SetCurSel(curtyp);//set cursel to previous

			//en/disable filename box and browse button
			HWindow* fn = pDlg->GetDlgItem(IDC_FN);
			fn->SetWindowText(szFWFileName);
			fn->EnableWindow(curtyp);
			EnableDlgItem(pDlg, IDC_BROWSE, curtyp);
			EnableDlgItem(pDlg, IDC_FILESTAT, curtyp);

			hfon = CreateFont(16, 0, 0, 0, FW_NORMAL, 0, 0, 0,
			                  DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
			                  DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, _T("Symbol"));
			inittxt(pDlg);
			switch (asstyp)
			{
			case 0:
				pDlg->CheckDlgButton(IDC_EQ, BST_CHECKED);
				break;
			case 1:
				pDlg->CheckDlgButton(IDC_OR, BST_CHECKED);
				break;
			case 2:
				pDlg->CheckDlgButton(IDC_AND, BST_CHECKED);
				break;
			case 3:
				pDlg->CheckDlgButton(IDC_XOR, BST_CHECKED);
				break;
			}
			return 0;//stop the system from setting focus to the control handle in (HWND) wParam because we already set focus above
		}
	case WM_COMMAND:
		switch (wParam)
		{
		case IDOK: //ok pressed
			{
				if (curtyp)
				{//1-file
					pDlg->GetDlgItemText(IDC_FN, szFWFileName, _MAX_PATH);//get file name
					FWFile = _topen(szFWFileName, _O_RDONLY | _O_BINARY);
					if (FWFile == -1)
					{//if there is error opening
						MessageBox(pDlg, GetLangString(IDS_ERR_OPENING_FILE), MB_ICONERROR);//tell user but don't close dlgbox
						return 1;//didn't process this message
					}//if
					FWFilelen = _filelength(FWFile);
					if (FWFilelen == 0)
					{//if filelen is zero
						MessageBox(pDlg, GetLangString(IDS_FILL_ZERO_SIZE_FILE), MB_ICONERROR);//tell user but don't close dlgbox
						_close(FWFile);//close file
						return 1;//didn't process this message
					}//if
					else if (FWFilelen == -1)
					{//error returned by _filelength
						MessageBox(pDlg, GetLangString(IDS_ERR_OPENING_FILE), MB_ICONERROR);//tell user but don't close dlgbox
						_close(FWFile);//close file
						return 1;//didn't process this message
					}//elseif
				}
				else
				{//0-input
					if (!buflen)
					{//no hex input
						MessageBox(pDlg, GetLangString(IDS_FILL_ZERO_SIZE_STR), MB_ICONERROR);//tell user but don't close dlgbox
						return 1;//didn't process this message
					}//if
					int i = pDlg->GetDlgItemText(IDC_HEX, pcFWText, FW_MAX);
					if (i == 0 || i == FW_MAX - 1)
					{//error
						MessageBox(pDlg, GetLangString(IDS_FILL_TOO_MANY_BYTES), MB_ICONERROR);//tell user but don't close dlgbox
						return 1;//didn't process this message
					}//if
					hexstring2charstring();//just in case
					//pcFWText[(aa?buflen:buflen*2)]='\0';//access violation if i do it in the above function
				}
				if (pDlg->IsDlgButtonChecked(IDC_EQ))
					asstyp = 0;
				else if (pDlg->IsDlgButtonChecked(IDC_OR))
					asstyp = 1;
				else if (pDlg->IsDlgButtonChecked(IDC_AND))
					asstyp = 2;
				else if (pDlg->IsDlgButtonChecked(IDC_XOR))
					asstyp = 3;

				// go ahead
				SetCursor(LoadCursor(nullptr, IDC_WAIT));
				BYTE (*fnc)(int);
				int iStartOfSelSetting;
				int iEndOfSelSetting;
				int iimax;
				if (curtyp)
				{//1-file
					fnc = file;
					iimax = FWFilelen;
				}//if
				else
				{//0-input
					fnc = input;
					iimax = buflen;
				}//else

				if (bSelected)
				{
					iStartOfSelSetting = iGetStartOfSelection();
					iEndOfSelSetting = iGetEndOfSelection();
				}
				else
				{
					iStartOfSelSetting = 0;
					iEndOfSelSetting = m_dataArray.GetUpperBound();
				}

				SimpleArray<BYTE> olddata(iEndOfSelSetting - iStartOfSelSetting + 1, &m_dataArray[iStartOfSelSetting]);
				int i = iStartOfSelSetting;
				int ii = 0;
				switch (asstyp)
				{// use switch instead of pointers to funcs that just call an operator as its faster
				case 0:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] = fnc(ii++);
						ii %= iimax;
					}
					break;
				case 1:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] |= fnc(ii++);
						ii %= iimax;
					}
					break;
				case 2:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] &= fnc(ii++);
						ii %= iimax;
					}
					break;
				case 3:
					while (i <= iEndOfSelSetting)
					{
						m_dataArray[i++] ^= fnc(ii++);
						ii %= iimax;
					}
					break;
				}
				push_undorecord(iStartOfSelSetting, olddata, olddata.GetLength(), &m_dataArray[iStartOfSelSetting], olddata.GetLength());
				if (curtyp)
					_close(FWFile);//close file
				SetCursor(LoadCursor(nullptr, IDC_ARROW));
				bFilestatusChanged = true;
				repaint();//you tell me
			}
			// fall through
		case IDCANCEL: //cancel pressed
			DeleteObject(hfon);// won't need till next time
			pDlg->EndDialog(wParam);//tell CMD_fw not to carry out the fill with operation
			return 1;//did process this message
		case MAKEWPARAM(IDC_TYPE, CBN_SELCHANGE):
			//thing to fill selection with changes
			curtyp = static_cast<char>(pDlg->SendDlgItemMessage(IDC_TYPE, CB_GETCURSEL, 0, 0));//get cursel
			EnableDlgItem(pDlg, IDC_FN, curtyp);//en/disable fnamebox and browse button
			EnableDlgItem(pDlg, IDC_BROWSE, curtyp);
			EnableDlgItem(pDlg, IDC_FILESTAT, curtyp);
			curtyp = !curtyp;//flip it for the others
			EnableDlgItem(pDlg, IDC_HEX, curtyp);//en/disable hexboxand relateds
			EnableDlgItem(pDlg, IDC_HEXSTAT, curtyp);
			curtyp = !curtyp;//restore original value -not for below -accurate value needed elsewhere
			//set text in boxes down below
			inittxt(pDlg);
			break;
		case IDC_BROWSE:
			{
				//prepare OPENFILENAME for the file open common dlg box
				szFWFileName[0] = '\0';
				OPENFILENAME ofn;
				ZeroMemory(&ofn, sizeof ofn);
				ofn.lStructSize = sizeof ofn;
				ofn.hwndOwner = pDlg->m_hWnd;
				ofn.lpstrFilter = GetLangString(IDS_OPEN_ALL_FILES);
				ofn.lpstrFile = szFWFileName;
				ofn.nMaxFile = _MAX_PATH ;
				ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
				//show open dlgbox and if file good save name & path in edit box
				if (GetOpenFileName(&ofn))
					pDlg->SetDlgItemText(IDC_FN, ofn.lpstrFile);
			}
			return TRUE;
		case MAKEWPARAM(IDC_HEX, EN_UPDATE): //hexedit updated
			pDlg->GetDlgItemText(IDC_HEX, pcFWText, FW_MAX);//gettext
			hexstring2charstring();//convert to char string
			//set text in boxes down below
			inittxt(pDlg);
			return TRUE;
		}
		break;

	case WM_HELP:
		OnHelp(pDlg);
		break;
	}
	return FALSE;
}
Exemple #6
0
/********************************************************************
* Function : WinMain()
* Purpose : Mandatory Windows Init function.
********************************************************************/
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
						 LPSTR lpCmdLine, int nCmdShow)
{
	MSG		msg;
	HWND		hwnd;
	WNDCLASS	wc;
	static char ClassName[] = "ChromeTestingFacility";
	DDSURFACEDESC	ddsd;
	DDSCAPS			ddscaps;
	HRESULT			ddreturn;
	int n;

	// Set all key booleans to FALSE, assume no key is pressed.
	bForwardKey = FALSE;
	bBackKey = FALSE;
	bLeftKey = FALSE;
	bRightKey = FALSE;
	nState = 0;
	nGauge = 0;

	lpCmdLine = lpCmdLine;
	hPrevInstance = hPrevInstance;
	RealTime = 0;	/* Start of using spacebar for frameflipping. */

	/* Register and realize our display window */
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName = ClassName;
	wc.lpszClassName = ClassName;
	RegisterClass(&wc);

	/* Initialize our test world. */
	if (!InitWorld(XRES, YRES, Colormap))
	{	return FALSE;
	}

	/* Convert the Chrome colormap to a windows colormap. */
	for (n = 0; n < 256; n++)
	{
		WinColormap[n].peRed = (unsigned char)((Colormap[n] & 0xFF0000) >> 16);
		WinColormap[n].peGreen = (unsigned char)((Colormap[n] & 0xFF00) >> 8);
		WinColormap[n].peBlue = (unsigned char)((Colormap[n] & 0xFF));
		WinColormap[n].peFlags = 0;
	}
	/* Create a full screen window so that GDI won't ever be
	 * called. */
	hwnd = CreateWindowEx(WS_EX_TOPMOST,
								 ClassName,
								 ClassName,
								 WS_POPUP,
								 0,
								 0,
								 GetSystemMetrics(SM_CXSCREEN),
								 GetSystemMetrics(SM_CYSCREEN),
								 NULL,
								 NULL,
								 hInstance,
								 NULL);
	if (hwnd == NULL)
		return FALSE;
	
	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);
	SetFocus(hwnd);
	ShowCursor(FALSE);		/* Remove cursor to prevent GDI from writing. */

	/* Instanciate our DirectDraw object */
	ddreturn = DirectDrawCreate(NULL, &lpDirectDrawObject, NULL);
	if (ddreturn != DD_OK)
	{
		DestroyWindow(hwnd);
		return FALSE;
	}

	ddreturn = lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN| DDSCL_ALLOWMODEX);
	if (ddreturn != DD_OK)
	{
		DestroyWindow(hwnd);
		return FALSE;
	}

	/* Create a palette for the surfaces. */
	ddreturn = lpDirectDrawObject->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
																(LPPALETTEENTRY)WinColormap,
																&lpPalette,
																NULL);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	/* Set the video mode to XRESxYRESx8. */
	ddreturn = lpDirectDrawObject->SetDisplayMode(XRES, YRES, 8);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	/* Create a default font for the application. */
	AppFont = CreateFont(11,
								0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
								ANSI_CHARSET,
								OUT_DEFAULT_PRECIS,
								CLIP_DEFAULT_PRECIS,
								NONANTIALIASED_QUALITY,
								VARIABLE_PITCH,
								"Comic Sans MS");

	/* Create the primary surface and one back buffer surface */
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
								 DDSCAPS_FLIP |
								 DDSCAPS_COMPLEX;
	ddsd.dwBackBufferCount = 1;
	ddreturn = lpDirectDrawObject->CreateSurface(&ddsd, &lpPrimary, NULL);

	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	ddreturn = lpPrimary->SetPalette(lpPalette);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	/* Get a surface pointer to our back buffer. */
	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	ddreturn = lpPrimary->GetAttachedSurface(&ddscaps, &lpBackbuffer);

	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

/*	ddreturn = lpBackbuffer->SetPalette(lpPalette);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}
*/
	{	/* Clear the background once for both buffers so we don't get anoying flicker effect. */
		DDBLTFX	BltFx;
		BltFx.dwSize = sizeof(BltFx);
		BltFx.dwFillColor = 255;
		ddreturn = lpBackbuffer->Blt(NULL,
											  NULL,
											  NULL,
											  DDBLT_COLORFILL | DDBLT_WAIT,
											  &BltFx);
		BltFx.dwSize = sizeof(BltFx);
		BltFx.dwFillColor = 255;
		ddreturn = lpPrimary->Blt(NULL,
											  NULL,
											  NULL,
											  DDBLT_COLORFILL | DDBLT_WAIT,
											  &BltFx);
	}

	while (1)
	{	if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{	if (!GetMessage(&msg, NULL, 0, 0))
				return msg.wParam;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		} else
		{	if (ActiveApp && RealTime)
			{	// Simulation Iteration should go here.
				// Only do this when running Realtime.
				SimLoop();
			} else
			{	WaitMessage();
			}
		}
	}
}
Exemple #7
0
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initializes device-dependent objects, including the vertex buffer used
//       for rendering text and the texture map which stores the font image.
//-----------------------------------------------------------------------------
HRESULT CD3DFont::InitDeviceObjects( LPDIRECT3DDEVICE9 pd3dDevice )
{
    HRESULT hr;

    // Keep a local copy of the device
    m_pd3dDevice = pd3dDevice;

    // Establish the font and texture size
    m_fTextScale  = 1.0f; // Draw fonts into texture without scaling

    // Large fonts need larger textures
    if( m_dwFontHeight > 60 )
        m_dwTexWidth = m_dwTexHeight = 4096;
    else if( m_dwFontHeight > 30 )
        m_dwTexWidth = m_dwTexHeight = 2048;
    else if( m_dwFontHeight > 15 )
        m_dwTexWidth = m_dwTexHeight = 1024;
    else
		m_dwTexWidth  = m_dwTexHeight = 512;

    // If requested texture is too big, use a smaller texture and smaller font,
    // and scale up when rendering.
    D3DCAPS9 d3dCaps;
    m_pd3dDevice->GetDeviceCaps( &d3dCaps );

    if( m_dwTexWidth > d3dCaps.MaxTextureWidth )
    {
        m_fTextScale = (FLOAT)d3dCaps.MaxTextureWidth / (FLOAT)m_dwTexWidth;
        m_dwTexWidth = m_dwTexHeight = d3dCaps.MaxTextureWidth;
    }

    // Create a new texture for the font
    hr = m_pd3dDevice->CreateTexture( m_dwTexWidth, m_dwTexHeight, 1,
                                      0, D3DFMT_A4R4G4B4,
                                      D3DPOOL_MANAGED, &m_pTexture, NULL );
    if( FAILED(hr) )
        return hr;

    // Prepare to create a bitmap
    DWORD*      pBitmapBits;
    BITMAPINFO bmi;
    ZeroMemory( &bmi.bmiHeader,  sizeof(BITMAPINFOHEADER) );
    bmi.bmiHeader.biSize        = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth       =  (int)m_dwTexWidth;
    bmi.bmiHeader.biHeight      = -(int)m_dwTexHeight;
    bmi.bmiHeader.biPlanes      = 1;
    bmi.bmiHeader.biCompression = BI_RGB;
    bmi.bmiHeader.biBitCount    = 32;

    // Create a DC and a bitmap for the font
    HDC     hDC       = CreateCompatibleDC( NULL );
    HBITMAP hbmBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
                                          (void**)&pBitmapBits, NULL, 0 );
    SetMapMode( hDC, MM_TEXT );

    // Create a font.  By specifying ANTIALIASED_QUALITY, we might get an
    // antialiased font, but this is not guaranteed.
    INT nHeight    = -MulDiv( m_dwFontHeight, 
        (INT)(GetDeviceCaps(hDC, LOGPIXELSY) * m_fTextScale), 72 );
    DWORD dwBold   = (m_dwFontFlags&D3DFONT_BOLD)   ? FW_BOLD : FW_NORMAL;
    DWORD dwItalic = (m_dwFontFlags&D3DFONT_ITALIC) ? TRUE    : FALSE;
    HFONT hFont    = CreateFont( nHeight,
								 0, 
								 0, 
								 0, 
								 dwBold, 
								 dwItalic,
								 FALSE, 
								 FALSE, 
								 DEFAULT_CHARSET,
								 OUT_DEFAULT_PRECIS,
								 CLIP_DEFAULT_PRECIS, 
								 ANTIALIASED_QUALITY,
								 VARIABLE_PITCH, 
								 m_strFontName );
    if( NULL==hFont )
        return E_FAIL;

    HGDIOBJ hbmOld = SelectObject( hDC, hbmBitmap );
    HGDIOBJ hFontOld = SelectObject( hDC, hFont );

    // Set text properties
    SetTextColor( hDC, RGB(255,255,255) );
    SetBkColor(   hDC, 0x00000000 );
    SetTextAlign( hDC, TA_TOP );

    // Loop through all printable character and output them to the bitmap..
    // Meanwhile, keep track of the corresponding tex coords for each character.
    DWORD x = 0;
    DWORD y = 0;
    TCHAR str[2] = _T("x");
    SIZE size;

    // Calculate the spacing between characters based on line height
    GetTextExtentPoint32( hDC, TEXT(" "), 1, &size );
    x = m_dwSpacing = (DWORD) ceil(size.cy * 0.3f);

    for( unsigned char c=32; c<255; c++ )
    {
        str[0] = c;
        GetTextExtentPoint32( hDC, str, 1, &size );

        if( (DWORD)(x + size.cx + m_dwSpacing) > m_dwTexWidth )
        {
            x  = m_dwSpacing;
            y += size.cy+1;
        }

        ExtTextOut( hDC, x+0, y+0, ETO_OPAQUE, NULL, str, 1, NULL );

        m_fTexCoords[c-32][0] = ((FLOAT)(x + 0       - m_dwSpacing))/m_dwTexWidth;
        m_fTexCoords[c-32][1] = ((FLOAT)(y + 0       + 0          ))/m_dwTexHeight;
        m_fTexCoords[c-32][2] = ((FLOAT)(x + size.cx + m_dwSpacing))/m_dwTexWidth;
        m_fTexCoords[c-32][3] = ((FLOAT)(y + size.cy + 0          ))/m_dwTexHeight;

        x += size.cx + (2 * m_dwSpacing);

		//HTMLLog("%c - %d\n", (char)c, (int)c);
    }

    // Lock the surface and write the alpha values for the set pixels
    D3DLOCKED_RECT d3dlr;
    m_pTexture->LockRect( 0, &d3dlr, 0, 0 );
    BYTE* pDstRow = (BYTE*)d3dlr.pBits;
    WORD* pDst16;
    BYTE bAlpha; // 4-bit measure of pixel intensity

    for( y=0; y < m_dwTexHeight; y++ )
    {
        pDst16 = (WORD*)pDstRow;
        for( x=0; x < m_dwTexWidth; x++ )
        {
            bAlpha = (BYTE)((pBitmapBits[m_dwTexWidth*y + x] & 0xff) >> 4);
            if (bAlpha > 0)
            {
                *pDst16++ = (WORD) ((bAlpha << 12) | 0x0fff);
            }
            else
            {
                *pDst16++ = 0x0000;
            }
        }
        pDstRow += d3dlr.Pitch;
    }

    // Done updating texture, so clean up used objects
    m_pTexture->UnlockRect(0);

	//D3DXSaveTextureToFile("font.jpg", D3DXIFF_JPG, m_pTexture, 0);

    SelectObject( hDC, hbmOld );
    SelectObject( hDC, hFontOld );
    DeleteObject( hbmBitmap );
    DeleteObject( hFont );
    DeleteDC( hDC );


    return S_OK;
}
BOOL CDrawCheckbox::Create(LPCTSTR lpszCaption, const RECT& rect, HWND hParentWnd,\
                          UINT nID, LPCTSTR lpszImage, LPCTSTR lpszLightImage,BKIMGLoadState bklState, COLORREF colorText, UINT szText, HDC hdcParent)
{
    if(m_hWnd)
    {
        return FALSE;
    }

    WCHAR wszImage[MAX_PATH] = {0};
    WCHAR wszLightImage[MAX_PATH] = {0};
    if(sizeof(TCHAR) == 2)
    {
        wcscpy_s(wszImage, (WCHAR *)lpszImage);
        wcscpy_s(wszLightImage, (WCHAR *)lpszLightImage);
    }
    else
    {
        setlocale(LC_ALL,".936");

        size_t returnValue = 0;
        mbstowcs_s(&returnValue, wszImage, (char *)lpszImage, _tcslen(lpszImage));
        mbstowcs_s(&returnValue, wszLightImage, (char *)lpszLightImage, _tcslen(lpszLightImage));
    }

    m_pNormalStateImg = Image::FromFile(wszImage);
    if( Ok != m_pNormalStateImg->GetLastStatus())
    {
        goto CREATE_FAIL;
    }

    if(NULL != lpszLightImage)
    {
        if(_tcslen(lpszLightImage) != 0)
        {
            m_pLightStateImg = Image::FromFile(wszLightImage);
            if( Ok != m_pLightStateImg->GetLastStatus())
            {
                goto CREATE_FAIL;
            }
        }
    }

	m_colorText = colorText;
    m_bkimState = bklState;

    WNDCLASS wc; 
	// Register the main window class. 
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; 
	wc.lpfnWndProc = (WNDPROC) CheckboxProc; 
	wc.cbClsExtra = 0; 
	wc.cbWndExtra = 0; 
	wc.hInstance = GetModuleHandle(NULL); 
	wc.hIcon = NULL; 
	wc.hCursor = LoadCursor(NULL, IDC_ARROW); 
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); 
	wc.lpszMenuName =  NULL; 
	wc.lpszClassName = _T("CDrawCheckbox"); 

	if (!RegisterClass(&wc)) 
	{
		if(ERROR_CLASS_ALREADY_EXISTS != GetLastError())
        {
            return FALSE;
        }
	}

	m_hWnd = CreateWindow(_T("CDrawCheckbox"), lpszCaption, \
		WS_CHILD | WS_VISIBLE | WS_TABSTOP, \
		rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, \
		hParentWnd,(HMENU)nID,NULL,NULL);

	if( NULL == m_hWnd)
	{
		return FALSE; 
	}

    SetWindowLong(m_hWnd, GWL_USERDATA, (LONG)this);

    m_hFont = CreateFont(szText, 0, 0, 0, FW_SEMIBOLD, FALSE, FALSE, 0, ANSI_CHARSET, \
				OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, _T("宋体"));

	//m_hCtrlRgn = CImageToRgn::CreateRgn(lpszImage, rect.bottom - rect.top, rect.bottom - rect.top, 0, 0, CImageToRgn::Default_Height);
    //m_hCtrlRgn = CreateRectRgn(0, 0, rect.right - rect.left, rect.bottom - rect.top);
    m_hCtrlRgn = CreateRectRgn(0, 0, rect.bottom - rect.top, rect.bottom - rect.top);

    if(hdcParent)
    {
		InitBkDC(hdcParent);
    }

    return TRUE;

CREATE_FAIL:

    SAFE_FREE(m_pNormalStateImg);
    SAFE_FREE(m_pLightStateImg);

    return FALSE;
}
HFONT CATCodeMgr::CheckFont( HDC hdc )
{
	HFONT hRetVal = NULL;

	TEXTMETRIC tm;
	BOOL bRes = GetTextMetrics(hdc, &tm);

	// 폰트 다시 로드
	if( bRes )//&& tm.tmHeight != lLastFontHeight )
	{
		
		HFONT font = NULL;
		long lFontSize = tm.tmHeight;
		
		if(m_strFontFace.IsEmpty())
		{
			m_strFontFace = _T("궁서");
		}

		// 폰트페이스명이 바뀌었으면 맵 초기화
		if(m_strLastFontFace.Compare(m_strFontFace))
		{
			for(map<long, HFONT>::iterator iter = m_mapFonts.begin();
				iter != m_mapFonts.end();
				iter++)
			{
				font = iter->second;
				DeleteObject(font);
			}
			m_mapFonts.clear();
		}
		
		// 폰트 크기 고정인 경우
		if(m_lFontSize !=0 && m_bFixedFontSize)
		{
			lFontSize = m_lFontSize;
		}

		// 이 크기에 해당하는 폰트가 없을 경우 폰트를 생성
		if( m_mapFonts.find(lFontSize) == m_mapFonts.end() )
		{
			font = CreateFont(lFontSize, 0, 0, 0, tm.tmWeight, tm.tmItalic, tm.tmUnderlined, tm.tmStruckOut,
				HANGEUL_CHARSET,	//ANSI_CHARSET,
				OUT_DEFAULT_PRECIS,
				CLIP_DEFAULT_PRECIS,
				ANTIALIASED_QUALITY,
				DEFAULT_PITCH,		// | FF_SWISS,
				m_strFontFace);

			m_mapFonts[lFontSize] = font;

		}
		else
		{
			font = m_mapFonts[lFontSize];
		}

		hRetVal = (HFONT)SelectObject(hdc, font);

	}

	/*
	TEXTMETRIC tm;
	BOOL bRes = GetTextMetrics(hdc, &tm);

	// 폰트 다시 로드
	if( bRes )
	{
		// 폰트 크기 고정인 경우
		if(m_lFontSize !=0 && m_bFixedFontSize)
		{
			tm.tmHeight = m_lFontSize;
		}

		HFONT font = InnerCreateFont(tm.tmHeight, 0, 0, 0, tm.tmWeight, tm.tmItalic, tm.tmUnderlined, tm.tmStruckOut,
			HANGEUL_CHARSET,	//ANSI_CHARSET,
			OUT_DEFAULT_PRECIS,
			CLIP_DEFAULT_PRECIS,
			ANTIALIASED_QUALITY,
			DEFAULT_PITCH,		// | FF_SWISS,
			(LPWSTR)(LPCWSTR)m_strFontFace);

		if(font)
		{
			hRetVal = (HFONT)SelectObject(hdc, font);
		}
	}
	*/

	return hRetVal;

}
NOEXPORT LRESULT CALLBACK window_proc(HWND main_window_handle,
        UINT message, WPARAM wParam, LPARAM lParam) {
    NOTIFYICONDATA nid;
    POINT pt;
    RECT rect;
    SERVICE_OPTIONS *section;
    unsigned int section_number;

#if 0
    if(message!=WM_CTLCOLORSTATIC && message!=WM_TIMER)
        s_log(LOG_DEBUG, "Window message: %d", message);
#endif
    switch(message) {
    case WM_CREATE:
#ifdef _WIN32_WCE
        /* create command bar */
        command_bar_handle=CommandBar_Create(ghInst, main_window_handle, 1);
        if(!command_bar_handle)
            error_box("CommandBar_Create");
        if(!CommandBar_InsertMenubar(command_bar_handle, ghInst, IDM_MAINMENU, 0))
            error_box("CommandBar_InsertMenubar");
        if(!CommandBar_AddAdornments(command_bar_handle, 0, 0))
            error_box("CommandBar_AddAdornments");
#endif

        /* create child edit window */
        edit_handle=CreateWindow(TEXT("EDIT"), NULL,
            WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_READONLY,
            0, 0, 0, 0, main_window_handle, (HMENU)IDE_EDIT, ghInst, NULL);
#ifndef _WIN32_WCE
        SendMessage(edit_handle, WM_SETFONT,
            (WPARAM)CreateFont(-12, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
                DEFAULT_CHARSET, OUT_RASTER_PRECIS, CLIP_DEFAULT_PRECIS,
                PROOF_QUALITY, DEFAULT_PITCH, TEXT("Courier")),
            MAKELPARAM(FALSE, 0)); /* no need to redraw right, now */
#endif
        /* NOTE: there's no return statement here -> proceeding with resize */

    case WM_SIZE:
        GetClientRect(main_window_handle, &rect);
#ifdef _WIN32_WCE
        MoveWindow(edit_handle, 0, CommandBar_Height(command_bar_handle),
            rect.right, rect.bottom-CommandBar_Height(command_bar_handle), TRUE);
#else
        MoveWindow(edit_handle, 0, 0, rect.right, rect.bottom, TRUE);
#endif
        UpdateWindow(edit_handle);
        /* CommandBar_Show(command_bar_handle, TRUE); */
        return TRUE;

    case WM_SETFOCUS:
        SetFocus(edit_handle);
        return TRUE;

    case WM_TIMER:
        if(visible)
            update_logs();
        return TRUE;

    case WM_CLOSE:
        ShowWindow(main_window_handle, SW_HIDE);
        return TRUE;

    case WM_SHOWWINDOW:
        visible=wParam; /* setup global variable */
        if(tray_menu_handle)
            CheckMenuItem(tray_menu_handle, IDM_SHOW_LOG,
                visible ? MF_CHECKED : MF_UNCHECKED);
        if(visible)
            update_logs();
        return TRUE;

    case WM_DESTROY:
#ifdef _WIN32_WCE
        CommandBar_Destroy(command_bar_handle);
#else
        if(main_menu_handle)
            DestroyMenu(main_menu_handle);
#endif
        if(tray_menu_handle)
            DestroyMenu(tray_menu_handle);
        ZeroMemory(&nid, sizeof nid);
        nid.cbSize=sizeof nid;
        nid.hWnd=main_window_handle;
        nid.uID=1;
        nid.uFlags=NIF_TIP; /* not really sure what to put here, but it works */
        Shell_NotifyIcon(NIM_DELETE, &nid); /* this removes the icon */
        PostQuitMessage(0);
        KillTimer(main_window_handle, 0x29a);
        return TRUE;

    case WM_COMMAND:
        if(wParam>=IDM_PEER_MENU && wParam<IDM_PEER_MENU+number_of_sections) {
            for(section=service_options.next, section_number=0;
                    section && wParam!=IDM_PEER_MENU+section_number;
                    section=section->next, ++section_number)
                ;
            if(!section)
                return TRUE;
            if(save_text_file(section->file, section->chain))
                return TRUE;
#ifndef _WIN32_WCE
            if(main_menu_handle)
                CheckMenuItem(main_menu_handle, wParam, MF_CHECKED);
#endif
            if(tray_menu_handle)
                CheckMenuItem(tray_menu_handle, wParam, MF_CHECKED);
            message_box(section->help, MB_ICONINFORMATION);
            return TRUE;
        }
        switch(wParam) {
        case IDM_ABOUT:
            DialogBox(ghInst, TEXT("AboutBox"), main_window_handle,
                (DLGPROC)about_proc);
            break;
        case IDM_SHOW_LOG:
            if(visible) {
                ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            } else {
                ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */
                SetForegroundWindow(main_window_handle); /* bring on top */
            }
            break;
        case IDM_CLOSE:
            ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            break;
        case IDM_EXIT:
            if(!error_mode) /* signal_pipe is active */
                signal_post(SIGNAL_TERMINATE);
            DestroyWindow(main_window_handle);
            break;
        case IDM_SAVE_LOG:
            if(!cmdline.service) /* security */
                save_log();
            break;
        case IDM_EDIT_CONFIG:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                edit_config(main_window_handle);
#endif
            break;
        case IDM_RELOAD_CONFIG:
            if(error_mode) /* unlock daemon_thread */
                SetEvent(config_ready);
            else /* signal_pipe is active */
                signal_post(SIGNAL_RELOAD_CONFIG);
            break;
        case IDM_REOPEN_LOG:
            signal_post(SIGNAL_REOPEN_LOG);
            break;
        case IDM_MANPAGE:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                ShellExecute(main_window_handle, TEXT("open"),
                    TEXT("stunnel.html"), NULL, NULL, SW_SHOWNORMAL);
#endif
            break;
        case IDM_HOMEPAGE:
#ifndef _WIN32_WCE
            if(!cmdline.service) /* security */
                ShellExecute(main_window_handle, TEXT("open"),
                    TEXT("http://www.stunnel.org/"), NULL, NULL, SW_SHOWNORMAL);
#endif
            break;
        }
        return TRUE;

    case WM_SYSTRAY: /* a taskbar event */
        switch(lParam) {
#ifdef _WIN32_WCE
        case WM_LBUTTONDOWN: /* no right mouse button on Windows CE */
            GetWindowRect(GetDesktopWindow(), &rect); /* no cursor position */
            pt.x=rect.right;
            pt.y=rect.bottom-25;
#else
        case WM_RBUTTONDOWN:
            GetCursorPos(&pt);
#endif
            SetForegroundWindow(main_window_handle);
            TrackPopupMenuEx(GetSubMenu(tray_menu_handle, 0), TPM_BOTTOMALIGN,
                pt.x, pt.y, main_window_handle, NULL);
            PostMessage(main_window_handle, WM_NULL, 0, 0);
            break;
#ifndef _WIN32_WCE
        case WM_LBUTTONDBLCLK: /* switch log window visibility */
            if(visible) {
                ShowWindow(main_window_handle, SW_HIDE); /* hide window */
            } else {
                ShowWindow(main_window_handle, SW_SHOWNORMAL); /* show window */
                SetForegroundWindow(main_window_handle); /* bring on top */
            }
            break;
#endif
        }
        return TRUE;

    case WM_VALID_CONFIG:
        valid_config();
        return TRUE;

    case WM_INVALID_CONFIG:
        invalid_config();
        return TRUE;

    case WM_LOG:
        win_log((LPSTR)wParam);
        return TRUE;

    case WM_NEW_CHAIN:
#ifndef _WIN32_WCE
        if(main_menu_handle)
            EnableMenuItem(main_menu_handle, IDM_PEER_MENU+wParam, MF_ENABLED);
#endif
        if(tray_menu_handle)
            EnableMenuItem(tray_menu_handle, IDM_PEER_MENU+wParam, MF_ENABLED);
        return TRUE;

    case WM_CLIENTS:
        update_tray_icon((int)wParam);
        return TRUE;
    }

    return DefWindowProc(main_window_handle, message, wParam, lParam);
}
Exemple #11
0
/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND checks[10];
    static int  IDs[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int x = 400,y = 500;
    static HDC hdcCat1, hdcCat2;

    static BITMAP bitmapCat1, bitmapCat2;
    static HBITMAP hbmpImg1 = NULL ;
    static HBITMAP hbmpImg2 = NULL;

    static HFONT font_forte, text_font, font_forte1, text_font1;;
    static RECT area  = {400, 80, 707, 470};
    static RECT write = {45, 501, 282, 522};

    PAINTSTRUCT Ps;
    HDC hdc = GetDC(hwnd);
    HBRUSH hbrush;


    static RECT diff[30];
    char* current_img = Images[random];
    char* current_story = Story[random];
    char str[15];

    if(toRender)
    {
       sprintf(str,"%s1.bmp",current_img);
    // load bitmaps
    hbmpImg1 = (HBITMAP)LoadImage(hInst, str, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hbmpImg1, sizeof(bitmapCat1), &bitmapCat1);

    sprintf(str,"%s2.bmp",current_img);
    hbmpImg2 = (HBITMAP)LoadImage(hInst, str, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hbmpImg2, sizeof(bitmapCat2), &bitmapCat2);
    toRender = false;
    }


    //Static variables for mouse Coordinates
    static int xMouse, yMouse;
	xMouse = GET_X_LPARAM(lParam);
	yMouse = GET_Y_LPARAM(lParam);



    //Coordinates of the differences
    diff[0] = {508,122,569,165};
    diff[1] = {511,161,568,180};  //sprincene
    diff[2] = {540, 197, 560, 217 };//ochi
    diff[3] = {583, 228, 614, 245};//mustata dreapta
    diff[4] = {645, 328, 685, 348};//coada
    diff[5] = {586, 292, 630, 327};//fluture
    diff[6] = {498, 359, 526, 388};//hand
    diff[7] = {520, 289, 557, 305};//piept
    diff[8] = {540, 390, 550, 400 };//flowerbottom
    diff[9] = {450, 310, 470, 330};//left

    diff[10] = {467, 155 , 489, 190 }; //acc
    diff[11] =  {503, 175,522, 192 } ;// paplivoc
    diff[12] = {521,123, 558, 155};// circioc
    diff[13] = {578, 140, 600, 163 }; //circioc dreapta
    diff[14] = {630,290, 653, 312}; //mina
    diff[15] = {471, 444,495, 464 };//ass
    diff[16] = {429, 292, 468, 325};//mp3
    diff[17] = {464, 265,481, 279 };//sunnglass
    diff[18] = {478, 305,494, 316 };//bunghi linga mp3
    diff[19] = {585, 400, 608, 419}; //bumb picior dreapta

    diff[20] ={416, 100, 494, 128};//nour stinga
    diff[21] ={619, 124, 638, 137}; //nour dreapta
    diff[22] ={678, 109, 700, 124 }; //sun
    diff[23] ={534, 207, 565, 245}; //wolf hands
    diff[24] ={637, 202,655, 215}; //barba
    diff[25] ={595, 405, 615, 417}; //picior Wolf
    diff[26] ={514,399,531,409 };//picior fetita
    diff[27] ={511,344, 526, 360 }; //fata jacketa
    diff[28] ={400,325,455,353};//deal
    diff[29] ={425,351,446,368};//floare



    switch (message)                  /* handle the messages */
    {
    case WM_GETMINMAXINFO:
        {
            LPMINMAXINFO pInfo = (LPMINMAXINFO)lParam;
            pInfo -> ptMaxTrackSize.x = 750;
            pInfo -> ptMaxTrackSize.y = 700;

            pInfo -> ptMinTrackSize.x= 750;
            pInfo -> ptMinTrackSize.y = 700;
        }
    break;

    case WM_COMMAND:
        {
        switch(LOWORD(wParam))
            {
             case IDI_EXIT:      //Exit Coammand
                {
                    PostQuitMessage (0);
                break;
                }

            case IDI_NEW:
                {
                    toRender  = true;
                    InvalidateRect(hwnd, &area, FALSE);
                    InvalidateRect(hwnd, &area, TRUE);

                    InvalidateRect(hwnd, &write, FALSE);
                    InvalidateRect(hwnd, &write, TRUE);
                    random = GetRandom(3);
                    for (int i=0; i<11; i++)
                    {
                        CheckDlgButton(hwnd, IDs[i], BST_UNCHECKED);
                    }
                break;
                }

            case IDI_ABOUT:
                {
                    DialogBox(hInst, MAKEINTRESOURCE(IDI_DIALOG), hwnd, AboutDlgProc);
                break;
                }

            case IDI_RULE:
                {
                    DialogBox(hInst, MAKEINTRESOURCE(IDI_DIALOG_RULE), hwnd, AboutDlgProc);
                break;
                }
            }
        break;
        }
    break;

    case WM_CREATE:
        {
           for(int i=0; i<sizeof(checks)/sizeof(HWND); i++)
            {
                checks[i] = CreateWindow(TEXT("button"), TEXT(""),
                        WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
                        x, 500, 12, 12,
                        hwnd, (HMENU) IDs[i], hInst, NULL);
                x+=33;
            }
       break;
        }

    //Work with LButton
    case WM_LBUTTONDOWN:
        {
            if(random == 0)
            {
                coeficient = 3 ;
            }
            if(random == 1)
                coeficient = 1.5;
            if(random == 2)
                coeficient = 1;

            for (int i = 0+ random * 10; i < (sizeof(diff)/sizeof(diff[0]))/coeficient  ; i++)
            {
                if(diff[i].left < xMouse && xMouse < diff[i].right && diff[i].top < yMouse && yMouse < diff[i].bottom )
                {
                    if(coeficient == 3)
                    PlaySound("Meow.wav", NULL, SND_ASYNC);
                    if(coeficient == 1.5)
                    PlaySound("goofy.wav", NULL, SND_ASYNC);
                    if(coeficient == 1)
                    PlaySound("Wolf.wav", NULL, SND_ASYNC);

                    DrawEdge(hdc, &diff[i], BDR_RAISEDOUTER | BDR_SUNKENINNER, BF_RECT);
                    CheckDlgButton(hwnd, IDs[i], BST_CHECKED);
                    nr_differences ++;
                    CheckDlgButton(hwnd, IDs[i - + (random * 10)], BST_CHECKED);
                   // MessageBoxA(NULL,"You found it! Good Job", "Congrats", MB_OK | MB_ICONINFORMATION);

                        if (nr_differences == 10)
                        {
                            PlaySound("Level.wav", NULL, SND_ASYNC);
                            MessageBoxA(NULL,"You won! Go to File->New game", "Congrats", MB_OK | MB_ICONINFORMATION);
                        }
                    notFound = false;
                }
            }
            if(notFound)
                PlaySound("FailSound.wav", NULL, SND_ASYNC);
            notFound = true;
        }
    break;

    case WM_LBUTTONDBLCLK:
        {
                     char str [256];
                    POINT pt;
                    pt.x = LOWORD(lParam);
                    pt.y = HIWORD(lParam);

                     wsprintf(str, "Co-ordinates are \nX=%i and Y=%i", pt.x, pt.y);
                    MessageBoxA(NULL,str, "Message", MB_OK | MB_ICONINFORMATION);
        }
    break;

    case WM_PAINT:
        {
            BeginPaint(hwnd, &Ps);

            hdcCat1 = CreateCompatibleDC(hdc);
            SelectObject(hdcCat1, hbmpImg1);
            BitBlt(hdc, 37, 80, bitmapCat1.bmWidth, bitmapCat1.bmHeight, hdcCat1, 0, 0, SRCCOPY);
            DeleteObject(hdcCat1);

            hdcCat2 = CreateCompatibleDC(hdc);
            SelectObject(hdcCat2, hbmpImg2);
            BitBlt(hdc, 400, 80, bitmapCat2.bmWidth, bitmapCat2.bmHeight, hdcCat2, 0, 0, SRCCOPY);
            DeleteObject(hdcCat2);

            // create the title
            font_forte   = CreateFont(30, 27.5, 0, 0, FW_DONTCARE, false, false, false,
                              DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                              DEFAULT_QUALITY, FF_DONTCARE, "Forte");
            font_forte1  = CreateFont(0, 0, 0, 0, FW_DONTCARE, false, false, false,
                              DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
                              DEFAULT_QUALITY, FF_DONTCARE, "Forte");

            text_font  = (HFONT)SelectObject(hdc, font_forte);   // setting new font for text
            SetTextColor(hdc, TITLE_COLOR);                     // setting new text color
            TextOut( hdc, 115, 20,  "Find the difference", 19);

            text_font1  = (HFONT)SelectObject(hdc, font_forte1);
            TextOut(hdc, 45, 501, current_story, 42);
            TextOut(hdc, 45, 520, "And have changed, it needs your ", 32);
            TextOut(hdc, 45, 539, "help to find differences!", 25);

            DeleteObject(font_forte);
            DeleteObject(text_font);
            DeleteObject(font_forte1);
            DeleteObject(text_font1);

            EndPaint(hwnd, &Ps);

        }
    break;

    case WM_CTLCOLORSTATIC:
        {
            SetBkMode((HDC)wParam,TRANSPARENT);                                // transparent background
            hbrush=(HBRUSH)GetStockObject(NULL_BRUSH);                         // handle to brush, no background color
            return(LRESULT) hbrush;
        }
    break;

    case WM_DESTROY:
        {
            DeleteFont(font_forte);
            DeleteFont(text_font);
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        }
    break;
   // InvalidateRect(hwnd, &all_area, FALSE);


        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
Exemple #12
0
//---------------------------------------------------------------------
// メッセージボックスのプロシージャ
LRESULT CALLBACK MyMessageBoxProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
	
	static LPMSGBOXDATA lpMsgBoxData;
	static HICON hIcon;
	static BOOL bDrawIcon; // アイコンを貼るかどうか
	static RECT textRt;  // テキスト描画領域
	static SIZE sizeText; //  テキスト描画領域のサイズ
	static LONG width,height; // ウィンドウ幅、高さ
	static HWND hWndBt[3];
	static int nResult[3];
	static HFONT hFont; // ボタン用フォント
	static LONG nButtonNum; // ボタン数
	static BOOL bOwnerDraw; // ボタンをオーナードローするか
	static UINT uCurFocus; // 現在のフォーカスボタンID
	
	CHAR szBtStr[3][CHR_BUF];
	LONG x1,x2,x3,y;
	HINSTANCE hInst;
	HDC hDC;
	LONG nButtonSize;
	UINT uIconType,uMskType;
	DWORD dwStyle;
	COLORREF rgbStr;
	WORD i;
	
	switch (msg) {
		
	case WM_INITDIALOG:  // ダイアログ初期化
		
		lpMsgBoxData = (LPMSGBOXDATA)lp;
		hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
		
		// アイコンロード
		uIconType = lpMsgBoxData->uType & MB_ICONMASK;
		
		if(uIconType > 0) bDrawIcon = TRUE;
		else bDrawIcon = FALSE;
		
		switch(uIconType){
			
		case MB_ICONQUESTION:
			hIcon = LoadIcon(NULL,IDI_QUESTION);
			break;
			
		case MB_ICONINFORMATION:
			hIcon = LoadIcon(NULL,IDI_INFORMATION);
			break;
			
		case MB_ICONEXCLAMATION:
			hIcon = LoadIcon(NULL,IDI_EXCLAMATION);
			break;
			
		case MB_ICONERROR:
			hIcon = LoadIcon(NULL,IDI_ERROR);
		}
		
		
		// テキスト領域の幅と高さ取得
		GetTextSize(hWnd,lpMsgBoxData->lpText,&sizeText,MSGBOXTEXTSIZE);
		
		// テキスト描画領域セット
		textRt.top = MSGBOXMERGIN + (sizeText.cy > MSGBOXICONHEIGHT? 0 : (MSGBOXICONHEIGHT-sizeText.cy)/2);
		textRt.left = MSGBOXICONWIDTH*bDrawIcon+MSGBOXMERGIN;
		textRt.right = textRt.left + sizeText.cx;
		textRt.bottom = textRt.top + sizeText.cy;
		
		// タイトルセット
		SetWindowText(hWnd,lpMsgBoxData->lpCaption);
		
		// ボタン名設定
		for(i=0;i<3;i++) nResult[i] = 0;
		switch(lpMsgBoxData->uType & MB_TYPEMASK){
			
		default:
			nResult[0] = IDOK;
			wsprintf(szBtStr[0],"OK");
			
			nButtonNum = 1;
			break;
			
		case MB_OKCANCEL:
			nResult[0] = IDOK;
			wsprintf(szBtStr[0],"OK");
			
			nResult[1] = IDCANCEL;
			wsprintf(szBtStr[1],"キャンセル");
			
			nButtonNum = 2;
			break;
			
		case MB_YESNOCANCEL:
			
			nResult[0] = IDYES;
			wsprintf(szBtStr[0],"はい(&Y)");
			
			nResult[1] = IDNO;
			wsprintf(szBtStr[1],"いいえ(&N)");
			
			nResult[2] = IDCANCEL;
			wsprintf(szBtStr[2],"キャンセル");
			
			nButtonNum = 3;
			break;
			
		case MB_YESNO:
			
			nResult[0] = IDYES;
			wsprintf(szBtStr[0],"はい(&Y)");
			
			nResult[1] = IDNO;
			wsprintf(szBtStr[1],"いいえ(&N)");
			
			nButtonNum = 2;
		}
		
		// ウィンドウリサイズ
		nButtonSize =MSGBOXBTWIDTH*nButtonNum+MSGBOXMERGIN*(nButtonNum-1);
		
		width = max(nButtonSize+MSGBOXMERGIN*2,sizeText.cx+MSGBOXMERGIN*2+MSGBOXICONWIDTH*bDrawIcon);
		height = max(MSGBOXICONHEIGHT*bDrawIcon,sizeText.cy)+ MSGBOXMERGIN*3+MSGBOXBTHEIGHT;
		
		SetWindowPos(hWnd,NULL,0,0,
			width+GetSystemMetrics(SM_CXFIXEDFRAME)*2,
			height+GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYFIXEDFRAME)*2
			,SWP_NOMOVE|SWP_NOREPOSITION);
		
		
		// ボタン作成
		x1 = (width - nButtonSize)/2;
		x2 = x1 + MSGBOXBTWIDTH+MSGBOXMERGIN;
		x3 = x2 + MSGBOXBTWIDTH+MSGBOXMERGIN;
		y = height-MSGBOXBTHEIGHT - MSGBOXMERGIN;
		
		uMskType = lpMsgBoxData->uType & MB_DEFMASK;
		bOwnerDraw = lpMsgBoxData->bOwnerDraw; // オーナードローか
		
		// ボタン 1
		if((nButtonNum >=2 && uMskType == MB_DEFBUTTON2) ||
			(nButtonNum == 3 && uMskType == MB_DEFBUTTON3))
			dwStyle = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;
		else dwStyle = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;
		if(bOwnerDraw) dwStyle |= BS_OWNERDRAW;
		CreateWindow("BUTTON","bt1",dwStyle,x1,y,MSGBOXBTWIDTH,MSGBOXBTHEIGHT,hWnd,(HMENU)IDC_BT1,hInst,NULL);
		
		// ボタン 2
		if(nButtonNum >= 2){
			if(uMskType == MB_DEFBUTTON2)
				dwStyle = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;
			else dwStyle = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;
			if(bOwnerDraw) dwStyle |= BS_OWNERDRAW;
			CreateWindow("BUTTON","bt2",dwStyle,x2,y,MSGBOXBTWIDTH,MSGBOXBTHEIGHT,hWnd,(HMENU)IDC_BT2,hInst,NULL);
		}
		
		
		// ボタン 3
		if(nButtonNum == 3){
			if(uMskType == MB_DEFBUTTON3)
				dwStyle = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;
			else dwStyle = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;
			if(bOwnerDraw) dwStyle |= BS_OWNERDRAW;
			CreateWindow("BUTTON","bt3",dwStyle,x3,y,MSGBOXBTWIDTH,MSGBOXBTHEIGHT,hWnd,(HMENU)IDC_BT3,hInst,NULL);
		}
		
		
		// ボタン用フォント作成
		if(!bOwnerDraw) hFont=CreateFont(10,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET
			,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"MS Pゴシック");
		
		// ボタンにフォントと文字セット
		hWndBt[0] = GetDlgItem(hWnd,IDC_BT1);
		hWndBt[1] = GetDlgItem(hWnd,IDC_BT2);
		hWndBt[2] = GetDlgItem(hWnd,IDC_BT3);
		
		for(i=0;i<3;i++)
		{
			// フォントセット
			if(!bOwnerDraw) SendMessage(hWndBt[i],WM_SETFONT,(WPARAM)hFont,(LPARAM)MAKELPARAM(TRUE,0));
			SetWindowText(hWndBt[i],szBtStr[i]);
		}
		
		// フォーカス移動
		switch(uMskType){
			
		case MB_DEFBUTTON2:
			uCurFocus = IDC_BT2;
			SetFocus(hWndBt[1]);
			break;
			
		case MB_DEFBUTTON3:
			uCurFocus = IDC_BT3;
			SetFocus(hWndBt[2]);
			break;
			
		default:
			uCurFocus = IDC_BT1;
			SetFocus(hWndBt[0]);
		}
		
		// 中心移動
		SetDlgCenter(hWnd);

		// forgrand
		if(lpMsgBoxData->uType & MB_SETFOREGROUND) SetForegroundWindow(hWnd);
		
		break;
		
		
		case WM_CTLCOLORDLG: // 背景色を変えたい場合
			
			if(bOwnerDraw){
				SetBkMode((HDC)wp,TRANSPARENT);			 
				SetTextColor((HDC)wp,RGB(255,255,255)) ;
				return ((BOOL)GetStockObject(GRAY_BRUSH)) ;    
			}
			
			break;
			
			
		case WM_DRAWITEM: // ボタンのオーナー描画をする場合
			
			if(bOwnerDraw){
				
				UINT uCtlID,uButtonStat;
				LPDRAWITEMSTRUCT lpDrawItem;
				
				uCtlID = (UINT)wp;
				lpDrawItem = (LPDRAWITEMSTRUCT)lp;
				uButtonStat = MYID_RELEASEBUTTON;
				
				if(lpDrawItem->CtlType == ODT_BUTTON){ // ボタンならば
					
					if(lpDrawItem->itemAction & ODA_SELECT){ // 選択
						if(lpDrawItem->itemState & ODS_FOCUS) uButtonStat = MYID_PUSHBUTTON;
					}
					else if(lpDrawItem->itemAction & ODA_FOCUS){ // フォーカス
						// 自前でフォーカスの管理をする
						if(lpDrawItem->itemState & ODS_FOCUS) uCurFocus = uCtlID;
					}
					
					// ボタン描画
					DrawMsgButton(hWnd,uCtlID,lpDrawItem->hDC,lpDrawItem->rcItem,uCurFocus,uButtonStat);
					
				}
			}
			
			break;
			
		case WM_PAINT: // 描画
			
			hDC = GetDC(hWnd);
			
			if(bOwnerDraw){
				// 枠描画
				DrawMyFrame(hDC,MSGBOXMERGIN-2,MSGBOXMERGIN-2,
					width - (MSGBOXMERGIN-2)*2,height-MSGBOXBTHEIGHT - MSGBOXMERGIN-(MSGBOXMERGIN-2)*2
					,RGB(0,0,0));
				rgbStr = RGB(255,255,255);
			}
			else rgbStr = RGB(0,0,0);
			
			// アイコン
			if(bDrawIcon)
				DrawIcon(hDC,MSGBOXMERGIN+1,MSGBOXMERGIN+1,hIcon);
			
			// テキスト
			DrawMyStringJP(hDC,lpMsgBoxData->lpText,
				textRt.left,textRt.top,textRt.right-textRt.left,
				textRt.bottom-textRt.top,MSGBOXTEXTSIZE,rgbStr);
			
			
			ReleaseDC(hWnd,hDC);
			
			break;
			
			
		case WM_SETTEXT: // ダイアログのタイトル変更
			
			// DefWindowProc に処理してもらう(なんか胡散臭いやり方 (^^; )
			return(DefWindowProc(hWnd, msg, wp, lp)); 
			
			break;
			
		case WM_COMMAND:
			
			// オーナードローの時はコントロール ID をもらえないので
			// 自前でフォーカス管理をする
			if(bOwnerDraw && HIWORD(wp)== BN_CLICKED) wp = uCurFocus;
			
			switch (LOWORD(wp)) {
				
			case IDC_BT1: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, nResult[0]);
				return TRUE;
				
			case IDC_BT2: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, nResult[1]);
				return TRUE;
				
			case IDC_BT3: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, nResult[2]);
				return TRUE;
				
			case IDCANCEL: 
				if(!bOwnerDraw) DeleteObject(hFont);
				EndDialog(hWnd, IDCANCEL);
				return TRUE;
				
			}
			break;
			
			default:
				break;
	}
    return FALSE;
}
Exemple #13
0
//-------------------------------------------------------------------
// ボタンの描画
// ボタン名をボタンの中に描画するバージョン
VOID DrawMsgButton(HWND hWnd,UINT uCtlID,HDC hCtlDC,
				   RECT rt,UINT uFocus,UINT uStatus){
	
	HFONT hFont,hOldFont;
	LONG width,height,pos;
	HPEN hOldPen;
	HBRUSH hBrush,hOldBrush;
	CHAR szStr[CHR_BUF];
	
	width = rt.right - rt.left;
	height = rt.bottom - rt.top;
	pos = (uStatus == MYID_PUSHBUTTON);
	GetWindowText(GetDlgItem(hWnd,uCtlID),szStr,CHR_BUF);

	// 枠描画
	hOldPen = (HPEN)SelectObject(hCtlDC,GetStockObject(BLACK_PEN));
	hOldBrush = (HBRUSH)SelectObject(hCtlDC,GetStockObject(NULL_BRUSH));
	Rectangle(hCtlDC, rt.left,rt.top,rt.right,rt.bottom);     
	SelectObject(hCtlDC, hOldPen); 
	SelectObject(hCtlDC, hOldBrush); 
	
	// 本体描画
	hOldPen = (HPEN)SelectObject(hCtlDC,GetStockObject(BLACK_PEN));
	hOldBrush = (HBRUSH)SelectObject(hCtlDC,GetStockObject(GRAY_BRUSH));
	Rectangle(hCtlDC, rt.left+pos,rt.top+pos,rt.right-1+pos,rt.bottom-1+pos);     
	SelectObject(hCtlDC, hOldPen); 
	SelectObject(hCtlDC, hOldBrush); 

	// 明るい部分
	if(uCtlID == uFocus) hBrush = CreateSolidBrush(RGB(0,255,255));
	else hBrush = CreateSolidBrush(RGB(255,255,255));
	hOldPen = (HPEN)SelectObject(hCtlDC,GetStockObject(NULL_PEN));
	hOldBrush = (HBRUSH)SelectObject(hCtlDC,hBrush);
	Rectangle(hCtlDC, rt.left+2+pos,rt.top+2+pos,rt.right-2+pos,rt.top+5+pos);
	SelectObject(hCtlDC, hOldPen); 
	SelectObject(hCtlDC, hOldBrush); 
	DeleteObject(hBrush);


	// 文字描画
	TEXTMETRIC textMet; 
	LONG nStrHeight;

	hFont=CreateFont(10,0,0,0,FW_NORMAL,FALSE,FALSE,FALSE,DEFAULT_CHARSET
			,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,"MS Pゴシック");
	hOldFont = (HFONT)SelectObject(hCtlDC,hFont);	
	GetTextMetrics(hCtlDC,&textMet);
	nStrHeight = textMet.tmAscent;
	rt.top += ((height-nStrHeight)/2)+1;
	rt.left += (pos+1);
	rt.right += (pos+1);
	
	// 文字描画
	SetBkMode(hCtlDC,TRANSPARENT);			 
    SetTextColor(hCtlDC,RGB(0,0,0)) ;
	DrawText(hCtlDC,szStr,strlen(szStr),&rt,DT_CENTER);
	rt.top -= 1;rt.left -= 1;rt.right -= 1;
    SetTextColor(hCtlDC,RGB(255,255,255)) ;
	DrawText(hCtlDC,szStr,strlen(szStr),&rt,DT_CENTER);
	// フォント削除
	SelectObject(hCtlDC,hOldFont);			  
	DeleteObject(hFont);
}
Exemple #14
0
int glPrintf(const char *format, ...)
{
	DWORD fdwCharSet = CHINESEBIG5_CHARSET;
	char szFace[] = "Courier New";
	int nHeight = 16;


	char buffer[65536];
	va_list args;
	va_start(args, format);
	vsprintf_s(buffer, format, args);
	va_end(args);

	static GLuint base = 0;
	static bool loaded[65536] = { 0 };
	static HFONT hFont;
	if (base == 0)
	{
		base = glGenLists(65536);
		hFont = CreateFont(nHeight, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, fdwCharSet,
			OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
			FF_DONTCARE | DEFAULT_PITCH, (LPCWSTR)szFace);
	}

	float p0[4], p1[4], c0[2][4] = { { 0, 0, 0, 1 }, { 1, 1, 1, 1 } };
	int i, j, len, offset[2] = { 1, 0 };
	wchar_t *wstr;
	GLint viewport[4];
	HDC hdc = 0;

	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetFloatv(GL_CURRENT_RASTER_POSITION, p0);

	glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0, viewport[2], 0, viewport[3]);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	static int x0 = 0, y0 = 0;
	if (memcmp(buffer, ">>glut", 6) == 0)
	{
		sscanf_s(buffer, ">>glut(%i,%i)", &x0, &y0);
		glRasterPos2f(4, viewport[3] - nHeight);
		glRasterPos2f(4, viewport[3] - nHeight);
	}
	else if (strcmp(buffer, ">>free") == 0)
	{
		glDeleteLists(base, 65536); base = 0;
		memset(loaded, 0, 65536 * sizeof(bool));
		DeleteObject(hFont);
	}
	else
	{
		glRasterPos2f(p0[0], p0[1]);
		glGetFloatv(GL_CURRENT_RASTER_COLOR, c0[1]);
		len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer, -1, 0, 0);
		wstr = (wchar_t*)malloc(len*sizeof(wchar_t));
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer, -1, wstr, len);
		for (j = 0; j<2; j++)
		{
			glColor4fv(c0[j]);
			glRasterPos2f(p0[0] + offset[j], p0[1] - offset[j]);
			for (i = 0; i<len - 1; i++)
			{
				if (wstr[i] == '\n')
				{
					glGetFloatv(GL_CURRENT_RASTER_POSITION, (float*)&p1);
					glRasterPos2f(4 + x0 + offset[j], p1[1] - (nHeight + 2));
				}
				else
				{
					if (!loaded[wstr[i]])
					{
						if (hdc == 0)
						{
							hdc = wglGetCurrentDC();
							SelectObject(hdc, hFont);
						}
						wglUseFontBitmapsW(hdc, wstr[i], 1, base + wstr[i]);
						loaded[wstr[i]] = true;
					}
					glCallList(base + wstr[i]);
				}
			}
		}
		free(wstr);
	}

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glPopAttrib();

	return 0;
}
Exemple #15
0
gxFont *gxGraphics::loadFont( const string &f,int height,int flags ){

	int bold=flags & gxFont::FONT_BOLD ? FW_BOLD : FW_REGULAR;
	int italic=flags & gxFont::FONT_ITALIC ? 1 : 0;
	int underline=flags & gxFont::FONT_UNDERLINE ? 1 : 0;
	int strikeout=0;

	string t;
	int n=f.find('.');
	if( n!=string::npos ){
		t=fullfilename(f);
		if( !font_res.count(t) && AddFontResource( t.c_str() ) ) font_res.insert( t );
		t=filenamefile( f.substr(0,n) );
	}else{
		t=f;
	}

	//save and turn off font smoothing....
	BOOL smoothing=FALSE;
	SystemParametersInfo( SPI_GETFONTSMOOTHING,0,&smoothing,0 );
	SystemParametersInfo( SPI_SETFONTSMOOTHING,FALSE,0,0 );

	HFONT hfont=CreateFont( 
		height,0,0,0,
		bold,italic,underline,strikeout,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
		DEFAULT_PITCH|FF_DONTCARE,t.c_str() );

	if( !hfont ){
		//restore font smoothing
		SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 );
		return 0;
	}

	HDC hdc=CreateCompatibleDC( 0 );
	HFONT pfont=(HFONT)SelectObject( hdc,hfont );

	TEXTMETRIC tm={0};
	if( !GetTextMetrics( hdc,&tm ) ){
		SelectObject( hdc,pfont );
		DeleteDC( hdc );
		DeleteObject( hfont );
		SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 );
		return 0;
	}
	height=tm.tmHeight;

	int first=tm.tmFirstChar,last=tm.tmLastChar;
	int sz=last-first+1;
	int *offs=d_new int[sz];
	int *widths=d_new int[sz];
	int *as=d_new int[sz];

	//calc size of canvas to hold font.
	int x=0,y=0,max_x=0;
	for( int k=0;k<sz;++k ){

		char t=k+first;

		SIZE sz;
		GetTextExtentPoint32( hdc,&t,1,&sz );
		int w=sz.cx;

		as[k]=0;

		ABC abc;
		if( GetCharABCWidths( hdc,t,t,&abc ) ){
			if( abc.abcA<0 ){
				as[k]=ceil(-abc.abcA);
				w+=as[k];
			}
			if( abc.abcC<0 ) w+=ceil(-abc.abcC);
		}

		if( x && x+w>getWidth() ){ x=0;y+=height; }
		offs[k]=(x<<16)|y;
		widths[k]=w;
		x+=w;if( x>max_x ) max_x=x;
	}
	SelectObject( hdc,pfont );
	DeleteDC( hdc );

	int cw=max_x,ch=y+height;

	if( gxCanvas *c=createCanvas( cw,ch,0 ) ){
		ddSurf *surf=c->getSurface();

		HDC surf_hdc;
		if( surf->GetDC( &surf_hdc )>=0 ){
			HFONT pfont=(HFONT)SelectObject( surf_hdc,hfont );

			SetBkColor( surf_hdc,0x000000 );
			SetTextColor( surf_hdc,0xffffff );

			for( int k=0;k<sz;++k ){
				int x=(offs[k]>>16)&0xffff,y=offs[k]&0xffff;
				char t=k+first;
				RECT rect={x,y,x+widths[k],y+height};
				ExtTextOut( surf_hdc,x+as[k],y,ETO_CLIPPED,&rect,&t,1,0 );
			}

			SelectObject( surf_hdc,pfont );
			surf->ReleaseDC( surf_hdc );
			DeleteObject( hfont );
			delete[] as;

			c->backup();
			gxFont *font=d_new gxFont( this,c,tm.tmMaxCharWidth,height,first,last+1,tm.tmDefaultChar,offs,widths );
			font_set.insert( font );

			//restore font smoothing
			SystemParametersInfo( SPI_SETFONTSMOOTHING,smoothing,0,0 );
			return font;
		}else{
Exemple #16
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static int cxChar, cyChar;
    static int xCaret, yCaret;
    static int cxClient, cyClient;
    static int cxBuffer, cyBuffer;
    static DWORD dwCharSet = DEFAULT_CHARSET;
    static TCHAR    *szBuffer;

    HDC         hdc;
    PAINTSTRUCT ps;
    TEXTMETRIC  tm;
    int         x, y;
    int         j;


    switch(uMsg)
    {
    case WM_INPUTLANGCHANGE:
    case WM_CREATE:
        if(uMsg == WM_INPUTLANGCHANGE)
        {
            dwCharSet = wParam ;
        }

        hdc = GetDC (hwnd) ;
        SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;

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

        DeleteObject (SelectObject (hdc, GetStockObject (SYSTEM_FONT))) ;
        ReleaseDC (hwnd, hdc) ;

        for (x = 0; x < cxBuffer; ++x)
            for(y=0; y < cyBuffer; ++y)
                BUFFER(x, y) = ' ';
        xCaret = 0;
        yCaret = 0;
        if (hwnd == GetFocus())
        {
            SetCaretPos(xCaret * cxChar, yCaret * cyChar);
        }
        InvalidateRect(hwnd, NULL, TRUE);
        return 0;
    case WM_SIZE:
        cxClient = LOWORD(lParam);
        cyClient = HIWORD(lParam);

        cxBuffer = cxClient / cxChar;
        cyBuffer = cyClient / cyChar;

        if (szBuffer != NULL)
        {
            free(szBuffer);
        }
        szBuffer = (TCHAR *)malloc(cxBuffer * cyBuffer * sizeof(TCHAR));

        for (x = 0; x < cxBuffer; ++x)
            for(y=0; y < cyBuffer; ++y)
                BUFFER(x, y) = ' ';
        xCaret = 0;
        yCaret = 0;
        if (hwnd == GetFocus())
        {
            SetCaretPos(xCaret * cxChar, yCaret * cyChar);
        }
        InvalidateRect(hwnd, NULL, TRUE);
        return 0;

    case WM_SETFOCUS:
        {
            CreateCaret (hwnd, NULL, cxChar, cyChar) ;
            SetCaretPos (xCaret * cxChar, yCaret * cyChar) ;
            ShowCaret (hwnd) ;
            return 0 ;
        }
    case WM_KILLFOCUS:
        {
            HideCaret (hwnd) ;
            DestroyCaret () ;
            return 0 ;
        }
    case WM_KEYDOWN:
        {
            switch(wParam)
            {
            case VK_DELETE:
                for (x = xCaret; x < cxBuffer -1; ++x)
                {
                    BUFFER(x, yCaret) = BUFFER(x+1, yCaret);
                }
                BUFFER(cxBuffer-1, yCaret) = ' ';

                hdc = GetDC(hwnd);
                HideCaret(hwnd);
                SelectObject(hdc, CreateFont(0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL));  
                TextOut(hdc, xCaret * cxChar, yCaret * cyChar, &BUFFER(xCaret, yCaret), cxBuffer - xCaret);
                DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
                ShowCaret(hwnd);
                ReleaseDC(hwnd, hdc);
                break;
            case VK_UP:
                if (yCaret > 0)
                    yCaret--;
                break;
            case VK_DOWN:
                if (yCaret < cyBuffer - 1)
                    yCaret++;
                break;
            case VK_LEFT:
                if (xCaret > 0)
                    xCaret--;
                break;
            case VK_RIGHT:
                if (xCaret < cxBuffer - 1)
                    xCaret++;
                break;
            case VK_HOME:
                xCaret = 0;
                break;
            case VK_END:
                xCaret = cxBuffer - 1;
                break;
            case VK_PRIOR:
                yCaret = 0;
                break;
            case VK_NEXT:
                yCaret = cyBuffer - 1;
                break;
            default:
                break;
            }
            SetCaretPos(xCaret*cxChar, yCaret*cyChar);
            return 0;
        }
    case WM_CHAR:
        {
            for (j = 0; j < LOWORD(lParam); ++j)
            {
                hdc = GetDC(hwnd);
                HideCaret(hwnd);
                switch(wParam)
                {
                    // Ctrl + Enter
                case '\n':
                    {
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;
                    }
                    //Enter
                case '\r':
                    {
                        xCaret = 0;
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;
                    }
                case '\t':
                    {
                        do
                        {
                            SendMessage(hwnd, WM_CHAR, ' ', 1);
                        }
                        while(xCaret % 8);
                        break;
                    }
                case '\b':      //backspace
                    {
                        if (xCaret > 0)
                        {
                            xCaret--;
                            SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1);
                        }
                        break;
                    }
                case '\x1B':    //Escape
                    {
                        for (x = 0; x < cxBuffer; ++x)
                        {
                            for (y = 0; y < cyBuffer; ++y)
                            {
                                BUFFER(x, y) = ' ';
                            }
                        }
                        xCaret = 0;
                        yCaret = 0;
                        SetCaretPos(xCaret * cxChar, yCaret * cyChar);
                        InvalidateRect(hwnd, NULL, TRUE);
                        break;
                    }
                default:
                    {
                    BUFFER(xCaret, yCaret) = (TCHAR)wParam;
                    SelectObject(hdc, CreateFont(0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL));  
                    TextOut(hdc, xCaret * cxChar, yCaret * cyChar, &BUFFER(xCaret, yCaret), sizeof(BUFFER(xCaret, yCaret))/sizeof(TCHAR));
                    DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
                    xCaret++;
                    break;
                    }
                }

                if (xCaret >= cxBuffer)
                {
                    xCaret = 0;
                    yCaret++;
                }
                if (yCaret >= cyBuffer)
                {
                    yCaret = 0;
                }
                SetCaretPos(xCaret * cxChar, yCaret * cyChar);
                ReleaseDC(hwnd, hdc);
                ShowCaret(hwnd);
            }
            return 0;
        }
    case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);
            SelectObject (hdc, CreateFont (0, 0, 0, 0, 0, 0, 0, 0, dwCharSet, 0, 0, 0, FIXED_PITCH, NULL)) ;
            for (y = 0; y < cyBuffer; ++y)
            {
                TextOut(hdc, 0, y * cyChar, &szBuffer[y*cxBuffer], cxBuffer);
            }
            DeleteObject(SelectObject(hdc, GetStockObject(SYSTEM_FONT)));
            EndPaint(hwnd, &ps);
            break;
        }
    case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
    default:
        {
            break;
        }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Exemple #17
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	int nItemCount;
	int nSelected;
	int *nIndexes;
	BOOL bFlag;
	WCHAR *pszFile;
	WCHAR *handle;
	WCHAR *token;
	Image *imgCurrent;
	Image out;

	switch (iMessage)
	{
		case WM_CREATE:
			HANDLE hToken;

			viewer.changeCaption(L"Preview");

			//Create Controls
			hListLayer = CreateWindow(L"ListBox", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_EXTENDEDSEL | LBS_HASSTRINGS | LBS_NOTIFY | LBS_MULTIPLESEL | LBS_NOINTEGRALHEIGHT, 0, 80, 240, 420, hWnd, (HMENU)ID_LAYER_LIST, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonStart = CreateWindow(L"Button", L"Start", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 0, 0, 80, 40, hWnd, (HMENU)ID_START_BUTTON, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonSave = CreateWindow(L"Button", L"Save Selected in merged file", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 80, 0, 80, 40, hWnd, (HMENU)ID_SAVE_BUTTON, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonSaveAll = CreateWindow(L"Button", L"Save All in individual file", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 160, 0, 80, 40, hWnd, (HMENU)ID_SAVE_ALL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonResetAll = CreateWindow(L"Button", L"Erase All", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 0, 40, 80, 40, hWnd, (HMENU)ID_RESET_ALL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonResetSelected = CreateWindow(L"Button", L"Erase Selected", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 80, 40, 80, 40, hWnd, (HMENU)ID_RESET_SEL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);
			hButtonResetUnselected = CreateWindow(L"Button", L"Erase Unelected", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_MULTILINE, 160, 40, 80, 40, hWnd, (HMENU)ID_RESET_UNSEL, ((LPCREATESTRUCT)lParam)->hInstance, NULL);

			hFont = CreateFont(16, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 3, 2, 1, FF_ROMAN, L"Segoe UI");

			SendMessage(hListLayer, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonStart, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonSave, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonSaveAll, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonResetAll, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonResetSelected, WM_SETFONT, (WPARAM)hFont, TRUE);
			SendMessage(hButtonResetUnselected, WM_SETFONT, (WPARAM)hFont, TRUE);

			//Create Events
			hAttachSucceeded = CreateEvent(NULL, TRUE, FALSE, NULL);
			hDebugEnd = CreateEvent(NULL, TRUE, FALSE, NULL);
			hDebugInit = CreateEvent(NULL, TRUE, FALSE, NULL);

			//Adjust Privileges
			if (OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
			{
				if (SetPrivilege(hToken, SE_DEBUG_NAME, TRUE))
					return 0;
				else
					MessageBox(hWnd, L"Fail to get debug privilege!!", L"Error", MB_OK | MB_ICONERROR);
			}
			else
				MessageBox(hWnd, L"Fail to get process token!!", L"Error", MB_OK | MB_ICONERROR);

			SendMessage(hWnd, WM_DESTROY, 0, 0);

			return 0;
		case WM_ACTIVATE:
			if (wParam == WA_CLICKACTIVE)
			{
				viewer.foreground();
				SetForegroundWindow(hWnd);
				SetFocus(hListLayer);
			}
			return 0;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case ID_START_BUTTON:
					if (!bStarted)
					{
						hAokanaWnd = FindAokana(&dwThreadID, &dwProcessID);

						if (dwThreadID != 0)
						{
							hDebugThread = CreateThread(NULL, 0, DebugThread, NULL, 0, NULL);

							WaitForSingleObject(hDebugInit, INFINITE);
							if (WaitForSingleObject(hAttachSucceeded, 0) != WAIT_OBJECT_0)
							{
								SetEvent(hDebugEnd);
								MessageBox(hWnd, L"Fail to attach process!!", L"Error", MB_OK | MB_ICONERROR);

								break;
							}

							SendMessage(hButtonStart, WM_SETTEXT, 0, (LPARAM)L"Stop");
							bStarted = TRUE;
						}
					}
					else
					{
						SetEvent(hDebugEnd);
						WaitForSingleObject(hDebugThread, INFINITE);

						ResetEvent(hDebugEnd);
						ResetEvent(hDebugInit);
						ResetEvent(hAttachSucceeded);
						CloseHandle(hDebugThread);

						SendMessage(hButtonStart, WM_SETTEXT, 0, (LPARAM)L"Start");
						bStarted = FALSE;
					}
					break;
				case ID_SAVE_BUTTON:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

					if (nSelected > 0)
					{
						nIndexes = (int *)calloc(nSelected, sizeof(int));

						SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

						memset(&out, 0, sizeof(Image));

						for (int i = nSelected - 1; i >= 0; i--)
						{
							imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, nIndexes[i], 0);

							if (imgCurrent == NULL)
								continue;

							if (i == nSelected - 1)
							{
								out.data = (PIXEL *)calloc(imgCurrent->width * imgCurrent->height, sizeof(PIXEL));
								out.width = imgCurrent->width;
								out.height = imgCurrent->height;
							}

							if (imgCurrent->width == out.width && imgCurrent->height == out.height)
								pixeloverlay(out.width, out.height, out.data, imgCurrent->data, out.data);
						}

						saveDialog(hWnd, out);

						free(nIndexes);
						free(out.data);
					}
					break;
				case ID_SAVE_ALL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);

					if (nItemCount > 0)
					{
						if (selectFolder(hWnd, pszFolder))
						{
							pszFile = (WCHAR *)calloc(256, sizeof(WCHAR));

							for (int i = nItemCount - 1; i >= 0; i--)
							{
								imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, i, 0);
								SendMessage(hListLayer, LB_GETTEXT, i, (LPARAM)pszFile);

								token = wcstok_s(pszFile, L" ", &handle);
								token = wcstok_s(NULL, L" ", &handle);

								if (pszFolder[wcslen(pszFolder) - 1] != '\\')
									wcscat_s(pszFolder, L"\\");

								nSelected = wcslen(pszFolder);	//Position of '\' + 1

								wcscat_s(pszFolder, token);
								wcscat_s(pszFolder, L".png");
								saveImage(*imgCurrent, pszFolder);

								pszFolder[nSelected] = 0;
							}

							free(pszFile);
						}
					}
					break;
				case ID_LAYER_LIST:
					if (HIWORD(wParam) == LBN_SELCHANGE)
					{
						nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
						nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

						if (nSelected > 0)
						{
							nIndexes = (int *)calloc(nSelected, sizeof(int));

							SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

							for (int i = nSelected - 1; i >= 0; i--)
							{
								imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, nIndexes[i], 0);

								if (imgCurrent == NULL)
									continue;

								if (i == nSelected - 1)
									viewer.create(imgCurrent->width, imgCurrent->height);

								if (imgCurrent->width == viewer.getwidth() && imgCurrent->height == viewer.getheight())
									viewer.overlay(imgCurrent->data);
							}

							viewer.show();

							free(nIndexes);
						}
						else
							viewer.hide();
					}
					break;
				case ID_RESET_ALL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					for (int i = 0; i < nItemCount; i++)
					{
						imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, i, 0);
						free(imgCurrent->data);
						free(imgCurrent);
					}
					SendMessage(hListLayer, LB_RESETCONTENT, 0, 0);
					viewer.hide();
					break;
				case ID_RESET_SEL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

					if (nSelected > 0)
					{
						nIndexes = (int *)calloc(nSelected, sizeof(int));

						SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

						for (int i = nSelected - 1; i >= 0; i--)
						{
							imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, nIndexes[i], 0);
							free(imgCurrent->data);
							free(imgCurrent);
							SendMessage(hListLayer, LB_DELETESTRING, nIndexes[i], 0);
						}

						free(nIndexes);
						viewer.hide();
					}
					break;
				case ID_RESET_UNSEL:
					nItemCount = SendMessage(hListLayer, LB_GETCOUNT, 0, 0);
					nSelected = SendMessage(hListLayer, LB_GETSELCOUNT, 0, 0);

					if (nSelected > 0)
					{
						nIndexes = (int *)calloc(nSelected, sizeof(int));

						SendMessage(hListLayer, LB_GETSELITEMS, nSelected, (LPARAM)nIndexes);

						for (int i = nItemCount - 1; i >= 0; i--)
						{
							bFlag = FALSE;

							for (int j = nSelected - 1; j >= 0; j--)
								if (i == nIndexes[j])
									bFlag = TRUE;

							if (!bFlag)
							{
								imgCurrent = (Image *)SendMessage(hListLayer, LB_GETITEMDATA, i, 0);
								free(imgCurrent->data);
								free(imgCurrent);
								SendMessage(hListLayer, LB_DELETESTRING, i, 0);
							}
						}

						free(nIndexes);
					}
					break;
			}
			return 0;
		case WM_DESTROY:
			if (bStarted)
				SendMessage(hWnd, WM_COMMAND, ID_START_BUTTON, 0);

			SendMessage(hWnd, WM_COMMAND, ID_RESET_ALL, 0);

			CloseHandle(hAttachSucceeded);
			CloseHandle(hDebugEnd);

			DeleteObject(hFont);

			PostQuitMessage(0);
			return 0;
	}

	return DefWindowProc(hWnd, iMessage, wParam, lParam);
}
Exemple #18
0
//*******
// this function initializes Direct3D... 
bool init3D(HWND hWnd)
{
   D3DDISPLAYMODE d3ddm;   // Direct3D Display Mode..
   D3DPRESENT_PARAMETERS d3dpp;    // d3d present parameters..details on how it should present
         // a scene.. such as swap effect.. size.. windowed or full screen.. 
   HFONT fnt;

   // create D3D8.. if error (like that ever happens..) return false..
    if (NULL == (lpD3D8 = Direct3DCreate8(D3D_SDK_VERSION)))
        return false;
   // get display adapter mode.. if error return false..
   if (FAILED(lpD3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
      return false;

   // NOTE:  it's possible that this example will not work as is
   //        in windowed mode due to display format and depth buffer format
   ZeroMemory(&d3dpp, sizeof(d3dpp));            // blank the memory for good measure..
   //   d3dpp.Windowed = true;                   // use this for window mode..
   d3dpp.Windowed = false;                       // use this for full screen... it's that easy!
   d3dpp.BackBufferWidth = 1024;                 // rather useless for windowed version
   d3dpp.BackBufferHeight = 768;                 // ditto..but left it in anyway for full screen
   d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP;        // flip using a back buffer...easy performance
   d3dpp.BackBufferFormat = D3DFMT_R5G6B5;       // just set back buffer format from display mode
   d3dpp.EnableAutoDepthStencil = true;
   d3dpp.AutoDepthStencilFormat =  D3DFMT_D16;   // 16 bit depth buffer..

   // Create the D3DDevice
   if (FAILED(lpD3D8->CreateDevice(D3DADAPTER_DEFAULT,   // which display adapter..
               D3DDEVTYPE_HAL,   
               hWnd, D3DCREATE_MIXED_VERTEXPROCESSING,   // mixed, software, or hardware..
                    &d3dpp, &lpD3DDevice8)))             // sends stuff.. and to receive
   {  // if it fails to create with HAL, then try (usually succeeds) to create
      // with ref (software) using a much lower screen res
      d3dpp.BackBufferWidth = 320;
      d3dpp.BackBufferHeight = 240;
      d3dpp.Windowed = false;
      if (FAILED(lpD3D8->CreateDevice(D3DADAPTER_DEFAULT,
                  D3DDEVTYPE_REF,
                  hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                  &d3dpp, &lpD3DDevice8)))
      {
         return false;     
      }
      else
      {  // create smaller font for software... lower res..
         fnt = CreateFont(20, 10, 2, 0, 500, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
               CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, 0);
         // disable dithering for software..
         lpD3DDevice8->SetRenderState( D3DRS_DITHERENABLE, false);
      }
   }
   else
   {  // create larger font for hardware.. higher res
      fnt = CreateFont(50, 22, 2, 0, 500, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
            CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, 0);
      // enable dithering for hardware... 
      lpD3DDevice8->SetRenderState( D3DRS_DITHERENABLE, true);
   }

   // cull counter clockwise.. triangles drawn counterclockwise from the
   // view will not be rendered.. this is rather normal culling
   lpD3DDevice8->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW );
   // turn off lighting since we have color values..
   // and no light sources exist..
   lpD3DDevice8->SetRenderState( D3DRS_LIGHTING, false );

   // create a D3DXFont from a windows font created above...
   // for use in drawing text with D3D
   D3DXCreateFont(lpD3DDevice8, fnt, &lpD3DXFont);

   return true;
}
Exemple #19
0
bool CChannelMenu::Create(const CChannelList *pChannelList,int CurChannel,UINT Command,
						  HMENU hmenu,HWND hwnd,unsigned int Flags,int MaxRows)
{
	Destroy();

	if (pChannelList==NULL)
		return false;

	m_ChannelList=*pChannelList;
	m_CurChannel=CurChannel;
	m_FirstCommand=Command;
	m_LastCommand=Command+m_ChannelList.NumChannels()-1;
	m_Flags=Flags;
	m_hwnd=hwnd;

	m_MenuPainter.Initialize(hwnd);
	m_MenuPainter.GetItemMargins(&m_Margins);
	if (m_Margins.cxLeftWidth<2)
		m_Margins.cxLeftWidth=2;
	if (m_Margins.cxRightWidth<2)
		m_Margins.cxRightWidth=2;

	HDC hdc=::GetDC(hwnd);

	CreateFont(hdc);
	HFONT hfontOld=DrawUtil::SelectObject(hdc,m_Font);

	CEpgProgramList &EpgProgramList=GetAppClass().EpgProgramList;
	const bool fCurServices=(Flags & FLAG_CURSERVICES)!=0;
	SYSTEMTIME st;
	if (!fCurServices)
		GetBaseTime(&st);
	m_ChannelNameWidth=0;
	m_EventNameWidth=0;
	if (hmenu==NULL) {
		m_hmenu=::CreatePopupMenu();
	} else {
		m_hmenu=hmenu;
		m_Flags|=FLAG_SHARED;
		ClearMenu(hmenu);
	}
	MENUITEMINFO mii;
	mii.cbSize=sizeof(MENUITEMINFO);
	mii.fMask=MIIM_FTYPE | MIIM_STATE | MIIM_ID | MIIM_DATA;
	int PrevSpace=-1;
	for (int i=0,j=0;i<m_ChannelList.NumChannels();i++) {
		const CChannelInfo *pChInfo=m_ChannelList.GetChannelInfo(i);
		if (!pChInfo->IsEnabled())
			continue;

		TCHAR szText[256];
		RECT rc;

		if (i==CurChannel)
			DrawUtil::SelectObject(hdc,m_FontCurrent);
		StdUtil::snprintf(szText,lengthof(szText),TEXT("%d: %s"),
						  pChInfo->GetChannelNo(),pChInfo->GetName());
		/*
		m_MenuPainter.GetItemTextExtent(hdc,0,szText,&rc,
										DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
		*/
		::SetRectEmpty(&rc);
		::DrawText(hdc,szText,-1,&rc,DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
		if (rc.right>m_ChannelNameWidth)
			m_ChannelNameWidth=rc.right;
		mii.wID=m_FirstCommand+i;
		mii.fType=MFT_OWNERDRAW;
		if ((MaxRows>0 && j==MaxRows)
				|| ((Flags&FLAG_SPACEBREAK)!=0 && pChInfo->GetSpace()!=PrevSpace)) {
			mii.fType|=MFT_MENUBREAK;
			j=0;
		}
		mii.fState=MFS_ENABLED;
		if (i==CurChannel)
			mii.fState|=MFS_CHECKED;
		CChannelMenuItem *pItem=new CChannelMenuItem(pChInfo);
		mii.dwItemData=reinterpret_cast<ULONG_PTR>(pItem);
		if ((Flags&FLAG_SHOWEVENTINFO)!=0) {
			const CEventInfoData *pEventInfo=
				pItem->GetEventInfo(&EpgProgramList,0,fCurServices?NULL:&st);

			if (pEventInfo!=NULL) {
				GetEventText(pEventInfo,szText,lengthof(szText));
				/*
				m_MenuPainter.GetItemTextExtent(hdc,0,szText,&rc,
												DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX);
				*/
				::SetRectEmpty(&rc);
				::DrawText(hdc,szText,-1,&rc,DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);
				if (rc.right>m_EventNameWidth)
					m_EventNameWidth=rc.right;
			}
		}
		::InsertMenuItem(m_hmenu,i,TRUE,&mii);
		if (i==CurChannel)
			DrawUtil::SelectObject(hdc,m_Font);
		PrevSpace=pChInfo->GetSpace();
		j++;
	}
	::SelectObject(hdc,hfontOld);
	::ReleaseDC(hwnd,hdc);

	if ((Flags&FLAG_SHOWTOOLTIP)!=0) {
		m_Tooltip.Create(hwnd);
		m_Tooltip.SetMaxWidth(480);
		m_Tooltip.SetPopDelay(30*1000);
		m_Tooltip.AddTrackingTip(1,TEXT(""));
	}

	if ((Flags & FLAG_SHOWLOGO)!=0) {
		if (!m_LogoFrameImage.IsCreated()) {
			m_LogoFrameImage.Load(GetAppClass().GetResourceInstance(),
								  MAKEINTRESOURCE(IDB_LOGOFRAME),LR_CREATEDIBSECTION);
		}
	}

	return true;
}
Exemple #20
0
HWND createWindow(HINSTANCE instance)
{
	WNDCLASSEX wndClass;
	ZeroMemory(&wndClass,sizeof(WNDCLASSEX));
	wndClass.cbSize = sizeof(WNDCLASSEX);
	wndClass.style = 0;
	wndClass.lpfnWndProc = windowProc;
	wndClass.hInstance = instance;
	wndClass.hIcon = LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(100));
	wndClass.hCursor = LoadCursor(0,IDC_ARROW);
	wndClass.lpszClassName = "DBWRender";
	if (RegisterClassEx(&wndClass) == 0)
		fatal("Could not create window class");

	wnd = CreateWindowEx(WS_EX_CLIENTEDGE,"DBWRender","DBW Render Display",
		WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,0,0,width,height,
		0,0,instance,0);
	if (wnd == 0)
		fatal("Could not create window");

	NONCLIENTMETRICS ncm;
	ZeroMemory(&ncm,sizeof ncm);
	ncm.cbSize = sizeof ncm;
	SystemParametersInfo(SPI_GETNONCLIENTMETRICS,ncm.cbSize,&ncm,0);

	HFONT font = CreateFont(ncm.lfMessageFont.lfHeight,0,0,0,FW_NORMAL,0,0,0,
		ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
		DEFAULT_PITCH,ncm.lfMessageFont.lfFaceName);
	if (font == 0)
		fatal("Could not create font");

	HDC dc = GetWindowDC(wnd);
	SIZE size;
	GetTextExtentPoint32(dc,"  Save  ",8,&size);
	buttonWidth = size.cx;
	buttonHeight = (int)(1.25*size.cy);
	ReleaseDC(wnd,dc);

	createButton(instance,font,"&Save",IDC_SAVE,0);
	createButton(instance,font,"E&xit",IDC_QUIT,1);

	ACCEL accelt[2] = {
		{ FALT,'s',IDC_SAVE },
		{ FALT,'x',IDC_QUIT }};
	accel = CreateAcceleratorTable(accelt,2);
	if (accel == 0)
		fatal("Could not create accelerator table");

	RECT wr, cr;
	GetWindowRect(wnd,&wr);
	GetClientRect(wnd,&cr);
	int w = width+(wr.right-wr.left)-(cr.right-cr.left);
	int h = height+buttonHeight+(wr.bottom-wr.top)-(cr.bottom-cr.top);

	int mw = GetSystemMetrics(SM_CXFULLSCREEN);
	int mh = GetSystemMetrics(SM_CYFULLSCREEN);
	int x = w < mw ? (mw-w)/2 : 0;
	int y = h < mh ? (mh-h)/2 : 0;
	MoveWindow(wnd,x,y,w,h,0);

	ShowWindow(wnd,SW_SHOW);
	return wnd;
}
Exemple #21
0
/*
================
Con_CreateConsole

create win32 console
================
*/
void Con_CreateConsole( void )
{
#ifdef _WIN32
	HDC	hDC;
	WNDCLASS	wc;
	RECT	rect;
	int	nHeight;
	int	swidth, sheight, fontsize;
	int	DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION;
	int	CONSTYLE = WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_BORDER|WS_EX_CLIENTEDGE|ES_LEFT|ES_MULTILINE|ES_AUTOVSCROLL|ES_READONLY;
	string	FontName;

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC)Con_WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = host.hInst;
	wc.hIcon         = LoadIcon( host.hInst, MAKEINTRESOURCE( IDI_ICON1 ));
	wc.hCursor       = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (void *)COLOR_3DSHADOW;
	wc.lpszClassName = SYSCONSOLE;
	wc.lpszMenuName  = 0;

	if( Sys_CheckParm( "-log" ) && host.developer != 0 )
		s_wcd.log_active = true;

	if( host.type == HOST_NORMAL )
	{
		rect.left = 0;
		rect.right = 536;
		rect.top = 0;
		rect.bottom = 364;
		Q_strncpy( FontName, "Fixedsys", sizeof( FontName ));
		Q_strncpy( s_wcd.title, va( "Xash3D %g", XASH_VERSION ), sizeof( s_wcd.title ));
		Q_strncpy( s_wcd.log_path, "engine.log", sizeof( s_wcd.log_path ));
		fontsize = 8;
	}
	else // dedicated console
	{
		rect.left = 0;
		rect.right = 640;
		rect.top = 0;
		rect.bottom = 392;
		Q_strncpy( FontName, "System", sizeof( FontName ));
		Q_strncpy( s_wcd.title, "Xash Dedicated Server", sizeof( s_wcd.title ));
		Q_strncpy( s_wcd.log_path, "dedicated.log", sizeof( s_wcd.log_path ));
		s_wcd.log_active = true; // always make log
		fontsize = 14;
	}

	Sys_InitLog();
	if( !RegisterClass( &wc ))
	{
		// print into log
		MsgDev( D_ERROR, "Can't register window class '%s'\n", SYSCONSOLE );
		return;
	} 

	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left;
	s_wcd.windowHeight = rect.bottom - rect.top;

	s_wcd.hWnd = CreateWindowEx( WS_EX_DLGMODALFRAME, SYSCONSOLE, s_wcd.title, DEDSTYLE, ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1, NULL, NULL, host.hInst, NULL );
	if( s_wcd.hWnd == NULL )
	{
		MsgDev( D_ERROR, "Can't create window '%s'\n", s_wcd.title );
		return;
	}

	// create fonts
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( fontsize, GetDeviceCaps( hDC, LOGPIXELSY ), 72 );
	s_wcd.hfBufferFont = CreateFont( nHeight, 0, 0, 0, FW_LIGHT, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN|FIXED_PITCH, FontName );
	ReleaseDC( s_wcd.hWnd, hDC );

	if( host.type == HOST_DEDICATED )
	{
		// create the input line
		s_wcd.hwndInputLine = CreateWindowEx( WS_EX_CLIENTEDGE, "edit", NULL, WS_CHILD|WS_VISIBLE|WS_BORDER|ES_LEFT|ES_AUTOHSCROLL, 0, 366, 550, 25, s_wcd.hWnd, (HMENU)INPUT_ID, host.hInst, NULL );

		s_wcd.hwndButtonSubmit = CreateWindow( "button", NULL, BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON, 552, 367, 87, 25, s_wcd.hWnd, (HMENU)SUBMIT_ID, host.hInst, NULL );
		SendMessage( s_wcd.hwndButtonSubmit, WM_SETTEXT, 0, ( LPARAM ) "submit" );
          }
          
	// create the scrollbuffer
	GetClientRect( s_wcd.hWnd, &rect );

	s_wcd.hwndBuffer = CreateWindowEx( WS_EX_DLGMODALFRAME|WS_EX_CLIENTEDGE, "edit", NULL, CONSTYLE, 0, 0, rect.right - rect.left, min(365, rect.bottom), s_wcd.hWnd, (HMENU)EDIT_ID, host.hInst, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, (WPARAM)s_wcd.hfBufferFont, 0 );

	if( host.type == HOST_DEDICATED )
	{
		s_wcd.SysInputLineWndProc = (WNDPROC)SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, (long)Con_InputLineProc );
		SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM )s_wcd.hfBufferFont, 0 );
          }

	// show console if needed
	if( host.con_showalways )
	{          
		// make console visible
		ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT );
		UpdateWindow( s_wcd.hWnd );
		SetForegroundWindow( s_wcd.hWnd );

		if( host.type != HOST_DEDICATED )
			SetFocus( s_wcd.hWnd );
		else SetFocus( s_wcd.hwndInputLine );
		s_wcd.status = true;
          }
	else s_wcd.status = false;
#endif

	if( Sys_CheckParm( "-log" ) && host.developer != 0 )
	{
		s_wcd.log_active = true;
		Q_strncpy( s_wcd.log_path, "engine.log", sizeof( s_wcd.log_path ));
	}

	Sys_InitLog();
}
Exemple #22
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    lastchar=-1;
    inputdelay=-1;

    std::string typeface = "Terminus";
    char * typeface_c = 0;
    std::ifstream fin;
    fin.open("data\\FONTDATA");
    if (!fin.is_open()){
        fontwidth = 8;
        fontheight = 16;
        std::ofstream fout;//create data/FONDATA file
        fout.open("data\\FONTDATA");
        if(fout.is_open()) {
            fout << typeface << "\n";
            fout << fontwidth << "\n";
            fout << fontheight;
            fout.close();
        }
    } else {
        getline(fin, typeface);
        fin >> fontwidth;
        fin >> fontheight;
        if ((fontwidth <= 4) || (fontheight <=4)){
            MessageBox(WindowHandle, "Invalid font size specified!", NULL, 0);
            fontheight = 16;
            fontwidth  = 8;
        }
    }
    typeface_c = new char [typeface.size()+1];
    strcpy (typeface_c, typeface.c_str());

    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS["VIEWPORT_X"] * 2 + 1)) * fontwidth;
    WindowHeight = (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight;

    WinCreate();    //Create the actual window, register it, etc
    timeBeginPeriod(1); // Set Sleep resolution to 1ms
    CheckMessages();    //Let the message queue handle setting up the window

    WindowDC   = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);

    BITMAPINFO bmi = BITMAPINFO();
    bmi.bmiHeader.biSize         = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth        = WindowWidth;
    bmi.bmiHeader.biHeight       = -WindowHeight;
    bmi.bmiHeader.biPlanes       = 1;
    bmi.bmiHeader.biBitCount     = 8;
    bmi.bmiHeader.biCompression  = BI_RGB; // Raw RGB
    bmi.bmiHeader.biSizeImage    = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed      = 16; // Colors in the palette
    bmi.bmiHeader.biClrImportant = 16; // Colors in the palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

    // Load private fonts
    if (SetCurrentDirectory("data\\font")){
        WIN32_FIND_DATA findData;
        for (HANDLE findFont = FindFirstFile(".\\*", &findData); findFont != INVALID_HANDLE_VALUE; )
        {
            if (!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Skip folders
                AddFontResourceExA(findData.cFileName, FR_PRIVATE,NULL);
            }
            if (!FindNextFile(findFont, &findData)){
                FindClose(findFont);
                break;
            }
        }
        SetCurrentDirectory("..\\..");
    }

    // Use desired font, if possible
    font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, typeface_c);

    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(55 + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Exemple #23
0
static LRESULT CALLBACK
WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
  int redraw = 0;
  switch (message) {
    case WM_CHAR:  {
      switch (wparam) {
      case '+':
	the_scale *= 1.2f;
	redraw = 1;
	break;
      case '-':
	the_scale /= 1.2f;
	redraw = 1;
	break;
      case 'f':
      case 'F': {
	float wscale, hscale;
	wscale = win_width / (float)the_width;
	hscale = win_height / (float)the_height;
	the_scale *= wscale > hscale ? hscale : wscale;
	redraw = 1;
	break;
      }
      case '1':
	the_scale = 1.0;
	redraw = 1;
	break;
      case 'q':
      case 'Q':
	finish = 1;
	break;
      }
      break;
    }

    case WM_PAINT: {
      HFONT font;
      BeginPaint(hwnd, &the_output.ps);
      font = CreateFont(fontsize, 0, 0, 0, 0, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL);
      SelectObject(the_output.ps.hdc, (HGDIOBJ) font);
      windows_box(&the_output, 0xff, 0xff, 0xff, 0, 0, win_width, 0, win_height);
      the_output.max_x = 0;
      the_output.max_y = 0;
      output_draw(&the_output.loutput);
      the_width = the_output.max_x;
      the_height = the_output.max_y;
      DeleteObject(font);
      EndPaint(hwnd, &the_output.ps);
      break;
    }
    case WM_LBUTTONDOWN:
      state = 1;
      x = GET_X_LPARAM(lparam);
      y = GET_Y_LPARAM(lparam);
      break;
    case WM_LBUTTONUP:
      state = 0;
      break;
    case WM_MOUSEMOVE:
      if (!(wparam & MK_LBUTTON))
        state = 0;
      if (state) {
        int new_x = GET_X_LPARAM(lparam);
        int new_y = GET_Y_LPARAM(lparam);
        x_delta -= new_x - x;
        y_delta -= new_y - y;
        x = new_x;
        y = new_y;
        redraw = 1;
      }
      break;
    case WM_KEYDOWN:
      switch (wparam) {
      case VK_ESCAPE:
        finish = 1;
        break;
      case VK_LEFT:
        x_delta -= win_width/10;
        redraw = 1;
        break;
      case VK_RIGHT:
        x_delta += win_width/10;
        redraw = 1;
        break;
      case VK_UP:
        y_delta -= win_height/10;
        redraw = 1;
        break;
      case VK_DOWN:
        y_delta += win_height/10;
        redraw = 1;
        break;
      case VK_PRIOR:
        if (control) {
          x_delta -= win_width;
          redraw = 1;
        } else {
          y_delta -= win_height;
          redraw = 1;
        }
        break;
      case VK_NEXT:
        if (control) {
          x_delta += win_width;
          redraw = 1;
        } else {
          y_delta += win_height;
          redraw = 1;
        }
        break;
      case VK_HOME:
        x_delta = 0;
        y_delta = 0;
        redraw = 1;
        break;
      case VK_END:
        x_delta = INT_MAX;
        y_delta = INT_MAX;
        redraw = 1;
        break;
      case VK_CONTROL:
        control = 1;
        break;
      }
      break;
    case WM_KEYUP:
      switch (wparam) {
      case VK_CONTROL:
        control = 0;
        break;
      }
      break;
    case WM_DESTROY:
      /* only kill the program if closing the actual toplevel, not the fake one */
      if (hwnd == the_output.toplevel)
	PostQuitMessage(0);
      return 0;
    case WM_SIZE: {
      float wscale, hscale;
      win_width = LOWORD(lparam);
      win_height = HIWORD(lparam);
      wscale = win_width / (float)the_width;
      hscale = win_height / (float)the_height;
      the_scale *= wscale > hscale ? hscale : wscale;
      if (the_scale < 1.0f)
	the_scale = 1.0f;
      redraw = 1;
      break;
    }
  }
  if (redraw) {
    if (x_delta > the_width - win_width)
      x_delta = the_width - win_width;
    if (y_delta > the_height - win_height)
      y_delta = the_height - win_height;
    if (x_delta < 0)
      x_delta = 0;
    if (y_delta < 0)
      y_delta = 0;
    fontsize = (unsigned)(the_fontsize * the_scale);
    gridsize = (unsigned)(the_gridsize * the_scale);
    RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE);
  }
  return DefWindowProc(hwnd, message, wparam, lparam);
}
Exemple #24
0
//Basic Init, create the font, backbuffer, etc
WINDOW *curses_init(void)
{
   // _windows = new WINDOW[20];         //initialize all of our variables
    BITMAPINFO bmi;
    lastchar=-1;
    inputdelay=-1;
    std::string typeface;
char * typeface_c;
std::ifstream fin;
fin.open("data\\FONTDATA");
 if (!fin.is_open()){
     MessageBox(WindowHandle, "Failed to open FONTDATA, loading defaults.",
                NULL, 0);
     fontheight=16;
     fontwidth=8;
 } else {
     getline(fin, typeface);
     typeface_c= new char [typeface.size()+1];
     strcpy (typeface_c, typeface.c_str());
     fin >> fontwidth;
     fin >> fontheight;
     if ((fontwidth <= 4) || (fontheight <=4)){
         MessageBox(WindowHandle, "Invalid font size specified!",
                    NULL, 0);
        fontheight=16;
        fontwidth=8;
     }
 }
    halfwidth=fontwidth / 2;
    halfheight=fontheight / 2;
    WindowWidth= (55 + (OPTIONS[OPT_VIEWPORT_X] * 2 + 1)) * fontwidth;
    WindowHeight= (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1) *fontheight;
    WindowX=(GetSystemMetrics(SM_CXSCREEN) / 2)-WindowWidth/2;    //center this
    WindowY=(GetSystemMetrics(SM_CYSCREEN) / 2)-WindowHeight/2;   //sucker
    WinCreate();    //Create the actual window, register it, etc
    CheckMessages();    //Let the message queue handle setting up the window
    WindowDC = GetDC(WindowHandle);
    backbuffer = CreateCompatibleDC(WindowDC);
    ZeroMemory(&bmi, sizeof(BITMAPINFO));
    bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmi.bmiHeader.biWidth = WindowWidth;
    bmi.bmiHeader.biHeight = -WindowHeight;
    bmi.bmiHeader.biPlanes = 1;
    bmi.bmiHeader.biBitCount=8;
    bmi.bmiHeader.biCompression = BI_RGB;   //store it in uncompressed bytes
    bmi.bmiHeader.biSizeImage = WindowWidth * WindowHeight * 1;
    bmi.bmiHeader.biClrUsed=16;         //the number of colors in our palette
    bmi.bmiHeader.biClrImportant=16;    //the number of colors in our palette
    backbit = CreateDIBSection(0, &bmi, DIB_RGB_COLORS, (void**)&dcbits, NULL, 0);
    DeleteObject(SelectObject(backbuffer, backbit));//load the buffer into DC

 int nResults = AddFontResourceExA("data\\termfont",FR_PRIVATE,NULL);
   if (nResults>0){
    font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, typeface_c);   //Create our font

  } else {
      MessageBox(WindowHandle, "Failed to load default font, using FixedSys.",
                NULL, 0);
       font = CreateFont(fontheight, fontwidth, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
                      ANSI_CHARSET, OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
                      PROOF_QUALITY, FF_MODERN, "FixedSys");   //Create our font
   }
    //FixedSys will be user-changable at some point in time??
    SetBkMode(backbuffer, TRANSPARENT);//Transparent font backgrounds
    SelectObject(backbuffer, font);//Load our font into the DC
//    WindowCount=0;

    delete typeface_c;
    mainwin = newwin((OPTIONS[OPT_VIEWPORT_Y] * 2 + 1),(55 + (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1)),0,0);
    return mainwin;   //create the 'stdscr' window and return its ref
}
Exemple #25
0
/*
 * ChangeFont:
 *    Changes the default global font
 */
void ChangeFont(const char *FontName, int Width, int Height, int Attributes)
{
    Font = CreateFont(Height, Width, 0, 0, Attributes, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, VARIABLE_PITCH, FontName);
}
Exemple #26
0
/*
** Sys_CreateConsole
*/
void Sys_CreateConsole( void )
{
	HDC hDC;
	WNDCLASS wc;
	RECT rect;
	const char *DEDCLASS = "Q3 WinConsole";
	int nHeight;
	int swidth, sheight;
	int DEDSTYLE = WS_POPUPWINDOW | WS_CAPTION | WS_MINIMIZEBOX;

	memset( &wc, 0, sizeof( wc ) );

	wc.style         = 0;
	wc.lpfnWndProc   = (WNDPROC) ConWndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = g_wv.hInstance;
	wc.hIcon         = LoadIcon( g_wv.hInstance, MAKEINTRESOURCE(IDI_ICON1));
	wc.hCursor       = LoadCursor (NULL,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
	wc.lpszMenuName  = 0;
	wc.lpszClassName = DEDCLASS;

	if ( !RegisterClass (&wc) )
		return;

	rect.left = 0;
	rect.right = 540;
	rect.top = 0;
	rect.bottom = 450;
	AdjustWindowRect( &rect, DEDSTYLE, FALSE );

	hDC = GetDC( GetDesktopWindow() );
	swidth = GetDeviceCaps( hDC, HORZRES );
	sheight = GetDeviceCaps( hDC, VERTRES );
	ReleaseDC( GetDesktopWindow(), hDC );

	s_wcd.windowWidth = rect.right - rect.left + 1;
	s_wcd.windowHeight = rect.bottom - rect.top + 1;

	s_wcd.hWnd = CreateWindowEx( 0,
							   DEDCLASS,
							   CONSOLE_WINDOW_TITLE,
							   DEDSTYLE,
							   ( swidth - 600 ) / 2, ( sheight - 450 ) / 2 , rect.right - rect.left + 1, rect.bottom - rect.top + 1,
							   NULL,
							   NULL,
							   g_wv.hInstance,
							   NULL );

	if ( s_wcd.hWnd == NULL )
	{
		return;
	}

	//
	// create fonts
	//
	hDC = GetDC( s_wcd.hWnd );
	nHeight = -MulDiv( 8, GetDeviceCaps( hDC, LOGPIXELSY), 72);

	s_wcd.hfBufferFont = CreateFont( nHeight,
									  0,
									  0,
									  0,
									  FW_LIGHT,
									  0,
									  0,
									  0,
									  DEFAULT_CHARSET,
									  OUT_DEFAULT_PRECIS,
									  CLIP_DEFAULT_PRECIS,
									  DEFAULT_QUALITY,
									  FF_MODERN | FIXED_PITCH,
									  "Courier New" );

	ReleaseDC( s_wcd.hWnd, hDC );

	//
	// create the input line
	//
	s_wcd.hwndInputLine = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | 
												ES_LEFT | ES_AUTOHSCROLL,
												6, 400, 528, 20,
												s_wcd.hWnd, 
												( HMENU ) INPUT_ID,	// child window ID
												g_wv.hInstance, NULL );

	//
	// create the buttons
	//
	s_wcd.hwndButtonCopy = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												5, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) COPY_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonCopy, WM_SETTEXT, 0, ( LPARAM ) "copy" );

	s_wcd.hwndButtonClear = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												82, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) CLEAR_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonClear, WM_SETTEXT, 0, ( LPARAM ) "clear" );

	s_wcd.hwndButtonQuit = CreateWindow( "button", NULL, BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
												462, 425, 72, 24,
												s_wcd.hWnd, 
												( HMENU ) QUIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndButtonQuit, WM_SETTEXT, 0, ( LPARAM ) "quit" );


	//
	// create the scrollbuffer
	//
	s_wcd.hwndBuffer = CreateWindow( "edit", NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_BORDER | 
												ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
												6, 40, 526, 354,
												s_wcd.hWnd, 
												( HMENU ) EDIT_ID,	// child window ID
												g_wv.hInstance, NULL );
	SendMessage( s_wcd.hwndBuffer, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	s_wcd.SysInputLineWndProc = ( WNDPROC ) SetWindowLong( s_wcd.hwndInputLine, GWL_WNDPROC, ( long ) InputLineWndProc );
	SendMessage( s_wcd.hwndInputLine, WM_SETFONT, ( WPARAM ) s_wcd.hfBufferFont, 0 );

	ShowWindow( s_wcd.hWnd, SW_SHOWDEFAULT);
	UpdateWindow( s_wcd.hWnd );
	SetForegroundWindow( s_wcd.hWnd );
	SetFocus( s_wcd.hwndInputLine );

	s_wcd.visLevel = 1;
}
// ----------------------------------------------------------------------
//  Windows proc for the one and only window in this app.
//
// ----------------------------------------------------------------------
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HBRUSH   hbrLit = NULL;
    static HBRUSH   hbrUnlit = NULL;
    static HFONT    hFont = NULL;
    static UINT_PTR nTimerId = 101;

    switch (message)
    {
        case WM_CREATE:
        {
            // Make BLACK the transparency color
            SetLayeredWindowAttributes(hWnd, RGB(0,0,0), 0, LWA_COLORKEY);

            // Initialize the DPI scalar.
            InitializeDPIScale(hWnd);

            // Create brushes and font that will be used in WM_PAINT
            hbrLit = CreateSolidBrush(RGB(0,128,255));
            hbrUnlit = CreateSolidBrush(RGB(0,64,128));
            hFont = CreateFont(DPIScale(64), 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, 0, 0, 0, 0, 0, L"Segoe UI");

            // Position at the center of the primary monitor
            POINT const ptZeroZero = {};
            HMONITOR hMonitor = MonitorFromPoint(ptZeroZero, MONITOR_DEFAULTTOPRIMARY);
            MONITORINFO mi = {sizeof(mi)};
            GetMonitorInfo(hMonitor, &mi);

            SIZE const size = { g_currentVolume.cSteps * DPIScale(10), DPIScale(60) };

            POINT const pt = 
            {
                mi.rcMonitor.left + (mi.rcMonitor.left + mi.rcMonitor.right - size.cx) / 2, 
                mi.rcMonitor.top + (mi.rcMonitor.top + mi.rcMonitor.bottom - size.cy) / 2
            };

            SetWindowPos(hWnd, HWND_TOPMOST, pt.x, pt.y, size.cx, size.cy, SWP_SHOWWINDOW);

            break;
        }

        case WM_DESTROY:
        {
            DeleteObject(hbrLit);
            DeleteObject(hbrUnlit);
            DeleteObject(hFont);

            PostQuitMessage(0);
            return 0;
        }

        case WM_ERASEBKGND:
        {
            // Don't do any erasing here.  It's done in WM_PAINT to avoid flicker.
            return 1;
        }

        case WM_VOLUMECHANGE:
        {
            // get the new volume level
            g_pVolumeMonitor->GetLevelInfo(&g_currentVolume);

            // make window visible for 2 seconds
            ShowWindow(hWnd, SW_SHOW);
            InvalidateRect(hWnd, NULL, TRUE);

            nTimerId = SetTimer(hWnd, 101, 2000, NULL);

            return 0;
        }

        case WM_ENDPOINTCHANGE:
        {
            g_pVolumeMonitor->ChangeEndpoint();
            return 0;
        }

        case WM_TIMER:
        {
            // make the window go away
            ShowWindow(hWnd, SW_HIDE);
            KillTimer(hWnd, nTimerId);

            return 0;
        }

        case WM_PAINT:
        {
            PAINTSTRUCT     ps;
            HPAINTBUFFER    hBufferedPaint = NULL;
            RECT            rc;

            GetClientRect(hWnd, &rc);
            HDC hdc = BeginPaint(hWnd, &ps);

            if (g_bDblBuffered)
            {
                // Get doublebuffered DC
                HDC hdcMem;
                hBufferedPaint = BeginBufferedPaint(hdc, &rc, BPBF_COMPOSITED, NULL, &hdcMem);
                if (hBufferedPaint)
                {
                    hdc = hdcMem;
                }
            }

            // black background (transparency color)
            FillRect(hdc, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));

            // Draw LEDs
            for (UINT i = 0; i < (g_currentVolume.cSteps-1); i++)
            {
                RECT const rcLed = { DPIScale(i * 10), DPIScale(10), DPIScale(i * 10 + 8), rc.bottom-DPIScale(15) };

                if ((i < g_currentVolume.nStep) && (!g_currentVolume.bMuted))
                    FillRect(hdc, &rcLed, hbrLit);
                else
                    FillRect(hdc, &rcLed, hbrUnlit);
            }

            if (g_currentVolume.bMuted)
            {
                HGDIOBJ hof = SelectObject(hdc, hFont);
                SetBkMode(hdc, TRANSPARENT);
                SetTextColor(hdc, RGB(255, 64, 64));
                RECT rcText = rc;
                rcText.bottom -= DPIScale(11);
                DrawText(hdc, L"MUTED", -1, &rcText, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
                SelectObject(hdc, hof);
            }

            if (hBufferedPaint)
            {
                // end painting
                BufferedPaintMakeOpaque(hBufferedPaint, NULL);
                EndBufferedPaint(hBufferedPaint, TRUE);
            }

            EndPaint(hWnd, &ps);
            return 0;
        }
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
Exemple #28
0
BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
  static int ids[]={IDC_INFO,IDC_NSISICON,IDC_SZIPFRAME,IDC_BROWSE,IDC_ZIPFILE,IDC_ZIPINFO_SUMMARY,IDC_ZIPINFO_FILES,IDC_OFRAME,IDC_INAMEST,
                        IDC_INSTNAME,IDC_INSTPATH,IDC_OEFST,IDC_OUTFILE,IDC_BROWSE2,IDC_COMPRESSOR,IDC_ZLIB,IDC_BZIP2,IDC_LZMA,IDC_SOLID,IDC_INTERFACE,IDC_MODERNUI,IDC_CLASSICUI};
  static HICON hIcon;
  static HFONT hFont;
  if (uMsg == WM_DESTROY) { if (hIcon) DeleteObject(hIcon); hIcon=0; if (hFont) DeleteObject(hFont); hFont=0; }
  switch (uMsg)
  {
    case WM_INITDIALOG:
      g_hwnd=hwndDlg;
      CheckDlgButton(hwndDlg,IDC_LZMA,BST_CHECKED);
      CheckDlgButton(hwndDlg,IDC_MODERNUI,BST_CHECKED);
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_poi);
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$TEMP"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$SYSDIR"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$WINDIR"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$DESKTOP"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$DESKTOP\\YourNameHere"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$PROGRAMFILES\\YourNameHere"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$STARTMENU"));
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)_T("$SMPROGRAMS"));

      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp);
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_plugins);
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_vis);
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_dsp);
      SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_skins);

      SetDlgItemText(hwndDlg,IDC_INSTPATH,gp_poi);

      hIcon=LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON1));
      SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);

      hFont=CreateFont(15,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,
              OUT_CHARACTER_PRECIS,
              CLIP_DEFAULT_PRECIS,
              DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,_T("Courier New"));
      SendDlgItemMessage(hwndDlg,IDC_OUTPUTTEXT,WM_SETFONT,(WPARAM)hFont,0);

      DragAcceptFiles(hwndDlg,TRUE);
    return 1;
    case WM_CLOSE:
      if (!g_hThread)
      {
        tempzip_cleanup(hwndDlg,0);
        EndDialog(hwndDlg,1);
      }
    break;
    case WM_USER+1203:

      if (g_hThread)
      {
        if (!lParam) ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_SHOWNA);
        CloseHandle(g_hThread);
        g_hThread=0;
      }
      made=1;
      ShowWindow(GetDlgItem(hwndDlg,IDC_BACK),SW_SHOWNA);
      EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
      if (nsifilename[0]) DeleteFile(nsifilename);
      nsifilename[0]=0;
    break;
    case WM_DROPFILES:
    {
      TCHAR dropped_file[MAX_PATH]=_T("");
      if (DragQueryFile((HDROP)wParam,(UINT)-1,NULL,0)==1)
      {
        DragQueryFile((HDROP)wParam,0,dropped_file,MAX_PATH);
        if (lstrlen(dropped_file)>0)
        {
          SetZip(hwndDlg,dropped_file);
        }
      }
      else
      {
        MessageBox(hwndDlg,_T("Dropping more than one zip file at a time is not supported"),g_errcaption,MB_OK|MB_ICONSTOP);
      }
      DragFinish((HDROP)wParam);
      return TRUE;
    }
    case WM_COMMAND:
      switch (LOWORD(wParam))
      {
        case IDC_BROWSE:
          if (!g_extracting) {
            OPENFILENAME l={sizeof(l),};
            TCHAR buf[1024];
            l.hwndOwner = hwndDlg;
            l.lpstrFilter = _T("ZIP Files\0*.zip\0All Files\0*.*\0");
            l.lpstrFile = buf;
            l.nMaxFile = 1023;
            l.lpstrTitle = _T("Open ZIP File");
            l.lpstrDefExt = _T("zip");
            l.lpstrInitialDir = NULL;
            l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST;
            buf[0]=0;
            if (GetOpenFileName(&l))
            {
              SetZip(hwndDlg,buf);
            }
          }
        break;
        case IDC_BROWSE2:
          {
            OPENFILENAME l={sizeof(l),};
            TCHAR buf[1024];
            l.hwndOwner = hwndDlg;
            l.lpstrFilter = _T("Executables\0*.exe\0All Files\0*.*\0");
            l.lpstrFile = buf;
            l.nMaxFile = 1023;
            l.lpstrTitle = _T("Select Output EXE File");
            l.lpstrDefExt = _T("exe");
            l.lpstrInitialDir = NULL;
            l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER;
            GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
            if (GetSaveFileName(&l))
            {
              SetDlgItemText(hwndDlg,IDC_OUTFILE,buf);
            }
          }
        break;
        case IDC_BACK:
          if (!g_hThread)
          {
            made=0;
            ShowWindow(GetDlgItem(hwndDlg,IDC_BACK),SW_HIDE);
            ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_HIDE);
            ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_HIDE);
            {
              for (size_t x = 0; x < COUNTOF(ids); x ++)
                ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_SHOWNA);
              SetDlgItemText(hwndDlg,IDOK,_T("&Generate"));
              EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
            }
          }
        break;
        case IDC_TEST:
          if (!g_hThread) {
            TCHAR buf[1024];
            GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,COUNTOF(buf));
            ShellExecute(hwndDlg,_T("open"),buf,_T(""),_T(""),SW_SHOW);
          }
        break;
        case IDOK:
          if (!g_hThread)
          {
            if (!made)
            {
              if (IsDlgButtonChecked(hwndDlg,IDC_ZLIB))
                g_compressor = 1;
              if (IsDlgButtonChecked(hwndDlg,IDC_BZIP2))
                g_compressor = 2;
              if (IsDlgButtonChecked(hwndDlg,IDC_LZMA))
                g_compressor = 3;
              if (IsDlgButtonChecked(hwndDlg,IDC_SOLID))
                g_compressor_solid = 1;
              else
                g_compressor_solid = 0;
              g_mui=!IsDlgButtonChecked(hwndDlg,IDC_CLASSICUI);
              SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, _T(""));
              for (size_t x = 0; x < COUNTOF(ids); x ++)
                ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE);
              ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_SHOWNA);
              SetDlgItemText(hwndDlg,IDOK,_T("&Close"));
              EnableWindow(GetDlgItem(hwndDlg,IDOK),0);

              makeEXE(hwndDlg);
            }
            else
            {
              tempzip_cleanup(hwndDlg,0);
              EndDialog(hwndDlg,0);
            }
          }
        break;
      }
    break;
  }
  return 0;
}
//-----------------------------------------------------------------------------
// Entry point into the program.
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, INT nCmdShow)
{
    Instance = hInstance;

    InitCommonControls();

    // A monospaced font
    FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0,
        FW_REGULAR, FALSE,
        FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console");
    if(!FixedFont)
        FixedFont = (HFONT)GetStockObject(SYSTEM_FONT);

    // Create the root windows: one for control, with text, and one for
    // the graphics
    CreateMainWindows();

    ThawWindowPos(TextWnd);
    ThawWindowPos(GraphicsWnd);

    ShowWindow(TextWnd, SW_SHOWNOACTIVATE);
    ShowWindow(GraphicsWnd, SW_SHOW);
   
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT); 
    SwapBuffers(GetDC(GraphicsWnd));
    glClearColor(0, 0, 0, 1);
    glClear(GL_COLOR_BUFFER_BIT); 
    SwapBuffers(GetDC(GraphicsWnd));

    // Create the heaps for all dynamic memory (AllocTemporary, MemAlloc)
    InitHeaps();

    // A filename may have been specified on the command line; if so, then
    // strip any quotation marks, and make it absolute.
    char file[MAX_PATH] = "";
    if(strlen(lpCmdLine)+1 < MAX_PATH) {
        char *s = lpCmdLine;
        while(*s == ' ' || *s == '"') s++;
        strcpy(file, s);
        s = strrchr(file, '"');
        if(s) *s = '\0';
    }
    if(*file != '\0') {
        GetAbsoluteFilename(file);
    }

    // Initialize the SpaceBall, if present. Test if the driver is running
    // first, to avoid a long timeout if it's not.
    HWND swdc = FindWindow("SpaceWare Driver Class", NULL);
    if(swdc != NULL) {
        SiOpenData sod;
        SiInitialize();
        SiOpenWinInit(&sod, GraphicsWnd);
        SpaceNavigator =
            SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod);
        SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS);
    }
    
    // Call in to the platform-independent code, and let them do their init
    SS.Init(file);

    // And now it's the message loop. All calls in to the rest of the code
    // will be from the wndprocs.
    MSG msg;
    DWORD ret;
    while(ret = GetMessage(&msg, NULL, 0, 0)) {
        // Is it a message from the six degree of freedom input device?
        if(ProcessSpaceNavigatorMsg(&msg)) goto done;

        // A message from the keyboard, which should be processed as a keyboard
        // accelerator?
        if(msg.message == WM_KEYDOWN) {
            if(ProcessKeyDown(msg.wParam)) goto done;
        }
        if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) {
            // If the user presses the Alt key when the text window has focus,
            // then that should probably go to the graphics window instead.
            SetForegroundWindow(GraphicsWnd);
        }

        // None of the above; so just a normal message to process.
        TranslateMessage(&msg);
        DispatchMessage(&msg);
done:
        SS.DoLater();
    }

    if(swdc != NULL) {
        if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator);
        SiTerminate();
    }

    // Write everything back to the registry
    FreezeWindowPos(TextWnd);
    FreezeWindowPos(GraphicsWnd);
    return 0;
}
Exemple #30
0
BOOL CALLBACK settings_ServerTab_Callback( HWND hDlg, UINT Message, WPARAM wParam, LPARAM lParam )
{
	switch ( Message )
	{
	case WM_INITDIALOG:

		g_hDlg_ServerTab = hDlg;

		// Enable tab gradients on XP and later.
		if ( pEnableThemeDialogTexture != NULL )
			pEnableThemeDialogTexture ( hDlg, ETDT_ENABLETAB );

		// Limit the input length for the text boxes.
		SendDlgItemMessage( hDlg, IDC_SERVERNAME, EM_SETLIMITTEXT, 96, 0 );
		SendDlgItemMessage( hDlg, IDC_WADURL, EM_SETLIMITTEXT, 96, 0 );
		SendDlgItemMessage( hDlg, IDC_EMAIL, EM_SETLIMITTEXT, 96, 0 );
		
		// Initialize all the fields.		
		SetDlgItemText( hDlg, IDC_SERVERNAME, sv_hostname.GetGenericRep( CVAR_String ).String );
		SetDlgItemText( hDlg, IDC_EMAIL, sv_hostemail.GetGenericRep( CVAR_String ).String );
		SetDlgItemText( hDlg, IDC_WADURL, sv_website.GetGenericRep( CVAR_String ).String );
		SendDlgItemMessage( hDlg, IDC_UPDATEMASTER, BM_SETCHECK, ( sv_updatemaster ? BST_CHECKED : BST_UNCHECKED ), 0 );
		SendDlgItemMessage( hDlg, IDC_BROADCAST, BM_SETCHECK, ( sv_broadcast ? BST_CHECKED : BST_UNCHECKED ), 0 );
		g_fsMOTD = sv_motd.GetGenericRep( CVAR_String ).String;

		// PWADs.		
		SendMessage( GetDlgItem( hDlg, IDC_PWADS ), WM_SETFONT, (WPARAM) CreateFont( 12, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, 0, "Tahoma" ), (LPARAM) 1 );
		{
			char		szString[256];
			
			int iNumChars = 0;
			sprintf( szString, "PWADs:" );
			for( std::list<FString>::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end(); ++i )
			{
				iNumChars += i->Len( );
				if ( iNumChars > 50 - 3 ) // Determined by width of label
				{
					sprintf( szString + strlen ( szString ), "...", *i->GetChars( ));
					break;
				}
				else
					sprintf( szString + strlen ( szString ), " %s", *i );
			}

			g_ulNumPWADs = NETWORK_GetPWADList( )->size( );
			if ( g_ulNumPWADs == 0 )
			{
				ShowWindow( GetDlgItem( hDlg, IDC_WADURL ), SW_HIDE );
				ShowWindow( GetDlgItem( hDlg, IDC_WADURLLABEL ), SW_HIDE );
				ShowWindow( GetDlgItem( hDlg, IDC_PWADS ), SW_HIDE );
				ShowWindow( GetDlgItem( hDlg, IDC_PWADGROUP ), SW_HIDE );
			}
			else
				SetDlgItemText( hDlg, IDC_PWADS, szString );
		}
		break;
	case WM_COMMAND:

		if ( LOWORD( wParam ) == IDC_STARTUPMESSAGE )
			DialogBox( g_hInst, MAKEINTRESOURCE( IDD_EDITMOTD ), hDlg, settings_ServerTab_MOTDCallback );
		break;
	}

	return FALSE;
}