Windows SDK APIs are seldom used directly in modern applications. There is one simple WinSDK example included in the standard WiT distribution. This example (demo\engine\winSDK\simple) creates a simple WinSDK application with the same functionality as ‘A Simple Example’. It loads and runs the WiT code file demo\engine\wic\simple.wic.
Most of the program is the same as the standard Windows application automatically generated by Visual Studio, including WinMain and message process procedure.
Two void pointer type global variables are added to store WiT Engine related handles: witDllHandle as WiT Engine handle, witExeHandle as WIC handle.
Most of the work is done in the message procedure WndProc. In the WM_CREATE message section, after the main window is created, we need to create a STATIC control to map the display operator in the WIC, and a BUTTON control to run the WIC. witDllInit4 is called to initialize WiT Engine. witSetDisplayWnd is called to map the display name ‘image’ to the Windows handle, and witLoad is called to load the WIC:
case WM_CREATE:
...
pictureWnd = CreateWindowEx(WS_EX_CLIENTEDGE,
"STATIC",
NULL,
WS_CHILD | WS_VISIBLE,
0, 2,
IM_SIZE + 4,
IM_SIZE + 4,
hWnd,
(HMENU)0,
hInst,
NULL);
buttonWnd = CreateWindow("BUTTON",
"Run",
WS_CHILD | WS_VISIBLE | WS_TABSTOP,
(IM_SIZE - BUTTON_WIDTH) / 2 + 2, 2 + IM_SIZE + 4 + 2,
BUTTON_WIDTH,
BUTTON_HEIGHT,
hWnd,
(HMENU)ID_READ_BUTTON,
hInst,
0);
if (!(witDllHandle = witDllInit4(hWnd, 0, NULL, NULL, hInst, NULL)))
{
MessageBox(hWnd, "witDllInit failed!", appName, MB_OK);
exit(1);
}
witSetDisplayWnd("image", pictureWnd);
withome = getenv("withome");
sprintf(fileName, "%s\\demoPrograms\\engine\\wic\\simple.wic", withome);
witExeHandle = witLoad(fileName);
...
break;
witControlExec is called when the button is clicked:
case WM_COMMAND:
if (LOWORD(wParam) == ID_READ_BUTTON)
witControlExec(witExeHandle, WIT_EXE_FLASH, 0);
break;
Before the application is closed, witDllExit is called to release and clean WiT Engine:
case WM_DESTROY:
...
witDllExit(witDllHandle);
...
|