建立如同Windows的桌面系统

窗口桌面类是CDesktop,一般为了模仿WINDOWS桌面,还需要有任务条,对于WinSail来说,可以用一个“普通按钮”、“状态条”函数、“工具条”来完成,下面的例子已经经过了完整的测试。

Sail3000演示程序的“Sail2000.Cpp”文件.

 

 控件函数”关联接口

        //包含头文件

        #include  <Symbol.h>

        #include  <MyFrame.h>

 

        //当单击Button1按钮时会调用ClickButton1函数

void far ClickButton1(CObject* pObject)

        {

                 //得到当前按钮的指针

                 CButton* pButton = (CButton *)pObject;

                 //得到父窗口的指针

CDialog* pDialog = (CDialog *)pObject->GetParent();

//得到按钮Button1的指针,假设Button1控件的ID号为1001

CButton* pButton1 = (CButton *)pDialog->ObjectFromID(1001);

//得到组合框ComboBox1的指针,假设ComboBox1控件的ID号为2001

CComboBox* pComboBox1 = (CcomboBox *)pDialog->ObjectFromID(2001);

 

//…

AfxMessageBox(“按钮演示”, “您单击了按钮Button1”);

        }

 

        //当组合框CombBox1选择某项时调用“EnterComboBox1”函数

void far EnterComboBox1(CComboBox* pComboBox, int nIndex)

{

        //得到父窗口的指针

CDialog* pDialog = (CDialog *)pComboBox->GetParent();

//得到按钮的指针,假设Button1控件的ID号为1001

CButton* pButton1 = (CButton *)pDialog->ObjectFromID(1001);

//得到组合框的指针,假设ComboBox1控件的ID号为2001

CComboBox* pComboBox1 = (CcomboBox *)pDialog->ObjectFromID(2001);

 

//…

char buf[256];

::sprintf (buf, “现在是选择了组框的第 %d项,第 %d 项”, nIndex, (int)pComboBox->GetIndex());

AfxMessageBox(“组合框演示”, buf);

        }

 

//建立窗口,在窗口中建立一个按钮,一个组合框,一个关闭按钮

void far VccFuntion()

{

CDialog* pDialog = new CDialog;//分配对话框实例

      pDialog->CreateWindow(0,0, 640, 480, “按钮、组合框、关闭按钮演示”);//建立按钮

      pDialog->Center(); //窗口居中

 

      new CCloseButton();//建立标题栏关闭按钮实例

 

CButton* pButton1 = new CButton(pDialog);//分配按钮

pButton1->CreateObject(10, 30, 100, 24, “确定”);//建立按钮

pButton1->SetID(1001);//设置按钮的ID号

pButton1->SetFc(ClickButton1); //按钮与“ClickButton1”函数关联

             

CComboBox* pComboBox1 = new CComboBox(pDialog); //分配组合框实例

              pComboBox1->CreateCombo (10, 60, 100, 24, NULL); //建立组合框

pComboBox1->SetID(2001);//设置给合框的ID号

pComboBox1->SetEnterFc(EnterComboBox1);//选择组合框的某项时与“EnterComboBox1”函数关联

 

        

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

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

 

              delete pDialog;//删除对话框

              return;

         }

 

建立标签,编辑框,组合框,按钮,复选框

extern int SystemFonSize;

void far MyInstance()

