Ejemplo n.º 1
0
int _tmain(int argc, _TCHAR* argv[])
{

/*
	//MT4|ASK!EURUSD
	char szApp[] = "MT4";
    char szTopic[] = "ASK";
    //char szCmd1[] = "[APP.MINIMIZE()]";
    char szItem1[] = "USDJPY";  char szDesc1[] = "A1 Contains: ";
    char szItem2[] = "USDCHF";  char szDesc2[] = "A2 Contains: ";
    //char szItem3[] = "R3C1";  char szData3[] = "Data from DDE Client";
    //char szCmd2[] = "[SELECT(\"R3C1\")][FONT.PROPERTIES(,\"Bold\")][SAVE()][QUIT()]";
*/
    //DDE Initialization
    
    UINT iReturn;
    iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback, 
                            APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );
    if (iReturn!=DMLERR_NO_ERROR)
    {
        printf("DDE Initialization Failed: 0x%04x\n", iReturn);
        Sleep(1500);
        return 0;
    }

    //Start DDE Server and wait for it to become idle.
    //HINSTANCE hRet = ShellExecute(0, "open", szTopic, 0, 0, SW_SHOWNORMAL);
    //if ((int)hRet < 33)
    //{
    //    printf("Unable to Start DDE Server: 0x%04x\n", hRet);
    //    Sleep(1500); DdeUninitialize(idInst);
    //    return 0;
    //}
    //Sleep(1000);

    //DDE Connect to Server using given AppName and topic.
    HCONV hConv;
    hszApp = DdeCreateStringHandle(idInst, szApp, 0);
    hszTopic = DdeCreateStringHandle(idInst, szTopic, 0);
    hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
    DdeFreeStringHandle(idInst, hszApp);
    DdeFreeStringHandle(idInst, hszTopic);
    if (hConv == NULL)
    {
        printf("DDE Connection Failed.\n");
        Sleep(1500); DdeUninitialize(idInst);
        return 0;
    }



    //Execute commands/requests specific to the DDE Server.
    //DDEExecute(idInst, hConv, szCmd1);
    DDERequest(idInst, hConv, szItem1, szDesc1); 
    DDERequest(idInst, hConv, szItem2, szDesc2);
    //DDEPoke(idInst, hConv, szItem3, szData3);
    //DDEExecute(idInst, hConv, szCmd2);

		BOOL bRet;
MSG msg;

while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
    if (bRet == -1)
    {
        // handle the error and possibly exit
    }
    else
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}

    //DDE Disconnect and Uninitialize.
    DdeDisconnect(hConv);
    DdeUninitialize(idInst);

    Sleep(3000);
    return 1;
}
Ejemplo n.º 2
0
void SampleMain()
{
	SfwOpenWindow("Gainput: Gesture sample");

	gainput::TrackingAllocator allocator(gainput::GetDefaultAllocator());

	gainput::InputManager manager(true, allocator);

	const gainput::DeviceId keyboardId = manager.CreateDevice<gainput::InputDeviceKeyboard>();
	const gainput::DeviceId mouseId = manager.CreateDevice<gainput::InputDeviceMouse>();

	gainput::InputDeviceTouch* touchDevice = manager.CreateAndGetDevice<gainput::InputDeviceTouch>();
	GAINPUT_ASSERT(touchDevice);
	gainput::DeviceId touchId = touchDevice->GetDeviceId();

#if defined(GAINPUT_PLATFORM_LINUX) || defined(GAINPUT_PLATFORM_WIN)
	manager.SetDisplaySize(SfwGetWidth(), SfwGetHeight());
#endif

	SfwSetInputManager(&manager);

	gainput::InputMap map(manager, "testmap", allocator);

	map.MapBool(ButtonConfirm, mouseId, gainput::MouseButtonLeft);

	gainput::DoubleClickGesture* dcg = manager.CreateAndGetDevice<gainput::DoubleClickGesture>();
	GAINPUT_ASSERT(dcg);
	dcg->Initialize(mouseId, gainput::MouseButtonLeft,
			mouseId, gainput::MouseAxisX, 0.01f,
			mouseId, gainput::MouseAxisY, 0.01f,
			500);
	map.MapBool(ButtonConfirmDouble, dcg->GetDeviceId(), gainput::DoubleClickTriggered);

	gainput::SimultaneouslyDownGesture* sdg = manager.CreateAndGetDevice<gainput::SimultaneouslyDownGesture>();
	GAINPUT_ASSERT(sdg);
	sdg->AddButton(mouseId, gainput::MouseButtonLeft);
	sdg->AddButton(keyboardId, gainput::KeyShiftL);
	map.MapBool(ButtonConfirmExtra, sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered);

	MultiTouchEmulator* mte = manager.CreateAndGetDevice<MultiTouchEmulator>();
	mte->Initialize(sdg->GetDeviceId(), gainput::SimultaneouslyDownTriggered,
			mouseId, gainput::MouseAxisX,
			mouseId, gainput::MouseAxisY,
			mouseId, gainput::MouseButtonLeft,
			mouseId, gainput::MouseAxisX,
			mouseId, gainput::MouseAxisY);

	if (!touchDevice->IsAvailable() || touchDevice->GetVariant() == gainput::InputDevice::DV_NULL)
	{
		touchId = mte->GetDeviceId();
	}

	gainput::HoldGesture* hg = manager.CreateAndGetDevice<gainput::HoldGesture>();
	GAINPUT_ASSERT(hg);
	hg->Initialize(touchId, gainput::Touch0Down,
			touchId, gainput::Touch0X, 0.1f,
			touchId, gainput::Touch0Y, 0.1f,
			true,
			800);
	map.MapBool(ButtonHoldGesture, hg->GetDeviceId(), gainput::HoldTriggered);

	gainput::TapGesture* tg = manager.CreateAndGetDevice<gainput::TapGesture>();
	GAINPUT_ASSERT(tg);
	tg->Initialize(touchId, gainput::Touch0Down,
			500);
	map.MapBool(ButtonTapGesture, tg->GetDeviceId(), gainput::TapTriggered);
	
	gainput::PinchGesture* pg = manager.CreateAndGetDevice<gainput::PinchGesture>();
	GAINPUT_ASSERT(pg);
	pg->Initialize(touchId, gainput::Touch0Down,
			touchId, gainput::Touch0X,
			touchId, gainput::Touch0Y,
			touchId, gainput::Touch1Down,
			touchId, gainput::Touch1X,
			touchId, gainput::Touch1Y);
	map.MapBool(ButtonPinching, pg->GetDeviceId(), gainput::PinchTriggered);
	map.MapFloat(ButtonPinchScale, pg->GetDeviceId(), gainput::PinchScale);

	gainput::RotateGesture* rg = manager.CreateAndGetDevice<gainput::RotateGesture>();
	GAINPUT_ASSERT(rg);
	rg->Initialize(touchId, gainput::Touch0Down,
			touchId, gainput::Touch0X,
			touchId, gainput::Touch0Y,
			touchId, gainput::Touch1Down,
			touchId, gainput::Touch1X,
			touchId, gainput::Touch1Y);
	map.MapBool(ButtonRotating, rg->GetDeviceId(), gainput::RotateTriggered);
	map.MapFloat(ButtonRotateAngle, rg->GetDeviceId(), gainput::RotateAngle);

	bool doExit = false;

	while (!SfwIsDone() && !doExit)
	{
		manager.Update();

#if defined(GAINPUT_PLATFORM_LINUX)
		XEvent event;
		while (XPending(SfwGetXDisplay()))
		{
			XNextEvent(SfwGetXDisplay(), &event);
			manager.HandleEvent(event);
			if (event.type == DestroyNotify || event.type == ClientMessage)
			{
				doExit = true;
			}
		}
#elif defined(GAINPUT_PLATFORM_WIN)
		MSG msg;
		while (PeekMessage(&msg, SfwGetHWnd(),  0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
			manager.HandleMessage(msg);
		}
#endif

		SfwUpdate();

		if (map.GetBoolWasDown(ButtonConfirm))
		{
			SFW_LOG("Confirmed!\n");
			SFW_LOG("Memory: %u allocs, %u deallocs, %u used bytes\n", static_cast<unsigned>(allocator.GetAllocateCount()), static_cast<unsigned>(allocator.GetDeallocateCount()), static_cast<unsigned>(allocator.GetAllocatedMemory()));
		}

		if (map.GetBoolWasDown(ButtonConfirmDouble))
		{
			SFW_LOG("Confirmed doubly!\n");
		}

		if (map.GetBoolWasDown(ButtonConfirmExtra))
		{
			SFW_LOG("Confirmed alternatively!\n");
		}

		if (map.GetBool(ButtonHoldGesture))
		{
			SFW_LOG("Hold triggered!\n");
		}

		if (map.GetBoolWasDown(ButtonTapGesture))
		{
			SFW_LOG("Tapped!\n");
		}

		if (map.GetBool(ButtonPinching))
		{
			SFW_LOG("Pinching: %f\n", map.GetFloat(ButtonPinchScale));
		}

		if (map.GetBool(ButtonRotating))
		{
			SFW_LOG("Rotation angle: %f\n", map.GetFloat(ButtonRotateAngle));
		}
	}

	SfwCloseWindow();
}
Ejemplo n.º 3
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                       HINSTANCE /*hPrevInstance*/,
                       LPTSTR    lpCmdLine,
                       int       /*nCmdShow*/)
{
    SetDllDirectory(L"");
    SetTaskIDPerUUID();
    CRegStdDWORD loc = CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
    long langId = loc;
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

    CLangDll langDLL;
    hResource = langDLL.Init(_T("TortoiseIDiff"), langId);
    if (hResource == NULL)
        hResource = hInstance;

    CCmdLineParser parser(lpCmdLine);

    if (parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
    {
        TCHAR buf[1024] = { 0 };
        LoadString(hResource, IDS_COMMANDLINEHELP, buf, _countof(buf));
        MessageBox(NULL, buf, _T("TortoiseIDiff"), MB_ICONINFORMATION);
        langDLL.Close();
        return 0;
    }


    MSG msg;
    hInst = hInstance;

    INITCOMMONCONTROLSEX used = {
        sizeof(INITCOMMONCONTROLSEX),
        ICC_STANDARD_CLASSES | ICC_BAR_CLASSES | ICC_WIN95_CLASSES
    };
    InitCommonControlsEx(&used);

    // load the cursors we need
    curHand = (HCURSOR)LoadImage(hInst, MAKEINTRESOURCE(IDC_PANCUR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
    curHandDown = (HCURSOR)LoadImage(hInst, MAKEINTRESOURCE(IDC_PANDOWNCUR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);

    std::unique_ptr<CMainWindow> mainWindow(new CMainWindow(hResource));
    mainWindow->SetRegistryPath(_T("Software\\TortoiseGit\\TortoiseIDiffWindowPos"));
    std::wstring leftfile = parser.HasVal(_T("left")) ? parser.GetVal(_T("left")) : _T("");
    std::wstring rightfile = parser.HasVal(_T("right")) ? parser.GetVal(_T("right")) : _T("");
    if ((leftfile.empty()) && (lpCmdLine[0] != 0))
    {
        int nArgs;
        LPWSTR * szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
        if (szArglist)
        {
            if (nArgs == 3)
            {
                // Four parameters:
                // [0]: Program name
                // [1]: left file
                // [2]: right file
                if (PathFileExists(szArglist[1]) && PathFileExists(szArglist[2]))
                {
                    leftfile = szArglist[1];
                    rightfile = szArglist[2];
                }
            }
        }

        // Free memory allocated for CommandLineToArgvW arguments.
        LocalFree(szArglist);
    }
    mainWindow->SetLeft(leftfile.c_str(), parser.HasVal(_T("lefttitle")) ? parser.GetVal(_T("lefttitle")) : _T(""));
    mainWindow->SetRight(rightfile.c_str(), parser.HasVal(_T("righttitle")) ? parser.GetVal(_T("righttitle")) : _T(""));
    if (parser.HasVal(L"base"))
        mainWindow->SetSelectionImage(FileTypeBase, parser.GetVal(L"base"), parser.HasVal(L"basetitle") ? parser.GetVal(L"basetitle") : L"");
    if (parser.HasVal(L"mine"))
        mainWindow->SetSelectionImage(FileTypeMine, parser.GetVal(L"mine"), parser.HasVal(L"minetitle") ? parser.GetVal(L"minetitle") : L"");
    if (parser.HasVal(L"theirs"))
        mainWindow->SetSelectionImage(FileTypeTheirs, parser.GetVal(L"theirs"), parser.HasVal(L"theirstitle") ? parser.GetVal(L"theirstitle") : L"");
    if (parser.HasVal(L"result"))
        mainWindow->SetSelectionResult(parser.GetVal(L"result"));
    if (mainWindow->RegisterAndCreateWindow())
    {
        HACCEL hAccelTable = LoadAccelerators(hResource, MAKEINTRESOURCE(IDR_TORTOISEIDIFF));
        if (!parser.HasVal(L"left") && parser.HasVal(L"base") && !parser.HasVal(L"mine") && !parser.HasVal(L"theirs"))
        {
            PostMessage(*mainWindow, WM_COMMAND, ID_FILE_OPEN, 0);
        }
        if (parser.HasKey(_T("overlay")))
        {
            PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_OVERLAPIMAGES, 0);
        }
        if (parser.HasKey(_T("fit")))
        {
            PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEHEIGHTS, 0);
            PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEWIDTHS, 0);
        }
        if (parser.HasKey(_T("fitwidth")))
        {
            PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEWIDTHS, 0);
        }
        if (parser.HasKey(_T("fitheight")))
        {
            PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITIMAGEHEIGHTS, 0);
        }
        if (parser.HasKey(_T("showinfo")))
        {
            PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_IMAGEINFO, 0);
        }
        // Main message loop:
        while (GetMessage(&msg, NULL, 0, 0))
        {
            if (!TranslateAccelerator(*mainWindow, hAccelTable, &msg))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        return (int) msg.wParam;
    }
    langDLL.Close();
    DestroyCursor(curHand);
    DestroyCursor(curHandDown);
    CoUninitialize();
    return 1;
}
Ejemplo n.º 4
0
int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
    // define our window class
    WNDCLASSEX wc = { 0 };
    wc.cbSize = sizeof(wc);
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.lpszClassName = "Module 3";

    RegisterClassExA(&wc);

    DWORD dwExStyle = 0;
    DWORD dwStyle = WS_OVERLAPPEDWINDOW;

    //BOOL Fullscreen = FALSE;
    //
    //if (Fullscreen)
    //{
    //    DEVMODE dmScreenSettings = { 0 };
    //    dmScreenSettings.dmSize = sizeof(dmScreenSettings);
    //    dmScreenSettings.dmPelsWidth = BufferWidth;
    //    dmScreenSettings.dmPelsHeight = BufferHeight;
    //    dmScreenSettings.dmBitsPerPel = 32;
    //    dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
    //
    //    if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) == //DISP_CHANGE_SUCCESSFUL)
    //    {
    //        dwExStyle = WS_EX_APPWINDOW;
    //        dwStyle = WS_POPUP;
    //    }
    //    else
    //    {
    //        Fullscreen = FALSE;
    //    }
    //}

    // create rectangle for window
    RECT r = { 0 };
    r.right = WindowWidth;
    r.bottom = WindowHeight;
    AdjustWindowRectEx(&r, dwStyle, 0, dwExStyle);

    // create our window
    HWND MainWindow = CreateWindowEx(
        dwExStyle, "Module 3",
        "Lesson 3.5", dwStyle,
        CW_USEDEFAULT, CW_USEDEFAULT,
        r.right - r.left, r.bottom - r.top,
        NULL, NULL,
        hInstance, 0);

    //if (Fullscreen)
    //    SetWindowLong(MainWindow, GWL_STYLE, 0);

    ShowWindow(MainWindow, nShowCmd);

    // define our bitmap info
    BitMapInfo.bmiHeader.biSize = sizeof(BitMapInfo.bmiHeader);
    BitMapInfo.bmiHeader.biWidth = BufferWidth;
    BitMapInfo.bmiHeader.biHeight = -BufferHeight;
    BitMapInfo.bmiHeader.biPlanes = 1;
    BitMapInfo.bmiHeader.biBitCount = 8 * BytesPerPixel;
    BitMapInfo.bmiHeader.biCompression = BI_RGB;

    BackBuffer = malloc(BufferWidth * BufferHeight * BytesPerPixel);

    //if (BytesPerPixel == 1)
    {
        FILE *Palette = fopen("palette.lmp", "rb");
        void *RawData = malloc(256 * 3);
        unsigned char* PaletteData = RawData;
        size_t Ret = fread(PaletteData, 1, 768, Palette);

        for (int i = 0; i < 256; i++)
        {
            BitMapInfo.acolors[i].rgbRed = *PaletteData++;
            BitMapInfo.acolors[i].rgbGreen = *PaletteData++;
            BitMapInfo.acolors[i].rgbBlue = *PaletteData++;
        }

        free(RawData);
        fclose(Palette);
    }

    FILE * Disc = fopen("DISC.lmp", "rb");
    int DiscWidth, DiscHeight;

    size_t RetVal = fread(&DiscWidth, 1, 4, Disc);
    RetVal = fread(&DiscHeight, 1, 4, Disc);
    void* DiscData = malloc(DiscWidth * DiscHeight);
    RetVal = fread(DiscData, 1, DiscWidth * DiscHeight, Disc);

    fclose(Disc);

    FILE *Pause = fopen("pause.lmp", "rb");
    int PauseWidth, PauseHeight;

    RetVal = fread(&PauseWidth, 1, 4, Pause);
    RetVal = fread(&PauseHeight, 1, 4, Pause);
    void *PauseData = malloc(PauseWidth * PauseHeight);
    RetVal = fread(PauseData, 1, PauseWidth * PauseHeight, Pause);

    fclose(Pause);
    MSG msg;
    while (Running)
    {
        while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if (BytesPerPixel == 4)
        {
            int *MemoryWalker = (int*)BackBuffer;
            for (int Height = 0; Height < BufferHeight; Height++)
            {
                for (int Width = 0; Width < BufferWidth; Width++)
                {
                    unsigned char Red = rand() % 256;
                    unsigned char Green = rand() % 256;
                    unsigned char Blue = rand() % 256;

                    *MemoryWalker++ = ((Red << 16) | (Green << 8) | Blue);
                }
            }

            DrawPic32(10, 10, DiscWidth, DiscHeight, DiscData, BackBuffer);
            DrawPic32(100, 100, PauseWidth, PauseHeight, PauseData, BackBuffer);
            //DrawRect(10, 10, 300, 150, 255, 0, 255, BackBuffer);
        }
        else if (BytesPerPixel == 1)
        {
            unsigned char *MemoryWalker = BackBuffer;
            for (int Height = 0; Height < BufferHeight; Height++)
            {
                for (int Width = 0; Width < BufferWidth; Width++)
                {
                    *MemoryWalker++ = rand() % 256;
                }
            }

            //DrawPic8(10, 10, DiscWidth, DiscHeight, DiscData, BackBuffer);
            //DrawPic8(100, 100, PauseWidth, PauseHeight, PauseData, BackBuffer);
            //DrawRect8(10, 10, 300, 150, 1, BackBuffer);
        }
        HDC dc = GetDC(MainWindow);
        StretchDIBits(dc,
            0, 0, WindowWidth, WindowHeight,
            0, 0, BufferWidth, BufferHeight,
            BackBuffer, (BITMAPINFO*)&BitMapInfo,
            DIB_RGB_COLORS, SRCCOPY);
        ReleaseDC(MainWindow, dc);
    }

    free(BackBuffer);
    free(DiscData);
    free(PauseData);

    return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
