/* static.c static child window controls with variable numeric output */
#include <windows.h>
#include "static.h"
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
HWND hWnd ; /* the window's "handle" */
MSG msg ; /* a message structure */
WNDCLASS wndclass ; /* window class structure */
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (hInstance, "MYICON") ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = "MYMENU" ;
wndclass.lpszClassName = "MyClass" ;
if (!RegisterClass (&wndclass))
return 0 ;
hWnd = CreateWindow ("MyClass", "Static Control Example",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ;
ShowWindow (hWnd, nCmdShow) ;
UpdateWindow (hWnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return (msg.wParam) ;
}
LPARAM CALLBACK WndProc (HWND hWnd, UINT wMessage,
WPARAM wParam, LPARAM lParam)
{
static HWND hStaticText, hStaticIcon, hStaticRect ;
HINSTANCE hInstance ;
static char cBuf[50];
static int nn=0; /* test message counter for display in static control */
switch (wMessage) /* process windows messages */
{
case WM_CREATE: /* program is just starting */
/* get the instance handle */
hInstance = (HINSTANCE)GetWindowLong (hWnd, GWL_HINSTANCE) ;
/* create three static controls */
hStaticText = CreateWindow ("STATIC", "This is static text.",
WS_CHILD | SS_CENTER,
10, 10, 130, 60,
hWnd, NULL, hInstance, NULL) ;
hStaticIcon = CreateWindow ("STATIC", "MYICON",
WS_CHILD | SS_ICON,
150, 10, 0, 0, /* icon height & width used */
hWnd, NULL, hInstance, NULL) ;
hStaticRect = CreateWindow ("STATIC", "",
WS_CHILD | SS_GRAYRECT,
10, 80, 200, 30,
hWnd, NULL, hInstance, NULL) ;
/* display the controls */
ShowWindow (hStaticText, SW_SHOWNORMAL) ;
ShowWindow (hStaticIcon, SW_SHOWNORMAL) ;
ShowWindow (hStaticRect, SW_SHOWNORMAL) ;
break ;
case WM_COMMAND:
switch (LOWORD(wParam)) /* menu items */
{
case IDM_CHANGE: /* change static text */
SetWindowText (hStaticText,
"New Text Via SetWindowText( ).") ;
break ;
case IDM_SEND: /* change static text */
wsprintf(cBuf, "This is test %d ", nn);
nn++;
SendMessage (hStaticText, WM_SETTEXT, 0,
(LPARAM) cBuf ) ;
break ;
case IDM_QUIT:
DestroyWindow (hWnd) ; /* destroy window, */
break ; /* terminating application */
}
break ;
case WM_DESTROY: /* stop application */
PostQuitMessage (0) ;
break ;
default: /* default windows message processing */
return DefWindowProc (hWnd, wMessage, wParam, lParam) ;
}
return (0) ;
}