1 // Static Control Test.c
2 
3 //#define WIN32_LEAN_AND_MEAN
4 #include <windows.h>
5 #include <assert.h>
6 
7 #ifndef SS_ENDELLIPSIS
8 #define SS_ENDELLIPSIS	0x00004000L
9 #endif /* SS_ENDELLIPSIS */
10 
11 
12 #define nMaxCtrls 32
13 #define nStaticWidth 384
14 #define nStaticHeight 18
15 
16 HWND g_hwnd = NULL;
17 HINSTANCE g_hInst = 0;
18 int nNextCtrl = 0;
19 HWND g_hwndCtrl[nMaxCtrls];
20 
21 static void CreateStatic ( const char* lpWindowName, DWORD dwStyle )
22 {
23 	int n = nNextCtrl++;
24 	assert ( n < nMaxCtrls );
25 	g_hwndCtrl[n] = CreateWindow (
26 		"STATIC", // lpClassName
27 		lpWindowName, // lpWindowName
28 		WS_VISIBLE|WS_CHILD|dwStyle, // dwStyle
29 		n+2, // x
30 		nStaticHeight*n+1, // y
31 		nStaticWidth, // nWidth
32 		nStaticHeight-1, // nHeight
33 		g_hwnd, // hWndParent
34 		NULL, // hMenu
35 		g_hInst, // hInstance
36 		NULL ); // lParam
37 }
38 
39 LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
40 {
41 	int i;
42 	switch ( msg )
43 	{
44 	case WM_CREATE:
45 		g_hwnd = hwnd;
46 		for ( i = 0; i < nMaxCtrls; i++ )
47 			g_hwndCtrl[i] = NULL;
48 
49 		CreateStatic ( "SS_NOTIFY test (click/double-click here)", SS_NOTIFY );
50 
51 		CreateStatic ( "SS_ENDELLIPSIS test test test test test test test test test test test", SS_ENDELLIPSIS );
52 
53 		CreateStatic ( "SS_CENTER test", SS_CENTER );
54 
55 		CreateStatic ( "SS_RIGHT test", SS_RIGHT );
56 
57 		CreateStatic ( "SS_BLACKFRAME test:", 0 );
58 		CreateStatic ( "this text shouldn't be visible!", SS_BLACKFRAME );
59 
60 		CreateStatic ( "SS_BLACKRECT test:", 0 );
61 		CreateStatic ( "this text shouldn't be visible!", SS_BLACKRECT );
62 
63 		CreateStatic ( "SS_ETCHEDFRAME test:", 0 );
64 		CreateStatic ( "this text shouldn't be visible!", SS_ETCHEDFRAME );
65 
66 		CreateStatic ( "SS_ETCHEDHORZ test:", 0 );
67 		CreateStatic ( "this text shouldn't be visible!", SS_ETCHEDHORZ );
68 
69 		CreateStatic ( "SS_ETCHEDVERT test", 0 );
70 		CreateStatic ( "this text shouldn't be visible!", SS_ETCHEDVERT );
71 
72 		CreateStatic ( "SS_GRAYFRAME test", 0 );
73 		CreateStatic ( "this text shouldn't be visible!", SS_GRAYFRAME );
74 
75 		CreateStatic ( "SS_GRAYRECT test", 0 );
76 		CreateStatic ( "this text shouldn't be visible!", SS_GRAYRECT );
77 
78 		CreateStatic ( "SS_NOPREFIX &test", SS_NOPREFIX );
79 
80 		CreateStatic ( "SS_OWNERDRAW test", SS_OWNERDRAW );
81 
82 		CreateStatic ( "SS_SUNKEN test", SS_SUNKEN );
83 
84 		CreateStatic ( "SS_WHITEFRAME test:", 0 );
85 		CreateStatic ( "this text shouldn't be visible!", SS_WHITEFRAME );
86 
87 		CreateStatic ( "SS_WHITERECT test:", 0 );
88 		CreateStatic ( "this text shouldn't be visible!", SS_WHITERECT );
89 
90 		//if ( creation fails )
91 		//	return 0;
92 		break;
93 
94 	case WM_COMMAND:
95 		if ( HIWORD(wParam) == STN_CLICKED )
96 			SetWindowText ( (HWND)lParam, "SS_NOTIFY:STN_CLICKED!" );
97 		if ( HIWORD(wParam) == STN_DBLCLK )
98 			SetWindowText ( (HWND)lParam, "SS_NOTIFY:STN_DBLCLK!" );
99 		break;
100 
101 	case WM_DRAWITEM:
102 		{
103 			LPDRAWITEMSTRUCT lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
104 			DrawText ( lpDrawItem->hDC, "SS_DRAWITEM test successful!", 28, &(lpDrawItem->rcItem), 0 );
105 		}
106 		break;
107 
108 	case WM_DESTROY:
109 		PostQuitMessage(0);
110 		return 0;
111 	}
112 	return DefWindowProc ( hwnd, msg, wParam, lParam );
113 }
114 
115 HWND RegisterAndCreateWindow (
116 	HINSTANCE hInst,
117 	const char* className,
118 	const char* title )
119 {
120 	WNDCLASSEX wc;
121 	HWND hwnd;
122 
123 	g_hInst = hInst;
124 
125 	wc.cbSize = sizeof (WNDCLASSEX);
126 	wc.lpfnWndProc = WndProc;   // window procedure: mandatory
127 	wc.hInstance = hInst;         // owner of the class: mandatory
128 	wc.lpszClassName = className; // mandatory
129 	wc.hCursor = LoadCursor ( 0, (LPCTSTR)IDC_ARROW ); // optional
130 	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // optional
131 	wc.style = 0;
132 	wc.cbClsExtra = 0;
133 	wc.cbWndExtra = 0;
134 	wc.hIcon = 0;
135 	wc.hIconSm = 0;
136 	wc.lpszMenuName = 0;
137 	if ( !RegisterClassEx ( &wc ) )
138 		return NULL;
139 
140 	hwnd = CreateWindowEx (
141 		0, // dwStyleEx
142 		className, // class name
143 		title, // window title
144 		WS_OVERLAPPEDWINDOW, // dwStyle
145 		CW_USEDEFAULT, // x
146 		CW_USEDEFAULT, // y
147 		CW_USEDEFAULT, // width
148 		CW_USEDEFAULT, // height
149 		NULL, // hwndParent
150 		NULL, // hMenu
151 		hInst, // hInstance
152 		0 ); // lParam
153 
154 	if ( !hwnd )
155 		return NULL;
156 
157 	ShowWindow ( hwnd, SW_SHOW );
158 	UpdateWindow ( hwnd );
159 
160 	return hwnd;
161 }
162 
163 int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdParam, int cmdShow )
164 {
165 	char className [] = "Static Control Test";
166 	HWND hwnd;
167 	MSG msg;
168 	int status;
169 
170 	hwnd = RegisterAndCreateWindow ( hInst, className, "Static Control Test" );
171 
172 	// Message loop
173 	while ((status = GetMessage (& msg, 0, 0, 0)) != 0)
174 	{
175 		if (status == -1)
176 			return -1;
177 		DispatchMessage ( &msg );
178 	}
179 	return msg.wParam;
180 }
181