WideStudio/MWT Logo
WideStudio/MWT
Programming Guide
WideStudio/MWT Index
Table of contents


文件选择对话框



显示文件选择对话框

这里,我们将介绍文件选择对话框的用法。对于文件选择对话框,提供有便利的popup函数。



[文件选择对话框]

popup函数,不仅显示对话框,还可以用函数返回操作者选择OK和解除等的结果。因此,虽然叫函数,却能实现对话框的显示,以及取得对话框的结束时的选择结果。以下是使用文件选择对话框和消息对话框的实际范例程序。

#include <WScom.h>
#include <WSCfunctionList.h>
#include <WSCbase.h>
#include <WSCfileSelect.h> //(A)
#include <WSCmessageDialog.h> //(B)
//----------------------------------------------------------
//Function for the event procedure
//----------------------------------------------------------
void btnep2(WSCbase* object){
  //Access to the global instance of the WSCfileSelect class.
  WSCfileSelect* fs = WSGIappFileSelect(); //(C)
  fs->setProperty(WSNmaskFileName,"cpp");  //(D)
  fs->setProperty(WSNdefaultPosition,True); //(E)
  long ret = fs->popup();                  //(F)

  //Access to the global instance of the WSCmessageDialog class.
  WSCmessageDialog* msg = WSGIappMessageDialog(); //(G)
  msg->setProperty(WSNwidth,500);                 //(H)
  msg->setProperty(WSNheight,120);                //(I)
  msg->setProperty(WSNdefaultPosition,True);      //(J)

  if (ret == WS_DIALOG_OK){           //(K)
    WSCstring  str;
    str << fs->getFileName() << " is selected.";
    msg->setProperty(WSNlabelString,str);
    msg->popup();
  }else if (ret == WS_DIALOG_NO){     //(L)
    msg->setProperty(WSNlabelString,"Nothing is selected.");
    msg->popup();
  }else if (ret == WS_DIALOG_CANCEL){
    msg->setProperty(WSNlabelString,"The selection is canceled.");
    msg->popup();                     //(M)
  }
}

因为在(A),(B)处访问文件选择对话框和消息对话框,所以预先追加所需.h文件。

(C)使用Global Instance访问文件选择对话框的Global Instance。在文件选择对话框等的Class中,预先都备有1个Global Instance。于是,可以使用Global Instance访问函数进行访问。

在(D),(E)处设定属性,并在(F)处将对话框变为显示状态。当被选择时,popup函数将返回。

使用消息对话框显示文件选择对话框的选择结果。在(G),(H),(I),(J)处,取得消息对话框的Global Instance,并设定属性。

在(K)处,被选择的文件将作为消息字符串显示。 在(L)处,显示说明没有文件被选择的消息字符串。 在(M)处,显示已被解除的消息字符串。

Document Release 3.90 for WideStudio/MWT ver 3.90, Jul 2005


WideStudio/MWT documents index | Table of contents

Copyright(C) WideStudio/MWT Development Team, 1999-2005 Last modified: Jul 31, 2005