1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| #include <windows.h>
#include <stdlib.h>
#include <dos.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <tchar.h>
HANDLE hInst; // current instance
HWND hMainWnd; // main window handle
char szErrMsg[80]; // Use for MESSAGEBOX function
LRESULT ErrCde; // Return error code
LONG DriverHandle = (LONG)NULL; // driver handle
BOOL bRun = FALSE; // flag for running
USHORT gwDevice = 0, gwSubDevice = 0; // device index
USHORT gwChannel = 0; // input channel
USHORT gwValue; // input value
SHORT gnNumOfDevices, gnNumOfSubdevices; // number of installed devices
USHORT gwScanTime = 1000; // scan time
DWORD gdwStartTime; // start time
DWORD gdwElapseTime = 0; // elapse time
USHORT gwOverrunCount = 0; // overrun count
FARPROC lpfnConfigDlgProc; // config. dialog procedure
FARPROC lpfnScanDlgProc;
// FUNCTION DECLARATION
// ------------------------------------------------------------------------
BOOL InitApplication(HANDLE);
BOOL InitInstance(HANDLE, int);
long _stdcall MainWndProc(HWND, UINT, WPARAM, LPARAM);
int _stdcall WinMain(HINSTANCE , HINSTANCE , LPSTR , int );
int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
//HANDLE hInstance; // current instance
//HANDLE hPrevInstance; // previous instance
//LPSTR lpCmdLine; // command line
//int nCmdShow; // show-window type (open/icon)
{
MSG msg; // message
if (!hPrevInstance) // Other instances of app running?
if (!InitApplication(hInstance)) // Initialize shared things
return (FALSE); // Exits if unable to initialize
// Perform initializations that apply to a specific instance
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
// Acquire and dispatch messages until a WM_QUIT message is received.
while (GetMessage(&msg, // message structure
(HWND)NULL, // handle of window receiving the message
(UINT)NULL, // lowest message to examine
(UINT)NULL)) // highest message to examine
{
TranslateMessage(&msg); // Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
return (msg.wParam); // Returns the value from PostQuitMessage
}
/****************************************************************************
FUNCTION: InitApplication(HANDLE)
PURPOSE: Initializes window data and registers window class
****************************************************************************/
BOOL InitApplication(HINSTANCE hInstance) // current instance */
{
// HINSTANCE hInstance;
WNDCLASS wc;
// Fill in window class structure with parameters that describe the
// main window.
wc.style = CS_HREDRAW | CS_VREDRAW; // Class style(s).
wc.lpfnWndProc = (WNDPROC)MainWndProc; // window process procedure
wc.cbClsExtra = 0; // No per-class extra data.
wc.cbWndExtra = 0; // No per-window extra data.
wc.hInstance = hInstance; // Application that owns the class.
wc.hIcon = LoadIcon(hInstance, (LPCWSTR)"IDI_ICON1");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = (LPCWSTR)"MyMenu"; // Name of menu resource in .RC file.
wc.lpszClassName = (LPCWSTR)"MyClass"; // Name used in call to CreateWindow.
// Register the window class and return success/failure code.
return (RegisterClass(&wc));
}
/***************************************************************************
FUNCTION: InitInstance(HANDLE, int)
PURPOSE: Saves instance handle and creates main window
****************************************************************************/
BOOL InitInstance
(
HINSTANCE hInstance, // Current instance identifier.
int nCmdShow // Param for first ShowWindow() call.
)
{
// Save the instance handle in static variable, which will be used in
// many subsequence calls from this application to Windows.
hInst = hInstance;
// Create a main window for this application instance.
hMainWnd = CreateWindow(
(LPCWSTR)"MyClass", /* See RegisterClass() call.
(LPCWSTR)"Advantech Driver Demo : Digital Input" , /* Window title bar */
WS_OVERLAPPEDWINDOW, /* Window style. */
CW_USEDEFAULT, /* Default horizontal position. */
CW_USEDEFAULT, /* Default vertical position. */
CW_USEDEFAULT, /* Default width. */
CW_USEDEFAULT, /* Default height. */
NULL, /* Overlapped windows have no parent. */
NULL, /* Use the window class menu. */
hInstance, /* This instance owns this window. */
NULL /* Pointer not needed. */
);
// If window could not be created, return "failure"
if (!hMainWnd)
return (FALSE);
// Make the window visible; update its client area; and return "success"
ShowWindow(hMainWnd, nCmdShow); // Show the window
UpdateWindow(hMainWnd); // Sends WM_PAINT message
return (TRUE); // Returns the value from PostQuitMessage
} |
Partager