pub unsafe fn runloop(accel: HACCEL) -> BOOLExpand description
A basic winapi runloop.
This runloop blocks on receiving messages and dispatches them to windows. It exits
on WM_QUIT.
It is tempting to try to get fancier with runloops, for example waiting on semaphores
or other events, but these strategies are risky. In particular, the main runloop is not
always in control; when the window is being resized, or a modal dialog is open, then
that runloop takes precedence. For waking the UI thread from another thread,
SendMessage is probably the best bet.
ยงSafety
The accel argument must be a valid HACCEL handle (though null_mut() is valid).
Examples found in repository?
examples/hello-win.rs (line 49)
33fn main() {
34 unsafe {
35 let icon = LoadIconW(0 as HINSTANCE, IDI_APPLICATION);
36 let cursor = LoadCursorW(0 as HINSTANCE, IDC_ARROW);
37 let brush = CreateSolidBrush(0xff_ff_ff);
38 let win_class = WindowClass::builder("rust")
39 .icon(icon)
40 .cursor(cursor)
41 .background(brush)
42 .build()
43 .unwrap();
44 let hwnd = WindowBuilder::new(MyWindowProc, &win_class)
45 .name("win-win example")
46 .style(WS_OVERLAPPEDWINDOW)
47 .build();
48 ShowWindow(hwnd, SW_SHOWNORMAL);
49 win_win::runloop(null_mut());
50 }
51}