nuclear@0: /* nuclear@0: This file is part of dynwatch, a win32 system tray applet which nuclear@0: updates automatically the dyndns entry of quake.gr. nuclear@0: nuclear@0: Copyright (c) 2005 John Tsiombikas nuclear@0: nuclear@0: This program is free software; you can redistribute it and/or modify nuclear@0: it under the terms of the GNU General Public License as published by nuclear@0: the Free Software Foundation; either version 2 of the License, or nuclear@0: (at your option) any later version. nuclear@0: nuclear@0: This program is distributed in the hope that it will be useful, nuclear@0: but WITHOUT ANY WARRANTY; without even the implied warranty of nuclear@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nuclear@0: GNU General Public License for more details. nuclear@0: nuclear@0: You should have received a copy of the GNU General Public License nuclear@0: along with this program; if not, write to the Free Software nuclear@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA nuclear@0: */ nuclear@0: nuclear@0: #include "gui.h" nuclear@0: #include "events.h" nuclear@0: #include "resource.h" nuclear@0: nuclear@0: HWND win_main, bn_exit, bn_tray, bn_config; nuclear@0: HWND win_cfg, lb_dnshost, lb_user, lb_pass, lb_hosts; nuclear@0: HWND en_dnshost, en_user, en_pass, en_hosts; nuclear@0: HWND bn_ok, bn_cancel; nuclear@0: int trayfied; nuclear@0: nuclear@0: void create_gui(void) { nuclear@0: static const int lb_xsz = 130; nuclear@0: static const int lb_ysz = 20; nuclear@0: static const int en_xsz = 100; nuclear@0: static const int en_ysz = 20; nuclear@0: static const int yinc = 25; nuclear@0: int ypos = 5; nuclear@0: nuclear@0: reg_win_class("dynwatch", win_proc); nuclear@0: reg_win_class("dynwatch.config", cfg_proc); nuclear@0: nuclear@0: win_main = create_window("dynwatch 1.0", 330, 80, "dynwatch"); nuclear@0: bn_config = create_button("Configure", 5, 5, 100, 30, win_main); nuclear@0: bn_tray = create_button("Send to tray", 110, 5, 100, 30, win_main); nuclear@0: bn_exit = create_button("Exit", 215, 5, 100, 30, win_main); nuclear@0: ShowWindow(win_main, 1); nuclear@0: nuclear@0: win_cfg = create_window("Configuration", 270, 190, "dynwatch.config"); nuclear@0: nuclear@0: lb_dnshost = create_label("dyndns host:", 5, ypos, lb_xsz, lb_ysz, win_cfg); nuclear@0: en_dnshost = create_entry("", lb_xsz + 10, ypos, en_xsz, en_ysz, win_cfg); nuclear@0: ypos += yinc; nuclear@0: lb_user = create_label("user name:", 5, ypos, lb_xsz, lb_ysz, win_cfg); nuclear@0: en_user = create_entry("", lb_xsz + 10, ypos, en_xsz, en_ysz, win_cfg); nuclear@0: ypos += yinc; nuclear@0: lb_pass = create_label("password:", 5, ypos, lb_xsz, lb_ysz, win_cfg); nuclear@0: en_pass = create_entry("", lb_xsz + 10, ypos, en_xsz, en_ysz, win_cfg); nuclear@0: ypos += yinc; nuclear@0: /*lb_hosts = create_label("hosts to update:", 5, ypos, lb_xsz, lb_ysz, win_cfg); nuclear@0: en_hosts = create_entry("", lb_xsz + 10, ypos, en_xsz, en_ysz, win_cfg);*/ nuclear@0: nuclear@0: ypos += 35; nuclear@0: bn_ok = create_button("OK", 5, ypos, 100, 25, win_cfg); nuclear@0: bn_cancel = create_button("Cancel", 140, ypos, 100, 25, win_cfg); nuclear@0: } nuclear@0: nuclear@0: void tray(int trayfy) { nuclear@0: NOTIFYICONDATA nicon; nuclear@0: memset(&nicon, 0, sizeof nicon); nuclear@0: nicon.cbSize = sizeof nicon; nuclear@0: nicon.hWnd = win_main; nuclear@0: nicon.uID = 0; nuclear@0: nicon.uCallbackMessage = WM_USER; nuclear@0: nicon.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; nuclear@0: nicon.hIcon = LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(ICON_DYNWATCH)); nuclear@0: strcpy(nicon.szTip, "Click to open the program window"); nuclear@0: nuclear@0: if(trayfy) { nuclear@0: ShowWindow(win_main, 0); nuclear@0: Shell_NotifyIcon(NIM_ADD, &nicon); nuclear@0: } else { nuclear@0: Shell_NotifyIcon(NIM_DELETE, &nicon); nuclear@0: ShowWindow(win_main, 1); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: HWND create_window(const char *title, int xsz, int ysz, const char *class_name) { nuclear@0: int x = (GetSystemMetrics(SM_CXSCREEN) - xsz) / 2; nuclear@0: int y = (GetSystemMetrics(SM_CYSCREEN) - ysz) / 2; nuclear@0: unsigned long style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU; nuclear@0: return CreateWindow(class_name, title, style, x, y, xsz, ysz, 0, 0, GetModuleHandle(0), 0); nuclear@0: } nuclear@0: nuclear@0: HWND create_button(const char *title, int x, int y, int xsz, int ysz, HWND parent) { nuclear@0: unsigned long style = BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE | WS_TABSTOP; nuclear@0: return CreateWindow("BUTTON", title, style, x, y, xsz, ysz, parent, 0, GetModuleHandle(0), 0); nuclear@0: } nuclear@0: nuclear@0: HWND create_label(const char *text, int x, int y, int xsz, int ysz, HWND parent) { nuclear@0: unsigned long style = SS_RIGHT | WS_CHILD | WS_VISIBLE; nuclear@0: return CreateWindow("STATIC", text, style, x, y, xsz, ysz, parent, 0, GetModuleHandle(0), 0); nuclear@0: } nuclear@0: nuclear@0: HWND create_entry(const char *text, int x, int y, int xsz, int ysz, HWND parent) { nuclear@0: unsigned long style = ES_AUTOHSCROLL | WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE; nuclear@0: return CreateWindow("EDIT", text, style, x, y, xsz, ysz, parent, 0, GetModuleHandle(0), 0); nuclear@0: } nuclear@0: nuclear@0: void en_set_text(HWND entry, const char *text) { nuclear@0: SendMessage(entry, WM_SETTEXT, 0, (long)text); nuclear@0: } nuclear@0: nuclear@0: const char *en_get_text(HWND entry) { nuclear@0: static char buf[512]; nuclear@0: SendMessage(entry, WM_GETTEXT, 512, (long)buf); nuclear@0: return buf; nuclear@0: } nuclear@0: nuclear@0: void reg_win_class(const char *class_name, msg_handler_t handler) { nuclear@0: WNDCLASSEX wc; nuclear@0: HINSTANCE pid = GetModuleHandle(0); nuclear@0: nuclear@0: memset(&wc, 0, sizeof wc); nuclear@0: wc.cbSize = sizeof wc; nuclear@0: wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); nuclear@0: wc.hCursor = LoadCursor(pid, MAKEINTRESOURCE(IDC_ARROW)); nuclear@0: wc.hIcon = wc.hIconSm = LoadIcon(pid, MAKEINTRESOURCE(ICON_DYNWATCH)); nuclear@0: wc.hInstance = pid; nuclear@0: wc.lpfnWndProc = handler; nuclear@0: wc.lpszClassName = class_name; nuclear@0: wc.style = CS_HREDRAW | CS_VREDRAW; nuclear@0: RegisterClassEx(&wc); nuclear@0: }