int WINAPI wWinMain ( HINSTANCE hInstance , HINSTANCE prevInstance , LPWSTR cmdLine , int cmdShow )
{
	UNREFERENCED_PARAMETER ( prevInstance );
	UNREFERENCED_PARAMETER ( cmdLine );

	WNDCLASSEX wndClass = { 0 };
	wndClass.cbSize = sizeof ( WNDCLASSEX );
	wndClass.style = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc = WndProc;
	wndClass.hInstance = hInstance;
	wndClass.hCursor = LoadCursor ( NULL , IDC_ARROW );
	wndClass.hbrBackground = ( HBRUSH ) ( COLOR_WINDOW + 1 );
	wndClass.lpszMenuName = NULL;
	wndClass.lpszClassName = "DX11BookWindowClass";
	
	if( !RegisterClassEx( &wndClass ))
	{
		return -1;
	}

	RECT rc = { 0 , 0 , 640 , 480 };
	AdjustWindowRect( &rc , WS_OVERLAPPEDWINDOW , FALSE );

	HWND hwnd = CreateWindowEx ( WS_EX_OVERLAPPEDWINDOW, "DX11BookWindowClass" , "Blank Direct3D 11 Window" , WS_OVERLAPPEDWINDOW ,
		CW_USEDEFAULT , CW_USEDEFAULT , rc.right - rc.left , rc.bottom - rc.top , NULL , NULL , hInstance , NULL );

/*
	HWND hwnd = CreateWindowA ( "DX11BookWindowClass" , "Blank Direct 3D 11 Window" , WS_OVERLAPPEDWINDOW , CW_USEDEFAULT , CW_USEDEFAULT , rc.right - rc.left , 
		rc.bottom - rc.top , NULL , NULL , hInstance , NULL );
*/


	if( !hwnd )
		return -1;

	ShowWindow( hwnd , cmdShow );

	std :: auto_ptr< Dx11DemoBase >demo ( new ColorInversionDemo());


	//Demo Initialize
	bool result = demo ->Initialize ( hInstance , hwnd );

	//Error reporting if there is an issue 
	if( result == false )
		return -1;
	MSG msg = { 0 };

	while ( msg.message != WM_QUIT )
	{
		if( PeekMessage ( &msg , 0 , 0 , 0 , PM_REMOVE ))
		{
			TranslateMessage( & msg );
			DispatchMessage ( & msg );
		}
		else 
		{
			//Update and draw
			demo ->Update (0.0f);
			demo ->Render ( );
		}
	}

	//demo shutdown
	demo ->Shutdown( );

	return static_cast<int>( msg.wParam );


}
Ejemplo n.º 6
0
void ShowErrorPane(const char *text)
{
	if (Window == NULL || ConWindow == NULL)
	{
		if (text != NULL)
		{
			MessageBox (Window, text,
				GAMESIG " Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL);
		}
		return;
	}

	if (StartScreen != NULL)	// Ensure that the network pane is hidden.
	{
		StartScreen->NetDone();
	}
	if (text != NULL)
	{
		char caption[100];
		mysnprintf(caption, countof(caption), "Fatal Error - "GAMESIG" %s "X64, GetVersionString());
		SetWindowText (Window, caption);
		ErrorIcon = CreateWindowEx (WS_EX_NOPARENTNOTIFY, "STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | SS_OWNERDRAW, 0, 0, 0, 0, Window, NULL, g_hInst, NULL);
		if (ErrorIcon != NULL)
		{
			SetWindowLong (ErrorIcon, GWL_ID, IDC_ICONPIC);
		}
	}
	ErrorPane = CreateDialogParam (g_hInst, MAKEINTRESOURCE(IDD_ERRORPANE), Window, ErrorPaneProc, (LONG_PTR)NULL);

	if (text != NULL)
	{
		CHARRANGE end;
		CHARFORMAT2 oldformat, newformat;
		PARAFORMAT2 paraformat;

		// Append the error message to the log.
		end.cpMax = end.cpMin = GetWindowTextLength (ConWindow);
		SendMessage (ConWindow, EM_EXSETSEL, 0, (LPARAM)&end);

		// Remember current charformat.
		oldformat.cbSize = sizeof(oldformat);
		SendMessage (ConWindow, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&oldformat);

		// Use bigger font and standout colors.
		newformat.cbSize = sizeof(newformat);
		newformat.dwMask = CFM_BOLD | CFM_COLOR | CFM_SIZE;
		newformat.dwEffects = CFE_BOLD;
		newformat.yHeight = oldformat.yHeight * 5 / 4;
		newformat.crTextColor = RGB(255,170,170);
		SendMessage (ConWindow, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&newformat);

		// Indent the rest of the text to make the error message stand out a little more.
		paraformat.cbSize = sizeof(paraformat);
		paraformat.dwMask = PFM_STARTINDENT | PFM_OFFSETINDENT | PFM_RIGHTINDENT;
		paraformat.dxStartIndent = paraformat.dxOffset = paraformat.dxRightIndent = 120;
		SendMessage (ConWindow, EM_SETPARAFORMAT, 0, (LPARAM)&paraformat);
		SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)"\n");

		// Find out where the error lines start for the error icon display control.
		SendMessage (ConWindow, EM_EXGETSEL, 0, (LPARAM)&end);
		ErrorIconChar = end.cpMax;

		// Now start adding the actual error message.
		SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)"Execution could not continue.\n\n");

		// Restore old charformat but with light yellow text.
		oldformat.crTextColor = RGB(255,255,170);
		SendMessage (ConWindow, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&oldformat);

		// Add the error text.
		SendMessage (ConWindow, EM_REPLACESEL, FALSE, (LPARAM)text);

		// Make sure the error text is not scrolled below the window.
		SendMessage (ConWindow, EM_LINESCROLL, 0, SendMessage (ConWindow, EM_GETLINECOUNT, 0, 0));
		// The above line scrolled everything off the screen, so pretend to move the scroll
		// bar thumb, which clamps to not show any extra lines if it doesn't need to.
		SendMessage (ConWindow, EM_SCROLL, SB_PAGEDOWN, 0);
	}

	BOOL bRet;
	MSG msg;

	while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
	{
		if (bRet == -1)
		{
			MessageBox (Window, text,
				GAMESIG " Fatal Error", MB_OK|MB_ICONSTOP|MB_TASKMODAL);
			return;
		}
		else if (!IsDialogMessage (ErrorPane, &msg))
		{
			TranslateMessage (&msg);
			DispatchMessage (&msg);
		}
	}
}
Ejemplo n.º 7
0
int WINAPI WinMain(	HINSTANCE	hInstance,			// Instance
					HINSTANCE	hPrevInstance,		// Previous Instance
					LPSTR		lpCmdLine,			// Command Line Parameters
					int			nCmdShow)			// Window Show State
{
	MSG		msg;									// Windows Message Structure
	BOOL	bDone = FALSE;								// Bool Variable To Exit Loop

	// Ask The User Which Screen Mode They Prefer
	if (MessageBox(NULL, MSG_RUNINFULLSCREEN,
		MSG_STARTFULLSCREEN, MB_YESNO | MB_ICONQUESTION) == IDNO)
	{
		g_bFullscreen = FALSE;							// Windowed Mode
	}

	// Create Our OpenGL Window
	if (!CreateGLWindow(WINDOW_TITLE, WINDOW_WIDTH,
		WINDOW_HEIGHT, WINDOW_BIT, g_bFullscreen))
	{
		return 0;									// Quit If Window Was Not Created
	}

	while (!bDone)									// Loop That Runs While done=FALSE
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))	// Is There A Message Waiting?
		{
			if (msg.message == WM_QUIT)				// Have We Received A Quit Message?
			{
				bDone = TRUE;							// If So done=TRUE
			}
			else									// If Not, Deal With Window Messages
			{
				TranslateMessage(&msg);				// Translate The Message
				DispatchMessage(&msg);				// Dispatch The Message
			}
		}
		else										// If There Are No Messages
		{
			// Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
			if (g_bActive)								// Program Active?
			{
				if (g_bKeysArr[VK_ESCAPE])				// Was ESC Pressed?
				{
					bDone = TRUE;						// ESC Signalled A Quit
				}
				else									// Not Time To Quit, Update Screen
				{
					DrawGLScene();						// Draw The Scene
					SwapBuffers(hDC);					// Swap Buffers (Double Buffering)
					if (g_bKeysArr['L'] && !g_bLPress)	// L key being pressed not held?
					{
						g_bLPress = TRUE;				// Become TRUE
						g_bLight = !g_bLight;			// Toggle light TRUE/FALSE
						if (!g_bLight)
						{
							glDisable(GL_LIGHTING);		// Disable lighting
						}
						else
						{
							glEnable(GL_LIGHTING);		// Enable lighting
						}
					}
					if (!g_bKeysArr['L'])				// Has L key been released?
					{
						g_bLPress = FALSE;				// If so, become FALSE
					}
					if (g_bKeysArr['F'] && !g_bFPress)	// Is F key being pressed not held?
					{
						g_bFPress = TRUE;
						g_uFilter += 1;
						if (g_uFilter > 2)
						{
							g_uFilter = 0;
						}
					}
					if (!g_bKeysArr['F'])
					{
						g_bFPress = FALSE;
					}
				}
			}

			if (g_bKeysArr[VK_F1])						// Is F1 Being Pressed?
			{
				g_bKeysArr[VK_F1] = FALSE;					// If So Make Key FALSE
				KillGLWindow();						// Kill Our Current Window
				g_bFullscreen = !g_bFullscreen;				// Toggle Full screen / Windowed Mode
				// Recreate Our OpenGL Window
				if (!CreateGLWindow(WINDOW_TITLE, WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_BIT, g_bFullscreen))
				{
					return 0;						// Quit If Window Was Not Created
				}
			}
			// Handle move left-right
			if (g_bKeysArr[VK_LEFT])
			{
				g_bKeysArr[VK_LEFT] = FALSE;
				g_MoveX -= g_MDeltaX;
			}
			if (g_bKeysArr[VK_RIGHT])
			{
				g_bKeysArr[VK_RIGHT] = FALSE;
				g_MoveX += g_MDeltaX;
			}
			// Handle move up-down
			if (g_bKeysArr[VK_UP])
			{
				g_bKeysArr[VK_UP] = FALSE;
				g_MoveY += g_MDeltaY;
			}
			if (g_bKeysArr[VK_DOWN])
			{
				g_bKeysArr[VK_DOWN] = FALSE;
				g_MoveY -= g_MDeltaY;
			}
			// Handle move forward-backward
			if (g_bKeysArr[VK_ADD])
			{
				g_bKeysArr[VK_ADD] = FALSE;
				g_MoveZ -= g_MDeltaZ;
			}
			// Handle rotate follow X asix
			if (g_bKeysArr[VK_INSERT])
			{
				g_bKeysArr[VK_INSERT] = FALSE;
				g_RotateX += g_RDeltaX;
			}
			if (g_bKeysArr[VK_DELETE])
			{
				g_bKeysArr[VK_DELETE] = FALSE;
				g_RotateX -= g_RDeltaX;
			}
			// Handle rotate follow Y asix
			if (g_bKeysArr[VK_HOME])
			{
				g_bKeysArr[VK_HOME] = FALSE;
				g_RotateY += g_RDeltaY;
			}
			if (g_bKeysArr[VK_END])
			{
				g_bKeysArr[VK_END] = FALSE;
				g_RotateY -= g_RDeltaY;
			}
			// Handle rotate follow Z axis
			if (g_bKeysArr[VK_PRIOR])
			{
				g_bKeysArr[VK_PRIOR] = FALSE;
				//g_RotateZ += g_RDeltaZ;
				g_MoveZ -= 0.02f;
			}
			if (g_bKeysArr[VK_NEXT])
			{
				g_bKeysArr[VK_NEXT] = FALSE;
				//g_RotateZ -= g_RDeltaZ;
				g_MoveZ += 0.02f;
			}
			if (g_bKeysArr[VK_SUBTRACT])
			{
				g_bKeysArr[VK_SUBTRACT] = FALSE;
				g_MoveZ += g_MDeltaZ;
			}

			if (g_bKeysArr[VK_TAB])
			{
				g_bKeysArr[VK_TAB] = FALSE;
			}
		}
	}

	// Shutdown
	KillGLWindow();									// Kill The Window
	return (msg.wParam);							// Exit The Program
}
Ejemplo n.º 8
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow) {

	WNDCLASSEX wcex;
	HMENU menu, popupMenu;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
	wcex.hCursor = LoadCursor(hInstance, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = szWindowClass;
	wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));

	if (!RegisterClassEx(&wcex))
	{
		MessageBox(NULL,
			_T("Call to RegisterClassEx failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	hInst = hInstance; // Store instance handle in our global variable

	// The parameters to CreateWindow explained:
	// szWindowClass: the name of the application
	// szTitle: the text that appears in the title bar
	// WS_SYSMENU: the type of window to create
	// CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
	// 500, 100: initial size (width, length)
	// NULL: the parent of this window
	// TODO: // NULL: this application does not have a menu bar
	// hInstance: the first parameter from WinMain
	// NULL: not used in this application
	hWnd = CreateWindow(
		szWindowClass,
		szTitle,
		WS_SYSMENU,
		CW_USEDEFAULT, CW_USEDEFAULT,
		WindowWidth, WindowHeight,
		NULL,
		NULL,
		hInstance,
		NULL
		);

	if (!hWnd)
	{
		MessageBox(NULL,
			_T("Call to CreateWindow failed!"),
			_T("Win32 Guided Tour"),
			NULL);

		return 1;
	}

	hButtonRefresh = CreateWindow(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 0, 0, 32, 32, hWnd, (HMENU)IDC_BUTTON_REFRESH, hInst, NULL);
	hButtonClear = CreateWindow(L"button", NULL, WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 0, 32, 32, 32, hWnd, (HMENU)IDC_BUTTON_CLEAR, hInst, NULL);

	// The parameters to ShowWindow explained:
	// hWnd: the value returned from CreateWindow
	// nCmdShow: the fourth parameter from WinMain
	ShowWindow(hWnd,
		nCmdShow);
	UpdateWindow(hWnd);

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

	return (int)msg.wParam;
}
/***********************************************************************************
WinMain - Entry point for program.
***********************************************************************************/
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    
    CLog *pLog = CLog::Instance();
    pLog->Log(" ");
    pLog->Log("***************************************");
    pLog->Log("Program Start"); 
    pLog->LogDate();   
    pLog->Log("***************************************");
    
    //request player choose fullscreen or windowed mode
    CConfigData cfg;
    cfg.LoadConfigFile("assets//data//config.cfg");
    bool bFullscreen = false;
    
    bFullscreen = cfg.FullScreen;
    //int msgReturn = ::MessageBox(NULL, "Fullscreen? (Y/N)", "Select Display Option", MB_YESNO);
    //if(msgReturn == IDYES)
    //  bFullscreen = true;
       
    //variable declarations
    CGameData gameData;
    CTimer gTimerFPS;
    int gLoopCount = 0;
    int gSecondCount = 0;
    bool g_bRunning = true;
    bool gExitProgram = false; //this is set true with ESC, for rendering to stop properly

    //determine if we play new or saved game
    /*
    gameData.m_playNewGame = true;
    HRESULT hr = ::MessageBox(0, "Play new game?", "New or saved game!", MB_YESNO);
    if(hr == IDYES)
      gameData.m_playNewGame = true;
    else
      gameData.m_playNewGame = false;
    */
    gameData.m_playNewGame = true;

    //setup game data    

    pLog->Log("Program Name", cfg.ProgramName);
    pLog->Log("Version", cfg.ProgramVersion);

    //create window
    HWND hWnd;
    WNDCLASSEX wc;
    ZeroMemory(&wc, sizeof(WNDCLASSEX));
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = (WNDPROC)WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = "WindowClass";
    wc.hIconSm = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_ICON1)); 
    RegisterClassEx(&wc);
        
    //screen data - need at least 800x600 
    int cxScreen = ::GetSystemMetrics(SM_CXFULLSCREEN);
    int cyScreen = ::GetSystemMetrics(SM_CYFULLSCREEN);
    if(cfg.ScreenWidth < 800 || cfg.ScreenWidth > cxScreen)
      cfg.ScreenWidth = cxScreen;   
    if(cfg.ScreenHeight < 600 || cfg.ScreenHeight > cyScreen)
      cfg.ScreenHeight = cyScreen;    
    cfg.ScreenLeft = cxScreen/2 - cfg.ScreenWidth/2;
    cfg.ScreenTop = cyScreen/2 - cfg.ScreenHeight/2;

    //create window
    std::string sCaption = cfg.ProgramName + " - " + cfg.ProgramVersion;
    hWnd = CreateWindowEx(NULL,
                          "WindowClass",
                          sCaption.c_str(), //cfg.ProgramVersion.c_str(),  
                          bFullscreen == true ? WS_EX_TOPMOST | WS_POPUP : WS_BORDER | WS_CAPTION | WS_SYSMENU,  
                          cfg.ScreenLeft, cfg.ScreenTop, 
                          bFullscreen == true ? CW_USEDEFAULT : cfg.ScreenWidth, 
                          bFullscreen == true ? CW_USEDEFAULT : cfg.ScreenHeight,
                          NULL,NULL,hInstance,NULL);
    ShowWindow(hWnd, nCmdShow);
    pLog->Log("Window Loaded and Displayed!");
    gameData.m_hWnd = hWnd;

    // set up and initialize Direct3D
    CGraphics con(hWnd, cfg.ScreenWidth, cfg.ScreenHeight,bFullscreen);// cfg.FullScreen);
    if(con.InitializeDirectX() == false){
      pLog->Log("Failure initializing DirectX!");
      ::MessageBox(hWnd,"Failed to initialize DirectX", "Error", 0);
      return 0;
    }
    pLog->Log("DirectX Initialized");

    //load framework assets
    if(con.LoadAssetFile(cfg.FrameworkAssetFile) == false){
      pLog->Log("Failure loading " + cfg.FrameworkAssetFile);
      ::MessageBox(hWnd,"Failed to load editor.dat file", "Error", 0);
      return 0;
    }
    else
      pLog->Log(cfg.FrameworkAssetFile + " (frame graphics) was loaded successfully!");

    //load game play assets
    if(con.LoadAssetFile(cfg.GamePlayAssetFile) == false){
      pLog->Log("Failure loading " + cfg.GamePlayAssetFile);
      ::MessageBox(hWnd,"Failed to load assets.dat file", "Error", 0);
      return 0;
    }
    else
      pLog->Log(cfg.GamePlayAssetFile + " (game play graphics) was loaded successfully!");

     //load objects
    //***************************************************************************
    if(gameData.LoadObjectFile(cfg.GameObjectFile) == false){
      pLog->Log("Failure loading " + cfg.GameObjectFile);
      ::MessageBox(hWnd,"Failed to load objects.dat file", "Error", 0);
      return 0;
    }
    else{
      pLog->Log(cfg.GameObjectFile + " (objects file) was loaded successfully!");
      for(int i = 0; i < gameData.m_catalog.GetTableSize();++i){
        pLog->Log("object", gameData.m_catalog.GetTerm(i, 0), gameData.m_catalog.GetTerm(i, 2));
      }
    }

    gTimerKey.Initialize();
    gTimerKey.ResetTimer();
    mouse.SetHandle(hWnd);
    gTimerFPS.Initialize();
    
    //game timer for update
    CTimer timerGame;
    timerGame.Initialize();

    //define events for changing game states
    //*************************************************************************
    //g_pStateIntro->AddTransitionEvent(EVENT_GO_PLAY1, g_pStatePlay1);
    //g_pStatePlay1->AddTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits);   
    g_pStateIntro->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
    g_pStateMain->AddTransitionEvent(EVENT_GO_PLAY1, g_pStatePlay1);
    g_pStateMain->AddTransitionEvent(EVENT_GO_HELP, g_pStateHelp);
    g_pStateMain->AddTransitionEvent(EVENT_GO_CREDITS, g_pStateCredits);
    g_pStatePlay1->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
    g_pStateHelp->AddTransitionEvent(EVENT_GO_MAIN, g_pStateMain);
    g_pStateCredits->AddTransitionEvent(EVENT_GO_QUIT, g_pStateQuit);    
    g_pCurrent = g_pStateIntro;

    //************************************** S O U N D ************************
    //initialize sound manager
    //audio setup
    CAudioManager *pAudio = CAudioManager::Instance();
    pAudio->LoadFile("assets\\data\\sounds.dat");

    //load sound asset file
    pAudio->LoadFile(cfg.SoundAssetFile);
