The BB2TDE01.C example creates two push buttons. The first push button is created by the CreateWindow function direct over the two BB2TD touch panel keys with the default scan codes 0x24 and 0x25. For this button position, the CreateWindow function needs the parameters width= 160 dots, height= 60 dots, x= 395 dots, y= 100 dots when the application window uses the WS_OVERLAPPEDWINDOW style (title bar and sizing border).
// Create and show two PushButton Controls
hButton1= CreateWindow ("BUTTON", "Button1",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
395, 100, 160, 60, hWnd, BUTTON1,
ghInstance, NULL);
ShowWindow (hButton1, SW_SHOW);
// ... second PushButton Control
hButton2= CreateWindow ("BUTTON", "Button2",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
395, 275, 160, 60, hWnd, BUTTON2,
ghInstance, NULL);
ShowWindow (hButton2, SW_SHOW);
The second push button is created over the BB2TD touch panel keys with the default
scan codes 0x06 and 0x07. For this button position, the CreateWindow function
needs the parameters width= 160 dots, height= 60 dots, x= 395 dots, y= 275
dots. The parameters for width and height are the size of the buttons. The
parameters for x and y are the x- coordinate and the y- coordinate within the client
area of the BB2TDE01.C example program application window. The constants BUTTON1 and
BUTTON2 identifies the push button. This identifiers are important for mouse
operation and not in BB2TD Windows- based application programs. The push buttons
belongs to the BUTTON window class and uses the BS_PUSHBUTTON style. The push buttons
are child windows and will be visible when first created.
By default, Windows push buttons are for mouse operation. When the mouse cursor is inside the push button, pressing the mouse button causes the button to repaint itself using 3D- style shading to appear as if itīs been depressed. Releasing the mouse button restores the push button original appearance. On the BB2TD the push buttons are operated by the touch panel keys. We must simulate a push button flash by sending the push button a BM_SETSTATE message:
SendMessage (hButton1, BM_SETSTATE, 1, 0l); //Button1 is depressed
SendMessage (hButton1, BM_SETSTATE, 0, 0l); //Button1 returns to normal
If a BB2TD user is depressing the touch panel keys over Button1, Windows sends
a WM_KEYDOWN message together with the OEM Scan Code 0x24 or 0x25 to the BB2TDE01.C
windows procedure. In this case, the windows procedure calls the SendMessage
function with the parameters hButton1, BM_SETSTATE, and 1 for
Button1. If the user release the touch panel keys over Button1, Windows sends
a WM_KEYUP message together with the OEM Scan Code 0x24 or 0x25 to the windows procedure.
Now, the windows procedure calls the SendMessage function with the parameters
hButton1, the message BM_SETSTATE, and 0 for Button1.
SendMessage (hButton2, BM_SETSTATE, 1, 0l); //Button2 is depressed
SendMessage (hButton2, BM_SETSTATE, 0, 0l); //Button2 returns to normal
It is the same with Button2. If a BB2TD user is depressing the touch panel keys over
Button2, Microsoft Windows sends the WM_KEYDOWN message together with the OEM Scan Code 0x06 or
0x07 to the BB2TDE01.C windows procedure. The windows procedure calls the SendMessage
function with the parameters hButton2, BM_SETSTATE, and 1 for
Button2. If the user release the touch panel keys over Button2, Windows sends
a WM_KEYUP message together with the OEM Scan Code 0x06 or 0x07 to the windows procedure.
The windows procedure calls the SendMessage function with the parameters
hButton2, BM_SETSTATE, and 0 for Button2.
// File...: BB2TDE01.C (c) SOFTWARE SYSTEMS 1997
// Version: 1.00
// Date...: 31.Aug.1997
#include windows.h
#define BUTTON1 100
#define BUTTON2 200
HANDLE ghInstance; // Global Instance
RECT rect; // Left side of client area
short cxChar, cyChar, // Font size (char height & width)
LineCount, MaxLineCount; // Lines in the left side of client area
BOOL ScrollFlag; // Flag: Scroll left side yes/no
// Function Prototyps
void MessageInfo (HWND, char *, int);
long FAR PASCAL WndFunction (HWND, WORD, WORD, LONG);
//****************************************************************************************
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
static char szAppName[]= "BB2TD-CONTROLS",
szTitleBar[]= "BB2TD Controls Example 01";
HWND hWnd;
WNDCLASS wndclass;
MSG msg;
// Register Class
ghInstance= hInstance;
if (! hPrevInstance) {
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndFunction;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground= GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName= szAppName;
RegisterClass (&wndclass);
}
// Create window with 640 * 480 dots at position x= y= 0 and show window
hWnd= CreateWindow (szAppName,
szTitleBar,
WS_OVERLAPPEDWINDOW,
0, // x position for this window
0, // y position for this window
640, // window width is 640 dots
480, // window height is 480 dots
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);
// Dispatch Message or exit program
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return (msg.wParam);
}
//******************************************************
void MessageInfo (HWND hWnd, char *szMessage, int Count)
{
HDC hDC;
// ... scroll left side of client area if necessary
if (ScrollFlag == TRUE)
ScrollWindow (hWnd, 0, -cyChar, &rect, &rect);
if (LineCount == MaxLineCount) ScrollFlag= TRUE;
// ... write message to left side of client area
hDC= GetDC (hWnd);
SelectObject (hDC, GetStockObject (SYSTEM_FIXED_FONT));
TextOut (hDC, cxChar, rect.top + (cyChar * LineCount), szMessage, Count);
ReleaseDC (hWnd, hDC);
ValidateRect (hWnd, NULL);
if (LineCount != MaxLineCount) LineCount++;
}
//**************************************************************************
long FAR PASCAL WndFunction (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam)
{
static HWND hButton1, hButton2;
int OemScanCode;
HDC hDC;
TEXTMETRIC tm;
switch (wMsg) {
// Create and show two PushButton Controls
case WM_CREATE: hButton1= CreateWindow ("BUTTON", "Button1",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
395, 100, 160, 60, hWnd, BUTTON1,
ghInstance, NULL);
ShowWindow (hButton1, SW_SHOW);
// ... second PushButton Control
hButton2= CreateWindow ("BUTTON", "Button2",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
395, 275, 160, 60, hWnd, BUTTON2,
ghInstance, NULL);
ShowWindow (hButton2, SW_SHOW);
// ... we need the font size (char height & width)
hDC= GetDC (hWnd);
SelectObject (hDC, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hDC, &tm);
cxChar= tm.tmAveCharWidth;
cyChar= tm.tmHeight;
ReleaseDC (hWnd, hDC);
rect.top= cyChar / 2;
break;
// ... we need the current size of the client area
case WM_SIZE: rect.right = rect.left + (35 * cxChar);
rect.bottom= HIWORD (lParam);
UpdateWindow (hWnd);
LineCount= 0;
MaxLineCount= ((rect.bottom - rect.top) / cyChar) - 1;
ScrollFlag= FALSE;
return (0);
// ... set focus allways to main window
case WM_COMMAND: MessageBeep (0);
SetFocus (hWnd);
break;
// ... check here for KEY DOWN, use OEM Scan Code
case WM_KEYDOWN: OemScanCode= HIWORD (lParam) & 0x00ff;
switch (OemScanCode) {
case 0x24: SendMessage (hButton1, BM_SETSTATE, 1, 0l);
MessageInfo (hWnd, "WM_KEYDOWN Button1, SC= 0x24...", 31);
break;
case 0x25: SendMessage (hButton1, BM_SETSTATE, 1, 0l);
MessageInfo (hWnd, "WM_KEYDOWN Button1, SC= 0x25...", 31);
break;
case 0x06: SendMessage (hButton2, BM_SETSTATE, 1, 0l);
MessageInfo (hWnd, "WM_KEYDOWN Button2, SC= 0x06...", 31);
break;
case 0x07: SendMessage (hButton2, BM_SETSTATE, 1, 0l);
MessageInfo (hWnd, "WM_KEYDOWN Button2, SC= 0x07...", 31);
break;
}
MessageBeep (0);
break;
// ... check here for KEY UP, use OEM Scan Code
case WM_KEYUP: OemScanCode= HIWORD (lParam) & 0x00ff;
switch (OemScanCode) {
case 0x24: SendMessage (hButton1, BM_SETSTATE, 0, 0l);
MessageInfo (hWnd, "WM_KEYUP Button1, SC= 0x24...", 31);
break;
case 0x25: SendMessage (hButton1, BM_SETSTATE, 0, 0l);
MessageInfo (hWnd, "WM_KEYUP Button1, SC= 0x25...", 31);
break;
case 0x06: SendMessage (hButton2, BM_SETSTATE, 0, 0l);
MessageInfo (hWnd, "WM_KEYUP Button2, SC= 0x06...", 31);
break;
case 0x07: SendMessage (hButton2, BM_SETSTATE, 0, 0l);
MessageInfo (hWnd, "WM_KEYUP Button2, SC= 0x07...", 31);
break;
}
MessageBeep (0);
break;
// ... destroy window
case WM_DESTROY: PostQuitMessage (0);
return (0);
}
return (DefWindowProc (hWnd, wMsg, wParam, lParam));
}
If you run this example program on your desktop or notebook PC, please use the keyboard for operating Button1 and Button2. The keys with the letters J (OEM Scan Code 0x24) and K (OEM Scan Code 0x25) works with Button1. The digits 5 (OEM Scan Code 0x06) and 6 (OEM Scan Code 0x07) works with Button2. On the BB2TD, the position of Button1 is direct over the touch panel keys with the default scan codes 0x24 and 0x25, and the position of Button2 on the BB2TD COLOR VGA TFT LCD is over the touch panel keys with the default scan codes 0x06 and 0x07.
The position of the BB2TD touch panel keys and the default scan codes are fix. It is important, to write MS Windows- based BB2TD applications with a full screen (640 * 480 dots) application window which donīt offer the title bar, the system menue box, the maximize box, the minimize box, and the sizing border. Which such application windows, there is no way for the user to move the application window on the screen. The position of buttons and other controls is then also fix.