windows编程通用控件

1

进度条和滑块控件

2

3

4

5

6

7

8

9

运行

10

用滑块控制进度条

11

12

13

14

15

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<Windows.h>
#include<CommCtrl.h>
#include"resource.h"
INT_PTR CALLBACK Dlgproc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
SendDlgItemMessageW(hwnd, IDC_PROGRESS1,PBM_SETRANGE,0,MAKELPARAM(0,100));
SendDlgItemMessageW(hwnd, IDC_SLIDER1, TBM_SETRANGE, TRUE, MAKELPARAM(0, 100));
SendDlgItemMessageW(hwnd, IDC_PROGRESS1, PBM_SETPOS, 50, 0);
SendDlgItemMessageW(hwnd, IDC_SLIDER1, TBM_SETPOS, TRUE, 80);
break;
}
case WM_CLOSE:
{
EndDialog(hwnd, 0);
}
case WM_HSCROLL:
{
if (GetDlgItem(hwnd, IDC_SLIDER1)==(HWND)lParam)
{
int pos = SendMessageW((HWND)lParam,TBM_GETPOS,0,0);
SendDlgItemMessageW(hwnd, IDC_PROGRESS1,PBM_SETPOS,pos,0);
}
break;
}
default:
return false;
break;
}
return TRUE;
}
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd
)
{
DialogBoxW(hInstance, MAKEINTRESOURCEW(IDD_DIALOG1),NULL, Dlgproc);
return 0;
}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!