demosld.cpp

来自「winsail v2.0是用于DOS下的图形界面空间系统」· C++ 代码 · 共 132 行

CPP
132
字号
#include <Symbol.h>
#include <MyFrame.h>


void far ChangeSlider1_DemoSliderAndPorcess(CSliderCtrl* pSliderCtrl)
{
	CDialog* pDialog = (CDialog *)pSliderCtrl->GetParent();
    CLabel* pLabel1 = (CLabel *)pDialog->ObjectFromID(LABELBASE + 1 - 1);

    long dwMin, dwMax, dwPos;
    pSliderCtrl->GetRange(&dwMin, &dwMax);
    dwPos = pSliderCtrl->GetPos();

    char buf[256], buf2[20];
    sprintf(buf,"计算值:%ld-%s%%       ", dwPos,
		SetDisplayBufferDot(buf2, 100.0f *
			(dwPos - dwMin) / (dwMax - dwMin)));

    pLabel1->SetWindowText(buf);

    pLabel1->SetBackColorDisplay(TRUE);
    pLabel1->Show();


}

void far OnTime_DemoSliderAndProcess(CObject* pCurObj)
{
	CDialog* pDialog = (CDialog *)pCurObj;
    CProgressCtrl* pProgressCtrl1 = (CProgressCtrl *)
		pDialog->ObjectFromID(PROGRESSBASE + 1 - 1);
    CProgressCtrl* pProgressCtrl2 = (CProgressCtrl *)
		pDialog->ObjectFromID(PROGRESSBASE + 2 - 1);

    pDialog->SetTimeFc(NULL);
    pDialog->OnTime();
    pDialog->SetTimeFc(OnTime_DemoSliderAndProcess);
    //pDialog->OnTime();

    static WORD dwLoop = 0;
    if (((++dwLoop) % 10) != 0)
    {
		return;
    }
    long dwMin,dwMax,dwPos;

    pProgressCtrl2->GetRange(&dwMin, &dwMax);
    dwPos = pProgressCtrl2->GetPos();

    DWORD dwNewPos= (dwPos + 1 <= dwMax)?dwPos+1:dwMin;
    pProgressCtrl2->AddShow(dwNewPos);
}

void far DemoSliderAndProcess()
{
	//Create a Dialog On the Center of Desktop
	CDialog* pDialog = new CDialog;//分配实例
	pDialog->CreateWindow(0, 0, 429, 300, "滑块和进度条演示");//建立窗口
	pDialog->Center();//窗口对中

	//Register Callback Function for Window
	pDialog->SetTimeFc(OnTime_DemoSliderAndProcess);//注册定时器回调函数
	pDialog->SetDrawFc(NULL);//注册画图回调函数
	pDialog->SetHelpFc(NULL);//注册帮助回调函数
	pDialog->SetKeyboardFc(NULL);//注册虚拟键盘回调函数

	//Create Close's Button Control
	new CCloseButton(pDialog);//分配和建立关闭按钮

	//Create a Button Control
	CButton* pButton1 = new CButton(pDialog);
	pButton1->CreateObject(127, 205, 75, 24, "确定(\x3\E\x3)");
	pButton1->SetShortcutKey(VK_ALT_E);
	pButton1->SetFc(ClickEnterButton);
	pButton1->SetID(BUTTONBASE + 1 - 1);
        pButton1->SetDefaultFlags(TRUE);

	//Create a Button Control
	CButton* pButton2 = new CButton(pDialog);
	pButton2->CreateObject(271, 204, 75, 24, "取消(\x3\C\x3)");
	pButton2->SetShortcutKey(VK_ALT_C);
	pButton2->SetFc(ClickCancelButton);
	pButton2->SetID(BUTTONBASE + 2 - 1);

	//Create Slider Control
	CSliderCtrl* pSliderCtrl1 = new CSliderCtrl(pDialog);
	pSliderCtrl1->CreateObject(136, 101, 259, 24, NULL);
	pSliderCtrl1->SetID(SLIDERBASE + 1 - 1);
	pSliderCtrl1->SetHorz(TRUE);

	//Create Process Control
	CProgressCtrl* pProgressCtrl1 = new CProgressCtrl(pDialog);
	pProgressCtrl1->CreateObject(136, 141, 259, 24, NULL);
	pProgressCtrl1->SetID(PROGRESSBASE + 1 - 1);
	pProgressCtrl1->SetHorz(TRUE);

	//Create Process Control
	CProgressCtrl* pProgressCtrl2 = new CProgressCtrl(pDialog);
	pProgressCtrl2->CreateObject(22, 50, 24, 204, NULL);
	pProgressCtrl2->SetID(PROGRESSBASE + 2 - 1);
	pProgressCtrl2->SetHorz(FALSE);

	//Create Slider Control
	CSliderCtrl* pSliderCtrl2 = new CSliderCtrl(pDialog);
	pSliderCtrl2->CreateObject(69, 50, 24, 204, NULL);
	pSliderCtrl2->SetID(SLIDERBASE + 2 - 1);
	pSliderCtrl2->SetHorz(FALSE);

	//Create a Label Control
	CLabel* pLabel1 = new CLabel(pDialog);
	pLabel1->CreateObject(184, 74, 73, 12, "计算值:3000 0.0%%");
	pLabel1->SetID(LABELBASE + 1 - 1);


    pSliderCtrl1->SetRange(100,200);
    pSliderCtrl1->SetChangeSliderFc(ChangeSlider1_DemoSliderAndPorcess);

	//Show Window
	pDialog->ShowWindow();//显示窗口

	//go into Message Loop
	pDialog->DoModal();//进入窗口消息循环

	//Destroy Window 
	delete pDialog;//删除对话框


	return;

}

⌨️ 快捷键说明

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