示例#1
0
文件: tray.c 项目: mcgwh/trayhost
void native_loop(const char *title, unsigned char *imageData, unsigned int imageDataLen)
{
    HWND hWnd;
    HINSTANCE hInstance = GetModuleHandle(NULL);

    MSG msg;
    
    DWORD dwUnicodeLen = MultiByteToWideChar(CP_UTF8,0,title,-1,NULL,0);
    

    titleWide = (wchar_t*)calloc(strlen(title) + 1, sizeof(wchar_t));
    
    MultiByteToWideChar(CP_UTF8,0,title,-1,titleWide,dwUnicodeLen);
    
    //mbstowcs(titleWide, title, strlen(title));

    wcscpy((wchar_t*)szTitle, titleWide);
    wcscpy((wchar_t*)szWindowClass, (wchar_t*)TEXT("MyClass"));
    MyRegisterClass(hInstance);

    hWnd = InitInstance(hInstance, FALSE); // Don't show window
    if (!hWnd)
    {
        return;
    }

    // Let's load up the tray icon
    HICON hIcon;
    {
        // This is really hacky, but LoadImage won't let me load an image from memory.
        // So we have to write out a temporary file, load it from there, then delete the file.

        // From http://msdn.microsoft.com/en-us/library/windows/desktop/aa363875.aspx
        TCHAR szTempFileName[MAX_PATH+1];
        TCHAR lpTempPathBuffer[MAX_PATH+1];
        int dwRetVal = GetTempPath(MAX_PATH+1,        // length of the buffer
                                   lpTempPathBuffer); // buffer for path
        if (dwRetVal > MAX_PATH+1 || (dwRetVal == 0))
        {
            return; // Failure
        }

        //  Generates a temporary file name.
        int uRetVal = GetTempFileName(lpTempPathBuffer, // directory for tmp files
                                      TEXT("_tmpicon"), // temp file name prefix
                                      0,                // create unique name
                                      szTempFileName);  // buffer for name
        if (uRetVal == 0)
        {
            return; // Failure
        }

        // Dump the icon to the temp file
        FILE* fIcon = _wfopen(szTempFileName, TEXT("wb"));
        fwrite(imageData, 1, imageDataLen, fIcon);
        fclose(fIcon);
        fIcon = NULL;

        // Load the image from the file
        hIcon = LoadImage(NULL, szTempFileName, IMAGE_ICON, 64, 64, LR_LOADFROMFILE);

        // Delete the temp file
        _wremove(szTempFileName);
    }

    nid.cbSize = sizeof(NOTIFYICONDATA);
    nid.hWnd = hWnd;
    nid.uID = 100;
    nid.uCallbackMessage = WM_MYMESSAGE;
    nid.hIcon = hIcon;

    wcscpy((wchar_t*)nid.szTip, (wchar_t*)titleWide); // MinGW seems to use ANSI
    nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;

    Shell_NotifyIcon(NIM_ADD, &nid);

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
示例#2
0
// Program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);

  g_appStartupTime = timeGetTime();

  CefMainArgs main_args(hInstance);
  CefRefPtr<ClientApp> app(new ClientApp);

  // Execute the secondary process, if any.
  int exit_code = CefExecuteProcess(main_args, app.get());
  if (exit_code >= 0)
    return exit_code;

  // Retrieve the current working directory.
  if (_getcwd(szWorkingDir, MAX_PATH) == NULL)
    szWorkingDir[0] = 0;

  // Parse command line arguments. The passed in values are ignored on Windows.
  AppInitCommandLine(0, NULL);

  // Determine if we should use an already running instance of Brackets.
  HANDLE hMutex = ::OpenMutex(MUTEX_ALL_ACCESS, FALSE, FIRST_INSTANCE_MUTEX_NAME);
  if ((hMutex != NULL) && AppGetCommandLine()->HasArguments() && (lpCmdLine != NULL)) {
	  // for subsequent instances, re-use an already running instance if we're being called to
	  //   open an existing file on the command-line (eg. Open With.. from Windows Explorer)
	  HWND hFirstInstanceWnd = cef_main_window::FindFirstTopLevelInstance();
	  if (hFirstInstanceWnd != NULL) {
		  ::SetForegroundWindow(hFirstInstanceWnd);
		  if (::IsIconic(hFirstInstanceWnd))
			  ::ShowWindow(hFirstInstanceWnd, SW_RESTORE);
		  
		  // message the other Brackets instance to actually open the given filename
		  std::wstring wstrFilename = lpCmdLine;
		  ConvertToUnixPath(wstrFilename);
		  // note: WM_COPYDATA will manage passing the string across process space
		  COPYDATASTRUCT data;
		  data.dwData = ID_WM_COPYDATA_SENDOPENFILECOMMAND;
		  data.cbData = (wstrFilename.length() + 1) * sizeof(WCHAR);
		  data.lpData = (LPVOID)wstrFilename.c_str();
		  ::SendMessage(hFirstInstanceWnd, WM_COPYDATA, (WPARAM)(HWND)hFirstInstanceWnd, (LPARAM)(LPVOID)&data);

		  // exit this instance
		  return 0;
	  }
	  // otherwise, fall thru and launch a new instance
  }

  if (hMutex == NULL) {
	  // first instance of this app, so create the mutex and continue execution of this instance.
	  hMutex = ::CreateMutex(NULL, FALSE, FIRST_INSTANCE_MUTEX_NAME);
  }

  CefSettings settings;

  // Populate the settings based on command line arguments.
  AppGetSettings(settings, app);

  // Check command
  if (CefString(&settings.cache_path).length() == 0) {
	  CefString(&settings.cache_path) = AppGetCachePath();
  }

  // Initialize CEF.
  CefInitialize(main_args, settings, app.get());

  CefRefPtr<CefCommandLine> cmdLine = AppGetCommandLine();
  if (cmdLine->HasSwitch(cefclient::kStartupPath)) {
	  wcscpy(szInitialUrl, cmdLine->GetSwitchValue(cefclient::kStartupPath).c_str());
  }
  else {
	// If the shift key is not pressed, look for the index.html file 
	if (GetAsyncKeyState(VK_SHIFT) == 0) {
	// Get the full pathname for the app. We look for the index.html
	// file relative to this location.
	wchar_t appPath[MAX_PATH];
	wchar_t *pathRoot;
	GetModuleFileName(NULL, appPath, MAX_PATH);

	// Strip the .exe filename (and preceding "\") from the appPath
	// and store in pathRoot
	pathRoot = wcsrchr(appPath, '\\');

	// Look for .\dev\src\index.html first
	wcscpy(pathRoot, L"\\dev\\src\\index.html");

	// If the file exists, use it
	if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) {
		wcscpy(szInitialUrl, appPath);
	}

	if (!wcslen(szInitialUrl)) {
		// Look for .\www\index.html next
		wcscpy(pathRoot, L"\\www\\index.html");
		if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) {
		wcscpy(szInitialUrl, appPath);
		}
	}
	}
  }

  if (!wcslen(szInitialUrl)) {
      // If we got here, either the startup file couldn't be found, or the user pressed the
      // shift key while launching. Prompt to select the index.html file.
      OPENFILENAME ofn = {0};
      ofn.lStructSize = sizeof(ofn);
      ofn.lpstrFile = szInitialUrl;
      ofn.nMaxFile = MAX_PATH;
      ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0";
      ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file.";
      ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER;

      if (!GetOpenFileName(&ofn)) {
        // User cancelled, exit the app
        CefShutdown();
        return 0;
      }
  }

  // Perform application initialization
  if (!InitInstance (hInstance, nCmdShow))
    return FALSE;

  // Start the node server process
  startNodeProcess();

  gFilesToOpen = GetFilenamesFromCommandLine();

  int result = 0;

  if (!settings.multi_threaded_message_loop) {
    // Run the CEF message loop. This function will block until the application
    // recieves a WM_QUIT message.
    CefRunMessageLoop();
  } else {
    MSG msg;

    // Run the application message loop.
    while (GetMessage(&msg, NULL, 0, 0)) {
      if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    }

    result = static_cast<int>(msg.wParam);
  }

  OnBeforeShutdown();

  // Shut down CEF.
  CefShutdown();

  // release the first instance mutex
  if (hMutex != NULL)
	  ReleaseMutex(hMutex);

  return result;
}
示例#3
0
INT
WINAPI
wWinMain(HINSTANCE hInst,
         HINSTANCE hPrev,
         LPWSTR Cmd,
         int iCmd)
{
    INITCOMMONCONTROLSEX iccx;
    INT Ret = 1;
    HMODULE hRichEd20;
    MSG Msg;
    HINSTANCE hGetUName = NULL;

    hInstance = hInst;

    iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
    iccx.dwICC = ICC_TAB_CLASSES;
    InitCommonControlsEx(&iccx);

    /* Loading the GetUName function */
    hGetUName = LoadLibraryW(L"getuname.dll");
    if (hGetUName != NULL)
    {
        GetUName = (GETUNAME) GetProcAddress(hGetUName, "GetUName");
        if (GetUName == NULL)
        {
            FreeLibrary(hGetUName);
            hGetUName = NULL;
        }
    }

    if (RegisterMapClasses(hInstance))
    {
        hRichEd20 = LoadLibraryW(L"RICHED20.DLL");

        if (hRichEd20 != NULL)
        {
            InitInstance(hInst);

            for (;;)
            {
                if (GetMessage(&Msg, NULL, 0, 0) <= 0)
                {
                    Ret = Msg.wParam;
                    break;
                }

                TranslateMessage(&Msg);
                DispatchMessage(&Msg);
            }

            FreeLibrary(hRichEd20);
        }
        UnregisterMapClasses(hInstance);
    }

    if (hGetUName != NULL)
        FreeLibrary(hGetUName);

    return Ret;
}
示例#4
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    Config cfg;
    string cmdline(lpCmdLine);
    size_t len = cmdline.length();
    if (len > 2 && cmdline[0] == '"' && cmdline[len - 1] == '"')
        cmdline = cmdline.substr(1, len - 2);
    if (!cfg.Load(cmdline)) {
        string err = "Unable to load config file: " + cmdline;
        MessageBox(NULL, err.c_str(), "Zimbra Desktop Service", MB_ICONERROR | MB_OK);
        return FALSE;
    }

    string mutexname = cfg.Get("mutex.name");
    if (!mutexname.empty()) {
        HANDLE mutex = CreateMutex(NULL, TRUE, mutexname.c_str());
        if (mutex != NULL && WaitForSingleObject(mutex, 0) != WAIT_OBJECT_0) {
            MessageBox(NULL, "Service is already running.", "Zimbra Desktop Service", MB_ICONERROR | MB_OK);         
            return FALSE;
        }
    }

    string workdir = cfg.Get("working.directory");
    if (!workdir.empty())
        SetCurrentDirectory(workdir.c_str());

    ofstream anchor(cfg.Get("anchor.file").c_str(), fstream::out | fstream::trunc);
    if (!anchor.is_open()) {
        MessageBox(NULL, "Unable to create anchor file", "Zimbra Desktop Service", MB_ICONERROR | MB_OK);
        return FALSE;
    }
    anchor << GetCurrentProcessId();
    anchor.close();

    RegisterClass(hInstance);
    nCmdShow = SW_HIDE; // hide the window
    if (!InitInstance(hInstance, nCmdShow)) {
        return FALSE;
    }

    java = new VirtualMachine(cfg);
    if (!java->Run()) {
        string err = "Failed to start Java VM: " + java->LastError();
        MessageBox(NULL, err.c_str(), "Zimbra Desktop Service", MB_ICONERROR | MB_OK);
        return FALSE;
    }

    DWORD monthrd_id;
    HANDLE monthrd_handle = CreateThread(NULL, 0, MonitorThread, (void *)&cfg, 0, &monthrd_id);
    if (monthrd_handle == NULL) {
        MessageBox(NULL, "Unable to start monitor thread", "Zimbra Desktop Service", MB_ICONERROR | MB_OK);
        return FALSE;
    }

    // main message loop:
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    delete java;
    TerminateThread(monthrd_handle, 0);
    return (int)msg.wParam;
}
示例#5
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_VUENGINE, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}
	
	// Get the Handle of the Device Context
	HDC hdc = GetDC(hWnd);
	if(hdc == NULL)
	{
		return FALSE;
	}

	// Set the Pixel Format
	if(SetPF(hdc) == FALSE)
	{
		return FALSE;
	}

	HGLRC hglrc = wglCreateContext(hdc);
	wglMakeCurrent(hdc, hglrc);

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_VUENGINE));

	// Main message loop:
	LARGE_INTEGER systemFrequency;
	QueryPerformanceFrequency(&systemFrequency);
	LARGE_INTEGER lastTickCount;	// used to produce DT
	QueryPerformanceCounter(&lastTickCount);

	VU::cVUColorRGBA rgbaColor = VU::kVUColorGreenA1;

	//char debugStr[100];

	while(1) 
	{
		LARGE_INTEGER currentTickCount;
		QueryPerformanceCounter(&currentTickCount);
		float dt = float(currentTickCount.QuadPart - lastTickCount.QuadPart)/systemFrequency.QuadPart;
		lastTickCount = currentTickCount;

		//sprintf_s(debugStr, sizeof(debugStr), "DT: %f\n", dt);
		//OutputDebugStringA(debugStr);

		// draw the new frame
		rgbaColor = glm::lerp(rgbaColor, VU::kVUColorBlueA1, dt);
		glClearColor(rgbaColor.r, rgbaColor.g, rgbaColor.b, rgbaColor.a);
		glClear(GL_COLOR_BUFFER_BIT);

		// swap buffers
		SwapBuffers(hdc);

		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) 
			&& !TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			if(msg.wParam == IDM_EXIT) break;

			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}

	}
	return (int) msg.wParam;
}
INT
APIENTRY
WinMain
(
    _In_ HINSTANCE      hInstance,
    _In_opt_ HINSTANCE  hPrevInstance,
    _In_ LPSTR          lpCmdLine,
    _In_ INT            nCmdShow
)
/*++

Routine Description:

    calls initialization function, processes message loop

    Windows recognizes this function by name as the initial entry point
    for the program.  This function calls the application initialization
    routine, if no other instance of the program is running, and always
    calls the instance initialization routine.  It then executes a message
    retrieval and dispatch loop that is the top-level control structure
    for the remainder of execution.  The loop is terminated when a WM_QUIT
    message is received, at which time this function exits the application
    instance by returning the value passed by PostQuitMessage().

    If this function must abort before entering the message loop, it
    returns the conventional value NULL.


Arguments:



Return Value:

    Integer


--*/
{
    MSG Msg;

    UNREFERENCED_PARAMETER(lpCmdLine);

    //
    // Other instances of app running?
    //

    if (!hPrevInstance)
    {
        if (!InitApplication(hInstance))
        {
            //
            // Initialize shared things, Exits if unable to initialize
            //
            return FALSE;
        }
    }

    //
    // 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, NULL, 0L, 0L))
    {
        //
        // Translates virtual key codes and Dispatches message to window
        //
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    //
    // Returns the value from PostQuitMessage
    //
    return((INT)Msg.wParam);
}
// Program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);

  g_appStartupTime = timeGetTime();

  CefMainArgs main_args(hInstance);
  CefRefPtr<ClientApp> app(new ClientApp);

  // Execute the secondary process, if any.
  int exit_code = CefExecuteProcess(main_args, app.get());
  if (exit_code >= 0)
    return exit_code;

  // Retrieve the current working directory.
  if (_getcwd(szWorkingDir, MAX_PATH) == NULL)
    szWorkingDir[0] = 0;

  // Parse command line arguments. The passed in values are ignored on Windows.
  AppInitCommandLine(0, NULL);

  CefSettings settings;

  // Populate the settings based on command line arguments.
  AppGetSettings(settings, app);

  // Check command
  if (CefString(&settings.cache_path).length() == 0) {
	  CefString(&settings.cache_path) = AppGetCachePath();
  }

  // Initialize CEF.
  CefInitialize(main_args, settings, app.get());

  HACCEL hAccelTable;

  // Initialize global strings
  LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING);
  MyRegisterClass(hInstance, settings.locale);
 

  // If the shift key is not pressed, look for the index.html file 
  if (GetAsyncKeyState(VK_SHIFT) == 0) {
    // Get the full pathname for the app. We look for the index.html
    // file relative to this location.
    wchar_t appPath[MAX_PATH];
    wchar_t *pathRoot;
    GetModuleFileName(NULL, appPath, MAX_PATH);

    // Strip the .exe filename (and preceding "\") from the appPath
    // and store in pathRoot
    pathRoot = wcsrchr(appPath, '\\');

    // Look for .\dev\src\index.html first
    wcscpy(pathRoot, L"\\dev\\src\\index.html");

    // If the file exists, use it
    if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) {
      wcscpy(szInitialUrl, appPath);
    }

    if (!wcslen(szInitialUrl)) {
      // Look for .\www\index.html next
      wcscpy(pathRoot, L"\\www\\index.html");
      if (GetFileAttributes(appPath) != INVALID_FILE_ATTRIBUTES) {
        wcscpy(szInitialUrl, appPath);
      }
    }
  }

  if (!wcslen(szInitialUrl)) {
      // If we got here, either the startup file couldn't be found, or the user pressed the
      // shift key while launching. Prompt to select the index.html file.
      OPENFILENAME ofn = {0};
      ofn.lStructSize = sizeof(ofn);
      ofn.lpstrFile = szInitialUrl;
      ofn.nMaxFile = MAX_PATH;
      ofn.lpstrFilter = L"Web Files\0*.htm;*.html\0\0";
      ofn.lpstrTitle = L"Please select the " APP_NAME L" index.html file.";
      ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_EXPLORER;

      if (!GetOpenFileName(&ofn)) {
        // User cancelled, exit the app
        CefShutdown();
        return 0;
      }
  }

  // Perform application initialization
  if (!InitInstance (hInstance, nCmdShow))
    return FALSE;

  // Temporary localization hack. Default to English. Check for French.
  DWORD menuId = IDC_CEFCLIENT;
  if (settings.locale.str && (settings.locale.length > 0) &&
      (CefString(settings.locale.str) == CefString("fr-FR")))
  {
	  menuId = IDC_CEFCLIENT_FR;
  }

  hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(menuId));

  int result = 0;

  if (!settings.multi_threaded_message_loop) {
    // Run the CEF message loop. This function will block until the application
    // recieves a WM_QUIT message.
    CefRunMessageLoop();
  } else {
    MSG msg;

    // Run the application message loop.
    while (GetMessage(&msg, NULL, 0, 0)) {
      if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    }

    result = static_cast<int>(msg.wParam);
  }

  OnBeforeShutdown();

  // Shut down CEF.
  CefShutdown();

  return result;
}
示例#8
0
//-----------------------------------------------------------------------------
// Name : DisplayWndProc ()
// Desc : The display devices internal WndProc function. All messages being
//        passed to this function are relative to the window it owns.
//-----------------------------------------------------------------------------
LRESULT CDDGameApp::DisplayWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    PAINTSTRUCT	ps;		   // used in WM_PAINT
	HDC hDC = NULL;
	
	//find out what the message is
	switch(uMsg)
	{	
	
	case WM_CREATE: //called when window is created
		{// do initialization stuff here
			//get the device context of the client area
			//hDC= GetDC(hWnd);
			
			return(0);
		} break;
	case WM_PAINT:
         {
			// start painting
			hDC = BeginPaint(hWnd,&ps);

			// end painting
			EndPaint(hWnd,&ps);
			ReleaseDC(hWnd, hDC);
			return(0);
        } break;
	case WM_ACTIVATEAPP: 
		{
			m_bActiveApp = (bool)wParam;
			break;
		}

	case WM_SIZE:
		{
            if ( wParam == SIZE_MINIMIZED )
            {
                // App is inactive
                m_bActiveApp = false;
            
            } // App has been minimized
            else
            {
                // App is active
                m_bActiveApp = true;      
            } // End if !Minimized

			break;
		}
	case WM_SETFOCUS:
		{
			//for(int i = 0; i<MAX_SPRITES; i++)
			//	Sprites[i].RestoreSurface();
			break;
		}
	case WM_KEYDOWN:
		{
			//m_pbKeyStatus[wParam] = true;
		
			switch (wParam) 
            {
				case VK_ESCAPE:
					m_bExitApp = true;
					//PostQuitMessage(0);
					return 0;
				case 0x57: //W
					{//Switch to windowed mode
						DestroyWindow(m_hWnd);
						UnregisterClass(m_WindowTitle,(HINSTANCE)GetModuleHandle(NULL));
						m_hWnd = NULL;//(HINSTANCE)GetModuleHandle(NULL)
						setDisplaySettings(true);
						ShutDown();
						InitInstance((HINSTANCE)GetModuleHandle(NULL), NULL, 0);
						ShowCursor(TRUE);
						OutputDebugString( "W pressed window destroyed no one created" );
						return 0;
					}
				case 0x56: //V
					{
						return 0;
					}
			}
			break;
		}

	case WM_KEYUP:
		{
			//m_pbKeyStatus[wParam] = false;
			break;
		}

	case WM_CLOSE:
		m_bExitApp = true;
		break;
	case WM_COMMAND:
		{
			// Process Menu Items
			switch( LOWORD(wParam) )
			{
				case ID_VIDEO_FULLSCREEN:
					{// Signal that we want to go full screen
						DestroyWindow(m_hWnd);
						UnregisterClass(m_WindowTitle,(HINSTANCE)GetModuleHandle(NULL));
						m_hWnd = NULL;
						setDisplaySettings(false);
						ShutDown();
						InitInstance((HINSTANCE)GetModuleHandle(NULL), NULL, 0);
						ShowCursor(FALSE);
						OutputDebugString( "Full screen mode activated" );
						return 0;
					}
               
				case ID_FILE_EXIT:
					// Recieved key/menu command to exit app
					m_bExitApp = true;
					SendMessage( m_hWnd, WM_CLOSE, 0, 0 );
					return 0;

			}//End switch( LOWORD(wParam) )
			break;	
		 }
	case WM_DESTROY: 
		{// kill the application			
			
			//close the program
			if( m_bExitApp ) PostQuitMessage(0);
			return(0);
		} break;

	default:break;

    } // end main switch

	// process any messages that we didn't take care of 
	return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
