ReactOS  0.4.14-dev-50-g13bb5e2
multiwin.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 hWnd1;
16  HWND hWnd2;
18 
19  wc.lpszClassName = "MultiClass";
22  wc.hInstance = hInstance;
25  wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
26  wc.lpszMenuName = NULL;
27  wc.cbClsExtra = 0;
28  wc.cbWndExtra = 0;
29  if (RegisterClass(&wc) == 0)
30  {
31  fprintf(stderr, "RegisterClass failed (last error 0x%lX)\n",
32  GetLastError());
33  return(1);
34  }
35 
36  hWnd1 = CreateWindow("MultiClass",
37  "TopLevel1",
39  0,
40  0,
41  320,
42  240,
43  NULL,
44  NULL,
45  hInstance,
46  NULL);
47 
48  hWndChild = CreateWindow("MultiClass",
49  "Child1 of TopLevel1",
51  20,
52  120,
53  200,
54  200,
55  hWnd1,
56  NULL,
57  hInstance,
58  NULL);
59 
60  hWnd2 = CreateWindow("MultiClass",
61  "TopLevel2",
63  400,
64  0,
65  160,
66  490,
67  NULL,
68  NULL,
69  hInstance,
70  NULL);
71 
72  if (! hWnd1 || ! hWnd2 || ! hWndChild)
73  {
74  fprintf(stderr, "CreateWindow failed (last error 0x%lX)\n",
75  GetLastError());
76  return(1);
77  }
78  WindowCount = 2;
79 
82 
83  while(GetMessage(&msg, NULL, 0, 0))
84  {
87  }
88  return msg.wParam;
89 }
90 
92 {
93  PAINTSTRUCT ps;
94  HDC hDC;
95  LONG Style;
96  RECT Client;
97  HBRUSH Brush;
98  static COLORREF Colors[] =
99  {
100  RGB(0x00, 0x00, 0x00),
101  RGB(0x80, 0x00, 0x00),
102  RGB(0x00, 0x80, 0x00),
103  RGB(0x00, 0x00, 0x80),
104  RGB(0x80, 0x80, 0x00),
105  RGB(0x80, 0x00, 0x80),
106  RGB(0x00, 0x80, 0x80),
107  RGB(0x80, 0x80, 0x80),
108  RGB(0xff, 0x00, 0x00),
109  RGB(0x00, 0xff, 0x00),
110  RGB(0x00, 0x00, 0xff),
111  RGB(0xff, 0xff, 0x00),
112  RGB(0xff, 0x00, 0xff),
113  RGB(0x00, 0xff, 0xff),
114  RGB(0xff, 0xff, 0xff)
115  };
116  static unsigned CurrentColor = 0;
117 
118  switch(msg)
119  {
120  case WM_PAINT:
121  hDC = BeginPaint(hWnd, &ps);
123  Brush = CreateSolidBrush(Colors[CurrentColor]);
124  FillRect(hDC, &Client, Brush);
126  CurrentColor++;
127  if (sizeof(Colors) / sizeof(Colors[0]) <= CurrentColor)
128  {
129  CurrentColor = 0;
130  }
131  EndPaint(hWnd, &ps);
132  break;
133 
134  case WM_DESTROY:
136  if (0 == (Style & WS_CHILD) && 0 == --WindowCount)
137  {
138  PostQuitMessage(0);
139  }
140  break;
141 
142  default:
143  return DefWindowProc(hWnd, msg, wParam, lParam);
144  }
145 
146  return 0;
147 }
#define SW_NORMAL
Definition: winuser.h:763
#define DispatchMessage
Definition: winuser.h:5666
BOOL WINAPI TranslateMessage(_In_ const MSG *)
Definition: client.c:29
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define CreateWindow
Definition: winuser.h:5655
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
static HDC
Definition: imagelist.c:92
#define CALLBACK
Definition: compat.h:27
HWND hWnd
Definition: settings.c:17
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
Definition: multiwin.c:8
int cbClsExtra
Definition: winuser.h:3139
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:3145
static UINT WindowCount
Definition: multiwin.c:4
#define IDI_APPLICATION
Definition: winuser.h:699
UINT_PTR WPARAM
Definition: windef.h:207
HBRUSH hbrBackground
Definition: winuser.h:3144
#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
HWND hWnd1
Definition: button.c:416
#define COLOR_WINDOW
Definition: winuser.h:908
WPARAM wParam
Definition: combotst.c:138
int cbWndExtra
Definition: winuser.h:3140
HINSTANCE hInstance
Definition: charmap.c:20
long LONG
Definition: pedump.c:60
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
HCURSOR hCursor
Definition: winuser.h:3143
void Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG style)
Definition: drawing.cpp:160
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
#define DefWindowProc
Definition: ros2win.h:31
#define WM_DESTROY
Definition: winuser.h:1591
#define WS_CAPTION
Definition: pedump.c:624
#define CS_VREDRAW
Definition: winuser.h:653
const DWORD Style
Definition: appswitch.c:71
HWND hWnd2
Definition: button.c:416
DWORD COLORREF
Definition: windef.h:285
Colors
Definition: ansiprsr.h:4
#define RGB(r, g, b)
Definition: wingdi.h:2935
#define WINAPI
Definition: msvc.h:8
#define WM_PAINT
Definition: winuser.h:1602
#define GetWindowLong
Definition: winuser.h:5697
LPCSTR lpszClassName
Definition: winuser.h:3146
#define LoadCursor
Definition: winuser.h:5713
UINT style
Definition: winuser.h:3137
#define GWL_STYLE
Definition: winuser.h:846
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define WS_BORDER
Definition: pedump.c:625
HINSTANCE hInstance
Definition: winuser.h:3141
LRESULT WINAPI MultiWndProc(HWND, UINT, WPARAM, LPARAM)
Definition: multiwin.c:91
unsigned int UINT
Definition: ndis.h:50
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define GetMessage
Definition: winuser.h:5691
WNDPROC lpfnWndProc
Definition: winuser.h:3138
#define msg(x)
Definition: auth_time.c:54
#define IDC_ARROW
Definition: winuser.h:682
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
FILE * stderr
#define RegisterClass
Definition: winuser.h:5737
#define LoadIcon
Definition: winuser.h:5714
LONG_PTR LRESULT
Definition: windef.h:209
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HWND hWndChild[NUM_TABS]
Definition: main.h:75
#define WS_VISIBLE
Definition: pedump.c:620
#define WS_SYSMENU
Definition: pedump.c:629
LPARAM lParam
Definition: combotst.c:139
__analysis_noreturn void WINAPI PostQuitMessage(_In_ int)
HICON hIcon
Definition: winuser.h:3142