file13
12-04-2002, 05:33 PM
i asked once upon a time how to make a non-console win32 app with Ocaml and finally found a way to do it--so i thought i'd share the insight.
Harry Chomskey's latest win32 ocaml bindings include code for a tool called "mkwinapp." you don't have to compile the entire win32 bindings to use the tool--i just did a "nmake mkwinapp" since i was looking at it for Tk apps.
then you've got a nifty prog that you can run after you've built a stand alone exe that won't pop up those annoying console windows for what looks like any windows GUI--haven't had a chance to try it with lablgtk, but i'm sure it'll work since it looks like mkwinapp is messing with the file format of the exe itself....
for more info see
http://www.speakeasy.org/~hchomsky/ocaml-win32.html
mkwinapp is included in release ocaml-win32-0.02.zip.
here's a test prog i built on win2k with ocaml 3.06, VC 6, Active Tcl 8.3.5:
(*
To build:
ocamlopt -o hello -I +labltk labltk.cmxa hello.ml
mkwinapp hello.exe
*)
class app (master) =
object (self)
val frame = Frame.create (master);
val frame2 = Frame.create (master);
val mutable button = Button.create (master);
val mutable hi_there = Button.create (master);
val mutable entry = Entry.create (master);
val mutable get_text_button = Button.create (master);
val mutable message = Text.create (master);
val mutable saying = "Go eat shit!";
method say_hi () = print_endline ("hi there, everyone!");
method get_text () =
begin
saying <- Entry.get (entry);
Text.delete
~start: (`Linechar (1, 1), [`Linestart])
~stop: (`End, [])
(message);
Text.insert ~index: (`End, []) ~text: (saying) (message);
end;
initializer
begin
Tk.pack ([frame; frame2]);
button <- Button.create
~text: ("Quit")
~foreground: (`Color ("red"))
~command: (Tk.closeTk)
(frame);
hi_there <- Button.create
~text: ("Hello")
~command: (self#say_hi)
(frame);
Tk.pack ~side: (`Left) ([button; hi_there]);
entry <- Entry.create (frame2);
get_text_button <- Button.create
~text: ("Enter")
~command: (self#get_text)
(frame2);
Tk.bind
~events: ([`KeyPressDetail "Return"])
~action: (fun _ -> self#get_text ())
(master);
Tk.pack ~side: (`Left) ([entry]);
Tk.pack ~side: (`Left) ([get_text_button]);
message <- Text.create (frame2);
Tk.pack ([message]);
Text.insert ~index: (`End, []) ~text: (saying) (message);
end;
end;;
let main () =
let root = Tk.openTk () in
let my_app = new app (root) in
Printexc.print (Tk.mainLoop) ();
;;
if !Sys.interactive then () else main ();;
anyways, thought i'd share. :)
Harry Chomskey's latest win32 ocaml bindings include code for a tool called "mkwinapp." you don't have to compile the entire win32 bindings to use the tool--i just did a "nmake mkwinapp" since i was looking at it for Tk apps.
then you've got a nifty prog that you can run after you've built a stand alone exe that won't pop up those annoying console windows for what looks like any windows GUI--haven't had a chance to try it with lablgtk, but i'm sure it'll work since it looks like mkwinapp is messing with the file format of the exe itself....
for more info see
http://www.speakeasy.org/~hchomsky/ocaml-win32.html
mkwinapp is included in release ocaml-win32-0.02.zip.
here's a test prog i built on win2k with ocaml 3.06, VC 6, Active Tcl 8.3.5:
(*
To build:
ocamlopt -o hello -I +labltk labltk.cmxa hello.ml
mkwinapp hello.exe
*)
class app (master) =
object (self)
val frame = Frame.create (master);
val frame2 = Frame.create (master);
val mutable button = Button.create (master);
val mutable hi_there = Button.create (master);
val mutable entry = Entry.create (master);
val mutable get_text_button = Button.create (master);
val mutable message = Text.create (master);
val mutable saying = "Go eat shit!";
method say_hi () = print_endline ("hi there, everyone!");
method get_text () =
begin
saying <- Entry.get (entry);
Text.delete
~start: (`Linechar (1, 1), [`Linestart])
~stop: (`End, [])
(message);
Text.insert ~index: (`End, []) ~text: (saying) (message);
end;
initializer
begin
Tk.pack ([frame; frame2]);
button <- Button.create
~text: ("Quit")
~foreground: (`Color ("red"))
~command: (Tk.closeTk)
(frame);
hi_there <- Button.create
~text: ("Hello")
~command: (self#say_hi)
(frame);
Tk.pack ~side: (`Left) ([button; hi_there]);
entry <- Entry.create (frame2);
get_text_button <- Button.create
~text: ("Enter")
~command: (self#get_text)
(frame2);
Tk.bind
~events: ([`KeyPressDetail "Return"])
~action: (fun _ -> self#get_text ())
(master);
Tk.pack ~side: (`Left) ([entry]);
Tk.pack ~side: (`Left) ([get_text_button]);
message <- Text.create (frame2);
Tk.pack ([message]);
Text.insert ~index: (`End, []) ~text: (saying) (message);
end;
end;;
let main () =
let root = Tk.openTk () in
let my_app = new app (root) in
Printexc.print (Tk.mainLoop) ();
;;
if !Sys.interactive then () else main ();;
anyways, thought i'd share. :)