示例#9
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
#ifdef _DEBUG
    // memory leak check
    ::_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

    char tmpURL[8192];
    tmpURL[0]=0;
    char *chanURL=NULL;

    //VERSION_EX = 0;

    iniFileName.set(".\\peercast.ini");

    WIN32_FIND_DATA fd; //JP-EX
    HANDLE hFind; //JP-EX

    OSVERSIONINFO osInfo; //JP-EX
    osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); //JP-EX
    GetVersionEx(&osInfo);
    if (osInfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
        winDistinctionNT = true;
    else
        winDistinctionNT = false;

    // off by default now
    showGUI = false;

    if (strlen(lpCmdLine) > 0)
    {
        char *p;
        if ((p = strstr(lpCmdLine,"-inifile"))!=NULL)
            iniFileName.setFromString(p+8);

        if (strstr(lpCmdLine,"-zen"))
            showGUI = false;

        if (strstr(lpCmdLine,"-multi"))
            allowMulti = true;

        if (strstr(lpCmdLine,"-kill"))
            killMe = true;

        if ((p = strstr(lpCmdLine,"-url"))!=NULL)
        {
            p+=4;
            while (*p)
            {
                if (*p=='"')
                {
                    p++;
                    break;
                }
                if (*p != ' ')
                    break;
                p++;
            }
            if (*p)
                strncpy(tmpURL,p,sizeof(tmpURL)-1);
        }
    }

    // get current path
    {
        exePath = iniFileName;
        char *s = exePath.cstr();
        char *end = NULL;
        while (*s)
        {
            if (*s++ == '\\')
                end = s;
        }
        if (end)
            *end = 0;
    }


    if (strnicmp(tmpURL,"peercast://",11)==0)
    {
        if (strnicmp(tmpURL+11,"pls/",4)==0)
            chanURL = tmpURL+11+4;
        else
            chanURL = tmpURL+11;
        showGUI = false;
    }


    MSG msg;
    HACCEL hAccelTable;

    // Initialize global strings
    //LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    //LoadString(hInstance, IDC_APP_TITLE, szWindowClass, MAX_LOADSTRING);

    strcpy(szTitle,"PeerCast");
    strcpy(szWindowClass,"PeerCast");

    if (!allowMulti)
    {
        HANDLE mutex = CreateMutex(NULL,TRUE,szWindowClass);

        if (GetLastError() == ERROR_ALREADY_EXISTS)
        {
            HWND oldWin = FindWindow(szWindowClass,NULL);
            if (oldWin)
            {
                if (killMe)
                {
                    SendMessage(oldWin,WM_DESTROY,0,0);
                    return 0;
                }

                if (chanURL)
                {
                    COPYDATASTRUCT copy;
                    copy.dwData = WM_PLAYCHANNEL;
                    copy.cbData = strlen(chanURL)+1;			// plus null term
                    copy.lpData = chanURL;
                    SendMessage(oldWin,WM_COPYDATA,NULL,(LPARAM)&copy);
                } else {
                    if (showGUI)
                        SendMessage(oldWin,WM_SHOWGUI,0,0);
                }
            }
            return 0;
        }
    }

    if (killMe)
        return 0;

    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
        return FALSE;

    peercastInst = new MyPeercastInst();
    peercastApp = new MyPeercastApp();

    peercastInst->init();

    LOG_DEBUG("Set OS Type: %s",winDistinctionNT?"WinNT":"Win9x");

    if (peercastApp->clearTemp()) //JP-EX
    {
        DeleteFile("play.pls");
        hFind = FindFirstFile("*.asx",&fd);
        if (hFind != INVALID_HANDLE_VALUE)
        {
            do
            {
                DeleteFile((char *)&fd.cFileName);
            }
            while (FindNextFile(hFind,&fd));

            FindClose(hFind);
        }
    }

    if (chanURL)
    {
        ChanInfo info;
        servMgr->procConnectArgs(chanURL,info);
        chanMgr->findAndPlayChannel(info,false);
    }


    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SIMPLE);

    // setup menu notifes
    int mask = peercastInst->getNotifyMask();
    if (mask & ServMgr::NT_PEERCAST)
        CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_PEERCAST,MF_CHECKED|MF_BYCOMMAND);
    if (mask & ServMgr::NT_BROADCASTERS)
        CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_BROADCASTERS,MF_CHECKED|MF_BYCOMMAND);
    if (mask & ServMgr::NT_TRACKINFO)
        CheckMenuItem(trayMenu,ID_POPUP_SHOWMESSAGES_TRACKINFO,MF_CHECKED|MF_BYCOMMAND);

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    Shell_NotifyIcon(NIM_DELETE, (NOTIFYICONDATA*)&trayIcon);

    peercastInst->saveSettings();
    peercastInst->quit();

    return msg.wParam;
}
示例#10
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	Sleep(test_main());
	/*
	Sleep(test_main()/1000);
.text:0040102A                 mov     ecx, eax
.text:0040102C                 mov     eax, 10624DD3h
.text:00401031                 imul    ecx
.text:00401033                 sar     edx, 6
.text:00401036                 mov     eax, edx
.text:00401038                 shr     eax, 1Fh
.text:0040103B                 add     edx, eax
.text:0040103D                 push    edx             ; dwMilliseconds
.text:0040103E                 call    ds:Sleep


		Sleep(test_main()/10000);
.text:0040102A 024                 mov     ecx, eax
.text:0040102C 024                 mov     eax, 68DB8BADh
.text:00401031 024                 imul    ecx
.text:00401033 024                 sar     edx, 0Ch
.text:00401036 024                 mov     eax, edx
.text:00401038 024                 shr     eax, 1Fh
.text:0040103B 024                 add     edx, eax
.text:0040103D 024                 push    edx             ; dwMilliseconds
.text:0040103E 028                 call    ds:Sleep

	*/

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_PETEST, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_PETEST);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

  //-------------- M A I N    D E L   P R O G R A M A   D E L    R O B O T------------//
  //----------------------------------------------------------------------------------------------------------
	
  //inicializaion de variables
  Aria::init();
  ArArgumentParser parser(&argc, argv);
  parser.loadDefaultArguments();
  ArSimpleConnector simpleConnector(&parser);
  ArRobot robot;
  ArSonarDevice sonar;
  ArAnalogGyro gyro(&robot);
  robot.addRangeDevice(&sonar);

  // presionar tecla escape para salir del programa
  ArKeyHandler keyHandler;
  Aria::setKeyHandler(&keyHandler);
  robot.attachKeyHandler(&keyHandler);
  printf("You may press escape to exit\n");

  // uso de sonares para evitar colisiones con las paredes u 
  // obstaculos grandes, mayores a 8cm de alto
  ArActionLimiterForwards limiterAction("speed limiter near", 300, 600, 250);
  ArActionLimiterForwards limiterFarAction("speed limiter far", 300, 1100, 400);
  ArActionLimiterTableSensor tableLimiterAction;
  robot.addAction(&tableLimiterAction, 100);
  robot.addAction(&limiterAction, 95);
  robot.addAction(&limiterFarAction, 90);


  // Inicializon la funcion de goto
  ArActionGoto gotoPoseAction("goto");
  robot.addAction(&gotoPoseAction, 50);
  
  // Finaliza el goto si es que no hace nada
  ArActionStop stopAction("stop");
  robot.addAction(&stopAction, 40);

  // Parser del CLI
  if (!Aria::parseArgs() || !parser.checkHelpAndWarnUnparsed())
  {    
    Aria::logOptions();
    exit(1);
  }
  
  // Conexion del robot
  if (!simpleConnector.connectRobot(&robot))
  {
    printf("Could not connect to robot... exiting\n");
    Aria::exit(1);
  }
  robot.runAsync(true);

  // enciende motores, apaga sonidos
  robot.enableMotors();
  robot.comInt(ArCommands::SOUNDTOG, 0);

  const int duration = 100000; //msec
  ArLog::log(ArLog::Normal, "Completados los puntos en %d segundos", duration/1000);

  bool first = true;
  int horiz = 1800;
  int vert = 380;
  int goalNum = 0;
  ArTime start;
  start.setToNow();
  while (Aria::getRunning()) 
  {
    robot.lock();
    // inicia el primer punto 
    if (first || gotoPoseAction.haveAchievedGoal())
    {
      first = false;
	  
      goalNum++; //cambia de 0 a 1 el contador
      if (goalNum > 7)
        goalNum = 1;

	  //comienza la secuencia de puntos
      if (goalNum == 1)
        gotoPoseAction.setGoal(ArPose(horiz, vert*0));
      else if (goalNum == 2)
        gotoPoseAction.setGoal(ArPose(0, vert*1));
      else if (goalNum == 3)
        gotoPoseAction.setGoa l(ArPose(horiz, vert*2)+5);
      else if (goalNum == 4)
        gotoPoseAction.setGoal(ArPose(0, vert*3));
	  else if (goalNum == 5)
        gotoPoseAction.setGoal(ArPose(horiz, vert*4+5));
	  else if (goalNum == 6)
        gotoPoseAction.setGoal(ArPose(0, vert*5));
	  else if (goalNum == 7)
        gotoPoseAction.setGoal(ArPose(0, vert*0));

      ArLog::log(ArLog::Normal, "Siguiente punto en %.0f %.0f", 
		    gotoPoseAction.getGoal().getX(), gotoPoseAction.getGoal().getY());
    }

    if(start.mSecSince() >= duration) {
      ArLog::log(ArLog::Normal, "%d seconds have elapsed. Cancelling current goal, waiting 3 seconds, and exiting.", duration/1000);
      gotoPoseAction.cancelGoal();
      robot.unlock();
      ArUtil::sleep(3000);
      break;
    }
    
    robot.unlock();
    ArUtil::sleep(100);
  }

  // Robot desconectado al terminal el sleep
  Aria::shutdown();
  return 0;

