Пример #1
0
INT_PTR CWin32InputBox::InputBoxEx(WIN32INPUTBOX_PARAM *param)
{
  // Check mandatory parameters
  if (param->szResult == 0)
  {
    ::SetLastError(ERROR_INVALID_PARAMETER);
    return 0;
  }

  LPDLGTEMPLATE dlgTemplate;

  if (param->DlgTemplateName != 0)
  {
    HMODULE hModule = (HMODULE)param->hInstance;
#ifdef __MINGW32__
    HRSRC rcDlg = ::FindResource(hModule, (LPWSTR)(ULONG_PTR)(size_t)(param->DlgTemplateName), RT_DIALOG);
#else
    HRSRC rcDlg = ::FindResource(hModule, MAKEINTRESOURCE(param->DlgTemplateName), RT_DIALOG);
#endif
    if (rcDlg == NULL)
      return 0;

    HGLOBAL hglobalDlg = ::LoadResource(hModule, rcDlg);
    if (hglobalDlg == NULL)
      return 0;

    dlgTemplate = (LPDLGTEMPLATE) hglobalDlg;
  }
  else if (param->DlgTemplateData != 0)
  {
    dlgTemplate = (LPDLGTEMPLATE) param->DlgTemplateData;
  }

  MSDN_DLGTEMPLATEEX *dlgTemplateEx = 
    IsDlgTemplateExtended((LPDLGTEMPLATE) dlgTemplate) ? (MSDN_DLGTEMPLATEEX *) dlgTemplate : 0;

  if (dlgTemplateEx != 0)
  {
    dlgTemplateEx->exStyle |= param->dwExStylesPlus;
    dlgTemplateEx->style   |= param->dwStylesPlus;
    dlgTemplateEx->exStyle &= param->dwExStylesMinus;
    dlgTemplateEx->style   &= param->dwStylesMinus;

    if (param->bCenter)
      dlgTemplateEx->style |= DS_CENTER;

    if (param->xPos != -1)
      dlgTemplateEx->x = param->xPos;
    if (param->yPos != -1)
      dlgTemplateEx->y = param->yPos;
  }
  else
  {
    dlgTemplate->dwExtendedStyle  |= param->dwExStylesPlus;
    dlgTemplate->style            |= param->dwStylesPlus;
    dlgTemplate->dwExtendedStyle  &= param->dwExStylesMinus;
    dlgTemplate->style            &= param->dwStylesMinus;

    if (param->bCenter)
      dlgTemplate->style |= DS_CENTER;

    if (param->xPos != -1)
      dlgTemplate->x = param->xPos;

    if (param->yPos != -1)
      dlgTemplate->y = param->yPos;
  }

  CWin32InputBox inputbox(param);

  // Resize dialog and SHOW or HIDE multiline
  INT_PTR r = ::DialogBoxIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)&inputbox);

  return r;
}
Пример #2
0
INT_PTR CWin32InputBox::InputBoxEx(WIN32INPUTBOX_PARAM *param,
	cocos2d::ui::EditBox::KeyboardReturnType eReturnType,
	cocos2d::ui::EditBox::InputMode eInputMode,
	cocos2d::ui::EditBox::InputFlag eInputFlag,
	const std::function<void (const char *)> &onTextChange,
	const std::function<void (INT_PTR)> &onClose)
{
	// Check mandatory parameters
	if (param->pstrResult == nullptr)
	{
		::SetLastError(ERROR_INVALID_PARAMETER);
		return 0;
	}

	LPDLGTEMPLATE dlgTemplate;

	if (param->DlgTemplateName != 0)
	{
		HMODULE hModule = (HMODULE)param->hInstance;
#ifdef __MINGW32__
		HRSRC rcDlg = ::FindResource(hModule, (LPWSTR)(ULONG_PTR)(size_t)(param->DlgTemplateName), RT_DIALOG);
#else
		HRSRC rcDlg = ::FindResource(hModule, MAKEINTRESOURCE(param->DlgTemplateName), RT_DIALOG);
#endif
		if (rcDlg == nullptr)
			return 0;

		HGLOBAL hglobalDlg = ::LoadResource(hModule, rcDlg);
		if (hglobalDlg == nullptr)
			return 0;

		dlgTemplate = (LPDLGTEMPLATE)hglobalDlg;
	}
	else if (param->DlgTemplateData != 0)
	{
		dlgTemplate = (LPDLGTEMPLATE)param->DlgTemplateData;
	}

	MSDN_DLGTEMPLATEEX *dlgTemplateEx =
		IsDlgTemplateExtended((LPDLGTEMPLATE)dlgTemplate) ? (MSDN_DLGTEMPLATEEX *)dlgTemplate : 0;

	if (dlgTemplateEx != 0)
	{
		dlgTemplateEx->exStyle |= param->dwExStylesPlus;
		dlgTemplateEx->style |= param->dwStylesPlus;
		dlgTemplateEx->exStyle &= param->dwExStylesMinus;
		dlgTemplateEx->style &= param->dwStylesMinus;

		if (param->bCenter)
			dlgTemplateEx->style |= DS_CENTER;

		if (param->xPos != -1)
			dlgTemplateEx->x = param->xPos;
		if (param->yPos != -1)
			dlgTemplateEx->y = param->yPos;
	}
	else
	{
		dlgTemplate->dwExtendedStyle |= param->dwExStylesPlus;
		dlgTemplate->style |= param->dwStylesPlus;
		dlgTemplate->dwExtendedStyle &= param->dwExStylesMinus;
		dlgTemplate->style &= param->dwStylesMinus;

		if (param->bCenter)
			dlgTemplate->style |= DS_CENTER;

		if (param->xPos != -1)
			dlgTemplate->x = param->xPos;

		if (param->yPos != -1)
			dlgTemplate->y = param->yPos;
	}

	CCASSERT(s_win32InputBox == nullptr, "Only one instance of Win32InputBox allowed");

	s_win32InputBox = new (std::nothrow) CWin32InputBox(param);
	s_win32InputBox->_returnType = eReturnType;
	s_win32InputBox->_inputMode = eInputMode;
	s_win32InputBox->_inputFlag = eInputFlag;
	s_win32InputBox->_onTextChange = onTextChange;
	s_win32InputBox->_onClose = onClose;

	HWND hDlg = ::CreateDialogIndirectParam(param->hInstance, dlgTemplate, param->hwndOwner, (DLGPROC)DlgProc, (LPARAM)s_win32InputBox);
	::ShowWindow(hDlg, SW_SHOW);
	::EnableWindow(param->hwndOwner, FALSE);

	return TRUE;
}