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