{

    

     CDialog *pDialog=new CDialog; //分配对话框实例

     pDialog->CreateWindow(100,100,270,210,"网络配置");//建立对话框

     pDialog->Center();//将对话框居中

 

     new CCloseButton(pDialog); //建立一个系统关闭按钮

    

     CLabel *pLabel1=new CLabel(pDialog); //分配标签实例

     CLabel *pLabel2=new CLabel(pDialog); //分配标签实例

     CLabel *pLabel3=new CLabel(pDialog); //分配标签实例

     CLabel *pLabel4=new CLabel(pDialog); //分配标签实例

 

     CComboBox *pComboBox1=new CComboBox(pDialog); //分配组合框实例

     CComboBox *pComboBox2=new CComboBox(pDialog); //分配组合框实例

     CRadio    *pRadio1   =new CRadio(pDialog); //分配按钮实例

     CEdit     *pEdit1    =new CEdit(pDialog); //分配编辑框实例

     CButton   *pButton1  =new CButton(pDialog); //分配按钮实例

     CButton   *pButton2  =new CButton(pDialog); //分配按钮实例

 

     pLabel1->CreateObject(005,30+(SystemFonSize+8)*0,130,SystemFonSize+6,"通讯口");//建立标签对象

     pLabel2->CreateObject(005,30+(SystemFonSize+8)*2,130,SystemFonSize+6,"波特率");//建立标签对象

     pLabel3->CreateObject(005,30+(SystemFonSize+8)*5,130,SystemFonSize+6,"本机端口");//建立标签对象

     pRadio1->CreateObject(005,30+(SystemFonSize+8)*4,130,SystemFonSize+8,"服务器/客户机");//建立单/复选按钮对象

     pComboBox1->CreateCombo(005,30+(SystemFonSize+8)*1,130,SystemFonSize+6,NULL); //建立组合框对象

     pComboBox2->CreateCombo(005,30+(SystemFonSize+8)*3,130,SystemFonSize+6,NULL); //建立组合框对象

     pEdit1->CreateObject(005,30+(SystemFonSize+8)*6,130,SystemFonSize+6,NULL); //建立编辑框对象

     pButton1->CreateObject(150,130+(SystemFonSize+25)*0,110,SystemFonSize+6,"确定(\x3\E\x3)"); //建立按钮对象

     pButton2->CreateObject(150,130+(SystemFonSize+25)*1,110,SystemFonSize+6,"取消(\x3\C\x3)"); //建立按钮对象

 

     pButton1->SetShortcutKey(VK_ALT_E); //设置按钮Button1的快捷键

     pButton2->SetShortcutKey(VK_ALT_C); //设置按钮Button2的快捷键

 

     pLabel4->CreateObject(165,40+(SystemFonSize+8)*0,120,SystemFonSize+6,NULL);//建立标签4对象并且其属性为图片

     pLabel4->SetBitmapFlags(TRUE);//说明标签显示的是图片

     pLabel4->SetBitmapFile("Bmp\\Computer.Bmp");//设置图片的文件名

     pLabel4->SetBackColorDisplay(FALSE);//不显示背景色

     pLabel4->SetBitmapColor(LIGHTGRAY);//设置图片背景色为LIGHTGRAY颜色

 

     //组合框1使用范例

     pComboBox1->SetCount(3); //组合框的选项个数

     pComboBox1->SetSel(0,"Com1");//组合框第0项的值为COM1

     pComboBox1->SetSel(1,"Com2");//组合框第1项的值为“COM2

     pComboBox1->SetSel(2,"Com3");//组合框第2项的值为“COM3

     pComboBox1->SetIndex(1); //组合框第“1”项作为当前项

 

     ////组合框2使用范例

     pComboBox2->SetCount(3); //组合框的选项个数

     pComboBox2->SetSel(0,"1200");//组合框第0项的值为“1200

     pComboBox2->SetSel(1,"2400");//组合框第1项的值为“2400

     pComboBox2->SetSel(2,"4800");//组合框第2项的值为“4800

     pComboBox2->SetIndex(0); //组合框第“0”项作为当前项

 

     //编辑框使用范例

     pEdit1->SetBuffer("3433"); //编辑框的内容

     pEdit1->SetNumberFlags(TRUE); //编辑框只能输入数值

     pEdit1->SetMaxCount(5);//编辑框最多只能输入5个字符

 

     //说明单/复选框是复选框而不是单选框

     pRadio1->SetBox(TRUE);

 

     pDialog->ShowWindow();//显示对话框

     pDialog->DoModal();//对话框进入消息循环

 

     //删除对话框实例

     DELETE(pDialog);

     return;

}

 

建立窗口菜单

//菜单函数一

Void far ClickMyMenu_1(CObject* pCurObj)

{

     AfxMessageBox(“调试”,“单击菜单1”,MB_OK);

}

//菜单函数二

Void far ClickMyMenu_2()

{

     AfxMessageBox(“调试”,“单击菜单2”,MB_OK);

}

//功能

Void far MenuInstance()

