Skip to content

Commit

Permalink
Properly register and unregister scroll class
Browse files Browse the repository at this point in the history
  • Loading branch information
petabyt committed Nov 14, 2024
1 parent 615b96a commit f770c26
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ clean:

clean_:
$(RM) $(O_FILES) *.o *.exe *.out *.res *.so *.a build *.dylib example/*.out ide/*.o *.res *.dll
$(RM) `find windows unix darwin test examples -regex ".*\.\(o\|d\)"`
7 changes: 7 additions & 0 deletions extras/scroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ ATOM registerScrollClass(HICON hDefaultIcon, HCURSOR hDefaultCursor)
return RegisterClassW(&wc);
}

void unregisterScrollClass(void)
{
if (UnregisterClassW(scrollClass, hInstance) == 0)
logLastError(L"error unregistering uiScroll window class");
}

static void scrollto(uiScroll *a, int which, struct scrollParams *p, int pos)
{
SCROLLINFO si;
Expand Down Expand Up @@ -606,3 +612,4 @@ uiScroll *uiNewScroll() {

return s;
}

10 changes: 5 additions & 5 deletions extras/win_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ if (extern_win_init(hDefaultIcon, hDefaultCursor)) {
*/

int extern_win_init(HICON hDefaultIcon, HCURSOR hDefaultCursor) {
extern ATOM registerScrollClass(HICON hDefaultIcon, HCURSOR hDefaultCursor);
if (registerScrollClass(hDefaultIcon, hDefaultCursor) == 0) {
puts("registering uiScroll window class");
return 1;
}
// extern ATOM registerScrollClass(HICON hDefaultIcon, HCURSOR hDefaultCursor);
// if (registerScrollClass(hDefaultIcon, hDefaultCursor) == 0) {
// puts("registering uiScroll window class");
// return 1;
// }

// Set DPI awareness
typedef void* fl_DPI_AWARENESS_CONTEXT;
Expand Down
3 changes: 2 additions & 1 deletion test/unit/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ static void initUninitTwice(void **state)
{
uiInitOptions o = {0};

assert_null(uiInit(&o));
printf("%s\n", uiInit(&o));
// assert_null(uiInit(&o));
uiUninit();

assert_null(uiInit(&o));
Expand Down
10 changes: 7 additions & 3 deletions win.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ LIBS += -lstdc++ -lgcc -lpthread -lssp -lurlmon -luuid

CFLAGS += -Iwindows -fvisibility=hidden -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -Wextra -Wpedantic -std=c++11 -Wno-unused-parameter -Wno-switch -D_UI_STATIC -Dlibui_EXPORTS

CFLAGS += -Isubprojects/cmocka-1.1.5/include

libui_win64.a: $(O_FILES)
x86_64-w64-mingw32-ar rsc libui_win64.a $(O_FILES)

Expand All @@ -34,11 +36,13 @@ build: libui_win64.a
ide/ide.res: ide/a.rc
x86_64-w64-mingw32-windres -Iwindows ide/a.rc -O coff -o ide/ide.res

win.res: example/a.rc
x86_64-w64-mingw32-windres -Iwindows example/a.rc -O coff -o win.res
win.res: examples/resources.rc
x86_64-w64-mingw32-windres examples/resources.rc -D_UI_STATIC -O coff -o win.res

TESTER_FILES := $(addprefix test/,drawtests.w.o images.w.o main.w.o menus.w.o page1.w.o page2.w.o page3.w.o page4.w.o page5.w.o page6.w.o page7.w.o page7a.w.o page7b.w.o page7c.w.o page11.w.o page12.w.o page13.w.o page14.w.o page15.w.o page16.w.o page17.w.o spaced.w.o)

tester.exe: $(TESTER_FILES) win.res libui_win64.a
$(CC) -static $(TESTER_FILES) libui_win64.a win.res $(LIBS) -o tester.exe

UNIT_FILES := $(patsubst %.c,%.$(TARGET).o,$(wildcard test/unit/*.c)) subprojects/cmocka-1.1.5/src/cmocka.w.o
unit.exe: $(UNIT_FILES) win.res libui_win64.a
$(CC) -static $(UNIT_FILES) libui_win64.a win.res $(LIBS) -o unit.exe
8 changes: 7 additions & 1 deletion windows/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include "uipriv_windows.hpp"
#include "attrstr.hpp"

int extern_win_init(HICON hDefaultIcon, HCURSOR hDefaultCursor);
ATOM registerScrollClass(HICON hDefaultIcon, HCURSOR hDefaultCursor);
int unregisterScrollClass(void);

HINSTANCE hInstance;
int nCmdShow;

Expand Down Expand Up @@ -125,7 +129,8 @@ const char *uiInit(uiInitOptions *o)
if (registerAreaClass(hDefaultIcon, hDefaultCursor) == 0)
return ieLastErr("registering uiArea window class");

int extern_win_init(HICON hDefaultIcon, HCURSOR hDefaultCursor);
registerScrollClass(hDefaultIcon, hDefaultCursor);

if (extern_win_init(hDefaultIcon, hDefaultCursor)) {
return ieLastErr("Error");
}
Expand Down Expand Up @@ -163,6 +168,7 @@ void uiUninit(void)
// no need to delete the default icon or cursor; see http://stackoverflow.com/questions/30603077/
uninitUtilWindow();
uninitAlloc();
unregisterScrollClass();
}

void uiFreeInitError(const char *err)
Expand Down

0 comments on commit f770c26

Please sign in to comment.