⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialogs.cxx

📁 windows mobile phone source code
💻 CXX
📖 第 1 页 / 共 3 页
字号:
typedef UINT (CALLBACK * LPPRINTHOOKPROC)(HWND, UINT, WPARAM, LPARAM);
#endif

void PPrintDialog::Construct()
{
  memset(&printDlgInfo, 0, sizeof(printDlgInfo));
  printDlgInfo.hInstance = owner->GetInstance();
  printDlgInfo.lStructSize = sizeof(printDlgInfo);
  printDlgInfo.hwndOwner = GetParent()->GetHWND();
  printDlgInfo.lpfnPrintHook =
         (LPPRINTHOOKPROC)owner->GetWndProcPtr(PApplication::PrintDlgProcType);
  printDlgInfo.lCustData = (DWORD)this;
  printDlgInfo.Flags = PD_ENABLEPRINTHOOK;
  printDlgInfo.hDevMode = printInfo.GetHDEVMODE();
  printDlgInfo.hDevNames = printInfo.GetDevNames();

  if (printInfo.GetStartPage() == 0)
    printDlgInfo.Flags |= PD_NOPAGENUMS;
  else {
    printDlgInfo.nFromPage = (WORD)printInfo.GetStartPage();
    printDlgInfo.nToPage = (WORD)printInfo.GetEndPage();
  }

  switch (printInfo.GetSelectionOnly()) {
    case PPrintInfo::NoSelectionOnly :
      printDlgInfo.Flags |= PD_NOSELECTION;
      break;
    case PPrintInfo::SelectionOnlyOn :
      printDlgInfo.Flags |= PD_SELECTION;
      break;
    default :
      break;
  }

  printDlgInfo.nCopies = (WORD)printInfo.GetCopies();
}


PPrintDialog::~PPrintDialog()
{
  if (_hWnd != P_DEAD_WINDOW)
    DestroyWindow(_hWnd);
  if (printDlgInfo.hDevMode != NULL)
    GlobalFree(printDlgInfo.hDevMode);
  if (printDlgInfo.hDevNames != NULL)
    GlobalFree(printDlgInfo.hDevNames);
  if (printDlgInfo.hDC != NULL)
    DeleteDC(printDlgInfo.hDC);
}


void PPrintDialog::SetTitle(const PString & title)
{
  if (_hWnd != NULL)
    PModalDialog::SetTitle(title);
  else
    dlgTitle = title;
}


int PPrintDialog::RunModal()
{
  if (PrintDlg(&printDlgInfo)) {
    runState = Ended;
    return TRUE;
  }

  DWORD err = CommDlgExtendedError();
#if defined(_WIN32)
  SetLastError(err);
#endif
  PAssertOS(err == 0);
  return FALSE;
}


void PPrintDialog::WndProc()
{
  switch (_msg->event) {
    case WM_INITDIALOG :
      if (!dlgTitle.IsEmpty())
        SetWindowText(_hWnd, dlgTitle);
      InitStandardDialog();
      return;

    case WM_COMMAND :
      switch (LOWORD(_msg->wParam)) {
        case IDOK : {
          OnOk();
          return;
        }

        case IDCANCEL :
          OnCancel();
          return;
      }
  }
  PModalDialog::WndProc();
}


void PPrintDialog::OnOk()
{
  printInfo.SetFromPrintDlg(printDlgInfo);
  DefWndProc();
}


void PPrintDialog::OnCancel()
{
  DefWndProc();
}


void PPrintDialog::CreateHWND()
{
  PAssertAlways("Illegal operation on Print Dialog");
}


///////////////////////////////////////////////////////////////////////////////
// PPrinterSetupDialog

void PPrinterSetupDialog::Construct()
{
  printDlgInfo.Flags |= PD_PRINTSETUP;
  if (pResourceID != PSTD_ID_DIALOG_PRINTER_SETUP) {
    printDlgInfo.Flags |= PD_ENABLEPRINTTEMPLATE;
    printDlgInfo.lpSetupTemplateName = MAKEINTRESOURCE(pResourceID);
  }
}


///////////////////////////////////////////////////////////////////////////////
// PPrintJobDialog

void PPrintJobDialog::Construct()
{
  if (pResourceID != PSTD_ID_DIALOG_PRINT_JOB) {
    printDlgInfo.Flags |= PD_ENABLEPRINTTEMPLATE;
    printDlgInfo.lpPrintTemplateName = MAKEINTRESOURCE(pResourceID);
  }
}


///////////////////////////////////////////////////////////////////////////////
// PFontDialog

#if !defined(_WIN32)
typedef UINT (CALLBACK * LPCFHOOKPROC)(HWND, UINT, WPARAM, LPARAM);
#endif