/*
    if(pAudio->LoadFile(cfg.SoundAssetFile) == false){
      pLog->Log("Failure loading " + cfg.GamePlayAssetFile);//assets.dat audio files!");
      ::MessageBox(hWnd,"Failed to load assets.dat audio files!", "Error", 0);
    }
    else
      pLog->Log(cfg.GamePlayAssetFile + " (audio) was loaded successfully!");
  */      
/*
    if(pAudio->IsValidSound() == true)
      pLog->Log("Audio system initialized (size)", pAudio->Size());
    else
      pLog->Log("Audio failure!");
*/
    //log all audio files    
    if(cfg.LogDebugInfo == true){
      pLog->Log("************************** Audio Files Loaded **************");
//      for(int i = 0; i < pAudio->Size(); i++){
//        pLog->Log(pAudio->GetFilename(i)); 
//      }
      pLog->Log("");
    }

    // enter the main loop
    //************************************** M A I N  L O O P *****************
    MSG msg;
    pLog->Log("Entering Main Control Loop");
    float timeDiff = 0.0f;
    g_pCurrent->Activate(gameData, cfg, con);

    //*********************
    // PYRO
    //con.InitializePyro();
    while(g_bRunning)
    {
      DWORD starting_point = GetTickCount();

      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
          if (msg.message == WM_QUIT)
              break;

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

      //manage frame count determination
      gLoopCount++;
      if(gTimerFPS.getTimer(1.0) == true){
        gameData.m_FPS = static_cast<float>(gLoopCount);
        gLoopCount = 0;   
        gSecondCount++;
        if(gSecondCount > 30){ //log every 30 seconds
          gSecondCount = 0;
          if(cfg.LogDebugInfo == true)
            pLog->Log("FPS",gameData.m_FPS);
        }
      }

      //stores mouse button status for use in other classes
      gameData.m_bLeftMouseDown =  mouse.LeftButtonDown();
      gameData.m_bRightMouseDown = mouse.RightButtonDown();
      
      //update
      g_pLast = g_pCurrent;
      g_pNext = g_pCurrent->Update(timerGame.getTimeDifference(), gameData, cfg, con);

      if(g_pNext == g_pStateQuit)
        g_bRunning = false;
      else if(NULL != g_pNext)
	    {
        if(g_pNext != g_pLast){
          g_pLast->Deactivate(gameData, cfg, con);
          g_pCurrent = g_pNext;
          g_pCurrent->Activate(gameData, cfg, con);
        }
      }  
      
      //render
      g_pCurrent->Render(con, gameData, cfg);

      // check the 'escape' key
      if(g_bRunning == false){
        gExitProgram = true;
        PostMessage(hWnd, WM_DESTROY, 0, 0);
      }
    }
    pLog->Log("Exited main loop");
    
    //**************************
    // PYRO
    //con.ClosePyro();
    
    // clean up DirectX and COM
    con.CleanupDirectX();
    Shutdown();

    pLog->Log("DirectX Cleaned Up");
    pLog->Log("Shutdown complete!");
    pLog->Log("***************************************");
    pLog->Log(" Program Terminated Normally");
    pLog->Log("***************************************");

    return static_cast<int>(msg.wParam);
}
Ejemplo n.º 10
0
void mswin_display_RIP_window (HWND hWnd)
{
    MSG msg;
    RECT rt;
    PNHRIPWindow data;
    HWND mapWnd;
    RECT riprt;
    RECT clientrect;
    RECT textrect;
    HDC hdc;
    HFONT OldFont;

    data = (PNHRIPWindow)GetWindowLong(hWnd, GWL_USERDATA);

    GetNHApp()->hPopupWnd = hWnd;
    mapWnd = mswin_hwnd_from_winid(WIN_MAP);
    if( !IsWindow(mapWnd) ) mapWnd = GetNHApp()->hMainWnd;
    GetWindowRect(mapWnd, &rt);
    GetWindowRect(hWnd, &riprt);
    GetClientRect (hWnd, &clientrect);
    textrect = clientrect;
    textrect.top += RIP_OFFSET_Y;
    textrect.left += RIP_OFFSET_X;
    textrect.right -= RIP_OFFSET_X;
    if (data->window_text)
    {
        hdc = GetDC (hWnd);
        OldFont = SelectObject (hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE));
        DrawText (hdc, data->window_text, strlen(data->window_text), &textrect,
                  DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
        SelectObject (hdc, OldFont);
        ReleaseDC(hWnd, hdc);
    }
    if (textrect.right - textrect.left > RIP_WIDTH)
        clientrect.right = textrect.right + RIP_OFFSET_X - clientrect.right;
    else
        clientrect.right = textrect.left + 2 * RIP_OFFSET_X + RIP_WIDTH - clientrect.right;
    clientrect.bottom = textrect.bottom + RIP_HEIGHT + RIP_OFFSET_Y - clientrect.bottom;
    GetWindowRect (GetDlgItem(hWnd, IDOK), &textrect);
    textrect.right -= textrect.left;
    textrect.bottom -= textrect.top;
    clientrect.bottom += textrect.bottom + RIP_OFFSET_Y;
    riprt.right -= riprt.left;
    riprt.bottom -= riprt.top;
    riprt.right += clientrect.right;
    riprt.bottom += clientrect.bottom;
    rt.left += (rt.right - rt.left - riprt.right) / 2;
    rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;

    MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
    GetClientRect (hWnd, &clientrect);
    MoveWindow (GetDlgItem(hWnd, IDOK),
                (clientrect.right - clientrect.left - textrect.right) / 2,
                clientrect.bottom - textrect.bottom - RIP_OFFSET_Y, textrect.right, textrect.bottom, TRUE);
    ShowWindow(hWnd, SW_SHOW);

    while( IsWindow(hWnd) &&
            GetMessage(&msg, NULL, 0, 0)!=0 ) {
        if( !IsDialogMessage(hWnd, &msg) ) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    GetNHApp()->hPopupWnd = NULL;
}
Ejemplo n.º 11
0
int PASCAL WinMain(HANDLE hInstance,
                   HANDLE hPrevInstance, LPSTR lpszCmdLine, int iCmd)

{
    int i;
    MSG msg;
    LPSTR pch,pch1;
    WORD    ret;
    WOWINFO wowinfo;
    char aszWOWDEB[CCHMAX];
    LPSTR pchWOWDEB;
    HANDLE hMMDriver;


    char        szBuffer[150];
    BOOL        bFinished;
    int         iStart;
    int         iEnd;


    hAppInstance = hInstance ;

    // Only Want One WOWExec
    if (hPrevInstance != NULL) {
        return(FALSE);
    }

    if (!InitializeApp(lpszCmdLine)) {
        OutputDebugString("WOWEXEC: InitializeApp failure!\n");
        return 0;
    }

/*
 * Look for a drivers= line in the [boot] section of SYSTEM.INI
 * If present it is the 16 bit MultiMedia interface, so load it
 */

#ifdef OLD_MMSYSTEM_LOAD
    if (GetPrivateProfileString((LPSTR)"boot", (LPSTR)"drivers",(LPSTR)"", aszMMDriver, sizeof(aszMMDriver), (LPSTR)"SYSTEM.INI")) {
/*
 * We have now discovered an app that rewrites the "drivers" entry with
 * multiple drivers - so the existing load method fails. As a temporary fix
 * while we decide what the "proper" fix is I will always load MMSYSTEM and
 * ONLY MMSYSTEM.
 *
 *       aszMMDriver[sizeof(aszMMDriver)-1] = '\0';
 *       hMMDriver = LoadLibrary((LPSTR)aszMMDriver);
 * #ifdef DEBUG
 *       if (hMMDriver < 32) {
 *           OutputDebugString("WOWEXEC: Load of MultiMedia driver failed\n");
 *       }
 * #endif
 */
        LoadLibrary("MMSYSTEM.DLL");
    }
#else
    /* Load DDL's from DRIVERS section in system.ini
     */
    GetPrivateProfileString( (LPSTR)"boot",      /* [Boot] section */
                            (LPSTR)"drivers",   /* Drivers= */
                            (LPSTR)"",          /* Default if no match */
                            szBuffer,    /* Return buffer */
                            sizeof(szBuffer),
                            (LPSTR)"system.ini" );

    if (!*szBuffer) {
        goto Done;
    }

    bFinished = FALSE;
    iStart    = 0;

    while (!bFinished) {
        iEnd = iStart;

        while (szBuffer[iEnd] && (szBuffer[iEnd] != ' ') &&
               (szBuffer[iEnd] != ',')) {
            iEnd++;
        }

        if (szBuffer[iEnd] == NULL) {
            bFinished = TRUE;
        }
        else {
            szBuffer[iEnd] = NULL;
        }

        /* Load and enable the driver.
         */
        OpenDriver( &(szBuffer[iStart]), NULL, NULL );
        iStart = iEnd + 1;
    }

Done:

#endif

/*
 * Look for a debug= line in the [boot] section of SYSTEM.INI
 * If present it is the 16 bit MultiMedia interface, so load it
 */

    if ( WOWQueryDebug() & 0x0001 ) {
        pchWOWDEB = "WOWDEB.EXE";
    } else {
        pchWOWDEB = "";
    }

    GetPrivateProfileString((LPSTR)"boot", (LPSTR)"debug",pchWOWDEB, aszWOWDEB, sizeof(aszWOWDEB), (LPSTR)"SYSTEM.INI");
    aszWOWDEB[sizeof(aszWOWDEB)-1] = '\0';

    if ( lstrlen(pchWOWDEB) != 0 ) {
        WinExec((LPSTR)aszWOWDEB,SW_SHOW);
    }

#if 0
/*  Preload winspool.exe.   Apps will keep loading and freeing it
 *  which is slow.   We might as well load it now so the reference
 *  count is 1 so it will never be loaded or freed
 */
    //
    // Disabled load of winspool.exe to save 8k.  Size vs. speed,
    // which one do we care about?  Right now, size!
    //
    LoadLibrary("WINSPOOL.EXE");
#endif

    // Always load SHELL.DLL, FileMaker Pro and Lotus Install require it.

    LoadLibrary("SHELL.DLL");

    //
    // Start any apps pending in basesrv queue
    //

    while (StartRequestedApp() && gfSharedWOW) {
        /* null stmt */ ;
    }


    while (1)  {
        if (!WowWaitForMsgAndEvent(ghwndMain) &&
            PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) &&
            msg.message != WM_WOWEXECHEARTBEAT )
           {
            if (msg.message != WM_QUIT) {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
    }

    return 1;
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
    CommandLineArgs args(argc, argv);
    if (!args.ok) {
        PrintUsage();
        return 1;
    }

    // Print init info
    std::cout << "AbsoluteTouch v" << VERSION_NAME << std::endl;
    std::cout << "Author: " << AUTHOR << std::endl;
    std::cout << "Project page: " << PROJECT_URL << std::endl;
    std::cout << "--------------------------------------------------" << std::endl;
    std::cout << "Starting..." << std::endl;

    // Initialize COM
    CCoInitialize init;

    // Set cleanup handler
    g_mainThreadId = GetCurrentThreadId();
    if (!SetConsoleCtrlHandler(OnConsoleSignal, TRUE)) {
        std::cerr << "Error: failed to register console control handler" << std::endl;
        CleanUp();
        return 1;
    }
    std::cout << "Registered console control handler" << std::endl;

    // Initialize touchpad manager
    try {
        g_touchpadManager = new TouchpadManager();
    } catch (const TouchpadInitException &e) {
        std::cerr << "Error: could not initialize touchpad manager" << std::endl;
        std::cerr << e.what() << std::endl;
        CleanUp();
        return 1;
    }
    std::cout << "Initialized touchpad manager" << std::endl;

    // Acquire exclusive touchpad access
    if (!g_touchpadManager->Acquire()) {
        std::cerr << "Error: could not acquire exclusive touchpad access" << std::endl;
        CleanUp();
        return 1;
    }
    std::cout << "Acquired exclusive touchpad access" << std::endl;

    // Register touchpad touch callback
    g_touchCallback = new AbsoluteTouchCallback();
    g_touchCallback->SetScreenRect(Rect<long>(0, 0, 65535, 65535).scale(args.screenRect));
    g_touchCallback->SetTouchpadRect(g_touchpadManager->GetTouchpadRect().scale(args.touchpadRect));
    g_touchCallback->SetSmoothingWeight(args.smoothingWeight);
    g_touchCallback->SetSendClick(args.sendClick);
    g_touchpadManager->SetTouchCallback(g_touchCallback);
    std::cout << "Registered touch listener" << std::endl;

    // Enable touchpad if option was specified
    if (args.manageTouchpad && !g_touchpadManager->IsTouchpadEnabled()) {
        g_touchpadManager->SetTouchpadEnabled(true);
        g_touchpadEnabledModified = true;
        std::cout << "Enabled touchpad" << std::endl;
    }

    // Print usage instructions
    std::cout << "--------------------------------------------------" << std::endl;
    std::cout << "Initialization complete, absolute touch mode enabled!" << std::endl;
    std::cout << "Keep this window open until you wish to exit absolute touch mode." << std::endl;
    std::cout << "To exit the program, you can use CTRL-C." << std::endl;

    // Main message loop
    MSG msg;
    BOOL ret;
    while ((ret = GetMessage(&msg, nullptr, 0, 0)) > 0) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    CleanUp();
    g_cleanupFinished = true;
    return 0;
}
Ejemplo n.º 13
0
int WINAPI WinMain(	HINSTANCE hinstance,
					HINSTANCE hprevinstance,
					LPSTR lpcmdline,
					int ncmdshow)
{

WNDCLASSEX winclass; // this will hold the class we create
HWND	   hwnd;	 // generic window handle
MSG		   msg;		 // generic message
HDC        hdc;      // graphics device context

// first fill in the window class stucture
winclass.cbSize         = sizeof(WNDCLASSEX);
winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                          CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc	= WindowProc;
winclass.cbClsExtra		= 0;
winclass.cbWndExtra		= 0;
winclass.hInstance		= hinstance;
winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor		= LoadCursor(NULL, IDC_ARROW); 
winclass.hbrBackground	= (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName	= NULL;
winclass.lpszClassName	= WINDOW_CLASS_NAME;
winclass.hIconSm        = LoadIcon(NULL, IDI_APPLICATION);

// save hinstance in global
hinstance_app = hinstance;

// register the window class
if (!RegisterClassEx(&winclass))
	return(0);

// create the window
if (!(hwnd = CreateWindowEx(NULL,                  // extended style
                            WINDOW_CLASS_NAME,     // class
						    "DirectDraw 24-Bit Bitmap Loading", // title
						    WS_POPUP | WS_VISIBLE,
					 	    0,0,	  // initial x,y
						    SCREEN_WIDTH,SCREEN_HEIGHT,  // initial width, height
						    NULL,	  // handle to parent 
						    NULL,	  // handle to menu
						    hinstance,// instance of this application
						    NULL)))	// extra creation parms
return(0);

// save main window handle
main_window_handle = hwnd;

// initialize game here
Game_Init();

// enter main event loop
while(TRUE)
	{
    // test if there is a message in queue, if so get it
	if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
	   { 
	   // test if this is a quit
       if (msg.message == WM_QUIT)
           break;
	
	   // translate any accelerator keys
	   TranslateMessage(&msg);

	   // send the message to the window proc
	   DispatchMessage(&msg);
	   } // end if
    
       // main game processing goes here
       Game_Main();
       
	} // end while

// closedown game here
Game_Shutdown();

// return to Windows like this
return(msg.wParam);

} // end WinMain
Ejemplo n.º 14
0
int PASCAL WinMain( HINSTANCE instance,
                    HINSTANCE previous_instance,
                    LPSTR cmd_line,
                    int cmd_show )
{
  //
  // Win32 locals.
  //

  HWND window = 0;
  MSG msg;

  //
  // Try to create our window.
  //

  window = Build_window_handle( instance,
                                previous_instance );
  if ( !window )
  {
    MessageBox( 0,
                "Error creating window.",
                "Windows",
                MB_OK | MB_ICONSTOP );
    return( 1 );
  }

  //
  // Tell Bink to use DirectSound (must be before BinkOpen)!
  //

  BinkSoundUseDirectSound( 0 );

  //
  // Try to open the Bink file.
  //
  
  Bink = BinkOpen( cmd_line, 0 );
  if ( !Bink )
  {
    MessageBox( window,
                BinkGetError( ),
                "Bink Error",
                MB_OK | MB_ICONSTOP );

    DestroyWindow( window );
    return( 3 );
  }

  //
  // Try to open the Bink buffer.
  //

  Bink_buffer = BinkBufferOpen( window, Bink->Width, Bink->Height, 0 );
  if ( !Bink_buffer )
  {
    MessageBox( window,
                BinkBufferGetError( ),
                "Bink Error",
                MB_OK | MB_ICONSTOP );

    DestroyWindow( window );
    BinkClose( Bink );

    return( 4 );
  }

  //
  // Size the window such that its client area exactly fits our Bink movie.
  //

  SetWindowPos( window, 0,
                0, 0,
                Bink_buffer->WindowWidth,
                Bink_buffer->WindowHeight,
                SWP_NOMOVE );

  //
  // Now display the window and start the message loop.
  //

  ShowWindow( window, cmd_show );

  for ( ; ; )
  {
    //
    // Are there any messages to handle?
    //

    if ( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
    {
      //
      // Yup, handle them.
      //

      if ( msg.message == WM_QUIT )
        break;

      TranslateMessage( &msg );
      DispatchMessage( &msg );
    }
    else
    {
      //
      // Is it time for a new Bink frame?
      //

      if ( !BinkWait( Bink ) )
      {
        //
        // Yup, draw the next frame.
        //

        Show_next_frame( Bink,
                         Bink_buffer,
                         window );
      }
      else
      {
        //
        // Nope, give the rest of the system a chance to run (500 MICROseconds).
        //

        Good_sleep_us( 500 );
      }

    }
  }

  //
  // Close the Bink file.
  //

  if ( Bink )
  {
    BinkClose( Bink );
    Bink = 0;
  }

  //
  // Close the Bink buffer.
  //

  if ( Bink_buffer )
  {
    BinkBufferClose( Bink_buffer );
    Bink_buffer = 0;
  }

  //
  // And exit.
  //

  return( 0 );
}
Ejemplo n.º 15
0
int APIENTRY _tWinMain(HINSTANCE hinst,	HINSTANCE foo1, LPTSTR foo2, int foo3) {
	MSG msg;
	WNDCLASSEX wcex = {sizeof(wcex)};
	HANDLE htray;
	HMENU hmenu;
	MENUITEMINFO mi = {sizeof(mi)};
	INITCOMMONCONTROLSEX icex;
	RECT rect;
	int style;
	HWND hwnd;

	wcex.lpfnWndProc = WndProc;
	wcex.lpszClassName = WINDOW_CLASS;
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	RegisterClassEx(&wcex);

	icex.dwSize = sizeof(icex);
	icex.dwICC = ICC_DATE_CLASSES;
	InitCommonControlsEx(&icex);

	hwnd = CreateWindowEx(WS_EX_NOACTIVATE | WS_EX_TOPMOST, WINDOW_CLASS, WINDOW_TITLE, 0,
		0, 0, 0, 0, NULL, NULL, hinst, NULL);
	if (!hwnd) return 1;
	style = GetWindowLong(hwnd, GWL_STYLE);
	if (style & WS_CAPTION)  { 
		style ^= WS_CAPTION;
		SetWindowLong(hwnd, GWL_STYLE, style);
		SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
	}

	hcal = CreateWindowEx(0, MONTHCAL_CLASS, _T(""),
		WS_CHILD | WS_VISIBLE | MCS_NOTODAY | MCS_NOTRAILINGDATES | MCS_SHORTDAYSOFWEEK | MCS_NOSELCHANGEONNAV,
		0, 0, 0, 0, hwnd, NULL, hinst, NULL);
	MonthCal_GetMinReqRect(hcal, &rect);
	SetWindowPos(hcal, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE);
	SetWindowPos(hwnd, NULL, 0, 0, rect.right, rect.bottom, SWP_NOZORDER | SWP_NOMOVE);

	tti.hwnd = hwnd;
	tti.hcal = hcal;
	tti.hnotify = CreateEvent(NULL, TRUE, FALSE, NULL);
	tti.exit = FALSE;
	htray = CreateThread(NULL, 0, &TrayThreadProc, &tti, 0, NULL);
	if (!htray) return 1;

	hsubmenu = CreateMenu();
	mi.fMask = MIIM_STRING | MIIM_ID;
	mi.wID = 1;
	mi.dwTypeData = EXIT_STRING;
	InsertMenuItem(hsubmenu, 0, TRUE, &mi);
	hmenu = CreateMenu();
	mi.fMask = MIIM_SUBMENU;
	mi.hSubMenu = hsubmenu;
	InsertMenuItem(hmenu, 0, TRUE, &mi);

	WM_TASKBARCREATED = RegisterWindowMessageA(_T("TaskbarCreated"));
	
	while (GetMessage(&msg, NULL, 0, 0)) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	DestroyMenu(hmenu);
	DestroyMenu(hsubmenu);

	WaitForSingleObject(htray, 1000);
	CloseHandle(htray);

	return (int)msg.wParam;
}
Ejemplo n.º 16
0
/********************************************************************
* Function : WinMain()
* Purpose : Mandatory Windows Init function.
********************************************************************/
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
						 LPSTR lpCmdLine, int nCmdShow)
{
	MSG		msg;
	HWND		hwnd;
	WNDCLASS	wc;
	static char ClassName[] = "ChromeTestingFacility";
	DDSURFACEDESC	ddsd;
	DDSCAPS			ddscaps;
	HRESULT			ddreturn;
	int n;

	// Set all key booleans to FALSE, assume no key is pressed.
	bForwardKey = FALSE;
	bBackKey = FALSE;
	bLeftKey = FALSE;
	bRightKey = FALSE;
	nState = 0;
	nGauge = 0;

	lpCmdLine = lpCmdLine;
	hPrevInstance = hPrevInstance;
	RealTime = 0;	/* Start of using spacebar for frameflipping. */

	/* Register and realize our display window */
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground = NULL;
	wc.lpszMenuName = ClassName;
	wc.lpszClassName = ClassName;
	RegisterClass(&wc);

	/* Initialize our test world. */
	if (!InitWorld(XRES, YRES, Colormap))
	{	return FALSE;
	}

	/* Convert the Chrome colormap to a windows colormap. */
	for (n = 0; n < 256; n++)
	{
		WinColormap[n].peRed = (unsigned char)((Colormap[n] & 0xFF0000) >> 16);
		WinColormap[n].peGreen = (unsigned char)((Colormap[n] & 0xFF00) >> 8);
		WinColormap[n].peBlue = (unsigned char)((Colormap[n] & 0xFF));
		WinColormap[n].peFlags = 0;
	}
	/* Create a full screen window so that GDI won't ever be
	 * called. */
	hwnd = CreateWindowEx(WS_EX_TOPMOST,
								 ClassName,
								 ClassName,
								 WS_POPUP,
								 0,
								 0,
								 GetSystemMetrics(SM_CXSCREEN),
								 GetSystemMetrics(SM_CYSCREEN),
								 NULL,
								 NULL,
								 hInstance,
								 NULL);
	if (hwnd == NULL)
		return FALSE;
	
	ShowWindow(hwnd, nCmdShow);
	UpdateWindow(hwnd);
	SetFocus(hwnd);
	ShowCursor(FALSE);		/* Remove cursor to prevent GDI from writing. */

	/* Instanciate our DirectDraw object */
	ddreturn = DirectDrawCreate(NULL, &lpDirectDrawObject, NULL);
	if (ddreturn != DD_OK)
	{
		DestroyWindow(hwnd);
		return FALSE;
	}

	ddreturn = lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN| DDSCL_ALLOWMODEX);
	if (ddreturn != DD_OK)
	{
		DestroyWindow(hwnd);
		return FALSE;
	}

	/* Create a palette for the surfaces. */
	ddreturn = lpDirectDrawObject->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE,
																(LPPALETTEENTRY)WinColormap,
																&lpPalette,
																NULL);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	/* Set the video mode to XRESxYRESx8. */
	ddreturn = lpDirectDrawObject->SetDisplayMode(XRES, YRES, 8);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	/* Create a default font for the application. */
	AppFont = CreateFont(11,
								0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
								ANSI_CHARSET,
								OUT_DEFAULT_PRECIS,
								CLIP_DEFAULT_PRECIS,
								NONANTIALIASED_QUALITY,
								VARIABLE_PITCH,
								"Comic Sans MS");

	/* Create the primary surface and one back buffer surface */
	ddsd.dwSize = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
								 DDSCAPS_FLIP |
								 DDSCAPS_COMPLEX;
	ddsd.dwBackBufferCount = 1;
	ddreturn = lpDirectDrawObject->CreateSurface(&ddsd, &lpPrimary, NULL);

	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	ddreturn = lpPrimary->SetPalette(lpPalette);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

	/* Get a surface pointer to our back buffer. */
	ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
	ddreturn = lpPrimary->GetAttachedSurface(&ddscaps, &lpBackbuffer);

	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}

/*	ddreturn = lpBackbuffer->SetPalette(lpPalette);
	if (ddreturn != DD_OK)
	{	DestroyWindow(hwnd);
		return FALSE;
	}
*/
	{	/* Clear the background once for both buffers so we don't get anoying flicker effect. */
		DDBLTFX	BltFx;
		BltFx.dwSize = sizeof(BltFx);
		BltFx.dwFillColor = 255;
		ddreturn = lpBackbuffer->Blt(NULL,
											  NULL,
											  NULL,
											  DDBLT_COLORFILL | DDBLT_WAIT,
											  &BltFx);
		BltFx.dwSize = sizeof(BltFx);
		BltFx.dwFillColor = 255;
		ddreturn = lpPrimary->Blt(NULL,
											  NULL,
											  NULL,
											  DDBLT_COLORFILL | DDBLT_WAIT,
											  &BltFx);
	}

	while (1)
	{	if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		{	if (!GetMessage(&msg, NULL, 0, 0))
				return msg.wParam;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		} else
		{	if (ActiveApp && RealTime)
			{	// Simulation Iteration should go here.
				// Only do this when running Realtime.
				SimLoop();
			} else
			{	WaitMessage();
			}
		}
	}
}
Ejemplo n.º 17
0
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
	
	MyDirectX = new DirectX();
	WNDCLASSEX wndClass;

	wndClass.cbSize = sizeof( WNDCLASSEX );
	wndClass.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
	wndClass.cbClsExtra = 0;
	wndClass.cbWndExtra = 0;
	wndClass.hbrBackground = ( HBRUSH )GetStockObject( BLACK_BRUSH );
	wndClass.hInstance = hInstance;
	wndClass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wndClass.hIconSm = LoadIcon( NULL, IDI_WINLOGO );
	wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
	wndClass.lpfnWndProc = ( WNDPROC )WndProc;
	wndClass.lpszClassName = "MainWndClass";
	wndClass.lpszMenuName = ( LPCSTR )NULL;

	if( !RegisterClassEx( &wndClass ) ) {
		MessageBox( HWND_DESKTOP, "Cannot register the main window\nclass.", "Error", MB_OK | MB_ICONERROR );
		return 0;
	}

	HWND hWndMain = CreateWindowEx(
		WS_EX_STATICEDGE,
		"MainWndClass",
		"DirectX Tutorial #1",
		WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		800, 600,
		HWND_DESKTOP,
		( HMENU )NULL,
		( HINSTANCE )hInstance,
		( LPVOID* )NULL
	);

	if( !hWndMain ) {
		MessageBox( HWND_DESKTOP, "Cannot create the main window.", "Error", MB_OK | MB_ICONERROR );
		UnregisterClass( "MainWndClass", hInstance );
		return 0;
	}

	ShowWindow( hWndMain, SW_SHOWNORMAL );
	UpdateWindow( hWndMain );

	MyDirectX->Init( hWndMain );

	MSG msg = {0};

	while( msg.message != WM_QUIT ) {
		
		if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}

		// Do game rendering/updating here
		MyDirectX->Render( );

	}

	MyDirectX->CleanDirectX( );
	delete [] MyDirectX;
	UnregisterClass( "MainWndClass", hInstance );
	return 0;

}
Ejemplo n.º 18
0
int PASCAL
WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow)
{
    MSG       msg;                      /* MSG structure to pass to windows proc */
    WNDCLASS  wndclass;
    char      *AppName;                 /* Name for the window */

    cbErrHandling (PRINTALL, STOPALL);  /* Set library's error handling */

    CmdLine = NULL;                     /* Not used */
    AppName = "WINCDEMO";               /* The name of this application */
    if(!hPrevInstance)
        {
        wndclass.style      = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc= MainMessageHandler;
        wndclass.cbClsExtra = 0;
        wndclass.cbWndExtra = 0;
        wndclass.hInstance  = hInstance;
        wndclass.hIcon      = LoadIcon (hInstance, AppName);
        wndclass.hCursor    = LoadCursor (NULL, IDC_ARROW);
        wndclass.hbrBackground  = GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName   = AppName;
        wndclass.lpszClassName  = AppName;
        RegisterClass (&wndclass);
        }

    /* create application's Main window                                    */
    hWndMain = CreateWindow (AppName,                  /* Window class name          */
                             "AInScan Foreground",
                             WS_OVERLAPPEDWINDOW,
                             CW_USEDEFAULT,           /* Use default X, Y            */
                             CW_USEDEFAULT,           /* Use default X, Y            */
                             GetSystemMetrics(SM_CXSIZE) * 12,   /* x - fit text      */
                             GetSystemMetrics(SM_CYSIZE) * 20,  /* y - fit text      */
                             NULL,                    /* Parent window's handle      */
                             NULL,                    /* Default to Class Menu       */
                             hInstance,               /* Instance of window          */
                             NULL);                   /* Create struct for WM_CREATE */


    if (hWndMain == NULL)
        {
        MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
        return (1);
        }

    ShowWindow(hWndMain, nCmdShow);     /* Display main window      */
    UpdateWindow(hWndMain);

    /* Start a 500ms timer to update display */
//    if(!SetTimer(hWndMain, TIMER_NUM, 500, NULL))
//        {
//        MessageBox(NULL, "Error starting Windows timer", NULL, MB_OK |
//                   MB_ICONEXCLAMATION);
 //       return (1);
 //       }                          
        
    while(GetMessage(&msg, NULL, 0, 0)) /* Main message loop */
        {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
        }

    UnregisterClass (AppName, hInstance);
    return (msg.wParam);
} 
Ejemplo n.º 19
0
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprev, PSTR cmdline, int ishow)
{
	HDC hDCScreen = GetDC(NULL);
	int Horres = GetDeviceCaps(hDCScreen, HORZRES);
	int Vertres = GetDeviceCaps(hDCScreen, VERTRES);

	HWND        hwnd = NULL;
	HMENU		hmenu;
	MSG         msg;
	WNDCLASSEX  wndclass = { 1 };


	wndclass.cbSize = sizeof(wndclass);
	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WinProc;
	wndclass.hInstance = hinstance;
	wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.lpszClassName = "Class";

	hmenu = LoadMenu(hinstance, MAKEINTRESOURCE(IDR_MENU1));

	if (!hmenu)
		return EXIT_FAILURE; // Something bad happened :(


	RegisterClassEx(&wndclass);
											
	hwnd = CreateWindowEx(NULL, // No extra style,
							"Class",
							"RSA Шифрование",
							WS_OVERLAPPEDWINDOW | WS_THICKFRAME, 
							GetDeviceCaps(hDCScreen, HORZRES) / 2 - WINDOW_WIDTH / 2,
							GetDeviceCaps(hDCScreen, VERTRES) / 2 - WINDOW_HEIGHT / 2,
							WINDOW_WIDTH,
							WINDOW_HEIGHT,
							NULL,
							hmenu,
							hinstance,
							NULL);
	SetCursorPos(GetDeviceCaps(hDCScreen, HORZRES) / 2, GetDeviceCaps(hDCScreen, VERTRES) / 2);

	ShowWindow(hwnd, ishow);
	UpdateWindow(hwnd);



	while (1) 
	{
												
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				break;
			
			TranslateMessage(&msg);							
			DispatchMessage(&msg);
		}
	}

	UnregisterClass("Class", hinstance);
	return msg.wParam;
}
Ejemplo n.º 20
0
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);


	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

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

	// グローバル文字列を初期化しています。
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
	LoadString(hInstance, IDC_WALL, 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_WALL));

	// 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;
}
int PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int nCmdShow)
{
  WNDCLASSEX wcex;
  MSG        Msg;
  HWND       hWnd;

  // Initialize the COM system
  CoInitialize(NULL);

  // Create the window class here and register it
  wcex.cbSize        = sizeof(wcex);
  wcex.style         = CS_CLASSDC;
  wcex.lpfnWndProc   = WindowProc;
  wcex.cbClsExtra    = 0;
  wcex.cbWndExtra    = 0;
  wcex.hInstance     = hInst;
  wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  wcex.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wcex.hbrBackground = NULL;
  wcex.lpszMenuName  = NULL;
  wcex.lpszClassName = g_szClass;
  wcex.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  if(!RegisterClassEx(&wcex))
    return FALSE;

  // Create the main window
  hWnd = CreateWindow(g_szClass, g_szCaption,
              WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
              0, 0, 640, 480,
              NULL, NULL, hInst, NULL);
  if(!hWnd)
    return FALSE;
  ShowWindow(hWnd, SW_NORMAL);
  UpdateWindow(hWnd);

  // Call init function and enter message pump
  if(DoInit(hWnd) == TRUE) {

    // Start message pump, waiting for user to exit
    ZeroMemory(&Msg, sizeof(MSG));
    while(Msg.message != WM_QUIT) {
      if(PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
      }

      // Render a single frame
      DoFrame();
    }
  }

  // Call shutdown
  DoShutdown();
 
  // Unregister the window class
  UnregisterClass(g_szClass, hInst);

  // Shut down the COM system
  CoUninitialize();

  return 0;
}
Ejemplo n.º 22
0
long CWorkgroupDocument::CopyMoveFile(DWORD folder_id, _bstr_t filepath, VARIANT_BOOL bSilent, CProgressDlg* dlg)
{
	long nFilesCopied = 0;

	DWORD attributes = GetFileAttributes(filepath);
	char* filepart = PathFindFileName(filepath);

	if (attributes & FILE_ATTRIBUTE_DIRECTORY)
	{
		folder_id = m_filesystem->FindOrCreateFolder(folder_id, filepart, L"");

		if (folder_id)
		{
			HANDLE hFindFile;
			WIN32_FIND_DATA	wfd;

			char	search[MAX_PATH];
			wsprintf(search, "%S\\*.*", (BSTR)filepath);

			if ((hFindFile = FindFirstFile(search, &wfd)) != INVALID_HANDLE_VALUE)
			{
				do
				{
					if (wfd.cFileName[0] != '.')
					{
						char pathName[_MAX_PATH];
						_makepath(pathName, NULL, filepath, wfd.cFileName, NULL);

						nFilesCopied += CopyMoveFile(folder_id, pathName, bSilent, dlg);

						if (dlg)
						{
							if (dlg->m_bCancel) break;
						}
					}
				}
				while (FindNextFile(hFindFile, &wfd));

				FindClose(hFindFile);
			}
		}
		else
		{
			if (!bSilent)
			{
				CUString str;
				str.Format("Couldn't create folder %S", (BSTR)filepath);
				MessageBox(NULL, str, "LXFramework", MB_OK);
			}
		}
	}
	else
	{
		SAFEARRAY* dataArray = NULL;
		long dataSize = 0;

		FILE* fp = fopen(filepath, "rb");
		if (fp)
		{
			fseek(fp, 0, SEEK_END);
			dataSize = ftell(fp);
			fseek(fp, 0, SEEK_SET);

			dataArray = SafeArrayCreateVector(VT_UI1, 0, dataSize);
			if (dataArray)
			{
				fread((dataArray)->pvData, 1, dataSize, fp);
			}

			fclose(fp);
		}
		else
		{
			if (!bSilent)
			{
				CUString str;
				str.Format("Couldn't open %S", (BSTR)filepath);
				MessageBox(NULL, str, "LXFramework", MB_OK);
			}
		}

		if (dataArray)
		{
			long file_id;
			VARIANT_BOOL success = m_filesystem->SaveArrayAsFile(folder_id, _bstr_t(filepart), dataArray, L"", &file_id);

			SafeArrayDestroy(dataArray);

			if (success)
			{
				nFilesCopied++;
			}
			else
			{
				if (!bSilent)
				{
					CUString str;
					str.Format("Failed to copy %s", filepart);
					MessageBox(NULL, str, "LXFramework", MB_OK);
				}
			}
		}

		if (dlg)
		{
			dlg->m_pos += dataSize/10;
			dlg->Invalidate();

			MSG msg;
			while (PeekMessage(&msg, dlg->m_hWnd, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
	}
	return nFilesCopied;
}
Ejemplo n.º 23
0
/*
	Initialize().
	We already have a window from the screensaver, so store it and pass along all 0's to initialize
	a child window.
*/
bool	CDisplayDX::Initialize( HWND _hWnd, bool _bPreview )
{
    m_bScreensaver = true;
    m_bPreview = _bPreview;
    m_WindowHandle = _hWnd;

    HMODULE    hInstance = GetModuleHandle( NULL );

    WNDCLASS wc = {0};

    wc.style = CS_VREDRAW | CS_HREDRAW;
    wc.lpfnWndProc = (WNDPROC)CDisplayDX::wndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(1));
    wc.hCursor = NULL;
    wc.hbrBackground = NULL;
    wc.lpszMenuName = NULL;
    wc.lpszClassName = L"ElectricsheepWndClass";
    RegisterClass( &wc );

    if( _bPreview )
    {
        g_bPreview = true;

        RECT rc;
        //GetWindowRect( _hWnd, &rc );
        GetClientRect( _hWnd, &rc );
        int32 cx = rc.right - rc.left;
        int32 cy = rc.bottom - rc.top;

        g_Log->Info( "rc: %d, %d", cx, cy );

        DWORD dwStyle = WS_VISIBLE | WS_CHILD;
        AdjustWindowRect( &rc, dwStyle, FALSE );
        m_WindowHandle = CreateWindow( L"ElectricsheepWndClass", L"Preview", dwStyle, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, _hWnd, NULL, hInstance, NULL );
        g_Log->Info( "CDisplayDX::Initialize x=%u y=%u w=%u h=%u",  rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top);
        if( m_WindowHandle == NULL )
        {
            g_Log->Error( "CDisplayDX::Initialize unable to create window for preview" );
            //ThrowStr( "Unable to create window..." );
            return false;
        }

        m_Width = cx;
        m_Height = cy;

        g_Log->Info( "Screensaver preview (%dx%d)", cx, cy );

        // In preview mode, "pause" (enter a limited message loop) briefly before proceeding, so the display control panel knows to update itself.
        m_bWaitForInputIdle = true;

        // Post a message to mark the end of the initial group of window messages
        PostMessage( m_WindowHandle, WM_USER, 0, 0 );

        InvalidateRect( GetParent( _hWnd ), NULL, FALSE );    // Invalidate the hwnd so it gets drawn
        UpdateWindow( GetParent( _hWnd ) );
        UpdateWindow( GetParent( _hWnd ) );

        MSG msg;
        while( m_bWaitForInputIdle )
        {
            // If GetMessage returns FALSE, it's quitting time.
            if( !GetMessage( &msg, m_WindowHandle, 0, 0 ) )
            {
                // Post the quit message to handle it later
                PostQuitMessage(0);
                break;
            }

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

        if( !InitDX9() )
            return false;

        //ShowWindow( _hWnd, SW_SHOW );
        //SetForegroundWindow( _hWnd );
        SetFocus( _hWnd );
        ShowCursor( true );
    }
    else
    {
//		int32 cx = GetSystemMetrics( SM_CXSCREEN );
//		int32 cy = GetSystemMetrics( SM_CYSCREEN );
        RECT rc;
        GetWindowRect( _hWnd, &rc );
        m_Width = rc.right - rc.left;
        m_Height = rc.bottom - rc.top;
        g_Log->Info( "CDisplayDX::Initialize right=%u left=%u bottom=%u top=%u",  rc.right, rc.left, rc.bottom, rc.top);
        //DWORD exstyle = 0;//WS_EX_TOPMOST;
        //DWORD style = WS_CHILD | WS_VISIBLE;

        m_WindowHandle = _hWnd;//CreateWindowEx( exstyle, "Electricsheep", "Saver", style, 0, 0, cx, cy, _hWnd, NULL, hInstance, NULL );
        if( m_WindowHandle == NULL )
        {
            g_Log->Error( "CDisplayDX::Initialize unable to create window from _hWnd" );
            return false;
        }

        g_Log->Info( "Screensaver (%dx%d)", m_Width, m_Height );

        //	Hide cursor.
        ShowCursor( false );

        if( !InitDX9() )
            return false;
    }

    return true;
}
Ejemplo n.º 24
0
void
mswin_display_RIP_window(HWND hWnd)
{
    MSG msg;
    RECT rt;
    PNHRIPWindow data;
    HWND mapWnd;
    RECT riprt;
    RECT clientrect;
    RECT textrect;
    HFONT OldFont;
    MonitorInfo monitorInfo;

    win10_monitor_info(hWnd, &monitorInfo);

    data = (PNHRIPWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);

    data->x = (int)(RIP_OFFSET_X * monitorInfo.scale);
    data->y = (int)(RIP_OFFSET_Y * monitorInfo.scale);
    data->width = (int)(RIP_WIDTH * monitorInfo.scale);
    data->height = (int)(RIP_HEIGHT * monitorInfo.scale);
    data->graveX = (int)(RIP_GRAVE_X * monitorInfo.scale);
    data->graveY = (int)(RIP_GRAVE_Y * monitorInfo.scale);
    data->graveWidth = (int)(RIP_GRAVE_WIDTH * monitorInfo.scale);
    data->graveHeight = (int)(RIP_GRAVE_HEIGHT * monitorInfo.scale);

    GetNHApp()->hPopupWnd = hWnd;
    mapWnd = mswin_hwnd_from_winid(WIN_MAP);
    if (!IsWindow(mapWnd))
        mapWnd = GetNHApp()->hMainWnd;
    GetWindowRect(mapWnd, &rt);
    GetWindowRect(hWnd, &riprt);
    GetClientRect(hWnd, &clientrect);
    textrect = clientrect;
    textrect.top += data->y;
    textrect.left += data->x;
    textrect.right -= data->x;
    if (data->window_text) {
        HDC hdc = GetDC(hWnd);
        OldFont = SelectObject(hdc, mswin_get_font(NHW_TEXT, 0, hdc, FALSE)->hFont);
        DrawText(hdc, data->window_text, strlen(data->window_text), &textrect,
                 DT_LEFT | DT_NOPREFIX | DT_CALCRECT);
        SelectObject(hdc, OldFont);
        ReleaseDC(hWnd, hdc);
    }
    if (textrect.right - textrect.left > data->width)
        clientrect.right = textrect.right + data->y - clientrect.right;
    else
        clientrect.right =
            textrect.left + 2 * data->x + data->width - clientrect.right;
    clientrect.bottom =
        textrect.bottom + data->height + data->y - clientrect.bottom;
    GetWindowRect(GetDlgItem(hWnd, IDOK), &textrect);
    textrect.right -= textrect.left;
    textrect.bottom -= textrect.top;
    clientrect.bottom += textrect.bottom + data->y;
    riprt.right -= riprt.left;
    riprt.bottom -= riprt.top;
    riprt.right += clientrect.right;
    riprt.bottom += clientrect.bottom;
    rt.left += (rt.right - rt.left - riprt.right) / 2;
    rt.top += (rt.bottom - rt.top - riprt.bottom) / 2;

    MoveWindow(hWnd, rt.left, rt.top, riprt.right, riprt.bottom, TRUE);
    GetClientRect(hWnd, &clientrect);
    MoveWindow(GetDlgItem(hWnd, IDOK),
               (clientrect.right - clientrect.left - textrect.right) / 2,
               clientrect.bottom - textrect.bottom - data->y,
               textrect.right, textrect.bottom, TRUE);
    ShowWindow(hWnd, SW_SHOW);

    while (IsWindow(hWnd) && GetMessage(&msg, NULL, 0, 0) != 0) {
        if (!IsDialogMessage(hWnd, &msg)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

    GetNHApp()->hPopupWnd = NULL;
}
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR szCmdLine, int iCmdShow)
{
	WNDCLASSEX winClass ;

	winClass.lpszClassName = "Vertex Alpha";
	winClass.cbSize        = sizeof(WNDCLASSEX);
	winClass.style         = CS_HREDRAW | CS_VREDRAW;
	winClass.lpfnWndProc   = MsgProc;
	winClass.hInstance     = hInstance;
	winClass.hIcon	       = NULL ;
	winClass.hIconSm	   = NULL ;
	winClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
	winClass.hbrBackground = NULL ;
	winClass.lpszMenuName  = NULL ;
	winClass.cbClsExtra    = 0;
	winClass.cbWndExtra    = 0;

	RegisterClassEx (&winClass) ;  

	HWND hWnd = CreateWindowEx(NULL,  
		winClass.lpszClassName,		// window class name
		"Vertex Alpha",					// window caption
		WS_OVERLAPPEDWINDOW, 		// window style
		32,							// initial x position
		32,							// initial y position
		600,						// initial window width
		600,						// initial window height
		NULL,						// parent window handle
		NULL,						// window menu handle
		hInstance,					// program instance handle
		NULL) ;						// creation parameters

	// Create window failed
	if(hWnd == NULL)
	{
		MessageBoxA(hWnd, "Create Window failed!", "Error", 0) ;
		return -1 ;
	}

	// Initialize Direct3D
	if( SUCCEEDED(InitD3D(hWnd)))
	{ 
		// Show the window
		ShowWindow( hWnd, SW_SHOWDEFAULT );
		UpdateWindow( hWnd );

		MSG msg ; 
		ZeroMemory( &msg, sizeof(msg) );
		PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE );

		// Get last time
		static DWORD lastTime = timeGetTime();

		while (msg.message != WM_QUIT)  
		{
			if(PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) != 0)
			{
				TranslateMessage (&msg) ;
				DispatchMessage (&msg) ;
			}
			else // Render the game if there is no message to process
			{
				// Get current time
				DWORD currTime  = timeGetTime();

				// Calculate time elapsed
				float timeDelta = (currTime - lastTime) * 0.001f;

				// Render
				Render() ;

				// Update last time to current time for next loop
				lastTime = currTime;
			}
		}
	}

	UnregisterClass(winClass.lpszClassName, hInstance) ;
	return 0;
}
Ejemplo n.º 26
0
//-----------------------------------WinMain-----------------------------------------
//	Entry point for our windows application
//-----------------------------------------------------------------------------------
int WINAPI WinMain(	HINSTANCE hinstance,
					          HINSTANCE hprevinstance,
					          LPSTR lpcmdline,
					          int ncmdshow)
{

	WNDCLASSEX winclass; 
	HWND	   hwnd;	 
	MSG		   msg;		 

	// first fill in the window class stucture
	winclass.cbSize       = sizeof(WNDCLASSEX);
	winclass.style			  = CS_HREDRAW | CS_VREDRAW;
	winclass.lpfnWndProc	= WindowProc;
	winclass.cbClsExtra		= 0;
	winclass.cbWndExtra		= 0;
	winclass.hInstance		= hinstance;
	winclass.hIcon			  = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));
	winclass.hCursor		  = LoadCursor(NULL, IDC_ARROW); 
	winclass.hbrBackground= NULL; 
	winclass.lpszMenuName	= NULL;
	winclass.lpszClassName= szWindowClassName;
	winclass.hIconSm      = LoadIcon(hinstance, MAKEINTRESOURCE(IDI_ICON1));


	// register the window class
	if (!RegisterClassEx(&winclass))
	{
		MessageBox(NULL, "Error Registering Class!", "Error", 0);
    return 0;
	}

	// create the window (one that cannot be resized)
	if (!(hwnd = CreateWindowEx(NULL,									
								              szWindowClassName,						
								              szApplicationName,						
								              WS_OVERLAPPED | WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
                              GetSystemMetrics(SM_CXSCREEN)/2 - CParams::WindowWidth/2,
                              GetSystemMetrics(SM_CYSCREEN)/2 - CParams::WindowHeight/2,									
								              CParams::WindowWidth,
                              CParams::WindowHeight,				
								              NULL,									
								              NULL,								
								              hinstance,								
								              NULL)))	
	{
    MessageBox(NULL, "Error Creating Window!", "Error", 0);
		return 0;
	}
	
	//Show the window
	ShowWindow(hwnd, SW_SHOWDEFAULT );
	UpdateWindow(hwnd);

	//create a timer
	CTimer timer(CParams::iFramesPerSecond);

	//start the timer
	timer.Start();

	// Enter the message loop
	bool bDone = FALSE;

	while(!bDone)
	{
					
		while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 
		{
			if( msg.message == WM_QUIT ) 
			{
				//Stop loop if it's a quit message
				bDone = TRUE;
			} 

			else 
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
		}
							
		if (timer.ReadyForNextFrame() || g_pController->FastRender())
		{	
		  if(!g_pController->Update())
			{
				//we have a problem, end app
				bDone = TRUE;
			}

			//this will call WM_PAINT which will render our scene
			InvalidateRect(hwnd, NULL, TRUE);
			UpdateWindow(hwnd);
    }					
					
	}//end while
	

    // Clean up everything and exit the app
    Cleanup();
    UnregisterClass( szWindowClassName, winclass.hInstance );
	
	return 0;

} // end WinMain
Ejemplo n.º 27
0
int
_tmain(int argc, const TCHAR *argv)
{
	HWND w;
	HINSTANCE hinst = GetModuleHandle(NULL);

	{
		WNDCLASS wc;
		wc.style = CS_HREDRAW|CS_VREDRAW;
		wc.lpfnWndProc = window_proc;
		wc.cbClsExtra = 0;
		wc.cbWndExtra = 0;
		wc.hInstance = hinst;
		wc.hIcon = NULL;
		wc.hCursor = LoadCursor(NULL, IDC_ARROW);
		wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
		wc.lpszMenuName = NULL;
		wc.lpszClassName = _T("MainWindowClass");
		RegisterClass(&wc);
	}

	// CreateWindow
	// http://msdn.microsoft.com/en-us/library/windows/desktop/ms632679(v=vs.85).aspx
	// > If an overlapped window is created with the WS_VISIBLE
	// > style bit set and the x parameter is set to
	// > CW_USEDEFAULT, then the y parameter determines how the
	// > window is shown. If the y parameter is CW_USEDEFAULT,
	// > then the window manager calls ShowWindow with the SW_SHOW
	// > flag after the window has been created. If the y
	// > parameter is some other value, then the window manager
	// > calls ShowWindow with that value as the nCmdShow
	// > parameter.

	// ShowWindow
	// http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx
	// > Controls how the window is to be shown.
	// >	This parameter is ignored the first time an
	// >	application calls ShowWindow, if the program that
	// >	launched the application provides a STARTUPINFO
	// >	structure.
	// > Otherwise, the first time ShowWindow is called, the value
	// > should be the value obtained by the WinMain function in
	// > its nCmdShow parameter. In subsequent calls, this
	// > parameter can be one of the following values.

	w = CreateWindow(_T("MainWindowClass"), _T("hello"),
		WS_OVERLAPPEDWINDOW|WS_VISIBLE,
		CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, 0,
		NULL, NULL, hinst, NULL);

	while (1) {
		MSG msg;
		BOOL b = GetMessage(&msg, NULL, 0, 0);
		if (b == 0) {
			return msg.wParam;
		}
		if (b == -1) {
			return 1;
		}
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return 0;
}
Ejemplo n.º 28
0
int PASCAL WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
	strcpy ( szMap, lpCmdLine );
	//strcpy ( szMap, "csg1.x" );

		char szFinal  [ 256 ];
	
	memset ( szFinal, 0, sizeof ( szFinal ) );

	for ( int iTemp = strlen ( szMap ); iTemp > 0; iTemp-- )
	{
		if ( szMap [ iTemp ] == '/' || szMap [ iTemp ] == '\\' )
		{
			memcpy ( szFinal, &szMap [ iTemp + 1 ], sizeof ( char ) * iTemp );

			break;
		}
	}

	strcpy ( szMap, szFinal );

//MessageBox ( NULL, szFinal, "info", MB_OK );

	//MessageBox ( NULL, szMap, "info", MB_OK );
	//MessageBox ( NULL, lpCmdLine, "lpCmdLine", MB_OK );

	hInst		  = hInstance;
    hPrevInstance = hPrevInstance;

	MSG			msg;

	BOOL		perf_flag	= FALSE;
	LONGLONG	last_time	= 0;
	LONGLONG	cur_time;
	LONGLONG	perf_cnt;
	float		time_scale;
	
	if ( !doInit ( hInst, nCmdShow ) ) 
		return FALSE;
	
	if ( QueryPerformanceFrequency ( ( LARGE_INTEGER* ) &perf_cnt ) )
	{ 
		QueryPerformanceCounter ( ( LARGE_INTEGER* ) &last_time );
		time_scale	= 1.0f / perf_cnt;
		perf_flag	= TRUE;
	}
	else
	{
		last_time	= timeGetTime ( );
		time_scale	= 0.001f;
	} 	

	// SetCursorPos ( 320,200 );
    // ShowCursor ( FALSE );

    BOOL bGotMsg;

	while ( quit != 1 )
	{
		while ( bGotMsg = PeekMessage ( &msg, NULL, 0U, 0U, PM_REMOVE ) )
		{
			TranslateMessage ( &msg );
            DispatchMessage  ( &msg );
        }

		if ( rendering == 1 )
		{
			if ( perf_flag ) 
				QueryPerformanceCounter ( ( LARGE_INTEGER* ) &cur_time );
			else 
				cur_time = timeGetTime ( ); 

			time_elapsed = ( cur_time - last_time ) * time_scale;
			last_time	 = cur_time;
	
			// CheckInput  ( );
			// renderframe ( );
		}
    }

	ShowCursor ( TRUE );

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

	SetDllDirectory(L"");
	SetTaskIDPerUUID();
	MSG msg;
	HACCEL hAccelTable;

	CCmdLineParser parser(lpCmdLine);

	if (parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
	{
		TCHAR buf[1024];
		LoadString(hInstance, IDS_COMMANDLINEHELP, buf, sizeof(buf)/sizeof(TCHAR));
		MessageBox(NULL, buf, _T("TortoiseGitUDiff"), MB_ICONINFORMATION);
		return 0;
	}

	INITCOMMONCONTROLSEX used = {
		sizeof(INITCOMMONCONTROLSEX),
		ICC_STANDARD_CLASSES | ICC_BAR_CLASSES
	};
	InitCommonControlsEx(&used);


	HMODULE hSciLexerDll = ::LoadLibrary(_T("SciLexer.DLL"));
	if (hSciLexerDll == NULL)
		return FALSE;

	CMainWindow mainWindow(hInstance);
	mainWindow.SetRegistryPath(_T("Software\\TortoiseGit\\UDiffViewerWindowPos"));
	if (parser.HasVal(_T("title")))
		mainWindow.SetTitle(parser.GetVal(_T("title")));
	else if (parser.HasVal(_T("patchfile")))
		mainWindow.SetTitle(parser.GetVal(_T("patchfile")));
	else
		mainWindow.SetTitle(_T("diff from pipe"));

	if (!mainWindow.RegisterAndCreateWindow())
	{
		FreeLibrary(hSciLexerDll);
		return 0;
	}

	bool bLoadedSuccessfully = false;
	if ( (lpCmdLine[0] == 0) ||
		(parser.HasKey(_T("p"))) )
	{
		// input from console pipe
		// set console to raw mode
		DWORD oldMode;
		GetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), &oldMode);
		SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), oldMode & ~(ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT));

		bLoadedSuccessfully = mainWindow.LoadFile(GetStdHandle(STD_INPUT_HANDLE));
	}
	else if (parser.HasVal(_T("patchfile")))
		bLoadedSuccessfully = mainWindow.LoadFile(parser.GetVal(_T("patchfile")));
	else if (lpCmdLine[0] != 0)
		bLoadedSuccessfully = mainWindow.LoadFile(lpCmdLine);


	if (!bLoadedSuccessfully)
	{
		FreeLibrary(hSciLexerDll);
		return 0;
	}

	::ShowWindow(mainWindow.GetHWNDEdit(), SW_SHOW);
	::SetFocus(mainWindow.GetHWNDEdit());

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

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

	FreeLibrary(hSciLexerDll);
	return (int) msg.wParam;
}
Ejemplo n.º 30
0
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int) {
#else // _DEBUG
void APIENTRY _myWinMain() {
#endif // _DEBUG

    g_hinstExe = GetModuleHandle(NULL);

	int nExitCode = 1;
	//HANDLE hmtx = NULL;
    
	__try {

		ParseCommandLine();

		if (!CheckVersion() && !(g_dwCmdLine & CCLF_NOCHECKVER)) {
			MessageBoxA(NULL, "This program requires features present in Windows XP/2003.", 
				"Error", MB_OK | MB_ICONERROR | MB_TOPMOST | MB_SETFOREGROUND);
			__leave;
		}

		/*hmtx = CreateMutex(NULL, FALSE, g_szTaskSwitch);
		if (GetLastError() == ERROR_ALREADY_EXISTS) {
			ReportError(IDS_ERR_EXISTS);
			__leave;
		}*/

		InitThreadLang2();
		InitLanguage();

		HWND hwndTs = FindWindowEx(NULL/*HWND_MESSAGE*/, NULL, g_szMainWnd, g_szWindowName);
		if (IsWindow(hwndTs)) {
			if (g_dwCmdLine != 0) {
				SetForegroundWindow(hwndTs);
				PostMessage(hwndTs, WM_REMOTECMD, g_dwCmdLine, 0);
			} else {
				if (ConfirmMessage(IDS_CONFIRM_RUNNING, MB_ICONEXCLAMATION | MB_DEFBUTTON2))
					PostMessage(hwndTs, WM_DESTROY, 0, 0);
				//PostMessage(hwndTs, WM_RELOADSETTINGS, 0, 0);
			}
			__leave;
		}

		HINSTANCE hinstUser32 = LoadLibrary(L"user32.dll");
		g_pfnIsHungAppWindow = (ISHUNGAPPWINDOW)GetProcAddress(hinstUser32, "IsHungAppWindow");
		//g_pfnEndTask = (ENDTASK)GetProcAddress(hinstUser32, "EndTask");

		WNDCLASSEX wcex;
		wcex.cbSize			= sizeof(WNDCLASSEX);
		wcex.style			= 0;
		wcex.lpfnWndProc	= (WNDPROC)MainWndProc;
		wcex.cbClsExtra		= 0;
		wcex.cbWndExtra		= 0;
		wcex.hInstance		= g_hinstExe;
		wcex.hIcon			= NULL;
		wcex.hCursor		= NULL;
		wcex.hbrBackground	= NULL;
		wcex.lpszMenuName	= NULL;
		wcex.lpszClassName	= g_szMainWnd;
		wcex.hIconSm		= NULL;
		if (!RegisterClassEx(&wcex))
			__leave;

		if (!CreateWindowEx(WS_EX_TOOLWINDOW, g_szMainWnd, g_szWindowName, 
			0, 0, 0, 0, 0, NULL/*HWND_MESSAGE*/, NULL, g_hinstExe, NULL)) __leave;

		MSG msg;
		while (GetMessage(&msg, NULL, 0, 0)) {
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		nExitCode = (int)msg.wParam;
	}
	__finally {
		DestroyThreadLang2();
		//if (hmtx) CloseHandle(hmtx);		
	}
#ifdef _DEBUG
	return(nExitCode);
#else // _DEBUG
	ExitProcess((UINT)nExitCode);
#endif
}