fixed window layout
[instimg] / src / widgets.c
index 1b97637..9ae4c1e 100644 (file)
@@ -6,6 +6,8 @@
 #include <commctrl.h>
 #include "widgets.h"
 
+#define WIN_STYLE      WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME
+
 struct wgt_window {
        HWND handle;
        struct wgt_rect rect;
@@ -98,8 +100,14 @@ struct wgt_window *wgt_window(const char *title, int width, int height)
                return 0;
        }
 
-       if(!(win->handle = CreateWindow(win->cname, title, WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME,
-                       CW_USEDEFAULT, CW_USEDEFAULT, width, height, 0, 0, hinst, 0))) {
+       rect.left = rect.top = 0;
+       rect.right = width;
+       rect.bottom = height;
+       AdjustWindowRect(&rect, WIN_STYLE, FALSE);
+
+       if(!(win->handle = CreateWindow(win->cname, title, WIN_STYLE, CW_USEDEFAULT,
+                       CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top,
+                       0, 0, hinst, 0))) {
                fprintf(stderr, "wgt_create_window: failed to create window\n");
                UnregisterClass(title, hinst);
                return 0;
@@ -154,9 +162,20 @@ void wgt_destroy_widget(struct wgt_widget *w)
 
 void wgt_resize_window(struct wgt_window *win, int width, int height)
 {
-       MoveWindow(win->handle, win->rect.x, win->rect.y, width, height, TRUE);
+       RECT rect;
+
        win->rect.width = width;
        win->rect.height = height;
+
+       rect.left = win->rect.x;
+       rect.top = win->rect.y;
+       rect.right = rect.left + width;
+       rect.bottom = rect.top + height;
+       if(AdjustWindowRect(&rect, WIN_STYLE, FALSE)) {
+               width = rect.right - rect.left;
+               height = rect.bottom - rect.top;
+       }
+       MoveWindow(win->handle, win->rect.x, win->rect.y, width, height, TRUE);
 }
 
 void wgt_quit_on_close(struct wgt_window *win, int quit)