EasyManua.ls Logo

STC micro STC8A8K64D4 Series - Page 873

Default Icon
901 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
STC8A8K64D4 Series Manual
- 857 -
const UINT ID_PROGRESS = 1044;
// Full path of publishing project program
path = _T("D:\\Work\\Upgrade.exe");
// variable initialization
memset(&si, 0, sizeof(STARTUPINFO));
memset(&pi, 0, sizeof(PROCESS_INFORMATION));
memset(&cp, 0, sizeof(CALLBACK_PARAM));
// Set startup variables
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.wShowWindow = SW_SHOWNORMAL; // If it is set to SW_HIDE here, the operation interface for
publishing the project program will not be displayed, and all ISP operations can be performed in the background
si.dwFlags = STARTF_USESHOWWINDOW;
// Create a process for publishing a project program
if (CreateProcess(NULL, (LPTSTR)(LPCTSTR)path, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
{
// Wait for the release project program process initialization to complete
WaitForInputIdle(pi.hProcess, 5000);
// Get the main window handle of the publishing project program
cp.dwProcessId = pi.dwProcessId;
cp.hMainWnd = NULL;
EnumWindows(EnumWindowCallBack, (LPARAM)&cp);
if (cp.hMainWnd != NULL)
{
HWND hProgram;
HWND hStop;
HWND hPort;
// Get the handle of some controls in the main window of the publishing project program
hProgram = ::GetDlgItem(cp.hMainWnd, ID_PROGRAM);
hStop = ::GetDlgItem(cp.hMainWnd, ID_STOP);
hPort = ::GetDlgItem(cp.hMainWnd, ID_COMPORT);
// Set the serial port number in the release project program, the third parameter is 0:COM1, 1:COM2, 2:COM3, ...
::SendMessage(hPort, CB_SETCURSEL, 0, 0);
// Trigger the programming button to start ISP programming
::SendMessage(hProgram, BM_CLICK, 0, 0);
// wait for programming to complete,
// Since the main process will be blocked here, it is recommended to create a new working process and wait in the
worker process
while (!::IsWindowEnabled(hProgram));
// Close the release project program after programming is complete
::SendMessage(cp.hMainWnd, WM_CLOSE, 0, 0);
}
// wait for the process to end
WaitForSingleObject(pi.hProcess,INFINITE);

Table of Contents

Related product manuals