📄 main.cpp
字号:
///////////////////////////////////////////////////////////
// NAME: main.cpp
// DESCRIPTION: The entry point fo this application
// This demo application is only intended to emulate the Siemens OptiSet
// MWI (Message Waiting Indicator). It will send and delete messages to any
// user selected extension. This will turn the MWI light on and off. This demo
// follows the keystroke sequences entered on OptiSet phones to accomplished sending and
// deleting messages. No other commands or key sequences are incorporated into
// this demo.
//////////////////////////////////////////////////////////
#define STRICT
#include <windows.h>
#include <windowsx.h>
#include <winuser.h>
#include <stdio.h>
#include <srllib.h>
#include <dxxxlib.h>
#include "resource.h"
#include "main.h"
#include "commands.h"
#include "dlgfunc.h"
// Main Window Globals
HINSTANCE g_hInst;
HDC g_hMemdc; // Handle for virtual window
HWND g_hMainWnd = NULL; // Main Window handle
int g_nMaxx; // Global coorinate for paint
int g_nMaxy; // Global coorinate for paint
HMENU g_hMenu; // Global menu handle
HCURSOR g_hCursor; // Handle for hour glass cursor
HCURSOR g_hCursorA; // Handle for arrow cursor
// Trace Window Globals
HINSTANCE g_hTraceInst;
HWND g_hTraceWnd = NULL;
HDC g_hTraceMemdc; // Handle for virtual trace window
int g_nTraceMaxx; // Global coorinate for paint
int g_nTraceMaxy; // Global coorinate for paint
HANDLE g_hTraceLog = NULL; // Handle to trace log file
BOOL g_bTraceLog = FALSE; // Boolean flag to write to log
// Dialog Box Globals
HWND g_hDlg; // Global dialog handle
// Test Globals
TESTINFO g_TestInfo; // Test settings info structure
CHANINFO g_ChanInfo[MAXCHAN+1]; // Channel info structure
// Error log Global handle
HANDLE g_hErrorLog = NULL;
// Generic results information logging handle
HANDLE g_hResultsLog = NULL;
// Status window handle
HWND g_hStatusWnd;
///////////////////////////////////////////////////////////
// NAME: WinMain
// DESCRIPTION:
//
//
//////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASS wcl;
MSG msg;
long lWinOps = WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_SYSMENU|WS_CLIPCHILDREN;
BOOL bRet;
// Load and get handle to cursors
g_hCursor = LoadCursor(NULL, IDC_WAIT); // Hour glass cursor
g_hCursorA = LoadCursor(NULL, IDC_ARROW); // Arrow cursor
// Initialize the error and trace log
bRet = InitializeLogs();
if (!bRet)
return(-1);
// Initialize the test parameter defaults
InitializeTestDefaults();
// Initialize Main windows parameters
g_hInst = hInstance;
g_hMenu = LoadMenu(g_hInst,MAKEINTRESOURCE(IDR_MAINMENU));
ZeroMemory(&wcl,sizeof(wcl));
// Prepare to register the main window class
wcl.lpfnWndProc = MainWndProc;
wcl.hInstance = g_hInst;
wcl.lpszClassName = MAINWINCLASSNAME;
wcl.lpfnWndProc = MainWndProc;
wcl.hbrBackground = (HBRUSH)(GetStockObject(WHITE_BRUSH));
wcl.hIcon = LoadIcon(g_hInst,MAKEINTRESOURCE(IDI_APPICON));
wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
// Register the Main window class
RegisterClass(&wcl);
// Prepare to register the trace window class
wcl.lpszClassName = TRACEWINCLASSNAME;
wcl.lpfnWndProc = TraceWndProc;
// Register the trace window class
RegisterClass(&wcl);
// Create the main window
g_hMainWnd=CreateWindowEx(0, MAINWINCLASSNAME, "Siemens Optiset MWI Demo",
lWinOps, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, g_hMenu,
g_hInst, NULL);
SetCursor(g_hCursorA); // Turn on arrow cursor
// Message Processing Loop
while (GetMessage(&msg, NULL,0,0))
{
if (!IsDialogMessage(g_hDlg,&msg))
{
TranslateMessage(&msg); // allows use of keyboard
DispatchMessage(&msg);
}
}
// Destroy the menu handle
DestroyMenu(g_hMenu);
// Close the error log
CloseHandle(g_hErrorLog);
// Close the results log
CloseHandle(g_hResultsLog);
// Close the trace log if necessary
if (g_hTraceLog != NULL)
CloseHandle(g_hTraceLog);
// Close all open voice channels
CloseVoxResources();
return(0);
}
///////////////////////////////////////////////////////////
// NAME: MainWndProc
// DESCRIPTION:
//
//
//////////////////////////////////////////////////////////
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Message Processing
switch (uMsg)
{
HANDLE_MSG(hwnd, WM_DESTROY, Main_OnDestroy);
HANDLE_MSG(hwnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hwnd, WM_PAINT, Main_OnPaint);
HANDLE_MSG(hwnd, WM_CLOSE, Main_OnClose);
HANDLE_MSG(hwnd, WM_CREATE, Main_OnCreate);
HANDLE_MSG(hwnd, WM_SIZE, Main_OnSize);
HANDLE_MSG(hwnd, WM_TIMER, Main_OnTimer);
HANDLE_MSG(hwnd, WM_MOUSEMOVE,Main_OnMouseMove);
default:
return(DefWindowProc(hwnd, uMsg, wParam, lParam));
}
return(0);
}
///////////////////////////////////////////////////////////
// NAME: Main_OnDestroy
// DESCRIPTION: Action of WM_DESTROY
//
//
//////////////////////////////////////////////////////////
void Main_OnDestroy(HWND hwnd)
{
PostQuitMessage(0);
return;
}
///////////////////////////////////////////////////////////
// NAME: Main_OnPaint
// DESCRIPTION: Action of WM_PAINT. Paint the virtual
// window to the displayed window.
//
//////////////////////////////////////////////////////////
void Main_OnPaint(HWND hwnd)
{
HDC hdc;
PAINTSTRUCT paint;
// Paint the shown window from the virtual window
hdc=BeginPaint(hwnd,&paint);
BitBlt(hdc,0,0,g_nMaxx,g_nMaxy,g_hMemdc,0,0,SRCCOPY);
EndPaint(hwnd, &paint);
return;
}
///////////////////////////////////////////////////////////
// NAME: Main_OnClose
// DESCRIPTION: Action of WM_CLOSE
//
//
//////////////////////////////////////////////////////////
void Main_OnClose(HWND hwnd)
{
// Destroy the main window
DeleteDC(g_hMemdc);
DestroyWindow(hwnd);
return;
}
///////////////////////////////////////////////////////////
// NAME: Main_OnMouseMove
// DESCRIPTION: Action of WM_MouseMove
//
//
//////////////////////////////////////////////////////////
void Main_OnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
// For future use
return;
}
///////////////////////////////////////////////////////////
// NAME: Main_OnTimer
// DESCRIPTION: Action of WM_TIMER
//
//
//////////////////////////////////////////////////////////
void Main_OnTimer(HWND hwnd, UINT id)
{
return;
}
///////////////////////////////////////////////////////////
// NAME: Main_OnSize
// DESCRIPTION: Action of sizing the window
//
//
//////////////////////////////////////////////////////////
void Main_OnSize(HWND hwnd, UINT state, int cx, int cy)
{
// Resize the status window
SendMessage(g_hStatusWnd,WM_SIZE, cx, cy);
}
///////////////////////////////////////////////////////////
// NAME: Main_Oncommand
// DESCRIPTION: Action of WM_COMMAND
// Process user commands on menus
//
//////////////////////////////////////////////////////////
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case ID_OPTIONS_SELECTCHANNEL:
CommandOptionsChannel(hwnd);
break;
case ID_OPTIONS_SENDMESSAGE:
CommandOptionsSendMessage(hwnd);
break;
case ID_OPTIONS_DELETEMESSAGE:
CommandOptionsDeleteMessage(hwnd);
break;
case ID_TOOLS_TRACE:
CommandToolsTrace(&g_hTraceWnd, g_hMenu);
break;
case ID_TOOLS_LOGTRACE:
CommandToolsLogTrace(&g_bTraceLog, g_hMenu);
break;
case ID_HELP_ABOUT:
CommandHelpAbout();
break;
default:
break;
}
}
///////////////////////////////////////////////////////////
// NAME: Main_OnCreate
// DESCRIPTION: Action of WM_Create, create a virtual
// to handle screen updates
//
//////////////////////////////////////////////////////////
BOOL Main_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
HDC hdc;
HBRUSH hbrush;
HBITMAP hbit;
// get screen attributes
g_nMaxx=GetSystemMetrics(SM_CXSCREEN);
g_nMaxy=GetSystemMetrics(SM_CYSCREEN);
// Get window DC
hdc=GetDC(hwnd);
// Create compatible virtual window
g_hMemdc=CreateCompatibleDC(hdc);
hbit=CreateCompatibleBitmap(hdc,g_nMaxx,g_nMaxy);
SelectObject(g_hMemdc, hbit);
hbrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(g_hMemdc, hbrush);
PatBlt(g_hMemdc,0,0,g_nMaxx,g_nMaxy,PATCOPY);
// Release window DC
ReleaseDC(hwnd,hdc);
return(TRUE);
}
///////////////////////////////////////////////////////////
//
// Trace Window Functions
//
///////////////////////////////////////////////////////////
// NAME: TraceWndProc
// DESCRIPTION: Trace window callback function
//
//
//////////////////////////////////////////////////////////
LRESULT CALLBACK TraceWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// Message Processing
switch(uMsg) {
HANDLE_MSG(hwnd, WM_PAINT, Trace_OnPaint);
HANDLE_MSG(hwnd, WM_CLOSE, Trace_OnClose);
HANDLE_MSG(hwnd, WM_CREATE, Trace_OnCreate);
HANDLE_MSG(hwnd, WM_SIZE, Trace_OnSize);
default:
return(DefWindowProc(hwnd, uMsg, wParam, lParam));
}
return(0);
}
///////////////////////////////////////////////////////////
// NAME: Trace_OnPaint
// DESCRIPTION: Action of WM_PAINT. Paint the virtual
// window to the displayed window.
//
//////////////////////////////////////////////////////////
void Trace_OnPaint(HWND hwnd)
{
HDC hdc;
PAINTSTRUCT paint;
// Paint the shown window from the virtual window
hdc=BeginPaint(hwnd,&paint);
BitBlt(hdc,0,0,g_nTraceMaxx,g_nTraceMaxy,g_hTraceMemdc,0,0,SRCCOPY);
EndPaint(hwnd, &paint);
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -