Download this source

I take no responsibility for this source. It's freeware, do whatever you like with it.

This source shows how to open a screen with the Screenmoderequester. You can press the gadget to change the screenmode


#include <intuition/intuition.h>

#include <clib/graphics_protos.h>
#include <clib/intuition_protos.h>
#include <clib/asl_protos.h>
#include <clib/utility_protos.h>

struct ScreenModeRequester *openASL(void);
void cleanup(void);
struct Window *openGUI(void);

struct Window *win;
struct Screen *scr;
struct Gadget *glist,*gad;
struct ScreenModeRequester *screenmode;
struct TagItem *tag;

APTR vi;
BYTE mysignal=-1;

struct TagItem smrtags[] =
{
  ASLSM_TitleText, (ULONG)"Select a screen!",
  ASLSM_InitialLeftEdge, 40,
  ASLSM_InitialTopEdge, 20,
  ASLSM_InitialWidth, 340,
  ASLSM_InitialHeight, 180,
  ASLSM_Screen, NULL,
  ASLSM_DoWidth, TRUE,
  ASLSM_DoHeight, TRUE,
  ASLSM_DoDepth, TRUE,
  ASLSM_DoOverscanType, FALSE,
  ASLSM_DoAutoScroll, FALSE,
  ASLSM_MinWidth, 200,
  ASLSM_MinHeight, 200,
  ASLSM_MinDepth, 4,
  ASLSM_MaxDepth, 24,
  ASLSM_InitialDisplayWidth, 200,
  ASLSM_InitialDisplayHeight, 300,
  ASLSM_InitialDisplayDepth, 4, TAG_DONE
};

struct NewGadget ng = {20,30,100,15,"ScreenMode",0,1,0,0,0};

void main()
{
  struct IntuiMessage *msg,cmsg;
  

  BOOL keepgoing=TRUE;

  if((mysignal = AllocSignal(-1)) != -1)
  {
    if(screenmode = openASL())
    {
      if(win = openGUI())
      {
        PubScreenStatus(scr,0);
        ScreenToFront(scr);

        while(keepgoing)
        {
          WaitPort(win->UserPort);
          while(msg = GT_GetIMsg(win->UserPort))
          {
            CopyMem(msg,&cmsg,sizeof(struct IntuiMessage));
            GT_ReplyIMsg(msg);

            switch(cmsg.Class)
            {
              case IDCMP_CLOSEWINDOW:
                keepgoing= FALSE;
                break;

              case IDCMP_GADGETUP:
                if(((struct Gadget *)(cmsg.IAddress))->GadgetID == 1)
                  if(screenmode = openASL())
                    if(!openGUI())
                      keepgoing = FALSE;
                   
            }
          }
        }
        cleanup();
      }
    }
  }
}

struct ScreenModeRequester *openASL()
{
  struct ScreenModeRequester *smr;
  BOOL result = FALSE;;

  if(smr = AllocAslRequest(ASL_ScreenModeRequest,NULL))
  {
    result = AslRequest(smr,smrtags);
    FreeAslRequest(smr);
  }
  if(result)
    return(smr);
  else
    return(FALSE);
}

struct Window *openGUI()
{
  cleanup();
  if(scr = OpenScreenTags(0,
    SA_Title, "Testprogram",
    SA_PubName, "Testscreen",     /* Make screen public, 
                                   note that this must be before SA_Pubtask */
    SA_PubTask, FindTask(NULL),
    SA_PubSig, mysignal, 
    SA_SysFont,1,                 /* Screen font as WB has */
    SA_DisplayID, screenmode->sm_DisplayID,TAG_DONE))
  {
    if(tag = FindTagItem(ASLSM_Screen,smrtags))
      tag->ti_Data = (ULONG)scr;         /* Open the asl on our screen next time */

      gad = CreateContext(&glist);

    if(vi = GetVisualInfo(scr,TAG_DONE))
    {
      ng.ng_VisualInfo = vi;
      if(gad = CreateGadget(BUTTON_KIND,gad, &ng, TAG_DONE))
      {
        if(win = OpenWindowTags(0,
        WA_Height, 200,
        WA_Width, 200,
        WA_PubScreen, scr,
        WA_Gadgets, glist,
        WA_IDCMP,IDCMP_CLOSEWINDOW | BUTTONIDCMP,
        WA_Flags,WFLG_CLOSEGADGET | WFLG_SIZEGADGET |
             WFLG_DEPTHGADGET | WFLG_DRAGBAR,
            WA_MinWidth,    64,
            WA_MinHeight,   64,
            WA_MaxWidth,    ~1,
            WA_MaxHeight,   ~1,TAG_DONE))
          return(win);
      }
    }
  }
  return(0);
}

void cleanup()
{
  if(win)
    CloseWindow(win);

  if(glist)
    FreeGadgets(glist);

  if(vi)
    FreeVisualInfo(vi);

  if(scr)
    while(!CloseScreen(scr))
      Wait(1L << mysignal);

  if(mysignal)
    FreeSignal(mysignal);
}