void PFontDialog::Construct(PRESOURCE_ID)
{
  memset(&fontDlgInfo, 0, sizeof(fontDlgInfo));
  fontDlgInfo.lStructSize = sizeof(fontDlgInfo);
  fontDlgInfo.hInstance = owner->GetInstance();
  fontDlgInfo.hwndOwner = GetParent()->GetHWND();
  fontDlgInfo.lpLogFont = &logFont;
  fontDlgInfo.lpfnHook =
             (LPCFHOOKPROC)owner->GetWndProcPtr(PApplication::FontDlgProcType);
  fontDlgInfo.lCustData = (DWORD)this;
  fontDlgInfo.Flags = CF_ANSIONLY|CF_EFFECTS|CF_INITTOLOGFONTSTRUCT|CF_ENABLEHOOK;
  if (printerCanvas == NULL)
    fontDlgInfo.Flags |= CF_SCREENFONTS;
  else {
    fontDlgInfo.Flags |= CF_PRINTERFONTS;
    fontDlgInfo.hDC = printerCanvas->GetHDC();
  }
  if (pResourceID != PSTD_ID_DIALOG_FONT) {
    fontDlgInfo.Flags |= CF_ENABLETEMPLATE;
    fontDlgInfo.lpTemplateName = MAKEINTRESOURCE(pResourceID);
  }

  SetDefaultFont(selectedFont);
}


PFontDialog::~PFontDialog()
{
  if (_hWnd != P_DEAD_WINDOW)
    DestroyWindow(_hWnd);
}


void PFontDialog::SetTitle(const PString & title)
{
  if (_hWnd != NULL)
    PModalDialog::SetTitle(title);
  else
    dlgTitle = title;
}


void PFontDialog::SetDefaultFont(const PFont & font)
{
  if (runState != Initialising)
    return;

  selectedFont = font;
  memset(&logFont, 0, sizeof(logFont));

  if (printerCanvas != NULL)
    logFont.lfHeight = printerCanvas->FromPointsY(font.GetSize());
  else {
    PDrawCanvas canvas(parent, TRUE);
    logFont.lfHeight = canvas.FromPointsY(font.GetSize());
  }
  logFont.lfWeight = font.IsBold() ? FW_BOLD : FW_NORMAL;
  logFont.lfItalic = (BYTE)font.IsItalic();
  logFont.lfUnderline = (BYTE)font.IsUnderlined();
  strncpy(logFont.lfFaceName, font.GetFacename(), LF_FACESIZE-1);
}


int PFontDialog::RunModal()
{
  if (ChooseFont(&fontDlgInfo)) {
    runState = Ended;
    return TRUE;
  }

  DWORD err = CommDlgExtendedError();
#if defined(_WIN32)
  SetLastError(err);
#endif
  PAssertOS(err == 0);
  return FALSE;
}


void PFontDialog::WndProc()
{
  switch (_msg->event) {
    case WM_INITDIALOG :
      if (!dlgTitle.IsEmpty())
        SetWindowText(_hWnd, dlgTitle);
      InitStandardDialog();
      return;

    case WM_COMMAND :
      switch (LOWORD(_msg->wParam)) {
        case IDOK : {
          SendMessage(_hWnd, WM_CHOOSEFONT_GETLOGFONT, 0, (DWORD)&logFont);
          PDIMENSION size = PABS(logFont.lfHeight);
          if (printerCanvas != NULL)
            size = printerCanvas->ToPointsY(size);
          else {
            PDrawCanvas canvas(parent, TRUE);
            size = canvas.ToPointsY(size);
          }
          WORD styles = PFont::Regular;
          if (logFont.lfWeight > FW_NORMAL)
            styles |= PFont::Bold;
          if (logFont.lfItalic)
            styles |= PFont::Italic;
          if (logFont.lfUnderline)
            styles |= PFont::Underline;
          selectedFont = PFont(logFont.lfFaceName, size, styles);
          OnOk();
          return;
        }

        case IDCANCEL :
          OnCancel();
          return;
      }
  }
  PModalDialog::WndProc();
}


void PFontDialog::OnOk()
{
  DefWndProc();
}


void PFontDialog::OnCancel()
{
  DefWndProc();
}


void PFontDialog::CreateHWND()
{
  PAssertAlways("Illegal operation on Print Dialog");
}


///////////////////////////////////////////////////////////////////////////////
// PColourDialog

#if !defined(_WIN32)
typedef UINT (CALLBACK * LPCCHOOKPROC)(HWND, UINT, WPARAM, LPARAM);
#endif

void PColourDialog::Construct(PRESOURCE_ID)
{
  PConfig cfg("CONTROL.INI", "Custom Colors");
  for (PINDEX i = 0; i < NumCustomColours; i++)
    customColours[i] = cfg.GetString(psprintf("Color%c", i+'A')).AsInteger(16);
  memset(&colourDlgInfo, 0, sizeof(colourDlgInfo));
  colourDlgInfo.lStructSize = sizeof(colourDlgInfo);
  colourDlgInfo.hInstance = (HWND)owner->GetInstance();
  colourDlgInfo.hwndOwner = GetParent()->GetHWND();
  colourDlgInfo.lpfnHook =
           (LPCCHOOKPROC)owner->GetWndProcPtr(PApplication::ColourDlgProcType);
  colourDlgInfo.rgbResult = colour.ToCOLORREF();
  colourDlgInfo.lpCustColors = customColours;
  colourDlgInfo.lCustData = (DWORD)this;
  colourDlgInfo.Flags = CC_RGBINIT|CC_ENABLEHOOK;
  if (pResourceID != PSTD_ID_DIALOG_COLOUR) {
    colourDlgInfo.Flags |= CC_ENABLETEMPLATE;
    colourDlgInfo.lpTemplateName = MAKEINTRESOURCE(pResourceID);
  }
}