{

 

CWindow *pWindow = new Cwindow;//分配对话框实例

pWindow->CreateWindow(0,0,600,300,”窗口实例”); //建立一个600*300的分辨率的窗口

pWindow->Center();//将窗口居中

 

new CCloseButton(pWindow); //建立关闭按钮

new CMaxButton(pWindow); //建立最大化按钮

new CMinButton(pWindow); //建立最小化按钮

 

CMenu *pMenu=new CMenu(pWindow); //建立一个窗口主菜单

 

//建立二个弹出菜单

CBar   *pBar1=new CBar(pMenu);//弹出菜单1

CBar   *pBar2=new CBar(pMenu); //弹出菜单2

 

pMenu->AddItem(“文件”,pBar1,NULL); //“窗口菜单”增加“弹出菜单1”

pMenu->AddItem(“编辑”,pBar2,NULL); //窗口菜单增加弹出菜单2

 

pMenu->AddItem(“关闭”,NULL,( void far (*pFc)(CObject*))CloseWindow); // CloseWindow是内核API

pBar1->AddItem(“新建”,ClickMyMenu_1); //弹出菜单1增加一菜单条

pBar1->AddItem(“打开”,( void far (*pFc)(CObject*))ClickMyMenu_2); //弹出菜单1增加一菜单条

pBar1->AddItem(“关闭”, ( void far (*pFc)(CObject*))CloseWindow); //弹出菜单1增加一菜单条

 

pBar2->AddItem(“取消”,NULL); //弹出菜单2增加一菜单条

pBar2->AddItem(“拷贝”,NULL); //弹出菜单2增加一菜单条

pBar2->AddItem(“粘贴”,NULL); //弹出菜单2增加一菜单条

 

pWindow->ShowWindow();//显示窗口

pWindow->PurseWindow();//进入窗口消息循环

 

delete pWindow; //删除窗口对象

 

}

 

建立表格

float  fsAfxAdjust[100][4];

void far STATICBOX_SettingAdjust(CObject*)

{

     int nTop   =15   +23;

     int nBottom = nTop+(16+6)*5+50;

     DrawBoxCaption(330+130,nTop,470+130,nBottom,"警告");

     DrawBoxCaption(0,2,470+130,2+16+9,"");

}

class CSettingGrid:public CGrid

{

public:

     void UpdateData(DWORD nIndexH,DWORD nIndexV,BOOL bFlags=TRUE);

public:

     CSettingGrid(CObject *pParent);

};

 

CSettingGrid::CSettingGrid(CObject *pParent):CGrid(pParent)

{

}

void CSettingGrid::UpdateData(DWORD nIndexH,DWORD /*nIndexV*/,BOOL bFlags)

{

     if(bFlags) return;

     CDialog  *pDialog=(CDialog *)this->GetParent();

     CGrid    *pGrid  =(CGrid *)this;

     CLabel   *pLabel6=(CLabel *)pDialog->ObjectFromID(1001);

     int nPoint = (int)pGrid->GetItemPoint();

     if(nPoint != nIndexH) return;

 

     char buf[200];

     strcpy(buf,"                                                    ");

     pLabel6->SetWindowText(buf);

     pLabel6->Show();

 

     CRegister *pRegister=new CRegister("Sys\\Prompt.Sys");

     nPoint = nIndexH + 1;

     sprintf(buf,"Prompt%03d",nPoint);

     _fstrcpy(buf,pRegister->GetProfileString("AdJust",buf,"......"));

     pLabel6->SetWindowText(buf);

     pLabel6->Show();

     delete pRegister;

     return;

}

void far SettingAdjust()