//----------------------------------------------------------------------------------------------------------

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_VENTANAROBOT, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_VENTANAROBOT));

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return (int) msg.wParam;
}
示例#12
0
文件: main.cpp 项目: 3A9C/ITstep
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {

    MSG msg;
    int dwRefresh;
    LARGE_INTEGER LargeInt;


    if (InitInstance(hInstance) == FALSE) {
        return FALSE;
    }

    //Init random seed
    QueryPerformanceCounter(&LargeInt);
    srand(LargeInt.LowPart);
    ////////////////////////////////////////

    InitializeCriticalSection(&crsCurPiece);

    ClearBoard();

    dwRefresh = GetTickCount();

    PushRandomPiece();
    DrawBoard();
    UpdateScreen();


    while (1) {

        if (PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE) {

            if (GetMessageA(&msg, NULL, 0, 0) == FALSE) {
                return 0;
            }

            TranslateMessage(&msg);
            DispatchMessage(&msg);

        }
        else {


            if (GetTickCount() >= (DWORD)(dwRefresh + FallingPieceSpeed)) {

                DrawBoard();
                UpdateScreen();

                dwRefresh = GetTickCount();

                EnterCriticalSection(&crsCurPiece);

                if (IsActionPossible(CurPiece.Piece, CurPiece.PosX, CurPiece.PosY + 1) == TRUE) {

                    CurPiece.PosY++;

                }
                else {

                    if (SaveCurPiece() == TRUE) {
                        MessageBoxA(NULL, "Game Over!", NULL, MB_OK);
                        ExitProcess(0);
                    }
                    DeleteLines();
                    PushRandomPiece();
                }

                LeaveCriticalSection(&crsCurPiece);

            }

            Sleep(100); //give that CPU some rest
        }
    }


    return 0;
}
示例#13
0
//——————————————————————
//エントリーポイント
//——————————————————————
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow)
{

#if _DEBUG
	_CrtDumpMemoryLeaks();
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	MSG msg;

	//ウィンドウクラスの登録
	if (!InitApp(hCurInst))
		return FALSE;

	//ウィンドウ生成
	if (!InitInstance(hCurInst, nCmdShow))
		return FALSE;

	//ランダムの準備
	srand((unsigned)time(NULL));

	//ゲームオブジェクトを作成
	game = new Game;

	//Direct3Dの初期化
	if (FAILED(game->InitD3d(hWnd)))
	{
		return FALSE;
	}

	//入力処理の初期化
	g_pInput = new Input();
	g_pInput->Init(hWnd);

	//読み込み処理
	if (FAILED(game->Load()))
	{
		return FALSE;
	}

	// メッセージを取得
	ZeroMemory(&msg, sizeof(msg));
	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			if (isEnd)
			{
				break;
			}
			//ゲームの更新
			if (FAILED(game->Update()))
			{
				return FALSE;
			}

			//衝突判定
			if (FAILED(game->Hit()))
			{
				return FALSE;
			}

			//ゲーム画面の描画
			if (FAILED(game->Render()))
			{
				return FALSE;
			}
		}
	}
	return (int)msg.wParam;
}
示例#14
0
文件: wemap.cpp 项目: toxeh/wemap
int WINAPI WinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPTSTR    lpCmdLine,
				   int       nCmdShow)
{
 hWnd_WEMAP = 0;
 hWnd_cid_gui = 0;
 hWnd_navitel = 0;
 hWndEdit = 0;
 hWnd_self = 0;
 hWnd_last = 0;


	fname = "\\Storage Card\\wemap\\wemap_WinMain.txt";
	fnamew = "\\Storage Card\\wemap\\Windows.txt";
	MSG msg;
	FILE * pFileTXT;
	Angle = DMDO_180;

	pFileTXT = fopen (fname,"a");

	UINT MS  = RegisterWindowMessageW(L"Private End Route Voice");
	fprintf (pFileTXT, "Private End Route Voice - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Start Route Voice");
	fprintf (pFileTXT, "Private Start Route Voice - %d\n", MS);

	MS = RegisterWindowMessageW(L"Private Close LCN_Upgrade Process");
	fprintf (pFileTXT, "Private Close LCN_Upgrade Process - %d\n", MS);	


	MS = RegisterWindowMessageW(L"Private Trip Info");
	fprintf (pFileTXT, "Private Trip Info - %d\n", MS);

	MS = RegisterWindowMessageW(L"Private Navi Start");
	fprintf (pFileTXT, "Private Navi Start - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Navi Closed");
	fprintf (pFileTXT, "Private Navi Closed - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Navi Destroyed");
	fprintf (pFileTXT, "Private Navi Destroyed - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Navi Exit");
	fprintf (pFileTXT, "Private Navi Exit - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Navi Volume");
	fprintf (pFileTXT, "Private Navi Volume - %d\n", MS);


	MS = RegisterWindowMessageW(L"Private Navi Button Down");
	fprintf (pFileTXT, "Private Navi Button Down - %d\n", MS);


	MS = RegisterWindowMessageW(L"Private Gps Ver Request");
	fprintf (pFileTXT, "Private Gps Ver Request - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Gps Ver Reply");
	fprintf (pFileTXT, "Private Gps Ver Reply - %d\n", MS);

	MS = RegisterWindowMessageW(L"Private TPEG Request");
	fprintf (pFileTXT, "Private TPEG Request - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private TPEG Reply");
	fprintf (pFileTXT, "Private TPEG Reply - %d\n", MS);

	MS = RegisterWindowMessageW(L"Private Gps Speed S12");
	fprintf (pFileTXT, "Private Gps Speed S12 - %d\n", MS);

	MS = RegisterWindowMessageW(L"Private Go To Main Dialog");
	fprintf (pFileTXT, "Private Go To Main Dialog - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Go To Setting Dialog");
	fprintf (pFileTXT, "Private Go To Setting Dialog - %d\n", MS);

	MS = RegisterWindowMessageW(L"Private Request Light Status");
	fprintf (pFileTXT, "Private Request Light Status - %d\n", MS);

	MS = RegisterWindowMessageW(L"UK SA Message Received");
	fprintf (pFileTXT, "UK SA Message Received - %d\n", MS);
	MS = RegisterWindowMessageW(L"UK Abort SA Client");
	fprintf (pFileTXT, "UK Abort SA Client - %d\n", MS);

	PrivateModeChange = RegisterWindowMessageW(L"Private Mode Change");
	fprintf (pFileTXT, "Private Mode Change - %d\n", PrivateModeChange);

	MS = RegisterWindowMessageW(L"Private Light Off");
	fprintf (pFileTXT, "Private Light Off - %d\n", MS);
	MS = RegisterWindowMessageW(L"Private Light On");
	fprintf (pFileTXT, "Private Light On - %d\n", MS);

	fclose (pFileTXT);


	// Perform application initialization:
	if (!InitInstance(hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	HACCEL hAccelTable;
	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WEMAP));
	int  ret;
	int i;
	i = 0;
	ret = 1;
	while (ret)
	{
		while (!PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE)) 
		{
			if (i++>1000)
			{
				if ((hWnd_navitel<=0) || (hWnd_WEMAP<=0) || (hWnd_cid_gui<=0))
					EnumWindows( enum_proc, (LPARAM)"Ѕлокнот" );
				i=0;

			}
		}
		ret = GetMessage(&msg, NULL, NULL, NULL);

		SYSTEMTIME st;
		GetLocalTime(&st);
		pFileTXT = fopen (fname,"a");
		fprintf(pFileTXT, "---> Date: [%02d, %02d, %d]  Time: [%02d:%02d:%02d] " ,st.wDay, st.wMonth, st.wYear, st.wHour, st.wMinute, st.wSecond);
		fprintf (pFileTXT, " wnd(%d) msg(%d) wParam(%d-%d) lParam(%d-%d) \n", msg.hwnd,msg.message,LOWORD(msg.wParam), HIWORD(msg.wParam),LOWORD(msg.lParam), HIWORD(msg.lParam));

		fclose (pFileTXT);

			
		if(  ret != -1 ) 
		{
			//else
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			if (msg.message==PrivateModeChange)
			{
				pFileTXT = fopen (fname,"a");
				int wmId;
				wmId    = LOWORD(msg.wParam);
				
				if (wmId==1)
				{
					if (hWnd_navitel>0)
					{
						fprintf (pFileTXT, " Show Navitel \n");
						ShowWindow(hWnd_navitel,SW_SHOW);
						SetForegroundWindow(hWnd_navitel);
						set_rotation(true);
						UpdateWindow(hWnd_navitel);

					} else 
					{
						if (hWnd_WEMAP>0)
						{
							fprintf (pFileTXT, " Show WEMAP \n");
							set_rotation(true);
						}
					}

				} else
				{
					if ((hWnd_navitel>0) || (hWnd_WEMAP>0))
						if (wmId!=5)
						{
							fprintf (pFileTXT, " Hide Navitel(WEMAP) \n");
							set_rotation(false);
							if (hWnd_navitel>0)
								ShowWindow(hWnd_navitel,SW_HIDE);
							else
								ShowWindow(hWnd_WEMAP,SW_HIDE);
							ShowWindow(hWnd_cid_gui,SW_SHOW);
						}
				}
				fclose (pFileTXT);
			}
		}
	}
	return( ret );

}
示例#15
0
文件: main.c 项目: Blandinium/eid-mw
int APIENTRY _tWinMain(HINSTANCE hInstance,
											 HINSTANCE hPrevInstance,
											 LPTSTR    lpCmdLine,
											 int       nCmdShow)
{
	//UNREFERENCED_PARAMETER(hPrevInstance);
	//UNREFERENCED_PARAMETER(lpCmdLine);

	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;
	void *pkcs11_handle = NULL;
	CK_RV retval = CKR_OK;
	DWORD   dwThreadId;
	HANDLE  hThreadHandle; 
	gStopThreads = PKCS11THREAD_RUN;

	// Initialize global strings
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_CERTREG, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}
	if (!InitPKCS11(pkcs11_handle))
	{
		SendMessage(hTextEdit, EM_REPLACESEL,0,  (LPARAM)"Exiting application in 5 seconds\r\n");
		Sleep(5000);
		return FALSE;
	}

	retval = (gfunctions->C_Initialize) (NULL);
	if (retval != CKR_OK)
	{	
		SendMessage(hTextEdit, EM_REPLACESEL,0,  (LPARAM)"ERROR: C_Initialize failed :\r\n");
	}
	else
	{
		// Create pkcs11Events thread
		hThreadHandle = CreateThread( 
			NULL,             // default security attributes
			0,                // use default stack size  
			pkcs11EventsThread,			// thread function name
			NULL,			// argument to thread function 
			0,                // use default creation flags 
			&dwThreadId);			// returns the thread identifier 

		if (hThreadHandle == NULL)
		{
			SendMessage(hTextEdit, EM_REPLACESEL,0,  (LPARAM)"ERROR: Failed to start CardEventThread\r\n");
			SendMessage(hTextEdit, EM_REPLACESEL,0,  (LPARAM)"Automated functionality is inactive\r\n");
		}

		hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CERTREG));

		// Main message loop:
		while (GetMessage(&msg, NULL, 0, 0))
		{
			if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
			if(gStopThreads == PKCS11THREAD_STOPPED)
			{
				if(msg.hwnd != NULL)
					DestroyWindow(msg.hwnd);
				break;
			}
		}
		//retval = (gfunctions->C_Finalize) (NULL_PTR);
	}

	if (hThreadHandle != NULL)
	{
		gStopThreads = 1;
		// Wait for max 5 seconds until pkcs11Events thread is terminated.
		if (WaitForSingleObject(hThreadHandle, 5000) == WAIT_OBJECT_0)
		{
			CloseHandle(hThreadHandle);
		}
	}


	dlclose(pkcs11_handle);

	return (int) msg.wParam;
}
示例#16
0
// Program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow) {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);

  void* sandbox_info = NULL;