PColourDialog::~PColourDialog()
{
  if (_hWnd != P_DEAD_WINDOW)
    DestroyWindow(_hWnd);
}


void PColourDialog::SetTitle(const PString & title)
{
  if (_hWnd != NULL)
    PModalDialog::SetTitle(title);
  else
    dlgTitle = title;
}


void PColourDialog::SetColour(const PColour & col)
{
  if (runState == Initialising)
    colour = col;
}


int PColourDialog::RunModal()
{
  if (ChooseColor(&colourDlgInfo)) {
    runState = Ended;
    colour.FromCOLORREF(colourDlgInfo.rgbResult);
    return TRUE;
  }

  DWORD err = CommDlgExtendedError();
#if defined(_WIN32)
  SetLastError(err);
#endif
  PAssertOS(err == 0);
  return FALSE;
}


void PColourDialog::WndProc()
{
  switch (_msg->event) {
    case WM_INITDIALOG :
      if (!dlgTitle.IsEmpty())
        SetWindowText(_hWnd, dlgTitle);
      InitStandardDialog();
      return;

    case WM_COMMAND :
      switch (LOWORD(_msg->wParam)) {
        case IDOK : {
          OnOk();
          return;
        }

        case IDCANCEL :
          OnCancel();
          return;
      }
  }
  PModalDialog::WndProc();
}


void PColourDialog::OnOk()
{
  DefWndProc();
}


void PColourDialog::OnCancel()
{
  DefWndProc();
}


void PColourDialog::CreateHWND()
{
  PAssertAlways("Illegal operation on Print Dialog");
}


///////////////////////////////////////////////////////////////////////////////
// PApplication

BOOL PApplication::DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg == WM_INITDIALOG)
    ShowWindow(hWnd, SW_HIDE);

  PInteractor * window = (PInteractor *)createdWindows.GetAt((HWNDKey)hWnd);
  if (window == NULL)
    return FALSE;

  PInteractor::_WindowsMessage message;
  message.event = msg;
  message.wParam = wParam;
  message.lParam = lParam;
  message.lResult = 0;
  message.processed = TRUE;
  PInteractor::_WindowsMessage * oldMessage = window->_msg;
  window->_msg = &message;
  window->WndProc();
  window->_msg = oldMessage;
  if (message.processed) {
    switch (msg) {
#ifdef WIN32
      case WM_CTLCOLORBTN :
      case WM_CTLCOLORDLG :
      case WM_CTLCOLOREDIT :
      case WM_CTLCOLORLISTBOX :
      case WM_CTLCOLORMSGBOX :
      case WM_CTLCOLORSCROLLBAR :
      case WM_CTLCOLORSTATIC :
#else
      case WM_CTLCOLOR :
#endif
      case WM_COMPAREITEM :
      case WM_VKEYTOITEM :
      case WM_CHARTOITEM :
      case WM_QUERYDRAGICON :
        return (UINT)message.lResult;
    }
    SetWindowLong(hWnd, DWL_MSGRESULT, message.lResult);
  }
  return message.processed;
}


BOOL PApplication::FileDlgProc(HWND hWnd,
                                        UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg == WM_INITDIALOG) {
    PInteractor * window = (PInteractor *)((LPOPENFILENAME)lParam)->lCustData;
    PAssert(window != NULL, PLogicError);
    AddWindowHandle(hWnd, window);
    window->_hWnd = hWnd;
  }
  return DlgProc(hWnd, msg, wParam, lParam);
}


BOOL PApplication::PrintDlgProc(HWND hWnd,
                                        UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg == WM_INITDIALOG) {
    PInteractor * window = (PInteractor *)((LPPRINTDLG)lParam)->lCustData;
    PAssert(window != NULL, PLogicError);
    AddWindowHandle(hWnd, window);
    window->_hWnd = hWnd;
  }
  return DlgProc(hWnd, msg, wParam, lParam);
}


BOOL PApplication::FontDlgProc(HWND hWnd,
                                        UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg == WM_INITDIALOG) {
    PInteractor * window = (PInteractor *)((LPCHOOSEFONT)lParam)->lCustData;
    PAssert(window != NULL, PLogicError);
    AddWindowHandle(hWnd, window);
    window->_hWnd = hWnd;
  }
  return DlgProc(hWnd, msg, wParam, lParam);
}


BOOL PApplication::ColourDlgProc(HWND hWnd,
                                        UINT msg, WPARAM wParam, LPARAM lParam)
{
  if (msg == WM_INITDIALOG) {
    PInteractor * window = (PInteractor *)((LPCHOOSECOLOR)lParam)->lCustData;
    PAssert(window != NULL, PLogicError);
    AddWindowHandle(hWnd, window);
    window->_hWnd = hWnd;
  }
  return DlgProc(hWnd, msg, wParam, lParam);
}



// End Of File ///////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -