Skip to content

Commit 324b53a

Browse files
kkent030315robincodex
authored andcommitted
Replace winapi with windows
1 parent 576511d commit 324b53a

File tree

4 files changed

+154
-138
lines changed

4 files changed

+154
-138
lines changed

Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,10 @@ rustc-args = ["--cfg", "windows"]
1818
[dependencies]
1919

2020
[target.'cfg(windows)'.dependencies]
21-
winapi = { version = "0.3", features = ["impl-default","winnt","commoncontrols","commctrl","libloaderapi"] }
22-
widestring = "1.0.2"
21+
windows = { version = "0.61", features = [
22+
"Win32_Foundation",
23+
"Win32_System_LibraryLoader",
24+
"Win32_UI_Controls",
25+
"Win32_UI_WindowsAndMessaging",
26+
] }
27+
widestring = "1.2"

example/src/main.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ fn hyperlink_callback(context: &str) {
1010

1111
unsafe extern "system" fn callback(
1212
hwnd: HWND,
13-
msg: u32,
14-
w_param: usize,
15-
l_param: isize,
13+
msg: TASKDIALOG_NOTIFICATIONS,
14+
w_param: WPARAM,
15+
l_param: LPARAM,
1616
ref_data: *mut TaskDialogConfig,
17-
) -> i32 {
17+
) -> HRESULT {
1818
println!(
1919
"callback: hwnd={:?} msg={} wparam={:#X} lparam={:#X} ref_data={:?}",
20-
hwnd, msg, w_param, l_param, ref_data
20+
hwnd, msg.0, w_param.0, l_param.0, ref_data
2121
);
22-
0
22+
23+
S_OK
2324
}
2425

2526
fn main() {
@@ -161,39 +162,40 @@ fn show_process_bar() {
161162
fn page_navigation() {
162163
unsafe extern "system" fn page1_callback(
163164
_: HWND,
164-
msg: u32,
165-
w_param: usize,
166-
_: isize,
165+
msg: TASKDIALOG_NOTIFICATIONS,
166+
w_param: WPARAM,
167+
_: LPARAM,
167168
ref_data: *mut TaskDialogConfig,
168-
) -> i32 {
169+
) -> HRESULT {
169170
if msg == TDN_NAVIGATED {
170171
} else if msg == TDN_BUTTON_CLICKED {
171172
// TDN_BUTTON_CLICKED
172173

173174
// Note that lifetime is limited in Rust objects
174175
// and we cannot make new struct in stack here.
175176
// Instead we should modify `ref_data`.
176-
if w_param as i32 == 1776 {
177+
if w_param.0 == 1776 {
177178
(*ref_data).window_title = "Page #1".to_owned();
178179
(*ref_data).main_instruction = "Page #1".to_owned();
179180
(*ref_data).buttons = vec![TaskDialogButton {
180181
id: 1777,
181182
text: "Continue".to_owned(),
182183
}];
183184
(*ref_data).navigate_page(&mut *ref_data);
184-
return 1; // S_FALSE
185-
} else if w_param as i32 == 1777 {
185+
return S_FALSE;
186+
} else if w_param.0 == 1777 {
186187
(*ref_data).window_title = "Page #2".to_owned();
187188
(*ref_data).main_instruction = "Page #2".to_owned();
188189
(*ref_data).buttons = vec![TaskDialogButton {
189190
id: 1776,
190191
text: "Back to page #1".to_owned(),
191192
}];
192193
(*ref_data).navigate_page(&mut *ref_data);
193-
return 1; // S_FALSE
194+
return S_FALSE;
194195
}
195196
}
196-
0
197+
198+
S_OK
197199
}
198200

199201
let mut conf = TaskDialogConfig {

src/constants.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#[cfg(windows)]
2-
extern crate winapi;
3-
4-
#[cfg(windows)]
5-
pub use winapi::um::commctrl::{
2+
pub use windows::Win32::UI::Controls::{
63
TDCBF_CANCEL_BUTTON, TDCBF_CLOSE_BUTTON, TDCBF_NO_BUTTON, TDCBF_OK_BUTTON, TDCBF_RETRY_BUTTON,
74
TDCBF_YES_BUTTON, TDF_ALLOW_DIALOG_CANCELLATION, TDF_CAN_BE_MINIMIZED, TDF_ENABLE_HYPERLINKS,
85
TDF_EXPANDED_BY_DEFAULT, TDF_EXPAND_FOOTER_AREA, TDF_NO_DEFAULT_RADIO_BUTTON,

0 commit comments

Comments
 (0)