rawdisk code added
[instimg] / src / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <windows.h>
4 #include "widgets.h"
5 #include "rawdisk.h"
6
7 static struct wgt_window *win;
8 static struct wgt_widget *lb_instto, *bn_inst, *bn_cancel, *cb_devs, *ck_usbonly;
9 static struct rawdisk_device rawdev[64];
10 static int num_rawdev;
11
12 static void onclick(struct wgt_widget *w);
13 static void onmodify(struct wgt_widget *w);
14
15 int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hprevinst, char *cmdline, int showcmd)
16 {
17         int i, x, y;
18         MSG msg;
19         static const char *items[64];
20
21         if((num_rawdev = rawdisk_detect(rawdev, sizeof rawdev / sizeof *rawdev)) == -1) {
22                 return 1;
23         }
24         for(i=0; i<num_rawdev; i++) {
25                 items[i] = rawdev[i].name;
26         }
27
28         if(!(win = wgt_window("256boss USB stick installer", 400, 300))) {
29                 return 1;
30         }
31         lb_instto = wgt_label(win, "Install to device:", 10, 10);
32
33         x = wgt_xpos_after(lb_instto, WGT_AUTO);
34         cb_devs = wgt_combo(win, items, num_rawdev, 0, x, 10, WGT_AUTO, WGT_AUTO,
35                         onmodify);
36
37         y = wgt_ypos_after(cb_devs, 16);
38         ck_usbonly = wgt_checkbox(win, "only show USB devices", 1, x, y,
39                         WGT_AUTO, WGT_AUTO, 0);
40
41         y = wgt_ypos_after(ck_usbonly, 16);
42         bn_inst = wgt_button(win, "Install", 10, y, WGT_AUTO, WGT_AUTO, onclick);
43
44         x = wgt_xpos_after(bn_inst, WGT_AUTO);
45         bn_cancel = wgt_button(win, "Cancel", x, y, WGT_AUTO, WGT_AUTO, onclick);
46
47         while(GetMessage(&msg, 0, 0, 0)) {
48                 TranslateMessage(&msg);
49                 DispatchMessage(&msg);
50         }
51
52         wgt_destroy_window(win);
53         return 0;
54 }
55
56 static void onclick(struct wgt_widget *w)
57 {
58         MessageBox(0, "clicked", "clicked", MB_OK);
59 }
60
61 static void onmodify(struct wgt_widget *w)
62 {
63         int sel = wgt_combo_selected(w);
64         if(sel >= 0) {
65                 const char *selstr = wgt_get_combo_item(w, sel);
66                 MessageBox(0, selstr, "selected item", MB_OK);
67         }
68 }