win32_gui 2.0.0
win32_gui: ^2.0.0 copied to clipboard
Win32 API GUI in Object-Oriented style with some helpers. Uses package `win32` and `dart:ffi`.
2.0.0 #
-
Migrated to
win326.x (breaking:win32_guire-exportspackage:win32).- See the
win32migration guide.
- See the
-
Breaking changes (typed handles):
WindowBase:hwnd/hwndIfCreated:HWND(wasint).create(): returnsFuture<HWND>.build,repaint:(HWND hwnd, HDC hdc).processCommand:(HWND hwnd, HDC hdc, int wParam, int lParam).processMessage:(HWND hwnd, int uMsg, int wParam, int lParam).callBuild/callRepaint:{HDC? hdc}.fillRect,drawText,drawBG:HDC hdc.drawImage:(HDC hdc, HBITMAP hBitmap, ...).
Window:loadImage/loadImageCached: returnHBITMAP;getBitmapDimension(HBITMAP).loadIcon/loadIconCached: returnHICON.createWindowImpl: returnsWin32Result<HWND>.windowNameNative:PCWSTR?(nullwhenwindowNameisnull).
WindowClass:windowProcDefaultandWindowProcFunction: nativeWNDPROCsignature(Pointer hwnd, int uMsg, int wParam, int lParam)(required byPointer.fromFunction).getWindowWithHWnd,getWindowWithCreateId,getWindowWithCreateIdPtr:HWND.classNameNative:PCWSTR.- New
createCtlColorBrush(handlesWM_CTLCOLOR*).
WindowClassColors.createSolidBrush:HBRUSH createSolidBrush(HDC hdc).Dialog:dialogProcDefault: nativeDLGPROCsignature(Pointer hwnd, int uMsg, int wParam, int lParam).getDialogWithHWnd,getDialogWithCreateId,getDialogWithCreateIdPtr:HWND.createDialogImpl: returnsWin32Result<HWND>.
RichEdit.setTextColor:(HDC hdc, int color).Win32Thread:createThreadreturnshThreadasHANDLE;waitThread(HANDLE).- Style parameters with combined-flag defaults are now nullable (same defaults), since
win326.x flags can't be combined inconstexpressions:Dialog(style:),DialogItem.button(style:),DialogItem.text(style:),Button(windowStyles:). - Colors, styles,
wParam/lParamandhMenuremainint(thewin326.x enum/param types implementint).
-
Fixes:
setupDarkMode,setupTitleColor,setWindowRoundedCorners: catchWindowsException(DwmSetWindowAttributenow throws; caption color and rounded corners require Windows 11).drawImage: release the memory DC withDeleteDC(wasDeleteObject).- Fixed native memory leaks:
WNDCLASSinregister(),getWindowText,setWindowText,RichEdit.replaceSel(perappendText),Win32Thread.createThreadthread ID,getSystemDefaultFontson error. - Error codes come from
Win32Result.error(captured atomically) instead of a laterGetLastError()call.
-
Fixes (review):
Dialog.dialogProcDefault: follows theDLGPROCcontract (returnsTRUE/FALSE, results viaDWLP_MSGRESULT) instead of callingDefWindowProc(broke caption drag/close,WM_NCHITTEST,WM_QUERYENDSESSION, and processed messages twice).WM_CLOSEdestroys the dialog.Dialog.createDialogTemplate: the buffer is sized from the actual strings/items (computeDialogTemplateSize,DialogItem.computeTemplateSize); it used to overflow the heap with several items or long texts. Nullx/y/width/heightdefault to0/0/defaultWidth/defaultHeight(CW_USEDEFAULTwas truncated to a 16-bit0, a zero-sized dialog).DialogItem.button: uses the predefinedbuttonclass ordinal (0x0080); it was0(invalid).Dialoglifecycle:- The
timeouttimer starts oncreate()(was the constructor). - The
resultis set only once (the first result wins);doCloseonly destroys a created, live dialog. - Destroyed without a result (e.g. closed by the user): cancels the timer and completes
waitResultwithfalse(it used to hang). waitResult(timeout:)applies the timeout per caller.setResultDynamicchecks the type instead of catching any error.- The default
processCommandonly sets the result for clicks (isClickCommand), not for notifications likeEN_SETFOCUS/EN_CHANGE.
- The
WindowClass.windowProcDefault/Dialog.dialogProcDefault: exceptions are caught and logged (they were silently converted to0at the native callback boundary);EndPaint/ReleaseDCinfinally.WM_CREATE: no longer crashes (null dereference) for a window without a name (lpszName == NULL) or created withoutlpCreateParams; looks up theWindowbycreateIdfirst (anHWNDcan be reused).WM_CTLCOLOR*: uses a cached brush (WindowClassColors.brush, released bydispose) instead of creating a GDI brush per message (GDI object leak). Without colors, delegates toDefWindowProc.WindowMessageLoop.runLoopAsyncstops onWM_QUIT;consumeQueuere-posts aWM_QUITinstead of swallowing it.close()with the default behavior callsdestroy()(Win32CloseWindowminimizes a window).minimize/maximize/restore: return the resulting state (ShowWindowreturns the previous visibility).showConfirmationDialog(okCancel: true): returnstrueforIDOK(always returnedfalse).setIcon:WM_SETICONwithICON_SMALL(ICON_SMALL2is only valid forWM_GETICON).RegisterClassfailures are detected and logged (were reported as success).- Children of a destroyed
Window(e.g.Button,RichEdit) are notified and unregistered (they stayed registered with a staleHWND). onClose/onDestroyed/onTimeoutare broadcast streams, closed when destroyed.callRepaint()outsideWM_PAINTusesGetDC/ReleaseDC(wasBeginPaintwith a leakedPAINTSTRUCT).RichEdit.getCharFormatsetscbSize(required byEM_GETCHARFORMAT);appendTextfrees itsCHARFORMAT.- Native memory:
createIdPtrand the dialog template are freed after creation;dimension, the rect buffer andwindowNameNativeare released by aNativeFinalizer(WindowBaseisFinalizable). Win32Thread.closeThread(the caller owns thecreateThreadhandle).- Logging:
logAllToworks (was never called);LoggerHandler.parentreturns the parent handler;logErrorToof a specific logger is used; long logger/isolate names are truncated. Win32Constants: removed non-message entries fromwmByID(CFM_COLOR,SCF_ALL), addedWM_CTLCOLOR*, removed a top-levelmain()exported by the library.
-
New constants:
DWLP_MSGRESULT,BN_CLICKED,DLG_CLASS_BUTTON. -
Tests:
test/win32_gui_logic_test.dart: pure Dart logic (runs on any OS).test/win32_gui_integration_test.dart: Windows integration tests for the fixes above.dart_test.yaml:concurrency: 1(Win32 window classes/message queues are per process/thread).
-
CI:
codecov/codecov-action@v5; a Codecov upload error doesn't fail the build. -
sdk: '>=3.10.0 <4.0.0'
-
ffi: ^2.2.0
-
win32: ^6.4.0
-
collection: ^1.19.1
-
lints: ^6.1.0
-
test: ^1.31.1
-
dependency_validator: ^5.1.0
-
coverage: ^1.15.1
1.2.0 #
-
sdk: '>=3.7.0 <4.0.0'
-
ffi: ^2.1.4
-
win32: ^5.12.0
-
logging: ^1.3.0
-
resource_portable: ^3.1.2
-
collection: ^1.19.0
-
lints: ^5.1.1
-
test: ^1.25.15
-
dependency_validator: ^5.0.2
-
coverage: ^1.11.1
1.1.5 #
- ffi: ^2.1.2
- win32: ^5.5.0
- collection: ^1.18.0
- lints: ^3.0.0
- test: ^1.25.5
- dependency_validator: ^3.2.3
- coverage: ^1.8.0
1.1.4 #
-
README.md:- Added
Win32 Message Loopsection
- Added
-
Dart CI: update and optimize jobs.
-
ffi: ^2.1.0
-
win32: ^5.0.7
-
test: ^1.24.6
1.1.3 #
WindowMessageLoop:- Added
consumeQueue.
- Added
WindowBase:destroy: tryconsumeQueuebefore retry.close: tryconsumeQueuebefore retry.
1.1.2 #
WindowBase:destroy: returnsbool, retry and warns failed calls.close: retry and warns failed calls.
1.1.1 #
WindowClassColors:- Added
dialogColors
- Added
Dialog: Added alisdialogColorstoWindowClassColors.dialogColors.
1.1.0 #
WindowBase:- Generalize
create.
- Generalize
Window:- Move
setIcontoWindowBase.
- Move
Dialog.create: callensureLoaded.
1.0.12 #
WindowBase:- Added
requestRepaint. - Removed unnecessary calls to
updateWindow.
- Added
1.0.11 #
- export 'src/win32_dialog.dart';
- Added
DialogItem.buttonandDialogItem.text.
1.0.10 #
- Improve
README.mdusage code. win32_gui_example.dart: improve comments.Window:- Added
showMessage,showConfirmationDialogandshowDialog. - Free some pointers.
- Added
- New
Dialog. - New
WindowBase: base class forWindowandDialog. - New
Win32Thread.
1.0.9 #
WindowMessageLoop.runLoopAsync: adjust maximum yield time.
1.0.8 #
Window:- Added
setWindowRoundedCorners - Fix
createbehavior.
- Added
1.0.7 #
Window:- Optimize
setIcon.i - Added
loadIconandloadIconCached.
- Optimize
- const
TextFormatted
1.0.6 #
- Fix
RichEdit.defaultFont.
1.0.5 #
TextFormatted: addedfaceName.RichEdit:- Added
defaultFontanddefaultSystemFont.
- Added
Window:- Added
getSystemDefaultFonts. - Added
minimize,maximize,restore,isMinimized,isMaximizedandgetWindowLongPtr. - Change close/processClose to allow abort of operation.
- Change destroy/processDestroy behavior.
- Added
1.0.4 #
Window:- Added
onCloseandprocessClose. - Renamed
onDestroytoonDestroyed(called afterWM_NCDESTROY). - Added
invalidateRect. - Added
defaultRepaint: customrepaintis only called ifdefaultRepaintis false. - Added
getBitmapDimension.
- Added
RichEdit:- Optimize
setTextFormatted.
- Optimize
1.0.3 #
Window: addedredrawWindow.WindowClassColors: addedbuttonColors.
1.0.2 #
WindowMessageLoop: optimizerunLoopAsyncyield time.- Changed
Window.quitto static.
1.0.1 #
WindowMessageLoop.runLoop/runLoopAsync:- Added
condition.
- Added
pubspec.yaml: fix repository.README.md:- Usage example.
- Added screenshot.
- Adjust example.
1.0.0 #
- Initial version.
