home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
alckey
/
alckey.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-08
|
20KB
|
616 lines
/****************************************************************************
PROGRAM: alckey
PURPOSE: Microsoft Sample Application that demonstrates ALC_ flags
and the ShowKeyboard API for Windows for Pens.
Author: Cynthia G. Anderson,
PSS Developer Support, Windows SDK Developer Support
Created: 9/15/92
FUNCTIONS:
WinMain() - calls initialization function, processes message loop
MainWndProc() - processes messages
About() - processes messages for "About" dialog box
InitApplication() - initializes window data and registers window
InitInstance() - saves instance handle and creates main window
AlcDlgProc() - Dialog procedure for setting ALC options
SetAlcBits() - sets bits if ALC_BITMAP selected in ALC Dialog
****************************************************************************/
// COPYRIGHT:
//
// (C) Copyright Microsoft Corp. 1993. All rights reserved.
//
// You have a royalty-free right to use, modify, reproduce and
// distribute the Sample Files (and/or any modified version) in
// any way you find useful, provided that you agree that
// Microsoft has no warranty obligations or liability for any
// Sample Application Files which are modified.
//
#include "windows.h"
#include "penwin.h"
#include "string.h"
#include "math.h"
#include "stdlib.h"
#include "alckey.h"
int _pascal WinMain( HANDLE, HANDLE, LPSTR, int );
long _far _pascal MainWndProc( HWND, unsigned, WORD, LONG );
BOOL _far _pascal About( HWND, unsigned, WORD, LONG );
BOOL _far _pascal AlcDlgProc( HWND, unsigned, WORD, LONG );
static BOOL InitApplication( HANDLE );
static BOOL InitInstance( HANDLE, int );
VOID SetAlcBits (LPRC lprc, LPSTR lp);
static HANDLE hInst;
static HWND hwnd; /* handle to main window */
static HWND hWndHedit, hWndBedit; /* handle to child windows..hedit and bedit */
static HWND hWndKeyBdButton; /* handle to pen windows keyboard button*/
static HWND hWndAlcButton; /* handle to alc settings button */
static HWND heditFocusWnd = NULL; //keeper of the last window to have focus
static HWND hPenWin; /* handle to penwin.dll if present */
static HBITMAP hKBUp, hKBDown; /* showkeyboard bitmaps handles */
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
****************************************************************************/
int _pascal WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if (hPrevInstance == 0)
if (InitApplication(hInstance) == 0)
return (FALSE);
if (InitInstance(hInstance, nCmdShow) == 0)
return (FALSE);
while (GetMessage(&msg, 0, 0, 0) != 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (msg.wParam);
}
/****************************************************************************
FUNCTION: InitApplication(HANDLE)
PURPOSE: Initializes window data and registers window class
****************************************************************************/
static BOOL InitApplication(HANDLE hInstance)
{
WNDCLASS wc;
char szMenu[11], szClass[12];
LoadString (hInstance, ID_MENUSTR, szMenu, sizeof (szMenu));
LoadString (hInstance, ID_CLASSSTR, szClass, sizeof (szClass));
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, "ALCKEY");
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW+1 ;
wc.lpszMenuName = szMenu;
wc.lpszClassName = szClass;
return (RegisterClass(&wc));
}
/****************************************************************************
FUNCTION: InitInstance(HANDLE, int)
PURPOSE: Saves instance handle and creates main window
****************************************************************************/
static BOOL InitInstance(HANDLE hInstance, int nCmdShow)
{
char szClass[12], szTitle[40];
LoadString (hInstance, ID_CLASSSTR, szClass, sizeof (szClass));
LoadString (hInstance, ID_CAPTIONSTR, szTitle, sizeof (szTitle));
hInst = hInstance;
hwnd = CreateWindow(
szClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
hInstance,
0 );
if (hwnd == 0 )
return ( FALSE );
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return (TRUE);
}
/****************************************************************************
FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages
****************************************************************************/
long _far _pascal MainWndProc(HWND hWnd, unsigned message,
WORD wParam, LONG lParam)
{
FARPROC lpProcAbout, lpProcAlcDlg;
char szDlgBox[9], szMsgBoxCap[12], szStatus1[14], szStatus2[14];
char szAlcDlgBox[10];
LoadString (hInst, ID_DLGBOX, szDlgBox, sizeof (szDlgBox));
LoadString (hInst, ID_MSGBOXCAP, szMsgBoxCap, sizeof (szMsgBoxCap));
LoadString (hInst, ID_STATUS1, szStatus1, sizeof (szStatus1));
LoadString (hInst, ID_STATUS2, szStatus2, sizeof (szStatus2));
LoadString (hInst, ID_ALCDLGBOX, szAlcDlgBox, sizeof(szAlcDlgBox));
switch ( message )
{
case WM_CREATE:
{
RECT crect;
int x,y,cx,cy;
//create keyboard button top,left corner
x=y=0;
cx=cy=40; //make buttons 40 pixels square
hWndKeyBdButton = CreateWindow(
(LPSTR)"button",
(LPSTR)"ShowKeyBoard",
WS_CHILD|WS_VISIBLE | WS_BORDER|BS_OWNERDRAW,
x,
y,
cx,
cy,
hWnd,
IDC_KEYBDBUTTON,
GetWindowWord(hWnd, GWW_HINSTANCE),
(LPSTR)NULL);
//load up the keyboard bitmaps, discard when app closes.
hPenWin = GetSystemMetrics(SM_PENWINDOWS);
hKBDown = LoadBitmap(hPenWin, MAKEINTRESOURCE(OBM_SKBBTNDOWN));
hKBUp = LoadBitmap(hPenWin, MAKEINTRESOURCE(OBM_SKBBTNUP));
//create alc settings button top,left corner next to keyboard button
x=40; y=0;
cx=cy=40;
hWndAlcButton = CreateWindow(
(LPSTR)"button",
(LPSTR)"ALC",
WS_CHILD|WS_VISIBLE | WS_BORDER,
x,
y,
cx,
cy,
hWnd,
IDC_ALCBUTTON,
GetWindowWord(hWnd, GWW_HINSTANCE),
(LPSTR)NULL);
// create two edit controls, an hedit and a bedit
GetClientRect(hWnd, &crect);
x = (crect.right-crect.left)/8;
cx = (crect.right-crect.left)*4/8;
y = (crect.bottom-crect.top)/8;
cy = (crect.bottom-crect.top)*2/8;
hWndHedit = CreateWindow(
(LPSTR)"hedit",
(LPSTR)NULL,
WS_CHILD|WS_VISIBLE |ES_MULTIL