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

📄 popup.cpp

📁 funambol window mobile客户端源代码
💻 CPP
字号:
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */
//

#include "stdafx.h"
#include "Popup.h"



IMPLEMENT_DYNAMIC(Popup, CDialog)

Popup::Popup(CWnd* pParent /*=NULL*/)
	: CDialog(Popup::IDD, pParent)
{

}

Popup::~Popup()
{
}

void Popup::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

void Popup::drawPopup(){

    SetDlgItemText(IDC_POPUP_TEXT, msg);

    SetDlgItemText(IDOK, buttonText1);
    SetDlgItemText(IDCANCEL, buttonText2);
    SetDlgItemText(IDCANCEL2, buttonText3);

    double yy = GetSystemMetrics(SM_CYSCREEN);
    double xx = GetSystemMetrics(SM_CXSCREEN);

    //Setting up the new size of the Dialog
    int lengthPercentage = 50; //60% of the client length (Y)
    int widthPercentage  = 90; //90% of the client width (X)
    int messageLengthPercentage = lengthPercentage - 5;
    int buttonHighPosition = lengthPercentage + 5;
    
    if (yy == 240) { // for square screen
        lengthPercentage = 60;
        //buttonHighPosition = lengthPercentage;
    }    
    
    // settings the button size high
    int highPercentageButton  = 20;

    //Setting up the new size of the Dialog
    int y = (int)((yy/100)*lengthPercentage); //60% of the client length
    int x = (int)((xx/100)*widthPercentage); //90% of the client widht

    //setting up the position of the Dialog. It will be centered
    int dy = (int)((yy - y) /3);
    int dx = (int)((xx - x) /2);

    //Ok let's resize and move the Dialog
    SetWindowPos(GetActiveWindow(), dx, dy, x, y,SWP_SHOWWINDOW);

    // Now we resize the text box
    GetDlgItem(IDC_POPUP_TEXT)->SetWindowPos(GetActiveWindow(), 0, 0,
        ((int)(((double)x/100)*widthPercentage)), ((int)(((double)y/100) * messageLengthPercentage)), SWP_NOMOVE);

    GetDlgItem(IDC_POPUP_TEXT)->GetDC()->SetBkMode(TRANSPARENT);
    GetDlgItem(IDC_POPUP_TEXT)->Invalidate();

   //and now we resize the buttons and move them to fit the new size

    if (buttonText2.IsEmpty() && buttonText3.IsEmpty()){
        int bdimx = ((int)(((double)x/100)*50)); //the 50% of width is setted for the button
        int spacingbut = (x - (bdimx))/2;

        int startingButtonpos = (int)(((double)y/100)*buttonHighPosition); // 75% 
        int bdimy = (int)(((double)y/100)*highPercentageButton);
        GetDlgItem(IDOK)->SetWindowPos(GetActiveWindow(), spacingbut, startingButtonpos,
            bdimx, bdimy, SWP_SHOWWINDOW);

        GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
        GetDlgItem(IDCANCEL2)->ShowWindow(SW_HIDE);
    
    }else if (buttonText3.IsEmpty()){
        int bdimx = ((int)(((double)x/100)*80))/2; //the 80% of width is setted for the button
        int spacingbut = (x - (bdimx*2))/3;

        int startingButtonpos = (int)(((double)y/100)*buttonHighPosition);
        int bdimy = (int)(((double)y/100)*highPercentageButton);
        GetDlgItem(IDOK)->SetWindowPos(GetActiveWindow(), spacingbut, startingButtonpos,
            bdimx, bdimy, SWP_SHOWWINDOW);

        GetDlgItem(IDCANCEL)->SetWindowPos(GetActiveWindow(), (spacingbut*2)+ bdimx, startingButtonpos,
            bdimx, bdimy, SWP_SHOWWINDOW);

        GetDlgItem(IDCANCEL2)->ShowWindow(SW_HIDE);

    }else{
        int bdimx = ((int)(((double)x/100)*95))/3; //the 80% of width is setted for the button
        int spacingbut = (x - (bdimx*3))/4;

        int startingButtonpos = (int)(((double)y/100)*buttonHighPosition);
        int bdimy = (int)(((double)y/100)*highPercentageButton);

        //lets resize and move all the buttons

        GetDlgItem(IDOK)->SetWindowPos(GetActiveWindow(), spacingbut, startingButtonpos,
            bdimx, bdimy, SWP_SHOWWINDOW);

        GetDlgItem(IDCANCEL)->SetWindowPos(GetActiveWindow(), (spacingbut*2)+ bdimx, startingButtonpos,
            bdimx, bdimy, SWP_SHOWWINDOW);

        GetDlgItem(IDCANCEL2)->SetWindowPos(GetActiveWindow(), (spacingbut*3)+ (bdimx*2), startingButtonpos,
            bdimx, bdimy, SWP_SHOWWINDOW);
    }
    
    ::SetFocus(GetDlgItem(IDOK)->GetSafeHwnd());

}


