Hextreme napisał(a):
Poniżej przedstawiam przykład skorzystania z console.device. Sprawdziłem, działa.
Tak działa. W wolnej chwili poobaczajam przerabiając sobie przykład. Poniżej załączam moje wypociny - mile widziane wszelkie uwagi.
Kod:
#include <intuition/intuition.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/asl.h>
#include <stdio.h>
static int init(void);
static void loop(void);
static void close(void);
static void ShowAbout(void);
static void FileRead(void);
struct IntuitionBase *IntuitionBase;
struct Library *GadToolsBase;
struct Library *AslBase;
struct Window *window;
struct IntuiMessage *msg;
struct Menu *menu;
struct Screen *pubscr;
void *vi;
char koniec;
struct TagItem taglist[]=
{
WA_Left, 0,
WA_Top, 0,
WA_Width, 250,
WA_Height, 180,
WA_MaxWidth, -1,
WA_MaxHeight, -1,
WA_Title, (ULONG)"Testowe okno",
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_Activate, TRUE,
WA_DepthGadget, TRUE,
WA_SizeGadget, TRUE,
WA_NewLookMenus,TRUE,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MENUPICK,
TAG_END
};
struct TagItem frtag[]=
{
ASL_Hail, (ULONG)"Wybierz plik",
ASL_LeftEdge, 0,
ASL_TopEdge, 0,
ASL_Width, 100,
ASL_Height, 150,
ASL_OKText, (ULONG)"Wczytaj",
ASL_CancelText, (ULONG)"Poniechaj",
ASL_File, (ULONG)"costam.bin",
ASL_Dir, (ULONG)"libs:",
TAG_DONE
};
struct EasyStruct AboutWindow =
{
sizeof(struct EasyStruct),
0,
"About .....",
"Takie tam pierwsze wypociny.\n",
"OK",
};
//Menu programu.
struct NewMenu tabnm[]=
{
{NM_TITLE, "File"},
{NM_ITEM, "Open", "O"},
{NM_ITEM, NM_BARLABEL},
{NM_ITEM, "Save", "S"},
{NM_ITEM, "Save as", "Z"},
{NM_ITEM, NM_BARLABEL},
{NM_ITEM, "Exit", "Q"},
{NM_TITLE, "Menu1"},
{NM_ITEM, "Podmenu0"},
{NM_ITEM, "Podmenu1..."},
{NM_ITEM, NM_BARLABEL},
{NM_ITEM, "Podmenu2"},
{NM_ITEM, "Podmenu3"},
{NM_TITLE, "Menu2"},
{NM_ITEM, "Podmenu0"},
{NM_ITEM, "Podmenu1"},
{NM_ITEM, "Podmenu2"},
{NM_TITLE, "Menu3"},
{NM_ITEM, "Podmenu1", 0, CHECKIT | MENUTOGGLE},
{NM_ITEM, "Podmenu2", 0, CHECKIT | MENUTOGGLE},
{NM_ITEM, "Podmenu3", 0, CHECKIT | CHECKED | MENUTOGGLE},
{NM_ITEM, "Podmenu4", 0, CHECKIT},
{NM_SUB, "Podpodmenu1", 0, CHECKIT, 2|4},
{NM_SUB, "Podpodmenu2", 0, CHECKIT | CHECKED, 1|4},
{NM_SUB, "Podpodmenu3", 0, CHECKIT, 1|2},
{NM_TITLE, "Help"},
{NM_ITEM, "About...", "?"},
{NM_ITEM, "Podmenu1..."},
NM_END
};
int main(void)
{
if(0 == init())
{
loop();
}
close();
return 0;
}
static int init(void)
{
IntuitionBase=(struct IntuitionBase*) OpenLibrary("intuition.library", 40L);
if (!IntuitionBase)
{
return -1;
}
GadToolsBase=OpenLibrary("gadtools.library", 40L);
if (!GadToolsBase)
{
return -1;
}
AslBase=OpenLibrary("asl.library", 40L);
if (!AslBase)
{
return -1;
}
menu=CreateMenusA(tabnm, 0);
if (!menu)
{
return -1;
}
pubscr=LockPubScreen(0);
if (!pubscr)
{
return -1;
}
vi=GetVisualInfoA(pubscr, 0);
if (!vi)
{
return -1;
}
LayoutMenus(menu, vi, GTMN_NewLookMenus, TRUE, TAG_DONE);
window=OpenWindowTagList(0, taglist);
if (!window)
{
return -1;
}
SetMenuStrip(window, menu);
return 0;
}
static void loop(void)
{
for (koniec=0; !koniec;)
{
WaitPort(window->UserPort);
if (msg=(struct IntuiMessage*) GetMsg(window->UserPort))
{
ULONG Clas=msg->Class;
UWORD Code=msg->Code;
ReplyMsg((struct Message*)msg);
switch (Clas)
{
case IDCMP_CLOSEWINDOW:
koniec = 1;
break;
case IDCMP_MENUPICK:
while (Code!=MENUNULL)
{
struct MenuItem *item=ItemAddress(menu, Code);
if (Code==FULLMENUNUM(0, 0, NOSUB))
FileRead();
if (Code==FULLMENUNUM(0, 5, NOSUB))
koniec = 1;
if (Code==FULLMENUNUM(4, 0, NOSUB))
ShowAbout();
Code=item->NextSelect;
}
}
}
}
}
static void close(void)
{
if (window)
{
ClearMenuStrip(window);
CloseWindow(window);
}
if (vi)
{
FreeVisualInfo(vi);
}
if (pubscr)
{
UnlockPubScreen(0, pubscr);
}
if (menu)
{
FreeMenus(menu);
}
if (AslBase)
{
CloseLibrary(AslBase);
}
if (GadToolsBase)
{
CloseLibrary(GadToolsBase);
}
if (IntuitionBase)
{
CloseLibrary((struct Library*)IntuitionBase);
}
}
static void ShowAbout(void)
{
EasyRequest(window, &AboutWindow, NULL, NULL);
}
static void FileRead(void)
{
struct FileRequester *fr;
if (fr = (struct FileRequester *) AllocAslRequest(ASL_FileRequest, frtag));
{
if (AslRequest(fr, NULL))
{
printf("OK.\n");
}
}
FreeAslRequest(fr);
}