#if CEF_ENABLE_SANDBOX
  // Manage the life span of the sandbox information object. This is necessary
  // for sandbox support on Windows. See cef_sandbox_win.h for complete details.
  CefScopedSandboxInfo scoped_sandbox;
  sandbox_info = scoped_sandbox.sandbox_info();
#endif

  CefMainArgs main_args(hInstance);
  CefRefPtr<ClientApp> app(new ClientApp);

  // Execute the secondary process, if any.
  int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
  if (exit_code >= 0)
    return exit_code;

  // Retrieve the current working directory.
  if (_getcwd(szWorkingDir, MAX_PATH) == NULL)
    szWorkingDir[0] = 0;

  // Parse command line arguments. The passed in values are ignored on Windows.
  AppInitCommandLine(0, NULL);

  CefSettings settings;

#if !CEF_ENABLE_SANDBOX
  settings.no_sandbox = true;
#endif

  // Populate the settings based on command line arguments.
  AppGetSettings(settings);

  // Initialize CEF.
  CefInitialize(main_args, settings, app.get(), sandbox_info);

  // Register the scheme handler.
  scheme_test::InitTest();

  HACCEL hAccelTable;

  // Initialize global strings
  LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING);
  LoadString(hInstance, IDS_OSR_WIDGET_CLASS, szOSRWindowClass, MAX_LOADSTRING);
  MyRegisterClass(hInstance);

  // Perform application initialization
  if (!InitInstance (hInstance, nCmdShow))
    return FALSE;

  hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT));

  // Register the find event message.
  uFindMsg = RegisterWindowMessage(FINDMSGSTRING);

  int result = 0;

  if (!settings.multi_threaded_message_loop) {
    // Run the CEF message loop. This function will block until the application
    // recieves a WM_QUIT message.
    CefRunMessageLoop();
  } else {
    // Create a hidden window for message processing.
    hMessageWnd = CreateMessageWindow(hInstance);
    ASSERT(hMessageWnd);

    MSG msg;

    // Run the application message loop.
    while (GetMessage(&msg, NULL, 0, 0)) {
      // Allow processing of find dialog messages.
      if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
        continue;

      if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    }

    DestroyWindow(hMessageWnd);
    hMessageWnd = NULL;

    result = static_cast<int>(msg.wParam);
  }

  // Shut down CEF.
  CefShutdown();

  return result;
}
示例#17
0
// エントリーポイント
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	MSG msg;

	TCHAR	szThisPath[MAX_PATH];
	DWORD   sLen;

	// 自身のディレクトリを取得する
	sLen = GetModuleFileName(NULL, szThisPath, MAX_PATH);
	for(unsigned int i = sLen; i >= 0; i--) {
		if(szThisPath[i] == _T('\\')) {
			szThisPath[i] = _T('\0');
			break;
		}
	}

	// カレントディレクトリを exe と同じ場所に設定
	SetCurrentDirectory(szThisPath);

	g_Settings = loadSettings(_T("gyazowin+.ini"), _T("gyazowin+"));

	// 引数にファイルが指定されていたら
	if ( 2 == __argc )
	{
		// ファイルをアップロードして終了
		if (isPng(__targv[1])) {
			// PNG はそのままupload
			uploadFile(NULL, __targv[1]);
		}else {
			// PNG 形式に変換
			TCHAR tmpDir[MAX_PATH], tmpFile[MAX_PATH];
			GetTempPath(MAX_PATH, tmpDir);
			GetTempFileName(tmpDir, _T("gya"), 0, tmpFile);
			
			if (convertPNG(tmpFile, __targv[1])) {
				//アップロード
				uploadFile(NULL, tmpFile);
			} else {
				// PNGに変換できなかった...
				MessageBox(NULL, _T("Cannot convert this image"), szTitle, 
					MB_OK | MB_ICONERROR);
			}
			DeleteFile(tmpFile);
		}
		return TRUE;
	}

	// ウィンドウクラスを登録
	MyRegisterClass(hInstance);

	// アプリケーションの初期化を実行します:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}
	
	// メイン メッセージ ループ:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (int) msg.wParam;
}
示例#18
0
文件: meos.cpp 项目: ledusledus/meos
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  atexit(dumpLeaks);	//
  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

  if (strstr(lpCmdLine, "-s") != 0) {
    Setup(true, false);
    exit(0);
  }

  lang.init();
  StringCache::getInstance().init();

  GetCurrentDirectory(MAX_PATH, programPath);

  getUserFile(settings, "meospref.xml");

  Parser::test();

  int rInit = (GetTickCount() / 100);
  InitRanom(rInit, rInit/379);

  tabList=new list<TabObject>;

  MSG msg;
  HACCEL hAccelTable;

  gdi_main = new gdioutput("main", 1.0, ANSI);
  gdi_extra.push_back(gdi_main);

  try {
    gEvent = new oEvent(*gdi_main);
  }
  catch (std::exception &ex) {
    gdi_main->alert(string("Failed to create base event: ") + ex.what());
    return 0;
  }

  gEvent->loadProperties(settings);

  lang.get().addLangResource("English", "104");
  lang.get().addLangResource("Svenska", "103");
  lang.get().addLangResource("Deutsch", "105");
  lang.get().addLangResource("Dansk", "106");
  lang.get().addLangResource("Russian (ISO 8859-5)", "107");
  lang.get().addLangResource("English (ISO 8859-2)", "108");

  if (fileExist("extra.lng")) {
    lang.get().addLangResource("Extraspråk", "extra.lng");
  }
  else {
    char lpath[260];
    getUserFile(lpath, "extra.lng");
    if (fileExist(lpath))
      lang.get().addLangResource("Extraspråk", lpath);
  }

  string defLang = gEvent->getPropertyString("Language", "Svenska");

  // Backward compatibility
  if (defLang=="103")
    defLang = "Svenska";
  else if (defLang=="104")
    defLang = "English";

  gEvent->setProperty("Language", defLang);

  try {
    lang.get().loadLangResource(defLang);
  }
  catch (std::exception &) {
    lang.get().loadLangResource("Svenska");
  }

  try {
    char listpath[MAX_PATH];
    getUserFile(listpath, "");
    vector<string> res;
    expandDirectory(listpath, "*.lxml", res);
    expandDirectory(listpath, "*.listdef", res);
#
#ifdef _DEBUG
    expandDirectory(".\\Lists\\", "*.lxml", res);
    expandDirectory(".\\Lists\\", "*.listdef", res);
#endif
    string err;

    for (size_t k = 0; k<res.size(); k++) {
      try {
        xmlparser xml(0);

        strcpy_s(listpath, res[k].c_str());
        xml.read(listpath);

        xmlobject xlist = xml.getObject(0);
        gEvent->getListContainer().load(MetaListContainer::InternalList, xlist, true);
      }
      catch (std::exception &ex) {
        string errLoc = "Kunde inte ladda X\n\n(Y)#" + string(listpath) + "#" + lang.tl(ex.what());
        if (err.empty())
          err = errLoc;
        else
          err += "\n" + errLoc;
      }
    }
    if (!err.empty())
      gdi_main->alert(err);
  }
  catch (std::exception &ex) {
    gdi_main->alert(ex.what());
    //exit(1);
  }

  gEvent->openRunnerDatabase("database");
  strcpy_s(szTitle, "MeOS");
  strcpy_s(szWindowClass, "MeosMainClass");
  strcpy_s(szWorkSpaceClass, "MeosWorkSpace");
  MyRegisterClass(hInstance);
  registerToolbar(hInstance);

  string encoding = lang.tl("encoding");
  gdi_main->setFont(gEvent->getPropertyInt("TextSize", 0),
                  gEvent->getPropertyString("TextFont", "Arial"), interpetEncoding(encoding));

  // Perform application initialization:
  if (!InitInstance (hInstance, nCmdShow)) {
    return FALSE;
  }

  RECT rc;
  GetClientRect(hWndMain, &rc);
  SendMessage(hWndMain, WM_SIZE, 0, MAKELONG(rc.right, rc.bottom));

  gdi_main->init(hWndWorkspace, hWndMain, hMainTab);
  gdi_main->getTabs().get(TCmpTab)->loadPage(*gdi_main);

  autoTask = new AutoTask(hWndMain, *gEvent, *gdi_main);

  autoTask->setTimers();

  // Install a hook procedure to monitor the message stream for mouse
  // messages intended for the controls in the dialog box.
  g_hhk = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc,
      (HINSTANCE) NULL, GetCurrentThreadId());

  hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MEOS);

  initMySQLCriticalSection(true);
  // Main message loop:
  while (GetMessage(&msg, NULL, 0, 0)) {
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }

  tabAutoRegister(0);
  tabList->clear();
  delete tabList;
  tabList=0;

  delete autoTask;
  autoTask = 0;

  for (size_t k = 0; k<gdi_extra.size(); k++) {
    if (gdi_extra[k]) {
      DestroyWindow(gdi_extra[k]->getHWND());
      if (k < gdi_extra.size()) {
        delete gdi_extra[k];
        gdi_extra[k] = 0;
      }
    }
  }

  gdi_extra.clear();

  if (gEvent)
    gEvent->saveProperties(settings);

  delete gEvent;
  gEvent = 0;

  initMySQLCriticalSection(false);

  removeTempFiles();

  #ifdef _DEBUG
    lang.get().debugDump("untranslated.txt", "translated.txt");
  #endif

  StringCache::getInstance().clear();
  lang.unload();

  return msg.wParam;
}
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPWSTR     lpCmdLine,
                     int       nCmdShow)
{
	INITCOMMONCONTROLSEX InitCtrls;
	HWND nethackWnd;
	int argc;
	char* argv[MAX_CMDLINE_PARAM];
	size_t len;
	TCHAR* p;
	TCHAR wbuf[NHSTR_BUFSIZE];
	char buf[NHSTR_BUFSIZE];

	/* ensure that we don't access violate on a panic() */
	windowprocs.win_raw_print = mswin_raw_print;
	windowprocs.win_raw_print_bold = mswin_raw_print_bold;

	/* init applicatio structure */
	_nethack_app.hApp = hInstance;
	_nethack_app.nCmdShow = nCmdShow;
	_nethack_app.hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WINHACK);
	_nethack_app.hMainWnd = NULL;
	_nethack_app.hPopupWnd = NULL;
	_nethack_app.hMenuBar = NULL;
	_nethack_app.bmpTiles = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_TILES));
	if( _nethack_app.bmpTiles==NULL ) panic("cannot load tiles bitmap");
	_nethack_app.bmpPetMark = LoadBitmap(hInstance, MAKEINTRESOURCE(IDB_PETMARK));
	if( _nethack_app.bmpPetMark==NULL ) panic("cannot load pet mark bitmap");
	_nethack_app.bmpMapTiles = _nethack_app.bmpTiles;
	_nethack_app.mapTile_X = TILE_X;
	_nethack_app.mapTile_Y = TILE_Y;
	_nethack_app.mapTilesPerLine = TILES_PER_LINE;
	_nethack_app.bNoHScroll = FALSE;
	_nethack_app.bNoVScroll = FALSE;