BOOL Popup::OnInitDialog(){

    SetWindowText(title);

    CDialog::OnInitDialog();
    
    //drawPopup();

    return TRUE;
}


BEGIN_MESSAGE_MAP(Popup, CDialog)
    //ON_WM_CTLCOLOR()
    ON_BN_CLICKED(IDOK, &Popup::OnBnClickedOk)
    ON_BN_CLICKED(IDCANCEL, &Popup::OnBnClickedCancel)
    ON_BN_CLICKED(IDCANCEL2, &Popup::OnBnClickedCancel2)
    //ON_WM_ACTIVATE()
    ON_WM_PAINT()
#if defined(_DEVICE_RESOLUTION_AWARE)
    ON_WM_SIZE()
#endif
END_MESSAGE_MAP()



void Popup::OnBnClickedOk()
{
    ret = 0;
    this->EndDialog(IDOK);
}

void Popup::OnBnClickedCancel()
{
    ret = 1;
    this->EndDialog(IDOK);
}

void Popup::OnBnClickedCancel2()
{
    ret = 2;
    this->EndDialog(IDOK);
}

HBRUSH Popup::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if(pWnd->GetDlgCtrlID() == IDC_POPUP_TEXT) {
        hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
        pDC->SetBkMode(TRANSPARENT);
    }
    return hbr;
}
/*
void Popup::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) {

    CDialog::OnActivate(nState, pWndOther, bMinimized);
    this->drawPopup();
    Invalidate();

}
*/
void Popup::OnPaint() {

    CDialog::OnPaint();
    this->drawPopup();
}


void Popup::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
    int resId = IDD_UI_DIALOG;

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
    switch(DRA::GetDisplayMode())
    {
    case DRA::Landscape:
        resId = IDD_UI_DIALOG_WIDE;
        break;
    case DRA::Portrait:
        resId = IDD_UI_DIALOG; break;
    case DRA::Square:
        resId = IDD_UI_DIALOG_SQUARE; break;
    default:
        resId = IDD_UI_DIALOG; break;
    };
#endif

    DRA::RelayoutDialog( AfxGetInstanceHandle(), this->m_hWnd, MAKEINTRESOURCE(resId));    
    
}


int CMessageBox(CString msg, CString button1, CString button2, CString button3){
    
    Popup pop;
    pop.m_bFullScreen = 0;
    pop.setTitle(getLocalizationUtils()->getLocalizationString(IDS_FUNAMBOL_ALERT));
    pop.setMessage(msg);
    pop.setbutton1(button1);
    pop.setbutton2(button2);
    pop.setbutton3(button3);

    INT_PTR result = pop.DoModal();

    int ret = pop.getResult();

    return ret;


}
/*
Popup *pp = NULL;
int LoadIconModal(){
    SetCursor(LoadCursor(NULL, IDC_WAIT));    
    
    pp = new Popup();
    pp->m_bFullScreen = 0;
    INT_PTR result = pp->DoModal();
    return result;
}

void RemoveIconModal(){    
    SetCursor(LoadCursor(NULL, IDC_ARROW)); 
    if (pp) {
        pp->OnOK();
        delete pp;
    }
       
}
*/

⌨️ 快捷键说明

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