ReactOS  0.4.12-dev-432-g3463b2d
buttontst2.c
Go to the documentation of this file.
1 #include <windows.h>
2 #include <stdio.h>
3 
6 
7 int WINAPI
9  HINSTANCE hPrevInstance,
10  LPSTR lpszCmdLine,
11  int nCmdShow)
12 {
13  WNDCLASS wc;
14  MSG msg;
15  HWND hWnd;
16  HWND hbtn[26];
17 
18  wc.lpszClassName = "ButtonTest";
21  wc.hInstance = hInstance;
25  wc.lpszMenuName = NULL;
26  wc.cbClsExtra = 0;
27  wc.cbWndExtra = 0;
28  if (RegisterClass(&wc) == 0)
29  {
30  fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
31  GetLastError());
32  return(1);
33  }
34 
35  hWnd = CreateWindow("ButtonTest",
36  "Button Test",
38  0,
39  0,
42  NULL,
43  NULL,
44  hInstance,
45  NULL);
46  if (hWnd == NULL)
47  {
48  fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
49  GetLastError());
50  return(1);
51  }
52 
56 
57  ShowWindow(hWnd, nCmdShow);
58 
59  hbtn[0] = CreateWindow(
60  "BUTTON","BS_DEFPUSHBUTTON",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
61  10, 10, 200, 40, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
62 
63  hbtn[1] = CreateWindow(
64  "BUTTON","BS_3STATE",WS_VISIBLE | WS_CHILD | BS_3STATE,
65  10, 60, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
66 
67  hbtn[2] = CreateWindow(
68  "BUTTON","BS_AUTO3STATE",WS_VISIBLE | WS_CHILD | BS_AUTO3STATE,
69  10, 90, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
70 
71  hbtn[3] = CreateWindow(
72  "BUTTON","BS_AUTOCHECKBOX",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
73  10, 120, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
74 
75  hbtn[4] = CreateWindow(
76  "BUTTON","BS_AUTORADIOBUTTON",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
77  10, 150, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
78 
79  hbtn[5] = CreateWindow(
80  "BUTTON","BS_CHECKBOX",WS_VISIBLE | WS_CHILD | BS_CHECKBOX,
81  10, 180, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
82 
83  hbtn[6] = CreateWindow(
84  "BUTTON","BS_GROUPBOX",WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
85  10, 210, 200, 80, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
86 
87  hbtn[7] = CreateWindow(
88  "BUTTON","BS_PUSHBUTTON",WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
89  20, 230, 180, 30, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
90 
91  hbtn[8] = CreateWindow(
92  "BUTTON","BS_RADIOBUTTON",WS_VISIBLE | WS_CHILD | BS_RADIOBUTTON,
93  10, 300, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
94 
95  hbtn[9] = CreateWindow(
96  "BUTTON","BS_AUTORADIOBUTTON",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
97  220, 160, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
98 
99  hbtn[10] = CreateWindow(
100  "BUTTON","BS_DEFPUSHBUTTON|BS_BOTTOM",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_BOTTOM,
101  220, 10, 250, 40, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
102 
103  hbtn[11] = CreateWindow(
104  "BUTTON","BS_DEFPUSHBUTTON|BS_LEFT",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_LEFT,
105  480, 10, 250, 40, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
106 
107  hbtn[12] = CreateWindow(
108  "BUTTON","BS_DEFPUSHBUTTON|BS_RIGHT|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_RIGHT |BS_MULTILINE,
109  740, 10, 150, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
110 
111  hbtn[13] = CreateWindow(
112  "BUTTON","BS_AUTORADIOBUTTON|BS_TOP",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_TOP,
113  220, 60, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
114 
115  // Other Combinations
116 
117  hbtn[14] = CreateWindow(
118  "BUTTON","BS_AUTORADIOBUTTON|BS_BOTTOM|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_BOTTOM | BS_MULTILINE,
119  480, 60, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
120 
121  hbtn[15] = CreateWindow(
122  "BUTTON","BS_AUTORADIOBUTTON|BS_LEFT",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_LEFT,
123  740, 80, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
124 
125  hbtn[16] = CreateWindow(
126  "BUTTON","BS_AUTORADIOBUTTON|BS_RIGHT|BS_TOP",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_RIGHT | BS_TOP,
127  220, 130, 200, 20, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
128 
129  hbtn[17] = CreateWindow(
130  "BUTTON","BS_AUTORADIOBUTTON|BS_TOP|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_TOP| BS_MULTILINE,
131  480, 130, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
132 
133  hbtn[18] = CreateWindow(
134  "BUTTON","BS_AUTOCHECKBOX|BS_BOTTOM|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_BOTTOM | BS_MULTILINE,
135  740, 130, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
136 
137  hbtn[19] = CreateWindow(
138  "BUTTON","BS_AUTOCHECKBOX|BS_TOP|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE,
139  480, 190, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
140 
141  hbtn[20] = CreateWindow(
142  "BUTTON","BS_AUTOCHECKBOX|BS_LEFT|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_LEFT | BS_MULTILINE,
143  220, 230, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
144 
145  hbtn[21] = CreateWindow(
146  "BUTTON","BS_AUTOCHECKBOX|BS_RIGHT|BS_MULTILINE",WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_RIGHT | BS_MULTILINE,
147  480, 240, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
148 
149  hbtn[22] = CreateWindow(
150  "BUTTON","BS_GROUPBOX|BS_TOP",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_TOP,
151  10, 340, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
152 
153  hbtn[23] = CreateWindow(
154  "BUTTON","BS_GROUPBOX|BS_BOTTOM",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_BOTTOM,
155  10, 410, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
156 
157  hbtn[24] = CreateWindow(
158  "BUTTON","BS_GROUPBOXBOX|BS_LEFT",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_LEFT,
159  520, 340, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
160 
161  hbtn[25] = CreateWindow(
162  "BUTTON","BS_GROUPBOX|BS_RIGHT|BS_BOTTOM",WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_BOTTOM | BS_RIGHT,
163  300, 340, 200, 60, hWnd, NULL, (HINSTANCE) GetWindowLongPtr(hWnd, GWLP_HINSTANCE),NULL);
164 
165  while(GetMessage(&msg, NULL, 0, 0))
166  {
169  }
170 
171  DeleteObject(tf);
172 
173  return msg.wParam;
174 }
175 
177 {
178  PAINTSTRUCT ps;
179  HDC hDC;
180 
181  switch(msg)
182  {
183  case WM_PAINT:
184  hDC = BeginPaint(hWnd, &ps);
185  SelectObject(hDC, tf);
186  EndPaint(hWnd, &ps);
187  break;
188 
189  case WM_DESTROY:
190  PostQuitMessage(0);
191  break;
192 
193  case WM_COMMAND:
194  switch(HIWORD(wParam))
195  {
196  case BN_CLICKED:
197  printf("BUTTON CLICKED !\n");
198  break;
199  case BN_DBLCLK:
200  printf("BUTTON DOUBLE-CLICKED !\n");
201  break;
202  case BN_PUSHED:
203  printf("BUTTON PUSHED !\n");
204  break;
205  case BN_PAINT:
206  printf("BUTTON PAINTED !\n");
207  break;
208  case BN_UNPUSHED:
209  printf("BUTTON UNPUSHED !\n");
210  break;
211 
212  }
213  break;
214 
215  default:
216  return DefWindowProc(hWnd, msg, wParam, lParam);
217  }
218  return 0;
219 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BS_3STATE
Definition: pedump.c:656
#define HDC
Definition: msvc.h:22
#define BS_LEFT
Definition: winuser.h:265
#define DispatchMessage
Definition: winuser.h:5631
BOOL WINAPI TranslateMessage(_In_ const MSG *)
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define DEFAULT_QUALITY
Definition: wingdi.h:435
#define CreateWindow
Definition: winuser.h:5620
#define FF_DONTCARE
Definition: wingdi.h:447
#define BS_RIGHT
Definition: winuser.h:274
#define BS_RADIOBUTTON
Definition: pedump.c:655
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define CALLBACK
Definition: compat.h:27
#define BS_DEFPUSHBUTTON
Definition: pedump.c:652
HWND hWnd
Definition: settings.c:17
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
int cbClsExtra
Definition: winuser.h:3118
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define CS_HREDRAW
Definition: winuser.h:648
LPCSTR lpszMenuName
Definition: winuser.h:3124
#define IDI_APPLICATION
Definition: winuser.h:699
#define BN_DBLCLK
Definition: winuser.h:1887
HBRUSH hbrBackground
Definition: winuser.h:3123
#define WS_CHILD
Definition: pedump.c:617
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
char * LPSTR
Definition: xmlstorage.h:182
#define BS_GROUPBOX
Definition: pedump.c:658
WPARAM wParam
Definition: combotst.c:138
UINT_PTR WPARAM
Definition: windef.h:207
LRESULT WINAPI MainWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: buttontst2.c:176
int cbWndExtra
Definition: winuser.h:3119
HINSTANCE hInstance
Definition: charmap.c:20
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
LONG_PTR LPARAM
Definition: windef.h:208
#define FIXED_PITCH
Definition: wingdi.h:443
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
#define TA_BASELINE
Definition: wingdi.h:927
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
HCURSOR hCursor
Definition: winuser.h:3122
#define CW_USEDEFAULT
Definition: winuser.h:225
UINT msg
Definition: msvc.h:92
smooth NULL
Definition: ftsmooth.c:416
#define BS_AUTOCHECKBOX
Definition: pedump.c:654
#define BS_CHECKBOX
Definition: pedump.c:653
#define BS_AUTO3STATE
Definition: pedump.c:657
#define GRAY_BRUSH
Definition: wingdi.h:897
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: buttontst2.c:8
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
HFONT tf
Definition: buttontst2.c:4
#define CS_VREDRAW
Definition: winuser.h:653
#define BS_MULTILINE
Definition: winuser.h:267
#define BS_TOP
Definition: winuser.h:277
unsigned int UINT
Definition: ndis.h:50
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
#define BN_CLICKED
Definition: winuser.h:1886
#define WM_PAINT
Definition: winuser.h:1602
#define BN_PUSHED
Definition: winuser.h:1893
#define WM_COMMAND
Definition: winuser.h:1716
LPCSTR lpszClassName
Definition: winuser.h:3125
#define BN_PAINT
Definition: winuser.h:1892
#define WINAPI
Definition: msvc.h:20
#define LoadCursor
Definition: winuser.h:5678
#define BS_PUSHBUTTON
Definition: pedump.c:651
HFONT WINAPI CreateFontA(_In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCSTR)
UINT style
Definition: winuser.h:3116
static HDC hDC
Definition: 3dtext.c:33
#define BS_AUTORADIOBUTTON
Definition: pedump.c:660
HINSTANCE hInstance
Definition: winuser.h:3120
#define BS_BOTTOM
Definition: winuser.h:259
#define GetMessage
Definition: winuser.h:5656
#define FW_NORMAL
Definition: wingdi.h:372
WNDPROC lpfnWndProc
Definition: winuser.h:3117
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define GWLP_HINSTANCE
Definition: winuser.h:850
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
#define HIWORD(l)
Definition: typedefs.h:246
FILE * stderr
#define RegisterClass
Definition: winuser.h:5702
#define LoadIcon
Definition: winuser.h:5679
#define GetWindowLongPtr
Definition: treelist.c:73
#define ANSI_CHARSET
Definition: wingdi.h:382
#define BN_UNPUSHED
Definition: winuser.h:1896
LONG_PTR LRESULT
Definition: windef.h:209
#define WS_VISIBLE
Definition: pedump.c:620
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
#define printf
Definition: config.h:203
HICON hIcon
Definition: winuser.h:3121