2 * psychlops_app_state_Win32.h
3 * Psychlops Standard Library (Universal)
5 * Last Modified 2007/06/22 by Kenchi HOSOKAWA
6 * (C) 2006 Kenchi HOSOKAWA, Kazushi MARUYA and Takao SATO
12 #include "psychlops_app_state_Win32.h"
13 #include "../../core/ApplicationInterfaces/psychlops_app_info.h"
18 int AppState::createSynchronousProcess(std::string command)
\r
20 const char *lpArg = command.c_str();
\r
21 PROCESS_INFORMATION pi;
\r
23 ZeroMemory(&si,sizeof(si));
\r
26 ZeroMemory(&pi,sizeof(pi));
\r
27 if(!CreateProcess(NULL,(LPTSTR)lpArg,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si, &pi))
\r
29 std::cout << "createSynchronousProcess:CreateProcess" << std::endl;
\r
32 CloseHandle(pi.hThread);
\r
33 WaitForSingleObject(pi.hProcess,INFINITE);
\r
34 CloseHandle(pi.hProcess);
\r
39 APIApplicationProperties APIApplicationProperties::startupinfo;
41 APIApplicationProperties::APIApplicationProperties(){
44 APIApplicationProperties::APIApplicationProperties(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPSTR _lpCmdLine, int _iCmdShow)
45 : hInstance_(_hInstance), hPrevInstance_(_hPrevInstance), lpCmdLine_(_lpCmdLine), iCmdShow_(_iCmdShow) {
48 APIApplicationProperties::~APIApplicationProperties() {
51 void APIApplicationProperties::set(HINSTANCE _hInstance, HINSTANCE _hPrevInstance, LPSTR _lpCmdLine, int _iCmdShow) {
52 hInstance_ = _hInstance;
53 hPrevInstance_ = _hPrevInstance;
54 lpCmdLine_ = _lpCmdLine;
55 iCmdShow_ = _iCmdShow;
58 DWORD APIApplicationProperties::getPrimaryThreadID() {
59 return primaryThreadID;
62 void APIApplicationProperties::initialize() {
63 primaryThreadID = GetCurrentThreadId();
64 pClassName = "PsychlopsWindow";
65 pAppName = "Psychlops Application";
67 thread_state_[AppState::SLEEP] = IDLE_PRIORITY_CLASS;
68 thread_state_[AppState::IDLE] = IDLE_PRIORITY_CLASS;
69 thread_state_[AppState::LOW] = BELOW_NORMAL_PRIORITY_CLASS;
70 thread_state_[AppState::NORMAL] = NORMAL_PRIORITY_CLASS;
71 thread_state_[AppState::HIGH] = HIGH_PRIORITY_CLASS;
72 SetPriorityClass(GetCurrentProcess(), thread_state_[AppState::NORMAL]);
74 LRESULT CALLBACK APIApplicationProperties::proc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
77 return DefWindowProc( hWnd, message, wParam, lParam );
84 return DefWindowProc( hWnd, message, wParam, lParam );
87 void APIApplicationProperties::setThreadPriority( unsigned int priority ) {
88 if(priority>=0 && priority<5) {
89 SetPriorityClass(GetCurrentProcess(), startupinfo.thread_state_[priority]);
92 int APIApplicationProperties::getThreadPriority() {
93 DWORD threadState = GetPriorityClass(GetCurrentProcess());
95 case IDLE_PRIORITY_CLASS:
96 return AppState::IDLE;
97 case BELOW_NORMAL_PRIORITY_CLASS:
100 case NORMAL_PRIORITY_CLASS:
101 return AppState::NORMAL;
102 case HIGH_PRIORITY_CLASS:
103 return AppState::HIGH;
107 void APIApplicationProperties::analyzeAPIError() {
109 FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
110 MessageBox(NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION);
116 void AppState::alert(std::string message) {
117 unsigned char str[255];
118 MessageBox( NULL, message.c_str(), "Psychlops Notification", MB_OK );
121 } /* <- namespace Psycholops */