{

     if (!bAfxManager) return;

     char buf[100],buf1[50],buf2[50],buf3[50],buf4[50];

     CDialog *pDialog = new CDialog;

     pDialog->CreateWindow(100,100,480+130,217+16+6+50,"修正参数");

     pDialog->Center();

     new CCloseButton(pDialog);

     CButton *pButton1=new CButton(pDialog);

     CButton *pButton2=new CButton(pDialog);

     CSettingGrid   *pGrid1  =new CSettingGrid(pDialog);

     CLabel  *pLabel1 =new CLabel(pDialog);

     CLabel  *pLabel2 =new CLabel(pDialog);

     CLabel  *pLabel3 =new CLabel(pDialog);

     CLabel  *pLabel4 =new CLabel(pDialog);

     CLabel  *pLabel5 =new CLabel(pDialog);

     CLabel  *pLabel6 =new CLabel(pDialog);

     CLabel  *pLabel7 =new CLabel(pDialog);

     pLabel1->CreateObject(pDialog->GetClientWidth()-140,48+(16+8)*0,120,SystemFonSize+6,"");//"      警告");

     pLabel2->CreateObject(pDialog->GetClientWidth()-140,48+(16+8)*1,120,SystemFonSize+6,"    此为供应商出");

     pLabel3->CreateObject(pDialog->GetClientWidth()-140,48+(16+8)*2,120,SystemFonSize+6,"厂预置参数,非系");

     pLabel4->CreateObject(pDialog->GetClientWidth()-140,48+(16+8)*3,120,SystemFonSize+6,"统调试人员严禁修");

     pLabel5->CreateObject(pDialog->GetClientWidth()-140,48+(16+8)*4,120,SystemFonSize+6,"改!");

     pLabel6->CreateObject(5,16+8,300,16+6,"Hi_Pot");

     pLabel6->SetID(1001);

     pLabel6->SetBackColorDisplay(TRUE);

     pLabel7->CreateObject(500,23+120,48,48,NULL);

     pLabel7->SetBitmapFlags(TRUE);

     pLabel7->SetBitmapFile("Bmp\\Computer.Bmp");

     pGrid1->CreateGrid(0,SystemFonSize*2+25,325+130,210+SystemFonSize+6+50);

     pButton1->CreateObject(pDialog->GetClientWidth()-140,178+(SystemFonSize+15)*0+50,135,SystemFonSize+6,"确定(E)");

     pButton2->CreateObject(pDialog->GetClientWidth()-140,178+(SystemFonSize+15)*1+50,135,SystemFonSize+6,"取消(C)");

     pButton1->SetFc(ClickEnterButton);

     pButton2->SetFc(ClickCancelButton);

     pButton1->SetShortcutKey(VK_ALT_E);

     pButton2->SetShortcutKey(VK_ALT_C);

     pDialog->SetDrawFc(STATICBOX_SettingAdjust);

     pGrid1->SetItemCount(100);

     pGrid1->SetVolumnCaption(0,"修正项目");

     pGrid1->SetVolumnCaption(1,"AD");

     pGrid1->SetVolumnCaption(2,"输入");

     pGrid1->SetVolumnCaption(3,"AD");

     pGrid1->SetVolumnCaption(4,"输入");

     pGrid1->SetVolumnSelWidth(0,11);

     pGrid1->SetVolumnSelWidth(1,10);

     pGrid1->SetVolumnSelWidth(2,10);

     pGrid1->SetVolumnSelWidth(3,10);

     pGrid1->SetVolumnSelWidth(4,10);

     pGrid1->SetOnlyRead((bAfxManager)?FALSE:TRUE);

     pGrid1->GetEdit()->SetMaxCount(10);

     for(int i=0;i<100;i++)

     {

         sprintf(buf,"Adjust%03d",i+1);

         pGrid1->SetItemCaption(i,buf);

         ::SetDisplayBufferDot(buf,fsAfxAdjust[i][0]);pGrid1->SetSel(i,1,buf);

         ::SetDisplayBufferDot(buf,fsAfxAdjust[i][1]);pGrid1->SetSel(i,2,buf);

         ::SetDisplayBufferDot(buf,fsAfxAdjust[i][2]);pGrid1->SetSel(i,3,buf);

         ::SetDisplayBufferDot(buf,fsAfxAdjust[i][3]);pGrid1->SetSel(i,4,buf);

     }

     //pCurrentObject = pGrid1;

     pDialog->ShowWindow();

     pGrid1->UpdateData(0,1,FALSE);

     if (pDialog->DoModal() == IDOK && bAfxManager)

     {

         CRegister *pRegister = new CRegister("Sys\\Adjust.Sys");

         for (int i=0; i < 100; i++)

         {

              fsAfxAdjust[i][0]=::atof(pGrid1->GetSel(i,1));

              fsAfxAdjust[i][1]=::atof(pGrid1->GetSel(i,2));

              fsAfxAdjust[i][2]=::atof(pGrid1->GetSel(i,3));

              fsAfxAdjust[i][3]=::atof(pGrid1->GetSel(i,4));

         }

         delete pRegister;

         mAfxSystemParameterManager.SaveAdjust();

     }

     delete pDialog;

     return;

}