Чу чуть криво но вроде все работает:
http://dump.ru/files/o/o920184640/ качать весь проект отсюда.
Создаем проект, но галочку на пустой не ставим.
Выйдет много файлов.
Добавляем файлы FormFunc.cpp и FormFunc.h
В них
FormFunc.cpp
#pragma once
#include "stdafx.h"
#include windows.h
#include "FormFunc.h"
struct FileCFG{int nled,
len,
ondown,
onsip,
keyon;}; // структура для файла конфигурации
int CreateWin(CREATESTRUCT* pCreateStruct) // упращаем вывод на экран
{
LPCWSTR StaticS[6] = {L"Num Led:",L"Length:",L"On Down:",L"On Sip:",L"Key On:",L"Add Config:"}; // строки для статического текста
LPCWSTR EditS[6] = {L"1",L"50",L"1",L"1",L"0",L""}; // строки для едитов
for (int i=0;i<6;i++)>hInstance, NULL)) return 1; // создаем в цикле статики
if (!CreateWindow(L"edit", EditS[i], WS_BORDER|WS_CHILD|WS_VISIBLE,
10, (40*i)+23, 90, 18, hWndF,
HMENU(IDC_MyEDIT+i),
pCreateStruct->hInstance, NULL)) return 1; // создаем в цикле едиты
}
return 0;
}
int LoadCFG()
{
WCHAR szPath[MAX_PATH];
GetModuleFileName(g_hInst,szPath,MAX_PATH);
(*((wcsrchr(szPath,'\\'))+1))=0;
StringCchCat(szPath,MAX_PATH,L"\\VOAManager.cfg");
HANDLE hFile = CreateFile(szPath,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(!hFile) return 1;
FileCFG CFG;
DWORD dwBytesRead;
if(!ReadFile(hFile,&CFG,sizeof FileCFG,&dwBytesRead,NULL))
{
CloseHandle(hFile);
return GetLastError();
}
CloseHandle(hFile);
wchar_t* s = new wchar_t[255];
_itow(CFG.nled,s,10);
SendDlgItemMessage(hWndF,IDC_MyEDIT+0,WM_SETTEXT,0,(LPARAM)s);
_itow(CFG.len,s,10);
SendDlgItemMessage(hWndF,IDC_MyEDIT+1,WM_SETTEXT,0,(LPARAM)s);
_itow(CFG.ondown,s,10);
SendDlgItemMessage(hWndF,IDC_MyEDIT+2,WM_SETTEXT,0,(LPARAM)s);
_itow(CFG.onsip,s,10);
SendDlgItemMessage(hWndF,IDC_MyEDIT+3,WM_SETTEXT,0,(LPARAM)s);
_itow(CFG.keyon,s,10);
SendDlgItemMessage(hWndF,IDC_MyEDIT+4,WM_SETTEXT,0,(LPARAM)s);
delete s;
return 0;
}
int SaveCFG()
{
wchar_t* s = new wchar_t[255];
SendDlgItemMessage(hWndF,IDC_MyEDIT+0,WM_GETTEXT,255,(LPARAM)s);
int nl = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+1,WM_GETTEXT,255,(LPARAM)s);
int len = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+2,WM_GETTEXT,255,(LPARAM)s);
int od = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+3,WM_GETTEXT,255,(LPARAM)s);
int os = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+4,WM_GETTEXT,255,(LPARAM)s);
int ko = _wtoi(s);
delete s;
WCHAR szPath[MAX_PATH];
GetModuleFileName(g_hInst,szPath,MAX_PATH);
(*((wcsrchr(szPath,'\\'))+1))=0;
StringCchCat(szPath,MAX_PATH,L"\\VOAManager.cfg");
HANDLE hFile = CreateFile(szPath,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if(!hFile) return 1;
FileCFG CFG;
DWORD dwBytesWrite;
CFG.keyon=ko;
CFG.len=len;
CFG.nled=nl;
CFG.ondown=od;
CFG.onsip=os;
if(!WriteFile(hFile,&CFG,sizeof FileCFG,&dwBytesWrite,NULL))
{
CloseHandle(hFile);
return GetLastError();
}
CloseHandle(hFile);
return 0;
}
int RunVOA()
{
HWND hWindow;
PROCESS_INFORMATION pi;
WCHAR szPath[MAX_PATH];
GetModuleFileName(g_hInst,szPath,MAX_PATH);
(*((wcsrchr(szPath,'\\'))+1))=0;
StringCchCat(szPath,MAX_PATH,L"\\VOA.exe");
// получаем путь и добавляем к пути файл ВОА
hWindow = FindWindow(L"VOA", 0);
// у меня не работает так как вибрации у меня нет и файл VOA не запускаеться
if (hWindow)
{
CreateProcess(szPath, L"", NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi);
}
// находим VOA если он запущен запускаем его чтобы он выгрузился (задумка автора VOA )
if(!hWindow) //проверяем на всякий пожарный запущен ли он если нет
{
wchar_t* s = new wchar_t[10];
wchar_t* SS = new wchar_t[255];
SendDlgItemMessage(hWndF,IDC_MyEDIT+0,WM_GETTEXT,255,(LPARAM)s);
int nled = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+1,WM_GETTEXT,255,(LPARAM)s);
int len = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+2,WM_GETTEXT,255,(LPARAM)s);
int ondown = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+3,WM_GETTEXT,255,(LPARAM)s);
int onsip = _wtoi(s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+4,WM_GETTEXT,255,(LPARAM)s);
int keyon = _wtoi(s); // смысол такой получаем все с едитов и добавляем в одну стр
SS[0]=0;
_itow(nled,s,10);
StringCchCat(SS,255,L" -nled ");
StringCchCat(SS,255,s);
_itow(len,s,10);
StringCchCat(SS,255,L" -len ");
StringCchCat(SS,255,s);
_itow(ondown,s,10);
StringCchCat(SS,255,L" -ondown ");
StringCchCat(SS,255,s);
_itow(onsip,s,10);
StringCchCat(SS,255,L" -onsip ");
StringCchCat(SS,255,s);
_itow(keyon,s,10);
StringCchCat(SS,255,L" -keyon ");
StringCchCat(SS,255,s);
SendDlgItemMessage(hWndF,IDC_MyEDIT+5,WM_GETTEXT,255,(LPARAM)s);
StringCchCat(SS,255,L" ");
StringCchCat(SS,255,s);
delete(s);
if(!CreateProcess(szPath, SS, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi))
{ // вот здесь запускаем фал с командной строкой.
return 1;
}
}
return 0;
}
FormFunc.h
#define IDC_MySTATIC 10000
#define IDC_MyEDIT 20000
extern HINSTANCE g_hInst;
extern HWND hWndF;
extern int CreateWin(CREATESTRUCT* pCreateStruct);
extern int LoadCFG();
extern int SaveCFG();
extern int RunVOA();
VOAManager.cpp
// VOAManager.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "VOAManager.h"
#include "FormFunc.h"
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
HWND g_hWndMenuBar; // menu bar handle
HWND hWndF;
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE, LPTSTR);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
// Perform application initialization:
if (!InitInstance(hInstance, nCmdShow))
{
return FALSE;
}
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_VOAMANAGER));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VOAMANAGER));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
TCHAR szTitle[MAX_LOADSTRING]; // title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // main window class name
g_hInst = hInstance; // Store instance handle in our global variable
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
// SHInitExtraControls should be called once during your application's initialization to initialize any
// of the device specific controls such as CAPEDIT and SIPPREF.
SHInitExtraControls();
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
HWND hWnd;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_VOAMANAGER, szWindowClass, MAX_LOADSTRING);
#if defined(WIN32_PLATFORM_PSPC) || defined(WIN32_PLATFORM_WFSP)
//If it is already running, then focus on the window, and exit
hWnd = FindWindow(szWindowClass, szTitle);
if (hWnd)
{
// set focus to foremost child window
// The "| 0x00000001" is used to bring any owned windows to the foreground and
// activate them.
SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
return 0;
}
#endif // WIN32_PLATFORM_PSPC || WIN32_PLATFORM_WFSP
if (!MyRegisterClass(hInstance, szWindowClass))
{
return FALSE;
}
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
#ifdef WIN32_PLATFORM_PSPC
// When the main window is created using CW_USEDEFAULT the height of the menubar (if one
// is created is not taken into account). So we resize the window after creating it
// if a menubar is present
if (g_hWndMenuBar)
{
RECT rc;
RECT rcMenuBar;
GetWindowRect(hWnd, &rc);
GetWindowRect(g_hWndMenuBar, &rcMenuBar);
rc.bottom -= (rcMenuBar.bottom - rcMenuBar.top);
MoveWindow(hWnd, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, FALSE);
}
#endif // WIN32_PLATFORM_PSPC
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
static SHACTIVATEINFO s_sai;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case ID_MENU_LOAD:
if (LoadCFG()>0){MessageBox(hWndF,L"Config not load.",L"Error",0);};
break;
case ID_MENU_SAVE:
if (SaveCFG()>0){MessageBox(hWndF,L"Config not saved.",L"Error",0);};
break;
case ID_EXIT:
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
case IDM_HELP_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
break;
#ifdef WIN32_PLATFORM_PSPC
case IDM_OK:
{
if (SaveCFG()>0){MessageBox(hWndF,L"Config not saved.",L"Error",0);};
if (RunVOA()>0){MessageBox(hWndF,L"Not run 'VOA.EXE'",L"Error",0);};
SendMessage (hWnd, WM_CLOSE, 0, 0);
break;
}
#endif // WIN32_PLATFORM_PSPC
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
#ifdef SHELL_AYGSHELL
hWndF = hWnd;
CreateWin((LPCREATESTRUCT)lParam);
LoadCFG();
SHMENUBARINFO mbi;
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hWnd;
mbi.nToolBarId = IDR_MENU;
mbi.hInstRes = g_hInst;
if (!SHCreateMenuBar(&mbi))
{
g_hWndMenuBar = NULL;
}
else
{
g_hWndMenuBar = mbi.hwndMB;
}
// Initialize the shell activate info structure
memset(&s_sai, 0, sizeof (s_sai));
s_sai.cbSize = sizeof (s_sai);
#endif // SHELL_AYGSHELL
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
#ifdef SHELL_AYGSHELL
CommandBar_Destroy(g_hWndMenuBar);
#endif // SHELL_AYGSHELL
PostQuitMessage(0);
break;
case WM_ACTIVATE:
// Notify shell of our activate message
SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
break;
case WM_SETTINGCHANGE:
SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
#ifdef SHELL_AYGSHELL
{
// Create a Done button and size it.
SHINITDLGINFO shidi;
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN | SHIDIF_EMPTYMENU;
shidi.hDlg = hDlg;
SHInitDialog(&shidi);
}
#endif // SHELL_AYGSHELL
return (INT_PTR)TRUE;
case WM_COMMAND:
#ifdef SHELL_AYGSHELL
if (LOWORD(wParam) == IDOK)
#endif
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, message);
return (INT_PTR)TRUE;
}
return (INT_PTR)FALSE;
}
понедельник, 11 февраля 2008 г.
Подписаться на:
Комментарии к сообщению (Atom)
Комментариев нет:
Отправить комментарий