#if  defined(WIN_CE_PS2xx) || defined(WIN_CE_POCKETPC) || defined(WIN_CE_SMARTPHONE)
	_nethack_app.bCmdPad = TRUE;
#else
	_nethack_app.bCmdPad = FALSE;
#endif

	_nethack_app.bWrapText = TRUE;
	_nethack_app.bFullScreen = TRUE;

#if defined(WIN_CE_SMARTPHONE)
	_nethack_app.bHideScrollBars = TRUE;
#else
	_nethack_app.bHideScrollBars = FALSE;
#endif

	_nethack_app.bUseSIP = TRUE;

	// check for running nethack programs
	nethackWnd = FindWindow(szMainWindowClass, NULL);
	if( nethackWnd ) {
		// bring on top
		SetForegroundWindow(nethackWnd);
		return FALSE;
	}

	// init controls
	ZeroMemory(&InitCtrls, sizeof(InitCtrls));
	InitCtrls.dwSize = sizeof(InitCtrls);
	InitCtrls.dwICC = ICC_LISTVIEW_CLASSES;
	if( !InitCommonControlsEx(&InitCtrls) ) {
		MessageBox(NULL, TEXT("Cannot init common controls"), TEXT("ERROR"), MB_OK | MB_ICONSTOP);
		return FALSE;
	}

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	/* get command line parameters */	
	p = _get_cmd_arg(
#if defined(WIN_CE_PS2xx) || defined(WIN32_PLATFORM_HPCPRO)
		lpCmdLine
#else
		GetCommandLine()
#endif
		);
	for( argc = 1; p && argc<MAX_CMDLINE_PARAM; argc++ ) {
		len = _tcslen(p);
		if( len>0 ) {
			argv[argc] = _strdup( NH_W2A(p, buf, BUFSZ) );
		} else {
			argv[argc] = "";
		}
		p = _get_cmd_arg(NULL);
	}
	GetModuleFileName(NULL, wbuf, BUFSZ);
	argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ));

	pcmain(argc,argv);

	moveloop();

	return 0;
}
示例#20
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

 	// TODO: ここにコードを挿入してください。
	MSG msg;
	HACCEL hAccelTable;

	// グローバル文字列を初期化しています。
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_HDRLIGHTING, szWindowClass, MAX_LOADSTRING);
	MyRegisterClass(hInstance);

	// アプリケーションの初期化を実行します:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}

	int ret;
	ret = OneTimeSceneInit();
	if( ret ){
		_ASSERT( 0 );
		return FALSE;
	}


	hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_HDRLIGHTING));

	// Now we're ready to recieve and process Windows messages.
    BOOL bGotMsg;
    //MSG  msg;
    PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );

    while( WM_QUIT != msg.message  )
    {
        // Use PeekMessage() if the app is active, so we can use idle time to
        // render the scene. Else, use GetMessage() to avoid eating CPU time.
       // if( m_bActive )
        bGotMsg = PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE );
        //else
          //  bGotMsg = GetMessage( &msg, NULL, 0U, 0U );

        if( bGotMsg )
        {
            // Translate and dispatch the message
            if( 0 == TranslateAccelerator(msg.hwnd, hAccelTable, &msg) )
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        }else{
			if( Render3DEnvironment() != 0 ){
                SendMessage( msg.hwnd, WM_CLOSE, 0, 0 );
            }
        }
    }

	E3DBye();

	return (int) msg.wParam;
}
示例#21
0
// Program entry point function.
int APIENTRY wWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);

  // Retrieve the current working directory.
  if(_getcwd(szWorkingDir, MAX_PATH) == NULL)
    szWorkingDir[0] = 0;

  // Parse command line arguments. The passed in values are ignored on Windows.
  AppInitCommandLine(0, NULL);

  CefSettings settings;
  CefRefPtr<CefApp> app;

  // Populate the settings based on command line arguments.
  AppGetSettings(settings, app);

  // Initialize CEF.
  CefInitialize(settings, app);

  // Register the internal client plugin.
  InitPluginTest();

  // Register the internal UI client plugin.
  InitUIPluginTest();

  // Register the internal OSR client plugin.
  InitOSRPluginTest();

  // Register the V8 extension handler.
  InitExtensionTest();

  // Register the scheme handler.
  InitSchemeTest();
  
  HACCEL hAccelTable;

  // Initialize global strings
  LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  LoadString(hInstance, IDC_CEFCLIENT, szWindowClass, MAX_LOADSTRING);
  MyRegisterClass(hInstance);

  // Perform application initialization
  if (!InitInstance (hInstance, nCmdShow))
  {
    return FALSE;
  }

  hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CEFCLIENT));

  // Register the find event message.
  uFindMsg = RegisterWindowMessage(FINDMSGSTRING);

  int result = 0;

  if (!settings.multi_threaded_message_loop) {
    // Run the CEF message loop. This function will block until the application
    // recieves a WM_QUIT message.
    CefRunMessageLoop();
  } else {
    MSG msg;
  
    // Run the application message loop.
    while (GetMessage(&msg, NULL, 0, 0)) {
      // Allow processing of find dialog messages.
      if (hFindDlg && IsDialogMessage(hFindDlg, &msg))
        continue;

      if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
    }

    result = (int)msg.wParam;
  }

  // Shut down CEF.
  CefShutdown();

  return result;
}