Beispiel #1
0
/*************************************************************************
    Win32 'Window Procedure' function
*************************************************************************/
LRESULT CALLBACK Win32AppHelper::wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
    case WM_CHAR:
        s_samplesFramework->injectChar((CEGUI::utf32)wParam);
        break;

    case WM_MOUSELEAVE:
        mouseLeaves();
        break;

    case WM_NCMOUSEMOVE:
        mouseLeaves();
        break;

    case WM_MOUSEMOVE:
        mouseEnters();

        s_samplesFramework->injectMousePosition((float)(LOWORD(lParam)), (float)(HIWORD(lParam)));
        break;

    case WM_LBUTTONDOWN:
        s_samplesFramework->injectMouseButtonDown(CEGUI::LeftButton);
        break;

    case WM_LBUTTONUP:
        s_samplesFramework->injectMouseButtonUp(CEGUI::LeftButton);
        break;

    case WM_RBUTTONDOWN:
        s_samplesFramework->injectMouseButtonDown(CEGUI::RightButton);
        break;

    case WM_RBUTTONUP:
        s_samplesFramework->injectMouseButtonUp(CEGUI::RightButton);
        break;

    case WM_MBUTTONDOWN:
        s_samplesFramework->injectMouseButtonDown(CEGUI::MiddleButton);
        break;

    case WM_MBUTTONUP:
        s_samplesFramework->injectMouseButtonUp(CEGUI::MiddleButton);
        break;

    case 0x020A: // WM_MOUSEWHEEL:
        s_samplesFramework->injectMouseWheelChange(static_cast<float>((short)HIWORD(wParam)) / static_cast<float>(120));
        break;

    case WM_DESTROY:
        PostQuitMessage(0);
        break;

    case WM_SIZE:
        {
            // get CEGUI::System as a pointer so we can detect if it's not
            // instantiated yet.
            CEGUI::System* cegui_system = CEGUI::System::getSingletonPtr();

            // only continue if CEGUI is up an running and window was not
            // minimised (else it's just a waste of time)
            if ((cegui_system != 0) && (wParam != SIZE_MINIMIZED))
            {
                // get renderer identification string
                CEGUI::Renderer* renderer = cegui_system->getRenderer();
                CEGUI::String id(renderer->getIdentifierString());

                // invoke correct function based on the renderer we have ID'd
#ifdef CEGUI_BUILD_RENDERER_DIRECT3D9
                if (id.find("Official Direct3D 9") != id.npos)
                    DeviceReset_Direct3D9(hWnd, renderer);
#endif
#ifdef CEGUI_BUILD_RENDERER_DIRECT3D10
                if (id.find("Official Direct3D 10") != id.npos)
                    DeviceReset_Direct3D10(hWnd, renderer);
#endif
#ifdef CEGUI_BUILD_RENDERER_DIRECT3D11
                if (id.find("Official Direct3D 11") != id.npos)
                    DeviceReset_Direct3D11(hWnd, renderer);
#endif
            }
        }
        break;

    case WM_PAINT:
        {
            HDC         hDC;
            PAINTSTRUCT ps;

            hDC = BeginPaint(hWnd, &ps);
            EndPaint(hWnd, &ps);
            break;
        }

    default:
        return(DefWindowProc(hWnd, message, wParam, lParam));
        break;
    }

    return 0;
}
Beispiel #2
0
static int Desktop(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	char cwd[MAX_PATH + 1];

        //DEB("-Desktop: \n ");

	switch (message) {
	case MSG_CREATE:
	{
                DEB("--MSG_CREATE\n ");	
                /*	
		CreateWindow(CTRL_LISTBOX,
			     "",
			     LBS_NOTIFY  | WS_VSCROLL | WS_BORDER | WS_VISIBLE,
			     IDC_FUN_3G_NOW_LISTBOX_FILE,
			     10, 30, 100, 100,
			     hWnd,
			     0);
*/
		CreateWindow(CTRL_LISTBOX,
			     "",
			     LBS_NOTIFY  | WS_VSCROLL | WS_BORDER | WS_VISIBLE,
			     IDC_FUN_3G_NOW_LISTBOX_FILE,
			     10, 30, 100, 100,
			     hWnd,
			     0);
			     
		CreateWindow(CTRL_LISTBOX,
			     "",
			     LBS_NOTIFY  | WS_VSCROLL | WS_BORDER | WS_VISIBLE,
			     IDC_FUN_3G_ADD_LISTBOX_FILE,
			     110, 30, 100, 100,
			     hWnd,
			     0);

		CreateWindow(CTRL_STATIC,
			     MSG_PATH,
			     WS_VISIBLE | SS_SIMPLE,
			     IDC_FUN_MPLAYER_MUSICADD_STATIC_PATH,
			     10, 10, 130, 15,
			     hWnd,
			     0);

		CreateWindow(CTRL_BUTTON,
			     MSG_DOWNLOAD,
			     WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
			     IDC_FUN_MPLAYER_MUSICADD_BUTTON_CHOOSE,
			     230, 50, 70, 25,
			     hWnd,
			     0);

		CreateWindow(CTRL_BUTTON,
			     MSG_CANCEL,
			     WS_TABSTOP | WS_VISIBLE | BS_DEFPUSHBUTTON,
			     IDC_FUN_MPLAYER_MUSICADD_BUTTON_CANCEL,
			     230, 100, 50, 25,
			     hWnd,
			     0);

		SetNotificationCallback(GetDlgItem(hWnd, IDC_FUN_3G_NOW_LISTBOX_FILE), now_notif_proc);
		SetNotificationCallback(GetDlgItem(hWnd, IDC_FUN_3G_ADD_LISTBOX_FILE), file_notif_proc);
		fill_boxes(hWnd, getcwd(cwd, MAX_PATH));
	}
	break;

	case MSG_COMMAND:
	{
                DEB("--MSG_COMMAND hWnd=%d\n ,hWnd");	
		switch (wParam)	{
		case IDC_FUN_MPLAYER_MUSICADD_BUTTON_CHOOSE:
                        DEB("---IDC_FUN_MPLAYER_MUSICADD_BUTTON_CHOOSE\n ");		
			fn_3gFileSave(hWnd);
                                     	
			DEB("---SendNotifyMessage fWnd=%d\n ",fWnd);
			SendNotifyMessage(fWnd, MSG_MUSIC_ADD, 0, 0L);
			DEB("---SendNotifyMessage end\n ");			
			break;

		case IDC_FUN_MPLAYER_MUSICADD_BUTTON_CANCEL:
                        DEB("---IDC_FUN_MPLAYER_MUSICADD_BUTTON_CANCEL\n ");		
			DestroyMainWindow(hWnd);
			PostQuitMessage(hWnd);
			return 0;
		}
                DEB("--MSG_COMMAND END\n ");		
	}
	break;

	case MSG_CLOSE:
	{
                DEB("--MSG_CLOSE\n ");	
		DestroyMainWindow(hWnd);
		PostQuitMessage(hWnd);
		return 0;
	}
	}
	
	
	return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
Beispiel #3
0
/*****************************************************************************
 * WinVoutEventProc: This is the window event processing function.
 *****************************************************************************
 * On Windows, when you create a window you have to attach an event processing
 * function to it. The aim of this function is to manage "Queued Messages" and
 * "Nonqueued Messages".
 * Queued Messages are those picked up and retransmitted by vout_Manage
 * (using the GetMessage and DispatchMessage functions).
 * Nonqueued Messages are those that Windows will send directly to this
 * procedure (like WM_DESTROY, WM_WINDOWPOSCHANGED...)
 *****************************************************************************/
static long FAR PASCAL WinVoutEventProc( HWND hwnd, UINT message,
                                         WPARAM wParam, LPARAM lParam )
{
    event_thread_t *p_event;

    if( message == WM_CREATE )
    {
        /* Store vd for future use */
        p_event = (event_thread_t *)((CREATESTRUCT *)lParam)->lpCreateParams;
        SetWindowLongPtr( hwnd, GWLP_USERDATA, (LONG_PTR)p_event );
        return TRUE;
    }
    else
    {
        LONG_PTR p_user_data = GetWindowLongPtr( hwnd, GWLP_USERDATA );
        p_event = (event_thread_t *)p_user_data;
        if( !p_event )
        {
            /* Hmmm mozilla does manage somehow to save the pointer to our
             * windowproc and still calls it after the vout has been closed. */
            return DefWindowProc(hwnd, message, wParam, lParam);
        }
    }
    vout_display_t *vd = p_event->vd;

#if 0
    if( message == WM_SETCURSOR )
    {
        msg_Err(vd, "WM_SETCURSOR: %d (t2)", p_event->is_cursor_hidden);
        SetCursor( p_event->is_cursor_hidden ? p_event->cursor_empty : p_event->cursor_arrow );
        return 1;
    }
#endif
    if( message == WM_CAPTURECHANGED )
    {
        for( int button = 0; p_event->button_pressed; button++ )
        {
            unsigned m = 1 << button;
            if( p_event->button_pressed & m )
                vout_display_SendEventMouseReleased( p_event->vd, button );
            p_event->button_pressed &= ~m;
        }
        p_event->button_pressed = 0;
        return 0;
    }

    if( hwnd == p_event->hvideownd )
    {
#ifdef MODULE_NAME_IS_directdraw
        vlc_mutex_lock( &p_event->lock );
        const bool use_overlay = p_event->use_overlay;
        vlc_mutex_unlock( &p_event->lock );
#endif

        switch( message )
        {
#ifdef MODULE_NAME_IS_directdraw
        case WM_ERASEBKGND:
        /* For overlay, we need to erase background */
            return !use_overlay ? 1 : DefWindowProc(hwnd, message, wParam, lParam);
        case WM_PAINT:
        /*
        ** For overlay, DefWindowProc() will erase dirty regions
        ** with colorkey.
        ** For non-overlay, vout will paint the whole window at
        ** regular interval, therefore dirty regions can be ignored
        ** to minimize repaint.
        */
            if( !use_overlay )
            {
                ValidateRect(hwnd, NULL);
            }
            // fall through to default
#else
        /*
        ** For OpenGL and Direct3D, vout will update the whole
        ** window at regular interval, therefore dirty region
        ** can be ignored to minimize repaint.
        */
        case WM_ERASEBKGND:
            /* nothing to erase */
            return 1;
        case WM_PAINT:
            /* nothing to repaint */
            ValidateRect(hwnd, NULL);
            // fall through
#endif
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
        }
    }

    switch( message )
    {

    case WM_WINDOWPOSCHANGED:
        vlc_mutex_lock( &p_event->lock );
        p_event->has_moved = true;
        vlc_mutex_unlock( &p_event->lock );
        return 0;

    /* the user wants to close the window */
    case WM_CLOSE:
        vout_display_SendEventClose(vd);
        return 0;

    /* the window has been closed so shut down everything now */
    case WM_DESTROY:
        msg_Dbg( vd, "WinProc WM_DESTROY" );
        /* just destroy the window */
        PostQuitMessage( 0 );
        return 0;

    case WM_SYSCOMMAND:
        switch (wParam)
        {
        case IDM_TOGGLE_ON_TOP:            /* toggle the "on top" status */
        {
            msg_Dbg(vd, "WinProc WM_SYSCOMMAND: IDM_TOGGLE_ON_TOP");
            HMENU hMenu = GetSystemMenu(vd->sys->hwnd, FALSE);
            vout_display_SendWindowState(vd, (GetMenuState(hMenu, IDM_TOGGLE_ON_TOP, MF_BYCOMMAND) & MF_CHECKED) ?
                    VOUT_WINDOW_STATE_NORMAL : VOUT_WINDOW_STATE_ABOVE);
            return 0;
        }
        default:
            break;
        }
        break;

    case WM_PAINT:
    case WM_NCPAINT:
    case WM_ERASEBKGND:
        return DefWindowProc(hwnd, message, wParam, lParam);

    case WM_KILLFOCUS:
        return 0;

    case WM_SETFOCUS:
        return 0;

    case WM_GESTURE:
        return DecodeGesture( VLC_OBJECT(vd), p_event->p_gesture, hwnd, message, wParam, lParam );

    default:
        //msg_Dbg( vd, "WinProc WM Default %i", message );
        break;
    }

    /* Let windows handle the message */
    return DefWindowProc(hwnd, message, wParam, lParam);
}
Beispiel #4
0
// Handles all the windows messages we might receive
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static bool gDragging = false;
    static uint8_t mouse_down = 0;

    // Messages we registered for manually (no const value)
    if (message == s_WmTaskbarList)
    {
        // Grab the Windows 7 taskbar list stuff
        if (gTaskbarList)
            gTaskbarList->Release();
        HRESULT result = CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, (void**)&gTaskbarList);
        if (FAILED(result))
            gTaskbarList = nil;
        return 0;
    }

    // Handle messages
    switch (message) {
    case WM_TIMECHANGE:
        // To prevent cheating and keep things better synchronized,
        // we will completely re-eval the offsets on the next NetMsg we
        // get from the server
        if (plNetClientMgr* nc = plNetClientMgr::GetInstance())
            nc->ResetServerTimeOffset(true);
        break;

    case WM_LBUTTONDOWN:
    case WM_RBUTTONDOWN:
    case WM_LBUTTONDBLCLK:
    case WM_MBUTTONDBLCLK:
    case WM_MBUTTONDOWN:
    case WM_RBUTTONDBLCLK:
        // Ensure we don't leave the client area during clicks
        if (!(mouse_down++))
            SetCapture(hWnd);
    // fall through to old case
    case WM_KEYDOWN:
    case WM_CHAR:
        // If they did anything but move the mouse, quit any intro movie playing.
        if (gClient)
        {
            gClient->SetQuitIntro(true);

            // normal input processing
            if (gClient->WindowActive() && gClient->GetInputManager())
                gClient->GetInputManager()->HandleWin32ControlEvent(message, wParam, lParam, hWnd);
        }
        break;
    case WM_LBUTTONUP:
    case WM_RBUTTONUP:
    case WM_MBUTTONUP:
        // Stop hogging the cursor
        if (!(--mouse_down))
            ReleaseCapture();
    // fall through to input processing
    case WM_MOUSEWHEEL:
    case WM_KEYUP:
        if (gClient && gClient->WindowActive() && gClient->GetInputManager())
            gClient->GetInputManager()->HandleWin32ControlEvent(message, wParam, lParam, hWnd);
        break;

    case WM_MOUSEMOVE:
    {
        if (gClient && gClient->GetInputManager())
            gClient->GetInputManager()->HandleWin32ControlEvent(message, wParam, lParam, hWnd);
    }
    break;

    case WM_SYSKEYUP:
    case WM_SYSKEYDOWN:
    {
        if (gClient && gClient->WindowActive() && gClient->GetInputManager())
        {
            gClient->GetInputManager()->HandleWin32ControlEvent(message, wParam, lParam, hWnd);
        }
        //DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;

    case WM_SYSCOMMAND:
        switch (wParam) {
        // Trap ALT so it doesn't pause the app
        case SC_KEYMENU :
        //// disable screensavers and monitor power downs too.
        case SC_SCREENSAVE:
        case SC_MONITORPOWER:
            return 0;
        case SC_CLOSE :
            // kill game if window is closed
            gClient->SetDone(TRUE);
            if (plNetClientMgr * mgr = plNetClientMgr::GetInstance())
                mgr->QueueDisableNet(false, nil);
            DestroyWindow(gClient->GetWindowHandle());
            break;
        }
        break;

    case WM_SETCURSOR:
    {
        static bool winCursor = true;
        bool enterWnd = LOWORD(lParam) == HTCLIENT;
        if (enterWnd && winCursor)
        {
            winCursor = !winCursor;
            ShowCursor(winCursor != 0);
            plMouseDevice::ShowCursor();
        }
        else if (!enterWnd && !winCursor)
        {
            winCursor = !winCursor;
            ShowCursor(winCursor != 0);
            plMouseDevice::HideCursor();
        }
        return TRUE;
    }
    break;

    case WM_ACTIVATE:
    {
        bool active = (LOWORD(wParam) == WA_ACTIVE || LOWORD(wParam) == WA_CLICKACTIVE);
        bool minimized = (HIWORD(wParam) != 0);

        if (gClient && !minimized && !gClient->GetDone())
        {
            gClient->WindowActivate(active);
        }
        else
        {
            gPendingActivate = true;
            gPendingActivateFlag = active;
        }
    }
    break;

    // Let go of the mouse if the window is being moved.
    case WM_ENTERSIZEMOVE:
        gDragging = true;
        if( gClient )
            gClient->WindowActivate(false);
        break;

    // Redo the mouse capture if the window gets moved
    case WM_EXITSIZEMOVE:
        gDragging = false;
        if( gClient )
            gClient->WindowActivate(true);
        break;

    // Redo the mouse capture if the window gets moved (special case for Colin
    // and his cool program that bumps windows out from under the taskbar)
    case WM_MOVE:
        if (!gDragging && gClient && gClient->GetInputManager())
            gClient->GetInputManager()->Activate(true);
        break;

    /// Resize the window
    // (we do WM_SIZING here instead of WM_SIZE because, for some reason, WM_SIZE is
    //  sent to the window when we do fullscreen, and what's more, it gets sent BEFORE
    //  the fullscreen flag is sent. How does *that* happen? Anyway, WM_SIZING acts
    //  just like WM_SIZE, except that it ONLY gets sent when the user changes the window
    //  size, not when the window is minimized or restored)
    case WM_SIZING:
    {
        RECT r;
        ::GetClientRect(hWnd, &r);
        gClient->GetPipeline()->Resize(r.right - r.left, r.bottom - r.top);
    }
    break;

    case WM_SIZE:
        // Let go of the mouse if the window is being minimized
        if (wParam == SIZE_MINIMIZED)
        {
            if (gClient)
                gClient->WindowActivate(false);
        }
        // Redo the mouse capture if the window gets restored
        else if (wParam == SIZE_RESTORED)
        {
            if (gClient)
                gClient->WindowActivate(true);
        }
        break;

    case WM_CLOSE:
        gClient->SetDone(TRUE);
        if (plNetClientMgr * mgr = plNetClientMgr::GetInstance())
            mgr->QueueDisableNet(false, nil);
        DestroyWindow(gClient->GetWindowHandle());
        break;
    case WM_DESTROY:
        gClient->SetDone(TRUE);
        if (plNetClientMgr * mgr = plNetClientMgr::GetInstance())
            mgr->QueueDisableNet(false, nil);
        PostQuitMessage(0);
        break;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) {
    PAINTSTRUCT Ps;
	switch(msg) {
    case WM_CREATE: {

		    /**
		    * Create AddFood Button
            */
            HFONT hFont = CreateFont(30,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
                CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact"));

            HWND hButtonAddFood = CreateWindowEx(NULL,
                "BUTTON",
                "ADD FOOD",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP,
                10,
                150,
                100,
                25,
                hWnd,
                (HMENU)BUTTON_ADD_FOOD,
                GetModuleHandle(NULL),
                NULL);

            /**
            * Create button ShowFoodNumber
            */
            HWND hShowFoodNumber = CreateWindowEx(NULL,
                "BUTTON",
                "Funny",
                WS_TABSTOP|WS_VISIBLE|
                WS_CHILD|BS_DEFPUSHBUTTON|BS_TOP,
                10,
                180,
                300,
                40,
                hWnd,
                (HMENU)BUTTON_DISPLAY_FOOD_NR,
                GetModuleHandle(NULL),
                NULL);
            SendMessage (hShowFoodNumber, WM_SETFONT, WPARAM (hFont), TRUE);

            /**
            * Draw Food List (In a input box)
            */


            hFoodList = CreateWindowEx(WS_EX_CLIENTEDGE,
                "EDIT",
                "",
                WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_READONLY|
                ES_MULTILINE,
                10,
                40,
                300,
                100,
                hWnd,
                (HMENU)INPUT_TEXT_SHOW_FOOD,
                GetModuleHandle(NULL),
                NULL);


            /**
            * Draw main Input food field
            */

            hInputFood = CreateWindowEx(
                (DWORD)NULL,
                TEXT("edit"),
                "",
                WS_VISIBLE | WS_CHILD | WS_BORDER,
                120,
                150,
                190,
                25,
                hWnd,
                (HMENU)INPUT_TEXT_ADD_FOOD,
                GetModuleHandle(NULL),
                NULL);
        }
        break;

		case WM_PAINT: {
            HDC hdc = BeginPaint(hWnd, &Ps);
            RECT rect;
            /**
            * Draw Text
            */

            // Second Text
            char foodNrMessage[256] = "Number : ";
            char nr[50];
            strcat(foodNrMessage, itoa(foodNumber, nr, 10));
            SetBkMode(hdc, TRANSPARENT);
            SetRect(&updateRect, 210, 10, 300, 30);
            DrawText( hdc, foodNrMessage, -1, &updateRect, DT_SINGLELINE | DT_NOCLIP  ) ;

            // First Text
            HFONT hFont = CreateFont(25,0,0,0,FW_DONTCARE,FALSE,TRUE,FALSE,DEFAULT_CHARSET,OUT_OUTLINE_PRECIS,
            CLIP_DEFAULT_PRECIS,NULL, VARIABLE_PITCH,TEXT("Impact"));
            SetRect(&rect, 10, 10, 50, 50);

            SelectObject(hdc, hFont);
            SetBkMode(hdc, OPAQUE);
            SetBkColor(hdc, RGB(0,255,255));
            SetTextColor(hdc, RGB(255,0,0));
            DrawText(hdc, TEXT(firstText), -1,&rect, DT_NOCLIP);

            EndPaint(hWnd, &Ps);
        }
        break;

        case WM_CTLCOLOREDIT: {
            HDC hdc = (HDC)wParam;
            HWND hwnd = (HWND)lParam;
            HBRUSH color;

            if (GetDlgCtrlID(hwnd) == INPUT_TEXT_ADD_FOOD) {
                color = CreateSolidBrush(RGB(225, 225, 225));
                SetTextColor(hdc, RGB(0, 0, 255));
                SetBkMode(hdc, TRANSPARENT);
                SetBkColor(hdc,(LONG)color);
            }
            return (LONG) color;
        }
        break;

		case WM_COMMAND: {
            switch(LOWORD(wParam)) {
                case BUTTON_ADD_FOOD: {

                    char buffer[256];
                    SendMessage(hInputFood,
                        WM_GETTEXT,
                        sizeof(buffer)/sizeof(buffer[0]),
                        reinterpret_cast<LPARAM>(buffer));

                    if(strlen(buffer) > 0){
                        char newInput[255] = "";
                        char stat[30];
                        strcat(newInput, itoa((foodNumber+1), stat, 10) );
                        strcat(newInput, " ) ");
                        strcat(newInput, buffer);
                        strcat(newInput, "\r\n");

                        SendMessage(hFoodList, EM_REPLACESEL, FALSE, (LPARAM)newInput);
                        SendMessage(hInputFood, WM_SETTEXT, NULL, (LPARAM)"");
                        foodNumber++;
                        InvalidateRect(hWnd, &updateRect, TRUE);
                    }

                }
                break;

                case BUTTON_DISPLAY_FOOD_NR: {
                    char buffer[255] = "";

                    switch(foodNumber){
                    case 0:http://pastebin.com/62fGU90U
                    case 1:
                    case 2:
                    case 3:
                        strcat(buffer, "You are not hungry at all");
                        break;
                    case 4:
                    case 5:
                    case 6:
                        strcat(buffer, "I see you are hungry now");
                        break;
                    default:
                        strcat(buffer, "You are starvin... go get something to eat");
                        break;
                    }
                    MessageBox(NULL,
                        buffer,
                        "Funny",
                        MB_ICONINFORMATION);
                }
                break;
            }
        }
        break;

        case WM_SIZE: {
            INT nWidth = LOWORD(lParam);
            HWND hFunnyButton = GetDlgItem(hWnd, BUTTON_DISPLAY_FOOD_NR);

            MoveWindow(hFunnyButton, 10, 180, nWidth - 17, 40, TRUE);

            HWND hShowFoodInput = GetDlgItem(hWnd, INPUT_TEXT_SHOW_FOOD);
            HWND hAddFood = GetDlgItem(hWnd, INPUT_TEXT_ADD_FOOD);

            MoveWindow(hShowFoodInput, 10, 40, nWidth - 18, 100, TRUE);
            MoveWindow(hAddFood, 120, 150, nWidth - 128, 25, TRUE);
        }
        break;

        case WM_GETMINMAXINFO: {
            MINMAXINFO * mmiStruct;
			mmiStruct = (MINMAXINFO*)lParam;

			POINT ptPoint;

			ptPoint.x = 335;    //Minimum width of the window.
			ptPoint.y = 260;    //Minimum height of the window.
			mmiStruct->ptMinTrackSize = ptPoint;

			ptPoint.x = GetSystemMetrics(SM_CXMAXIMIZED);   //Maximum width of the window.
			ptPoint.y = GetSystemMetrics(SM_CYMAXIMIZED);   //Maximum height of the window.
			mmiStruct->ptMaxTrackSize = ptPoint;
        }
        break;

		case WM_DESTROY: {
			PostQuitMessage(0);
			return 0;
		}
		break;
	}

	return DefWindowProc(hWnd,msg,wParam,lParam);
}
Beispiel #6
0
VOID jcwin32::jcwin32_exit(INT exitCode)
{
	PostQuitMessage(exitCode);
}
Beispiel #7
0
void OnDestroy() {
	PostQuitMessage(0);
}
Beispiel #8
0
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	int mX, mY;
	PAINTSTRUCT ps;
	HDC hdc;

	::GetClientRect(hWnd, &winRect);
	WorldRenderer worldHandle(hWnd, hdc, winRect, player);

	/*
	*/
	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	case WM_PAINT:
		hdc = BeginPaint(hWnd, &ps);
		worldHandle.update(playerAct);
		EndPaint(hWnd, &ps);
		break;	
	
	case WM_MOUSEMOVE:
		// 부드럽게 보이기 위해서는 잔상처리를 그대로 하는 게 더 부드럽게 보임
		// 잔상처리를 안할경우 화면이 번쩍거리는 현상이 보이게 됨
		mX = LOWORD(lParam); // x coordinate
		mY = HIWORD(lParam); // y coordinate
		/*
		*/
		switch (wParam){
		case MK_LBUTTON:
			if (player.moveFlag == true){
				player.pos = worldHandle.getPlayerCoordinate(mX, mY);
				player.curpos = { mX, mY };

				if (worldHandle.isCurInside(player)){
					player.obj = worldHandle.getTileCoordnate(mX, mY);
					hdc = ::GetDC(hWnd);
					::Ellipse(hdc, player.obj.left, player.obj.top, player.obj.right, player.obj.bottom);
					::ReleaseDC(hWnd, hdc);
					playerAct = true;
				}
				else if (playerAct){
					hdc = ::GetDC(hWnd);
					::Ellipse(hdc, player.obj.left, player.obj.top, player.obj.right, player.obj.bottom);
					::ReleaseDC(hWnd, hdc);
				}
				else{
					//
				}
			}
			break;				
		}			
		/*
		*/
		break;

	case WM_LBUTTONUP:
		InvalidateRect(hWnd, NULL, true);
		break;

	case WM_LBUTTONDOWN:
		mX = LOWORD(lParam); // x coordinate
		mY = HIWORD(lParam); // y coordinate

		//test
		if (player.pos.x == worldHandle.getPlayerCoordinate(mX, mY).x &&
			player.pos.y == worldHandle.getPlayerCoordinate(mX, mY).y){
			player.moveFlag = true;
		}
		else {
			player.moveFlag = false;
		}
		//

		player.pos = worldHandle.getPlayerCoordinate(mX, mY);
		player.curpos = { mX, mY };

		if ( worldHandle.isCurInside(player) ){
			player.obj = worldHandle.getTileCoordnate(mX, mY);
			InvalidateRect(hWnd, NULL, true);
			playerAct = true;
		}
		else if(playerAct){
			InvalidateRect(hWnd, NULL, true);
		}
		else{
			playerAct = false;
		}		
		break;

	case WM_DESTROY:
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Beispiel #9
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static HWND  hwndList, hwndText ;
     int          iIndex, iLength, cxChar, cyChar ;
     TCHAR      * pVarName, * pVarValue ;

     switch (message)
     {
     case WM_CREATE :
          cxChar = LOWORD (GetDialogBaseUnits ()) ;
          cyChar = HIWORD (GetDialogBaseUnits ()) ;

               // Create listbox and static text windows.
          
          hwndList = CreateWindow (TEXT ("listbox"), NULL,
                              WS_CHILD | WS_VISIBLE | LBS_STANDARD,
                              cxChar, cyChar * 3,
                              cxChar * 16 + GetSystemMetrics (SM_CXVSCROLL),
                              cyChar * 5,
                              hwnd, (HMENU) ID_LIST,
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                              NULL) ;
          
          hwndText = CreateWindow (TEXT ("static"), NULL,
                              WS_CHILD | WS_VISIBLE | SS_LEFT,
                              cxChar, cyChar, 
                              GetSystemMetrics (SM_CXSCREEN), cyChar,
                              hwnd, (HMENU) ID_TEXT,
                              (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
                              NULL) ;

          FillListBox (hwndList) ;
          return 0 ;
          
     case WM_SETFOCUS :
          SetFocus (hwndList) ;
          return 0 ;
          
     case WM_COMMAND :
          if (LOWORD (wParam) == ID_LIST && HIWORD (wParam) == LBN_SELCHANGE)
          {
                    // Get current selection.

               iIndex  = SendMessage (hwndList, LB_GETCURSEL, 0, 0) ;
               iLength = SendMessage (hwndList, LB_GETTEXTLEN, iIndex, 0) + 1 ;
               pVarName = calloc (iLength, sizeof (TCHAR)) ;
               SendMessage (hwndList, LB_GETTEXT, iIndex, (LPARAM) pVarName) ;

                    // Get environment string.

               iLength = GetEnvironmentVariable (pVarName, NULL, 0) ;
               pVarValue = calloc (iLength, sizeof (TCHAR)) ;
               GetEnvironmentVariable (pVarName, pVarValue, iLength) ;

                    // Show it in window.
               
               SetWindowText (hwndText, pVarValue) ;
               free (pVarName) ;
               free (pVarValue) ;
          }
          return 0 ;

     case WM_DESTROY :
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Beispiel #10
0
LRESULT CALLBACK window_procedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CREATE:
		{
			game.create_dc(GetDC(hWnd));

			int
				resolution_x = GetSystemMetrics(SM_CXSCREEN),
				resolution_y = GetSystemMetrics(SM_CYSCREEN);
			RECT window_rectangle;
			GetWindowRect(hWnd, &window_rectangle);
			int
				width = window_rectangle.right - window_rectangle.left,
				height = window_rectangle.bottom - window_rectangle.top;

			SetWindowPos(hWnd, HWND_TOP, (resolution_x - width) / 2, (resolution_y - height) / 2, 0, 0, SWP_NOSIZE);
			break;
		}

		case WM_ERASEBKGND:
			return 1;

		case WM_PAINT:
			game.process_frame(hWnd);
			break;

		/*
		case WM_TIMER:
			game.invalidate(hWnd);
			break;

		case WM_ERASEBKGND:
			return 1;

		case WM_PAINT:
			try
			{
				game_mutex.lock();
				game.process_frame(hWnd);
				game_mutex.unlock();
			}
			catch(std::exception const & exception)
			{
				MessageBox(hWnd, (std::string("The following exception has occured:\n\n\t") + exception.what() + "\n\nTerminating program.").c_str(), "Exception", MB_OK | MB_ICONERROR);
				run_timer = false;
				PostQuitMessage(WM_QUIT);
			}
			break;
			*/

		case WM_CLOSE:
		case WM_DESTROY:
			run = false;
			PostQuitMessage(WM_QUIT);
			break;

		case WM_LBUTTONDOWN:
			return DefWindowProc(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);

		case WM_KEYDOWN:
			game.process_key_down(wParam);
			break;

		case WM_KEYUP:
			game.process_key_up(wParam);
			break;
	}

	return DefWindowProc(hWnd, msg, wParam, lParam);
}
Beispiel #11
0
void OnCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
    if (wParam == IDM_LOCK_NOW)
    {
        Lock(hWnd);
    }
    else if (wParam == IDM_BLACK_SCREEN)
    {
        CheckMenuRadioItem(g_hTrayMenu, IDM_BLACK_SCREEN, IDM_SCREENSHOT, 
            IDM_BLACK_SCREEN, MF_BYCOMMAND);
        g_enumMode = Black;
    }
    else if (wParam == IDM_TRANSPARENT)
    {
        CheckMenuRadioItem(g_hTrayMenu, IDM_BLACK_SCREEN, IDM_SCREENSHOT, 
            IDM_TRANSPARENT, MF_BYCOMMAND);
        g_enumMode = Transparent;
    }
    else if (wParam == IDM_TRANSPARENT_50)
    {
        CheckMenuRadioItem(g_hTrayMenu, IDM_BLACK_SCREEN, IDM_SCREENSHOT, 
            IDM_TRANSPARENT_50, MF_BYCOMMAND);
        g_enumMode = Transparent50;
    }
    if (wParam == IDM_SCREENSHOT)
    {
        CheckMenuRadioItem(g_hTrayMenu, IDM_BLACK_SCREEN, IDM_SCREENSHOT, 
            IDM_SCREENSHOT, MF_BYCOMMAND);
        g_enumMode = Screenshot;
    }
    if (wParam == IDM_AUTO_LOCK)
    {
        CheckMenuItem(g_hTrayMenu, IDM_AUTO_LOCK, MF_BYCOMMAND | 
            (!g_bAutoLock ? MF_CHECKED : MF_UNCHECKED));
        g_bAutoLock = !g_bAutoLock;
    }
    else if (wParam == IDM_SET_PASSWORD)
    {
        // 1. If HKCU\Software\ScreenLock does not exist, display the set password window
        // 2. If HKCU\Software\ScreenLock\Password does not exist, display the set password window
        // 3. Otherwise, display the modify password window
        HKEY hScreenLockKey;
        if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\ScreenLock", 
            0, KEY_QUERY_VALUE, &hScreenLockKey) != 0) // Key not exist
        {
            RegCloseKey(hScreenLockKey);
            DialogBoxParam(g_hInstance, "DLG_SET_PASSWORD", hWnd, ProcDlgSetPassword, 0);
        }
        else if (RegGetValue(hScreenLockKey, 0, "Password", 
            RRF_RT_REG_SZ, 0, 0, 0) != 0) // Value not exist
        {
            RegCloseKey(hScreenLockKey);
            DialogBoxParam(g_hInstance, "DLG_SET_PASSWORD", hWnd, ProcDlgSetPassword, 0);
        }
        else
        {
            DialogBoxParam(g_hInstance, "DLG_MODIFY_PASSWORD", hWnd, ProcDlgModifyPassword, 0);
        }
    }
    else if (wParam == IDM_SET_TIMEOUT)
    {
        DialogBoxParam(g_hInstance, "DLG_SET_TIMEOUT", hWnd, ProcDlgSetTimeout, 0);
    }
    else if (wParam == IDM_EXIT)
    {
        // Delete Tray Icon
        NOTIFYICONDATA nti; 

        nti.hIcon = LoadIcon(g_hInstance, MAKEINTRESOURCE(ICO_MAIN)); 
        nti.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; 
        nti.hWnd = hWnd; 
        nti.uID = 0;
        nti.uCallbackMessage = WM_USER_TRAY; 
        strcpy_s(nti.szTip, sizeof(nti.szTip), "Screen Locker"); 

        Shell_NotifyIcon(NIM_DELETE, &nti);

        // Exit
        PostQuitMessage(0);
    }
}
Beispiel #12
0
LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
	LRESULT  lRet = 1;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	switch (uMsg){
		case WM_CREATE:
			break;
		case WM_PAINT:
			ValidateRect(g_wnd, NULL);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case WM_CHAR:
			break;
		case WM_LBUTTONDOWN:
		{
			POINT ptMouse;
			GetCursorPos(&ptMouse);
			ScreenToClient(g_wnd, &ptMouse);
			g_ptLastPoint = ptMouse;
		}
		break;
		case WM_RBUTTONDOWN:
		{
			GetCursorPos(&g_ptLastPoint);
			ScreenToClient(g_wnd, &g_ptLastPoint);
		break;
		}
		case WM_MOUSEMOVE:
		{
			switch (wParam)
			{
			case MK_LBUTTON:
			{

			}
			break;
			case MK_RBUTTON:
			{
			POINT pt;
			pt.x = LOWORD(lParam);
			pt.y = HIWORD(lParam);
			g_camera->SetRotAngleDelta((pt.y - g_ptLastPoint.y) / 150.0f, (pt.x - g_ptLastPoint.x) / 150.0f, 0.0f);
			g_ptLastPoint = pt;
			}
			default:
			break;
			}
			break;
			}
			case WM_KEYDOWN:
			{
			Vector *vcDirc = new Vector();
			Vector *vcUp = new Vector();
			Vector *vcRight = new Vector();
			g_camera->GetDirection(vcDirc, vcUp, vcRight);
			switch (wParam)
			{
			case VK_A:
			{
			g_camera->SetMoveDirection(*vcRight);
			g_camera->SetMoveDelta(-20.0f);

			g_camera->Update();
			Matrix matView;
			g_camera->GetViewMatrix(&matView);
			break;
			}
			case VK_D:
			{
			Vector vcPosCamera;
			g_camera->SetMoveDirection(*vcRight);
			g_camera->SetMoveDelta(20.0f);
			g_camera->Update();
			Matrix matView;
			g_camera->GetViewMatrix(&matView);
			break;
			}
			case VK_W:
			{
			g_camera->SetMoveDirection(*vcDirc);
			g_camera->SetMoveDelta(20.0f);

			g_camera->Update();
			Matrix matView;
			g_camera->GetViewMatrix(&matView);
			break;
			}
			case VK_S:
			{
			g_camera->SetMoveDirection(*vcDirc);
			g_camera->SetMoveDelta(-20.0f);

			g_camera->Update();
			Matrix matView;
			g_camera->GetViewMatrix(&matView);
			break;
			}
			case VK_Q:
			{
			g_camera->SetMoveDirection(*vcUp);
			g_camera->SetMoveDelta(20.0f);
			g_camera->Update();
			Matrix matView;
			g_camera->GetViewMatrix(&matView);
			break;
			}
			case VK_E:
			{
			g_camera->SetMoveDirection(*vcUp);
			g_camera->SetMoveDelta(-20.0f);
			g_camera->Update();
			Matrix matView;
			g_camera->GetViewMatrix(&matView);
			break;
			}

			default:
			break;
		}
		g_camera->Update();
		Matrix viewMat;
		viewMat.Identity();
		g_camera->GetViewMatrix(&viewMat);
		}
		break;
		default:
			lRet = DefWindowProc(hWnd, uMsg, wParam, lParam);
			break;
	}

	return lRet;
}
Beispiel #13
0
LRESULT CALLBACK WndProc(	HWND	hWnd,			// Handle For This Window
							UINT	uMsg,			// Message For This Window
							WPARAM	wParam,			// Additional Message Information
							LPARAM	lParam)			// Additional Message Information
{
	switch (uMsg)									// Check For Windows Messages
	{
		case WM_ACTIVATE:							// Watch For Window Activate Message
		{
			if (!HIWORD(wParam))					// Check Minimization State
			{
				active=TRUE;						// Program Is Active
			}
			else
			{
				active=FALSE;						// Program Is No Longer Active
			}

			return 0;								// Return To The Message Loop
		}

		case WM_SYSCOMMAND:							// Intercept System Commands
		{
			switch (wParam)							// Check System Calls
			{
				case SC_SCREENSAVE:					// Screensaver Trying To Start?
				case SC_MONITORPOWER:				// Monitor Trying To Enter Powersave?
				return 0;							// Prevent From Happening
			}
			break;									// Exit
		}

		case WM_CLOSE:								// Did We Receive A Close Message?
		{
			PostQuitMessage(0);						// Send A Quit Message
			return 0;								// Jump Back
		}

		case WM_LBUTTONDOWN:
		{
			gleft=TRUE;
			return 0;
		}

		case WM_LBUTTONUP:
		{
			gleft=FALSE;
			return 0;
		}

		case WM_RBUTTONDOWN:
		{
			gright=TRUE;
			return 0;
		}

		case WM_RBUTTONUP:
		{
			gright=FALSE;
			return 0;
		}

		case WM_KEYDOWN:							// Is A Key Being Held Down?
		{
			keys[wParam] = TRUE;					// If So, Mark It As TRUE
			return 0;								// Jump Back
		}

		case WM_KEYUP:								// Has A Key Been Released?
		{
			keys[wParam] = FALSE;					// If So, Mark It As FALSE
			return 0;								// Jump Back
		}

		case WM_SIZE:								// Resize The OpenGL Window
		{
			b1.ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  // LoWord=Width, HiWord=Height
			return 0;								// Jump Back
		}

		case WM_MOUSEMOVE:
		{
			mousex=LOWORD(lParam);
			mousey=HIWORD(lParam);
			return 0;
		}
	}

	// Pass All Unhandled Messages To DefWindowProc
	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
Beispiel #14
0
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
  switch (uMessage)
    {
    case WM_PAINT:
      {
	PAINTSTRUCT ps;
	BeginPaint(hwnd, &ps);
	SetMapMode(ps.hdc, MM_ANISOTROPIC);
	/* Set the window extent to a sane value in case the metafile doesn't */
	SetWindowExtEx(ps.hdc, width, height, NULL);
	SetViewportExtEx(ps.hdc, width, height, NULL);
	SetViewportOrgEx(ps.hdc, deltax, deltay, NULL);
       if (isEnhanced && enhmf)
       {
           RECT r;
           GetClientRect(hwnd, &r);
           PlayEnhMetaFile(ps.hdc, enhmf, &r);
       }
       else if (hmf)
           PlayMetaFile(ps.hdc, hmf);
	EndPaint(hwnd, &ps);
      }
      break;

    case WM_COMMAND: /* message: command from application menu */
        switch (LOWORD(wparam))
	{
	case IDM_OPEN:
	  {
              WCHAR filename[MAX_PATH];
              if (FileOpen(hwnd, filename, sizeof(filename)/sizeof(WCHAR)))
              {
                  szFileTitle[0] = 0;
                  GetFileTitleW(filename, szFileTitle, sizeof(szFileTitle)/sizeof(WCHAR));
                  DoOpenFile(filename);
                  UpdateWindowCaption();
              }
	  }
	  break;

	case IDM_SET_EXT_TO_WIN:
	  {
	    RECT r;
	    GetClientRect(hwnd, &r);
	    width = r.right - r.left;
	    height = r.bottom - r.top;
	    deltax = deltay = 0;
	    InvalidateRect( hwnd, NULL, TRUE );
	  }
	  break;


	case IDM_LEFT:
	  deltax += 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;
	case IDM_RIGHT:
	  deltax -= 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;
	case IDM_UP:
	  deltay += 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;
	case IDM_DOWN:
	  deltay -= 100;
	  InvalidateRect( hwnd, NULL, TRUE );
	  break;

	case IDM_EXIT:
	  DestroyWindow(hwnd);
	  break;

	default:
	  return DefWindowProcW(hwnd, uMessage, wparam, lparam);
	}
      break;

    case WM_DESTROY:  /* message: window being destroyed */
      PostQuitMessage(0);
      break;

    default:          /* Passes it on if unprocessed */
      return DefWindowProcW(hwnd, uMessage, wparam, lparam);
    }
    return 0;
}
Beispiel #15
0
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg,
			     WPARAM wParam, LPARAM lParam)
{
    // Window dimensions

    RECT rWnd;
    RECT rClt;

    switch (uMsg)
    {
    case WM_CREATE:

	// Get the window and client dimensions

	GetWindowRect(hWnd, &rWnd);
	GetClientRect(hWnd, &rClt);

	// Calculate desired window width and height

	int border = (rWnd.right - rWnd.left) - rClt.right;
	int width  = WIDTH + border;
	int height = HEIGHT;

	// Set new dimensions

	SetWindowPos(hWnd, NULL, 0, 0,
		     width, height,
		     SWP_NOMOVE | SWP_NOZORDER);

	// Get client dimensions

	GetWindowRect(hWnd, &rWnd);
	GetClientRect(hWnd, &rClt);

	width = rClt.right - rClt.left;
	height = rClt.bottom - rClt.top;

	// Create scale

	scale.hwnd =
	    CreateWindow(WC_STATIC, NULL,
			 WS_VISIBLE | WS_CHILD |
			 SS_NOTIFY | SS_OWNERDRAW,
			 8, 8, 160, 40, hWnd,
			 (HMENU)SCALE_ID, hInst, NULL);

	// Create tooltip

	tooltip.hwnd =
	    CreateWindow(TOOLTIPS_CLASS, NULL,
			 WS_POPUP | TTS_ALWAYSTIP,
			 CW_USEDEFAULT, CW_USEDEFAULT,
			 CW_USEDEFAULT, CW_USEDEFAULT,
			 hWnd, NULL, hInst, NULL);

	SetWindowPos(tooltip.hwnd, HWND_TOPMOST, 0, 0, 0, 0,
		     SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

	// Add scale to tooltip

	tooltip.info.cbSize = sizeof(tooltip.info);
	tooltip.info.hwnd = hWnd;
	tooltip.info.uFlags = TTF_IDISHWND | TTF_SUBCLASS;

	tooltip.info.uId = (UINT_PTR)scale.hwnd;
	tooltip.info.lpszText = "Frequency scale";

	SendMessage(tooltip.hwnd, TTM_ADDTOOL, 0,
		    (LPARAM) &tooltip.info);

	// Create display

	display.hwnd =
	    CreateWindow(WC_STATIC, NULL,
			 WS_VISIBLE | WS_CHILD |
			 SS_NOTIFY | SS_OWNERDRAW,
			 176, 8, 136, 60, hWnd,
			 (HMENU)DISPLAY_ID, hInst, NULL);

	// Add display to tooltip

	tooltip.info.uId = (UINT_PTR)display.hwnd;
	tooltip.info.lpszText = "Frequency and level display";

	SendMessage(tooltip.hwnd, TTM_ADDTOOL, 0,
		    (LPARAM) &tooltip.info);

	// Create knob

	knob.hwnd =
	    CreateWindow(KNOBCLASS, NULL,
			 WS_VISIBLE | WS_CHILD,
			 4, 52, 168, 168, hWnd,
			 (HMENU)KNOB_ID, hInst, NULL);

	// Add knob to tooltip

	tooltip.info.uId = (UINT_PTR)knob.hwnd;
	tooltip.info.lpszText = "Frequency adjustment knob";

	SendMessage(tooltip.hwnd, TTM_ADDTOOL, 0,
		    (LPARAM) &tooltip.info);

	// Create frequency slider

	fine.hwnd =
	    CreateWindow(TRACKBAR_CLASS, NULL,
			 WS_VISIBLE | WS_CHILD |
			 TBS_VERT | TBS_NOTICKS,
			 176, 76, 24, 140, hWnd,
			 (HMENU)FINE_ID, hInst, NULL);

	SendMessage(fine.hwnd, TBM_SETRANGE, TRUE,
		    MAKELONG(FINE_MIN, FINE_MAX));
	SendMessage(fine.hwnd, TBM_SETPAGESIZE, 0, FINE_STEP);
	SendMessage(fine.hwnd, TBM_SETPOS, TRUE, FINE_REF);

	// Add slider to tooltip

	tooltip.info.uId = (UINT_PTR)fine.hwnd;
	tooltip.info.lpszText = "Fine frequency adjustment";

	SendMessage(tooltip.hwnd, TTM_ADDTOOL, 0,
		    (LPARAM) &tooltip.info);

	// Create level slider

	level.hwnd =
	    CreateWindow(TRACKBAR_CLASS, NULL,
			 WS_VISIBLE | WS_CHILD |
			 TBS_VERT | TBS_NOTICKS | TBS_LEFT,
			 208, 76, 24, 140, hWnd,
			 (HMENU)LEVEL_ID, hInst, NULL);

	SendMessage(level.hwnd, TBM_SETRANGE, TRUE,
		    MAKELONG(LEVEL_MIN, LEVEL_MAX));
	SendMessage(level.hwnd, TBM_SETPAGESIZE, 0, LEVEL_STEP);
	SendMessage(level.hwnd, TBM_SETPOS, TRUE, LEVEL_REF);

	// Add slider to tooltip

	tooltip.info.uId = (UINT_PTR)level.hwnd;
	tooltip.info.lpszText = "Level adjustment";

	SendMessage(tooltip.hwnd, TTM_ADDTOOL, 0,
		    (LPARAM) &tooltip.info);

	// Create sine button

	buttons.sine.hwnd =
	    CreateWindow(WC_BUTTON, "Sine",
			 WS_VISIBLE | WS_CHILD | WS_GROUP |
			 BS_AUTORADIOBUTTON | BS_PUSHLIKE,
			 240, 76, 72, 24, hWnd,
			 (HMENU)SINE_ID, hInst, NULL);

	SendMessage(buttons.sine.hwnd, BM_SETCHECK, BST_CHECKED, 0);

	// Create square button

	buttons.square.hwnd =
	    CreateWindow(WC_BUTTON, "Square",
			 WS_VISIBLE | WS_CHILD |
			 BS_AUTORADIOBUTTON | BS_PUSHLIKE,
			 240, 105, 72, 24, hWnd,
			 (HMENU)SQUARE_ID, hInst, NULL);

	// Create sawtooth button

	buttons.sawtooth.hwnd =
	    CreateWindow(WC_BUTTON, "Sawtooth",
			 WS_VISIBLE | WS_CHILD |
			 BS_AUTORADIOBUTTON | BS_PUSHLIKE,
			 240, 134, 72, 24, hWnd,
			 (HMENU)SAWTOOTH_ID, hInst, NULL);

	// Create mute button

	buttons.mute.hwnd =
	    CreateWindow(WC_BUTTON, "Mute",
			 WS_VISIBLE | WS_CHILD |
			 BS_AUTOCHECKBOX | BS_PUSHLIKE,
			 240, 161, 72, 24, hWnd,
			 (HMENU)MUTE_ID, hInst, NULL);

	// Create quit button

	buttons.quit.hwnd =
	    CreateWindow(WC_BUTTON, "Quit",
			 WS_VISIBLE | WS_CHILD,
			 240, 192, 72, 24, hWnd,
			 (HMENU)QUIT_ID, hInst, NULL);

	// Create status bar

	status.hwnd =
	    CreateWindow(STATUSCLASSNAME,
			 " Turn knob to adjust frequency,"
			 " fine left, level right slider",
			 WS_VISIBLE | WS_CHILD,
			 0, 0, 0, 0, hWnd,
			 (HMENU)STATUS_ID, hInst, NULL);

	// Start audio thread

	audio.thread = CreateThread(NULL, 0, AudioThread,
				    hWnd, 0, &audio.id);
	break;

    // Colour static text

    case WM_CTLCOLORSTATIC:
	return (LRESULT)GetSysColorBrush(COLOR_WINDOW);
	break;

	// Draw item

    case WM_DRAWITEM:
	return DrawItem(wParam, lParam);
	break;

	// Disable menus by capturing this message

    case WM_INITMENU:
	break;

	// Capture system character key to stop pop up menus and other
	// nonsense

    case WM_SYSCHAR:
	break;

	// Char pressed

    case WM_CHAR:
	CharPressed(wParam, lParam);
	break;

	// Key pressed

    case WM_KEYDOWN:
	KeyDown(wParam, lParam);
	break;

	// Buttons

    case WM_COMMAND:
	switch (LOWORD(wParam))
	{
	    // Sine
	case SINE_ID:
	    audio.waveform = SINE;
	    break;

	    // Square

	case SQUARE_ID:
	    audio.waveform = SQUARE;
	    break;

	    // Sawtooth

	case SAWTOOTH_ID:
	    audio.waveform = SAWTOOTH;
	    break;

	    // Mute

	case MUTE_ID:
	    audio.mute = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
	    break;

	    // Quit

	case QUIT_ID:
	    waveOutReset(audio.hwo);
	    waveOutClose(audio.hwo);
	    PostQuitMessage(0);
	    break;
	}

	// Set the focus back to the window

	SetFocus(hWnd);
	break;

	// Slider change

    case WM_VSCROLL:
	SliderChange(wParam, lParam);

	// Set the focus back to the window

	SetFocus(hWnd);
	break;

	// Set the focus back to the window by clicking

    case WM_LBUTTONDOWN:
    case WM_MBUTTONDOWN:
	SetFocus(hWnd);
	break;

    case WM_RBUTTONDOWN:
	// Not used
	break;

	// Notify

    case WM_NOTIFY:
	switch (((LPNMHDR)lParam)->code)
	{
	    // Tooltip

	case TTN_SHOW:
	    TooltipShow(wParam, lParam);
	    break;

	case TTN_POP:
	    TooltipPop(wParam, lParam);
	    break;
	}
	break;

        // Process other messages.

    case WM_DESTROY:

	PostQuitMessage(0);
	waveOutReset(audio.hwo);
	waveOutClose(audio.hwo);
	break;

	// Everything else

    default:
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }

    return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) {
  struct WindowData *data=window_data();

  // WindowHandle handle = (WindowHandle)GetWindowLong(hWnd,GWL_USERDATA);

  if(!data->created) {
    return DefWindowProc(hWnd,message,wParam,lParam);
  } else if(message==WM_INPUT) {
    // UINT dwSize = 40;
    // static BYTE lpb[40];
    // GetRawInputData((HRAWINPUT)lParam,RID_INPUT,lpb,&dwSize,sizeof(RAWINPUTHEADER));
    // RAWINPUT* raw = (RAWINPUT*)lpb;

    RAWINPUT raw;
    UINT DataSize = sizeof(RAWINPUT);
    GetRawInputData((HRAWINPUT)lParam, RID_INPUT, &raw, &DataSize, sizeof(RAWINPUTHEADER));

    if(raw.header.dwType == RIM_TYPEMOUSE) {
      if(raw.data.mouse.usButtonFlags & RI_MOUSE_WHEEL) {
        data->mouseZ=(int)raw.data.mouse.usButtonData;
      } else if(raw.data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_DOWN) {
        data->inputs[WINDOW_MOUSE_LEFT]=WINDOW_INPUT_PRESS;
      } else if(raw.data.mouse.usButtonFlags & RI_MOUSE_LEFT_BUTTON_UP &&
                data->inputs[WINDOW_MOUSE_LEFT]!=WINDOW_INPUT_UP) {
        data->inputs[WINDOW_MOUSE_LEFT]=WINDOW_INPUT_RELEASE;
      } else if(raw.data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN) {
        data->inputs[WINDOW_MOUSE_RIGHT]=WINDOW_INPUT_PRESS;
      } else if(raw.data.mouse.usButtonFlags & RI_MOUSE_RIGHT_BUTTON_UP &&
                data->inputs[WINDOW_MOUSE_RIGHT]!=WINDOW_INPUT_UP) {
        data->inputs[WINDOW_MOUSE_RIGHT]=WINDOW_INPUT_RELEASE;
      } else if(raw.data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN) {
        data->inputs[WINDOW_MOUSE_MIDDLE]=WINDOW_INPUT_PRESS;
      } else if(raw.data.mouse.usButtonFlags & RI_MOUSE_MIDDLE_BUTTON_UP &&
                data->inputs[WINDOW_MOUSE_MIDDLE]!=WINDOW_INPUT_UP) {
        data->inputs[WINDOW_MOUSE_MIDDLE]=WINDOW_INPUT_RELEASE;
      }

      data->mouseX=(int)raw.data.mouse.lLastX;
      data->mouseY=(int)raw.data.mouse.lLastY;
    } else if(raw.header.dwType == RIM_TYPEKEYBOARD) {
      USHORT vk=raw.data.keyboard.VKey;
      USHORT up=raw.data.keyboard.Flags & RI_KEY_BREAK;
      USHORT right=raw.data.keyboard.Flags & RI_KEY_E0;

      if(up && data->inputs[window_key_convert(vk)]!=WINDOW_INPUT_UP) {
        data->inputs[window_key_convert(vk)]=WINDOW_INPUT_RELEASE;
      }else if(!up) {
        data->inputs[window_key_convert(vk)]=WINDOW_INPUT_PRESS;
      }
    }
  } else if(message==WM_DESTROY) {
    PostQuitMessage(0);
    return 0;
  } else if(message==WM_SIZE) {
    //data->clientWidth=(int)LOWORD(lParam);
    //data->clientHeight=(int)HIWORD(lParam);
    data->sized=true;
    data->iconified=(wParam==SIZE_MINIMIZED);
  } else if(message==WM_KILLFOCUS) {
    data->focused=false;
  } else if(message==WM_SETFOCUS) {
    data->focused=true;
  } else {
    return DefWindowProc(hWnd,message,wParam,lParam);
  }

  return 0;
}
Beispiel #17
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static int  cxChar, cxCaps, cyChar, cyClient, iVscrollPos ;
    HDC         hdc ;    
    int         i, y ;    
    PAINTSTRUCT ps ;
//    TCHAR       szBuffer[10] ;    
    TEXTMETRIC  tm ;    
	static int LoadDLLTag=0;
	static int poehackTag=0;
	static BOOL	show_flag=TRUE;

	switch (message)    
    {
	case WM_LBUTTONDOWN:
		if(LoadDLLTag==1)
		{
			show_flag=!show_flag;
	        InvalidateRect (hwnd, NULL, TRUE) ;
			return 0;
		}
		LoadDLLTag=1;
		PoeIntercept(hwnd);
		/*
		typedef void(*pExecute)(DWORD);
		pExecute p;
		p=(pExecute)GetProcAddress(poehackModule,"Execute");
		if(p)
			p((DWORD)hwnd);
		*/
		return 0;
	case WM_RBUTTONDOWN: 
		if(poehackTag==1){
			return 0;
		}
		char dllFullName[10240];
		GetCurrentDirectory(255, dllFullName);
		strcpy(dllFullName, "c:\\bot\\d3\\poehack.dll");
		
		poehackModule = LoadLibrary(dllFullName);
		if(!poehackModule) _showinfo("poehack load failed: %s",dllFullName);
		else
		{
			_showinfo("poehack loaded");
			poehackTag=1;
		}
		if(!_PassValueAddr)
			_PassValueAddr=(pPassValue)GetProcAddress(poehackModule,"PassValue");
		_showinfo("_PassValueAddr %x",_PassValueAddr);		
		return 0;
	case WM_MBUTTONDOWN:		
		if(poehackTag==0) return 0;

		_value.id = DO_UNLOAD;
		if(_PassValueAddr) _PassValueAddr(&_value);

		/*
		typedef void(*pUnload)();
		pUnload p;
		p=(pUnload)GetProcAddress(poehackModule,"Unload");
		if(p) p();
		*/
		FreeLibrary(poehackModule);
		poehackModule=NULL;
		_PassValueAddr=NULL;
		_showinfo("poehack unloaded");
		poehackTag=0;
		return 0;
	case WM_CREATE:
		hdc = GetDC (hwnd) ;
	    GetTextMetrics (hdc, &tm) ;
		cxChar = tm.tmAveCharWidth ;
	    cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2 ;
		cyChar = tm.tmHeight + tm.tmExternalLeading ;

	    ReleaseDC (hwnd, hdc) ;
		SetScrollRange (hwnd, SB_VERT, 0, NUMLINES - 1, FALSE) ;
	    SetScrollPos   (hwnd, SB_VERT, iVscrollPos, TRUE) ;
		_window_up=TRUE;
        return 0 ;

    case WM_SIZE:
        cyClient = HIWORD (lParam) ;
        return 0 ;

    case WM_VSCROLL:
        switch (LOWORD (wParam))
          {
			case SB_LINEUP:
          iVscrollPos -= 1 ;
        break ;
     
    case SB_LINEDOWN:
        iVscrollPos += 1 ;
        break ;

    case SB_PAGEUP:
        iVscrollPos -= cyClient / cyChar ;
        break ;
     
    case SB_PAGEDOWN:
        iVscrollPos += cyClient / cyChar ;
        break ;
     
    case SB_THUMBPOSITION:
        iVscrollPos = HIWORD (wParam) ;
        break ;
     
    default :
        break ;
          }

    iVscrollPos = max (0, min (iVscrollPos, NUMLINES - 1)) ;
    if (iVscrollPos != GetScrollPos (hwnd, SB_VERT))
          {
        SetScrollPos (hwnd, SB_VERT, iVscrollPos, TRUE) ;
        InvalidateRect (hwnd, NULL, TRUE) ;
          }
        return 0 ;
    case WM_PAINT:
		if(show_flag)
		{
	        hdc = BeginPaint (hwnd, &ps) ;
		    for (i = 0 ; i < NUMLINES ; i++)
			{
				int len=   strlen (display_buf[i].text) ;
				if(len==0) continue;
		        y = cyChar * (i - iVscrollPos) ;
			    TextOut (hdc, 0, y,
				    display_buf[i].text,
					strlen (display_buf[i].text)) ;
			}
			EndPaint (hwnd, &ps) ;
		}
		else
		{
		typedef void(*pDrawMap)(HWND);
		pDrawMap p;
		p=(pDrawMap)GetProcAddress(poehackModule,"DrawMap");
		if(p) p(hwnd);
		}
        return 0 ;

    case WM_DESTROY:
  		_window_up=FALSE;
		PostQuitMessage (0) ;
        return 0 ;
     }
 
	return DefWindowProc (hwnd, message, wParam, lParam) ;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	RECT rect;
	COLORREF colorText = RGB(0, 0, 255); // задаём цвет текста
	
	switch (message)
	{

	case WM_COMMAND:

	case BN_CLICKED:

		if (LOWORD(wParam) == ID_BUTTON1)
		{
			
			GetClientRect(hWnd, &rect);
			edit1 = CreateWindowEx(
				WS_EX_CLIENTEDGE,
				L"edit",
				L"Нажмите правую клавишу мыши",
				WS_CHILD | WS_VISIBLE | EM_FMTLINES,
				rect.right / 4,									/*координаты по X*/
				rect.bottom / 4,								/*координаты по Y*/
				rect.right / 2,									/*Ширина окошка*/
				rect.bottom / 2,
				hWnd,
				(HMENU)ID_EDIT1,
				hinst,
				NULL);
		
		}
		
		break;

	case WM_RBUTTONDOWN:
			
			ShowWindow(edit1, SW_HIDE);
			break;

	case WM_CREATE:

		GetClientRect(hWnd, &rect);
				
		button1 = CreateWindowEx(
			WS_EX_CLIENTEDGE,
			L"button",
			L"Показать",
			WS_CHILD | WS_VISIBLE,
			rect.right / 2 - ARRAYSIZE(L"Показать") * 4 - 10,		/*координаты по X*/
			rect.bottom - 30,						/*координаты по Y*/
			ARRAYSIZE(L"Показать") * 10,						/*Ширина окошка*/
			25,
			hWnd,
			(HMENU)ID_BUTTON1,
			hinst,
			NULL);

		
		break;

	case WM_PAINT:

		hdc = BeginPaint(hWnd, &ps); // инициализируем контекст устройства
		GetClientRect(hWnd, &rect); // получаем ширину и высоту области для рисования
		SetTextColor(hdc, colorText); // устанавливаем цвет контекстного устройства
		
		
				DrawText(hdc, L"В в е д и т е   т е к с т", -1, &rect, DT_SINGLELINE | DT_CENTER); // рисуем текст
			
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
		break;
	}

	return 0;
}
//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
                         LPARAM lParam) {
  static HWND backWnd = NULL, forwardWnd = NULL, reloadWnd = NULL,
      stopWnd = NULL, editWnd = NULL;
  static WNDPROC editWndOldProc = NULL;

  // Static members used for the find dialog.
  static FINDREPLACE fr;
  static WCHAR szFindWhat[80] = {0};
  static WCHAR szLastFindWhat[80] = {0};
  static bool findNext = false;
  static bool lastMatchCase = false;

  int wmId, wmEvent;
  PAINTSTRUCT ps;
  HDC hdc;

#ifdef SHOW_TOOLBAR_UI
  if (hWnd == editWnd) {
    // Callback for the edit window
    switch (message) {
    case WM_CHAR:
      if (wParam == VK_RETURN && g_handler.get()) {
        // When the user hits the enter key load the URL
        CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
        wchar_t strPtr[MAX_URL_LENGTH+1] = {0};
        *((LPWORD)strPtr) = MAX_URL_LENGTH;
        LRESULT strLen = SendMessage(hWnd, EM_GETLINE, 0, (LPARAM)strPtr);
        if (strLen > 0) {
          strPtr[strLen] = 0;
          browser->GetMainFrame()->LoadURL(strPtr);
        }

        return 0;
      }
    }
    return (LRESULT)CallWindowProc(editWndOldProc, hWnd, message, wParam,
                                   lParam);
  } else
#endif // SHOW_TOOLBAR_UI
  {
    // Callback for the main window
    switch (message) {
    case WM_CREATE: {
      // Create the single static handler class instance
      g_handler = new ClientHandler();
      g_handler->SetMainHwnd(hWnd);

      // Create the child windows used for navigation
      RECT rect;
      int x = 0;

      GetClientRect(hWnd, &rect);

#ifdef SHOW_TOOLBAR_UI
      backWnd = CreateWindow(L"BUTTON", L"Back",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_BACK, hInst, 0);
      x += BUTTON_WIDTH;

      forwardWnd = CreateWindow(L"BUTTON", L"Forward",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_FORWARD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      reloadWnd = CreateWindow(L"BUTTON", L"Reload",
                                WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                                | WS_DISABLED, x, 0, BUTTON_WIDTH,
                                URLBAR_HEIGHT, hWnd, (HMENU) IDC_NAV_RELOAD,
                                hInst, 0);
      x += BUTTON_WIDTH;

      stopWnd = CreateWindow(L"BUTTON", L"Stop",
                              WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON
                              | WS_DISABLED, x, 0, BUTTON_WIDTH, URLBAR_HEIGHT,
                              hWnd, (HMENU) IDC_NAV_STOP, hInst, 0);
      x += BUTTON_WIDTH;

      editWnd = CreateWindow(L"EDIT", 0,
                              WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT |
                              ES_AUTOVSCROLL | ES_AUTOHSCROLL| WS_DISABLED,
                              x, 0, rect.right - BUTTON_WIDTH * 4,
                              URLBAR_HEIGHT, hWnd, 0, hInst, 0);

      // Assign the edit window's WNDPROC to this function so that we can
      // capture the enter key
      editWndOldProc =
          reinterpret_cast<WNDPROC>(GetWindowLongPtr(editWnd, GWLP_WNDPROC));
      SetWindowLongPtr(editWnd, GWLP_WNDPROC,
          reinterpret_cast<LONG_PTR>(WndProc));
      g_handler->SetEditHwnd(editWnd);
      g_handler->SetButtonHwnds(backWnd, forwardWnd, reloadWnd, stopWnd);

      rect.top += URLBAR_HEIGHT;
#endif // SHOW_TOOLBAR_UI

      CefWindowInfo info;
      CefBrowserSettings settings;

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

      settings.file_access_from_file_urls_allowed = true;
      settings.universal_access_from_file_urls_allowed = true;

      // Initialize window info to the defaults for a child window
      info.SetAsChild(hWnd, rect);

      // Creat the new child browser window
      CefBrowserHost::CreateBrowser(info,
          static_cast<CefRefPtr<CefClient> >(g_handler),
          szInitialUrl, settings);

      return 0;
    }

    case WM_COMMAND: {
      CefRefPtr<CefBrowser> browser;
      if (g_handler.get())
        browser = g_handler->GetBrowser();

      wmId    = LOWORD(wParam);
      wmEvent = HIWORD(wParam);
      // Parse the menu selections:
      switch (wmId) {
      case IDM_EXIT:
        if (g_handler.get()) {
          g_handler->QuittingApp(true);
    	  g_handler->DispatchCloseToNextBrowser();
    	} else {
          DestroyWindow(hWnd);
		}
        return 0;
      case ID_WARN_CONSOLEMESSAGE:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"Console messages will be written to "
              << std::wstring(CefString(g_handler->GetLogFile()));
          MessageBox(hWnd, ss.str().c_str(), L"Console Messages",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
      case ID_WARN_DOWNLOADCOMPLETE:
      case ID_WARN_DOWNLOADERROR:
        if (g_handler.get()) {
          std::wstringstream ss;
          ss << L"File \"" <<
              std::wstring(CefString(g_handler->GetLastDownloadFile())) <<
              L"\" ";

          if (wmId == ID_WARN_DOWNLOADCOMPLETE)
            ss << L"downloaded successfully.";
          else
            ss << L"failed to download.";

          MessageBox(hWnd, ss.str().c_str(), L"File Download",
              MB_OK | MB_ICONINFORMATION);
        }
        return 0;
#ifdef SHOW_TOOLBAR_UI
      case IDC_NAV_BACK:   // Back button
        if (browser.get())
          browser->GoBack();
        return 0;
      case IDC_NAV_FORWARD:  // Forward button
        if (browser.get())
          browser->GoForward();
        return 0;
      case IDC_NAV_RELOAD:  // Reload button
        if (browser.get())
          browser->Reload();
        return 0;
      case IDC_NAV_STOP:  // Stop button
        if (browser.get())
          browser->StopLoad();
        return 0;
#endif // SHOW_TOOLBAR_UI
      }
      break;
    }

    case WM_PAINT:
      hdc = BeginPaint(hWnd, &ps);
      EndPaint(hWnd, &ps);
      return 0;

    case WM_SETFOCUS:
      if (g_handler.get() && g_handler->GetBrowser()) {
        // Pass focus to the browser window
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd)
          PostMessage(hwnd, WM_SETFOCUS, wParam, NULL);
      }
      return 0;

    case WM_SIZE:
      // Minimizing resizes the window to 0x0 which causes our layout to go all
      // screwy, so we just ignore it.
      if (wParam != SIZE_MINIMIZED && g_handler.get() &&
          g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Resize the browser window and address bar to match the new frame
          // window size
          RECT rect;
          GetClientRect(hWnd, &rect);
#ifdef SHOW_TOOLBAR_UI
          rect.top += URLBAR_HEIGHT;

          int urloffset = rect.left + BUTTON_WIDTH * 4;
#endif // SHOW_TOOLBAR_UI

          HDWP hdwp = BeginDeferWindowPos(1);
#ifdef SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, editWnd, NULL, urloffset,
            0, rect.right - urloffset, URLBAR_HEIGHT, SWP_NOZORDER);
#endif // SHOW_TOOLBAR_UI
          hdwp = DeferWindowPos(hdwp, hwnd, NULL,
            rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
            SWP_NOZORDER);
          EndDeferWindowPos(hdwp);
        }
      }
      break;

    case WM_ERASEBKGND:
      if (g_handler.get() && g_handler->GetBrowser()) {
        CefWindowHandle hwnd =
            g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        if (hwnd) {
          // Dont erase the background if the browser window has been loaded
          // (this avoids flashing)
          return 0;
        }
      }
      break;

    case WM_CLOSE:
      if (g_handler.get()) {
        // If we already initiated the browser closing, then let default window proc handle it.
        HWND browserHwnd = g_handler->GetBrowser()->GetHost()->GetWindowHandle();
        HANDLE closing = GetProp(browserHwnd, CLOSING_PROP);
        if (closing) {
		    RemoveProp(browserHwnd, CLOSING_PROP);
			break;
		}

        g_handler->QuittingApp(true);
        g_handler->DispatchCloseToNextBrowser();
        return 0;
      }
      break;

    case WM_DESTROY:
      // The frame window has exited
      PostQuitMessage(0);
      return 0;
    }

    return DefWindowProc(hWnd, message, wParam, lParam);
  }
}
Beispiel #20
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
   PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	// Below we define our controls for this simple tutorial.
	// The controls are: 

	// Left Mouse Button - Changes the Render mode from normal to wireframe.
	// Right Mouse Button - Turns lighting On/Off
	// Left Arrow Key - Spins the model to the left
	// Right Arrow Key - Spins the model to the right
	// Escape - Quits

	case WM_LBUTTONDOWN:								// If the left mouse button was clicked
		
		if(g_ViewMode == GL_TRIANGLES) {				// We our drawing mode is at triangles
			g_ViewMode = GL_LINE_STRIP;					// Go to line strips
		} else {
			g_ViewMode = GL_TRIANGLES;					// Go to triangles
		}
		break;

	case WM_RBUTTONDOWN:								// If the right mouse button was clicked.
		
		g_bLighting = !g_bLighting;						// Turn lighting ON/OFF

		if(g_bLighting) {								// If lighting is ON
			glEnable(GL_LIGHTING);						// Enable OpenGL lighting
		} else {
			glDisable(GL_LIGHTING);						// Disable OpenGL lighting
		}
		break;

	case WM_KEYDOWN:									// If we pressed a key

		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:								// If we hit the escape key
				PostQuitMessage(0);						// Send a QUIT message to the window
				break;

			case VK_LEFT:								// If the LEFT arrow key was pressed
				g_RotationSpeed -= 0.05f;				// Decrease the rotation speed (eventually rotates left)
				break;

			case VK_RIGHT:								// If the RIGHT arrow key is pressed
				g_RotationSpeed += 0.05f;				// Increase the rotation speed (rotates right)
				break;
		}
		break;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////


    case WM_CLOSE:										// If the window is being closed
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break; 
     
    default:											// Return by default
        return DefWindowProc (hWnd, uMsg, wParam, lParam); 
    } 
 
    return 0;											// If we handled the messge return 0
}
Beispiel #21
0
//------------------------------------------------------------------------
void OnDestroy(HWND hwnd)
{
	PostQuitMessage(0);
}
internal LRESULT CALLBACK Win32MainWindowCallback(HWND window, UINT msg, WPARAM w_param, LPARAM l_param)
{
    if (EasyTab_HandleEvent(window, msg, l_param, w_param) == EASYTAB_OK) {
        return true;  // Tablet input
    }

    LRESULT result = 0;
    ImGuiIO& io = ImGui::GetIO();

    switch (msg) {
        // Mouse
        case WM_LBUTTONDOWN: {
            io.MouseDown[0] = true;
            return true;
        } break;

        case WM_LBUTTONUP: {
            io.MouseDown[0] = false;
            return true;
        } break;

        case WM_RBUTTONDOWN: {
            io.MouseDown[1] = true;
            return true;
        } break;

        case WM_RBUTTONUP: {
            io.MouseDown[1] = false;
            return true;
        } break;

        case WM_MBUTTONDOWN: {
            io.MouseDown[2] = true;
            return true;
        } break;

        case WM_MBUTTONUP: {
            io.MouseDown[2] = false;
            return true;
        } break;

        case WM_MOUSEWHEEL: {
            io.MouseWheel += GET_WHEEL_DELTA_WPARAM(w_param) > 0 ? +1.0f : -1.0f;
            return true;
        } break;

        case WM_MOUSEMOVE: {
            TRACKMOUSEEVENT track_param = {};
            track_param.dwFlags |= TME_LEAVE;
            track_param.hwndTrack = window;
            track_param.cbSize = sizeof(track_param);
            TrackMouseEvent(&track_param);
            io.MousePos.x = (signed short)(l_param);
            io.MousePos.y = (signed short)(l_param >> 16);
            return true;
        } break;

        case WM_MOUSELEAVE: {
            ImGui::GetIO().MouseDown[0] = false;
            ImGui::GetIO().MouseDown[1] = false;
            ImGui::GetIO().MouseDown[2] = false;
            return true;
        } break;

        // Keyboard
        case WM_KEYDOWN: {
            if (w_param < 256)
                io.KeysDown[w_param] = 1;
            return true;
        } break;

        case WM_KEYUP: {
            if (w_param < 256)
                io.KeysDown[w_param] = 0;
            return true;
        } break;

        case WM_CHAR: {
            // You can also use ToAscii()+GetKeyboardState() to retrieve characters.
            if (w_param > 0 && w_param < 0x10000)
                io.AddInputCharacter((unsigned short)w_param);
            return true;
        } break;


        // window handling
        case WM_DESTROY: {
            mem.is_running = false;
            if (rendering_context)
            {
                wglMakeCurrent(NULL, NULL);
                wglDeleteContext(rendering_context);
            }
            ReleaseDC(window, device_context);
            PostQuitMessage(0);
        } break;

        case WM_PAINT: {
            PAINTSTRUCT paint;
            BeginPaint(window, &paint);
            // TODO: Redraw here
            EndPaint(window, &paint);
        } break;

        case WM_CLOSE: {
            // TODO: Handle this with a message to the user?
            mem.is_running = false;
        } break;

        case WM_SIZE: {
            int32 width, height;

            if (w_param == SIZE_MAXIMIZED) {
                int32 work_area_width = windows_work_area.right - windows_work_area.left;
                int32 work_area_height = windows_work_area.bottom - windows_work_area.top;
                SetWindowPos(window, HWND_TOP, windows_work_area.left, windows_work_area.top, work_area_width, work_area_height, NULL);
                width = work_area_width;
                height = work_area_height;
            }
            else
            {
                width = (int32) LOWORD(l_param);
                height = (int32) HIWORD(l_param);
            }

            core::resize(&mem, width, height);

            // Clear and swap buffers
            {
                if (mem.colors[PapayaCol_Clear]) {
                    glClearBufferfv(GL_COLOR, 0, (GLfloat*)&mem.colors[PapayaCol_Clear]);
                }
                SwapBuffers(device_context);
            }
        } break;

        // WM_NCHITTEST

        case WM_NCHITTEST: {
            const LONG border_width = 8; //in pixels
            RECT window_rect;
            GetWindowRect(window, &window_rect);
            long X = GET_X_LPARAM(l_param);
            long Y = GET_Y_LPARAM(l_param);

            if (!IsMaximized(window))
            {
                //bottom left corner
                if (X >= window_rect.left && X < window_rect.left + border_width &&
                    Y < window_rect.bottom && Y >= window_rect.bottom - border_width) {
                    return HTBOTTOMLEFT;
                }
                //bottom right corner
                if (X < window_rect.right && X >= window_rect.right - border_width &&
                    Y < window_rect.bottom && Y >= window_rect.bottom - border_width) {
                    return HTBOTTOMRIGHT;
                }
                //top left corner
                if (X >= window_rect.left && X < window_rect.left + border_width &&
                    Y >= window_rect.top && Y < window_rect.top + border_width) {
                    return HTTOPLEFT;
                }
                //top right corner
                if (X < window_rect.right && X >= window_rect.right - border_width &&
                    Y >= window_rect.top && Y < window_rect.top + border_width) {
                    return HTTOPRIGHT;
                }
                //left border
                if (X >= window_rect.left && X < window_rect.left + border_width) {
                    return HTLEFT;
                }
                //right border
                if (X < window_rect.right && X >= window_rect.right - border_width) {
                    return HTRIGHT;
                }
                //bottom border
                if (Y < window_rect.bottom && Y >= window_rect.bottom - border_width) {
                    return HTBOTTOM;
                }
                //top border
                if (Y >= window_rect.top && Y < window_rect.top + border_width) {
                    return HTTOP;
                }
            }

            if (Y - window_rect.top <= (float)mem.window.title_bar_height &&
                X > window_rect.left + 200.0f &&
                X < window_rect.right - (float)(mem.window.title_bar_buttons_width + 10)) {
                return HTCAPTION;
            }

            SetCursor(LoadCursor(NULL, IDC_ARROW));
            return HTCLIENT;
        } break;

        default: {
            result = DefWindowProcA(window, msg, w_param, l_param);
        } break;
    }

    return(result);
}
Beispiel #23
0
INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_COMMAND:
		{
			switch(LOWORD(wParam))
			{
			case IDCANCEL:
				if(g_bSuccess) RunLaunch();
				PostQuitMessage(0);
				break;
				
			case IDOK:
				HMENU hMenu = ::GetSystemMenu(hwndDlg, FALSE);
				::EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND|MF_DISABLED|MF_GRAYED);
				::EnableWindow(::GetDlgItem(hwndDlg, IDOK), FALSE);
				::EnableWindow(::GetDlgItem(hwndDlg, IDCANCEL), FALSE);
				if(g_hBeginHandle) SetEvent(g_hBeginHandle);
				break;
			}
		}
		break;

	case WM_MSG_ENTERFAULT:
		_enterFaultMode();
		break;

	case WM_MSG_SETPROGRESS:
		{
			UINT nPosOld = (UINT)::SendDlgItemMessage(hwndDlg, IDC_PROGRESS_MAIN, PBM_GETPOS, 
				0, 0);
			UINT nPosNow = (UINT)wParam;
			if(nPosNow != nPosOld)
			{
				::SendDlgItemMessage(hwndDlg, IDC_PROGRESS_MAIN, PBM_SETPOS, nPosNow, 0);
			}
		}
		break;

	case WM_MSG_SUCCESS:
		{
			HMENU hMenu = ::GetSystemMenu(hwndDlg, FALSE);
			::EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
			::EnableWindow(::GetDlgItem(hwndDlg, IDOK), FALSE);
			::EnableWindow(::GetDlgItem(hwndDlg, IDCANCEL), TRUE);
			::SetDlgItemText(hwndDlg, IDCANCEL, "确定");
			::CloseHandle(g_hBeginHandle); g_hBeginHandle=0;
			::SendDlgItemMessage(hwndDlg, IDC_PROGRESS_MAIN, PBM_SETPOS, 100, 0);

			char szTemp[MAX_PATH] = {0};
			_snprintf(szTemp, MAX_PATH, "《天龙八部》成功更新到%s!", g_szVersionTo);
			MessageBox(g_hMainWnd, szTemp, "《天龙八部》", MB_OK|MB_ICONINFORMATION);

			g_bSuccess = TRUE;
		}
		break;

	case WM_INITDIALOG:
		{
			g_hMainWnd = hwndDlg;

			//Center main window
			CenterDlg(hwndDlg);

			//设置图标
			HICON hMainIcon = LoadIcon(g_hInst, (LPCTSTR)IDD_DIALOG_MAIN);
			::SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hMainIcon);
			::SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hMainIcon);

			//set status
			::SetDlgItemText(hwndDlg, IDC_STATIC_STATUS, "读取版本信息...");
			::SendDlgItemMessage(hwndDlg, IDC_PROGRESS_MAIN, PBM_SETRANGE, 
				0, MAKELPARAM(0, 100));

			g_hBeginHandle = ::CreateEvent(0, TRUE, FALSE, 0);
			::ResetEvent(g_hBeginHandle);

			//create work thread
			UINT nThreadID;
			g_hWorkThread = (HANDLE)::_beginthreadex(NULL, 0, _WorkThread, 0, CREATE_SUSPENDED|THREAD_QUERY_INFORMATION, &nThreadID );
			if(g_hWorkThread == NULL)
			{
				::SetDlgItemText(hwndDlg, IDC_STATIC_STATUS, "创建线程失败");
				_enterFaultMode();
				break;
			}

			//go!
			::ResumeThread(g_hWorkThread);
			//not care
			::CloseHandle(g_hWorkThread); g_hWorkThread=0;
		}
		break;

	case WM_CTLCOLORSTATIC:
		{
			HWND hStatic = (HWND)lParam;

			if(g_bFaultMode && hStatic == GetDlgItem(hwndDlg, IDC_STATIC_STATUS))
			{
				HBRUSH hBrush = (HBRUSH)(INT_PTR)::DefWindowProc(hwndDlg, WM_CTLCOLORSTATIC, wParam, lParam);

				SetTextColor((HDC)wParam, RGB(255, 0, 0));
				return (BOOL)(INT)(INT_PTR)hBrush;
			}
			else return FALSE;
		}
		break;

	case WM_CLOSE:
		PostQuitMessage(0);
		break;

	default:
		break;
	}
	return FALSE;
}
Beispiel #24
0
void sysStop(system_t* system)
{
    PostQuitMessage(0);
    UNUSED_PARAMETER(system);
}
Beispiel #25
0
LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    PAINTSTRUCT ps;
    HDC hdc;
	int wmId, wmEvent;
	RotateImage *rotate = new RotateImage();
    switch( message )
    {
        case WM_PAINT:
            hdc = BeginPaint( hWnd, &ps );
            EndPaint( hWnd, &ps );
            break;
		case WM_LBUTTONDOWN:
		{
		  // Сохраняем координаты курсора мыши
		  xPosDown   = LOWORD(lParam);
		  yPosDown   = HIWORD(lParam); 
		  mMouseMove = true;
        }

		case WM_MOUSEMOVE:
			{
				xPosMove   = LOWORD(lParam);
				yPosMove   = HIWORD(lParam);

			if(mMouseMove)
				rotate->mouseMove(xPosMove -xPosDown , yPosMove - yPosDown );
			xPosDown = xPosMove;
			yPosDown = yPosMove;
				break;
			}

		case WM_LBUTTONUP:
			mMouseMove = FALSE;
		break;

        case WM_DESTROY:
            PostQuitMessage( 0 );
            break;

		case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		switch (wmId)
		{
			case IDM_FILE_OP:
				flag =true;
				InitContext();
				CreateGeometryScene *scene = new CreateGeometryScene(g_hWnd);
				scene->InitGeometryScene();
				//InitGeometry() ;
				break;
		}

			break;

        default:
            return DefWindowProc( hWnd, message, wParam, lParam );
    }

    return 0;
}
Beispiel #26
0
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
	SOCKET s,newsock;
	char recvbuf[128];
	struct sockaddr remote;
	int len;
	int retval;
	

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   Stop_server(hWnd);
				   DestroyWindow(hWnd);
				   break;
				case IDM_START:
				   Start_server(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		case UM_SOCK:
			s = (SOCKET)wParam;
			wmEvent = LOWORD(lParam);

			switch(wmEvent){
			case FD_ACCEPT:
				len = sizeof(remote);
				newsock = accept(s,&remote,&len);
				WSAAsyncSelect(newsock,hWnd,UM_SOCK,FD_READ|FD_CLOSE);//|FD_WRITE);
				break;
			case FD_READ:
				retval = recv(s,recvbuf,sizeof(recvbuf),0);
				if(retval <= 0){
					closesocket(s);
					break;
				}
				recvbuf[retval] = 0;
				
				hdc = BeginPaint(hWnd, &ps);
				// TODO: Add any drawing code here...
				hdc = GetDC(hWnd);
				TextOut(hdc,0,row,recvbuf,strlen(recvbuf));
				row += 16;
				ReleaseDC(hWnd,hdc);
				//»ØËÍÐÅÏ¢
				send(s,"ACK",3,0);
				
				break;
			case FD_CLOSE:
				MessageBox(hWnd,"closesocket\n","server",MB_OK);
				closesocket(s);
				break;
			case FD_WRITE:
				MessageBox(hWnd,"write event\n","server",MB_OK);
				break;
			default:
				if(WSAGETSELECTERROR(lParam) != 0){
					MessageBox(hWnd,"select report error\n","server",MB_OK);
					closesocket(s);
					WSACleanup();
				}
			}
		break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
Beispiel #27
0
// Process window messages
LRESULT CALLBACK Daemon::WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
	// This is a static method, so we don't know which instantiation we're 
	// dealing with. We have stored a pseudo-this in the window user data, 
	// though.
	Daemon *_this = (Daemon *) GetWindowLong(hwnd, GWL_USERDATA);

	switch (iMsg) {

	case WM_CREATE:
		{
			return 0;
		}

	case WM_SOCKEVENT:
		{
			assert(HIWORD(lParam) == 0);
			// A new socket created by accept might send messages to
			// this procedure. We can ignore them.
			if(wParam != _this->m_sock) {
				return 0;
			}

			switch(lParam) {
			case FD_ACCEPT:
				{
					SOCKET hNewSock;
					hNewSock = accept(_this->m_sock, NULL, NULL);
					WSAAsyncSelect(hNewSock, hwnd, 0, 0);
					unsigned long nbarg = 0;
					ioctlsocket(hNewSock, FIONBIO, &nbarg);

					pApp->NewConnection(hNewSock);
					
					break;
				}
			case FD_READ:
				{
					unsigned long numbytes;
					ioctlsocket(_this->m_sock, FIONREAD, &numbytes);
					recv(_this->m_sock, _this->netbuf, numbytes, 0);
					break;
				}
			case FD_CLOSE:
				Log::info(_T("Daemon connection closed\n"));
				DestroyWindow(hwnd);
				break;
			}
			
			return 0;
		}
	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case ID_NEWCONN:
			pApp->NewConnection();
			break;
		case IDC_OPTIONBUTTON:
			{
				Control ctrlThis;
				ctrlThis.setWindow(_this->m_hwnd);

				ConnectionConfigDialog conConfDialog;
				conConfDialog.setParent(&ctrlThis);
				conConfDialog.setConnectionConfig(&_this->m_conConf);
				if (conConfDialog.showModal() == IDOK) {
					ConnectionConfigSM ccsm(_T(".listen"));
					_this->m_conConf.saveToStorage(&ccsm);
				}
			}
			break;
		case ID_CLOSEDAEMON:
			PostQuitMessage(0);
			break;
		case IDD_APP_ABOUT:
			ShowAboutBox();
			break;
		case IDD_CONFIGURATION:
			g_vncViewerConfigDialog.showModal();
			break;
		}
		return 0;
	case WM_TRAYNOTIFY:
		{
			HMENU hSubMenu = GetSubMenu(_this->m_hmenu, 0);
			if (lParam==WM_LBUTTONDBLCLK) {
				// double click: execute first menu item
				::SendMessage(_this->m_nid.hWnd, WM_COMMAND, 
					GetMenuItemID(hSubMenu, 0), 0);
			} else if (lParam==WM_RBUTTONUP) {
				if (hSubMenu == NULL) { 
					Log::warning(_T("No systray submenu\n"));
					return 0;
				}
				// Make first menu item the default (bold font)
				::SetMenuDefaultItem(hSubMenu, 0, TRUE);
				
				// Display the menu at the current mouse location. There's a "bug"
				// (Microsoft calls it a feature) in Windows 95 that requires calling
				// SetForegroundWindow. To find out more, search for Q135788 in MSDN.
				//
				POINT mouse;
				GetCursorPos(&mouse);
				::SetForegroundWindow(_this->m_nid.hWnd);
				::TrackPopupMenu(hSubMenu, 0, mouse.x, mouse.y, 0,
					_this->m_nid.hWnd, NULL);
				
			} 
			return 0;
		}
	case WM_TIMER:
		_this->CheckTrayIcon();
		return 0;
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;
	}
	
	return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
Beispiel #28
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    static int cxClient, cyClient;
    static int cxGrid, cyGrid;
    static int CheckedGrid[5][5];

    PAINTSTRUCT ps;
    HDC         hdc;
    int         i, j;
    int         cxCursor, cyCursor;
    RECT        rectGrid;
    POINT       ptCursor;

    switch(uMsg)
    {
    case WM_KEYDOWN:
        {
            //Get Cursor current position
            GetCursorPos(&ptCursor);
            ScreenToClient(hwnd, &ptCursor);
            i = ptCursor.x / cxGrid;
            j = ptCursor.y / cyGrid;


            switch(wParam)
            {
            case VK_LEFT:
                i--;
                break;
            case VK_RIGHT:
                i++;
                break;
            case VK_UP:
                j--;
                break;
            case VK_DOWN:
                j++;
                break;
            case VK_HOME:
                i = 0;
                j = 0;
                break;
            case VK_END:
                i = ROWCOUNT - 1;
                j = COLUMNCOUNT - 1;
                break;
            default:
                break;
            }
            if (i > COLUMNCOUNT - 1)
            {
                i = 0;
            }
            else if (i < 0)
            {
                i = COLUMNCOUNT - 1;
            }
            if (j > ROWCOUNT - 1)
            {
                j = 0;
            }
            else if (j < 0)
            {
                j = ROWCOUNT - 1;
            }
            ptCursor.x = i * cxGrid + cxGrid / 2;
            ptCursor.y = j * cyGrid + cyGrid / 2;
            ClientToScreen(hwnd, &ptCursor);
            SetCursorPos(ptCursor.x, ptCursor.y);
            break;
        }
    case WM_CHAR:
        {
            switch (wParam)
            {
            case ' ':       //Space
            case '\r':      //Enter
                {
                    GetCursorPos(&ptCursor);
                    ScreenToClient(hwnd, &ptCursor);
                    SendMessage(hwnd, WM_LBUTTONDOWN, 0, MAKELONG(ptCursor.x, ptCursor.y));
                break;
                }
            }
            break;
        }
    case WM_SIZE:
        {
            cxClient    = LOWORD(lParam);
            cyClient    = HIWORD(lParam);
            cxGrid      = cxClient / COLUMNCOUNT;
            cyGrid      = cyClient / ROWCOUNT;
            InvalidateRect(hwnd, NULL, TRUE);
            break;
        }
    case WM_LBUTTONDOWN:
        {
            cxCursor = LOWORD(lParam);
            cyCursor = HIWORD(lParam);
            i = cxCursor / cxGrid;
            j = cyCursor /cyGrid;
            CheckedGrid[i][j] = !CheckedGrid[i][j];
            rectGrid.left   = i * cxGrid;
            rectGrid.right  = (i+1) * cxGrid;
            rectGrid.top    = j * cyGrid;
            rectGrid.bottom = (j+1) * cyGrid;
            InvalidateRect(hwnd, &rectGrid, TRUE);
            break;
        }
    case WM_PAINT:
        {
            hdc = BeginPaint(hwnd, &ps);

            // Draw lines
            for (i = 0; i < ROWCOUNT; ++i)
            {
                MoveToEx(hdc, 0, cyGrid * (1 + i), NULL);
                LineTo(hdc, cxGrid * COLUMNCOUNT, cyGrid * (1 + i));
            }
            for (i = 0; i < COLUMNCOUNT; ++i)
            {
                MoveToEx(hdc, cxGrid * (1 + i), 0, NULL);
                LineTo(hdc, cxGrid * (1 + i), cyGrid * ROWCOUNT);
            }

            for (i = 0; i < ROWCOUNT; ++i)
            {
                for (j=0; j < COLUMNCOUNT; ++j)
                {
                    if (CheckedGrid[i][j])
                    {
                        //Draw Cross line
                        MoveToEx(hdc, i * cxGrid, j * cyGrid, NULL);
                        LineTo(hdc, (i+1) * cxGrid, (j+1) * cyGrid);

                        MoveToEx(hdc, (i+1) * cxGrid, j * cyGrid, NULL);
                        LineTo(hdc, i * cxGrid, (j+1) * cyGrid);
                    }
                }
            }
            // Draw Checkers
            EndPaint(hwnd, &ps);
            break;
        }
    case WM_DESTROY:
        {
            PostQuitMessage(0);
            return 0;
        }
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
// Processes messages for main Window
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    PTOUCHINPUT pInputs;
    TOUCHINPUT tInput;
    HTOUCHINPUT hInput;
    int iNumContacts;
    POINT ptInputs;
    PAINTSTRUCT ps;

    // Handle each type of inData and based on which event we handle continue processing
    // the inData for manipulations by calling the ComTouchDriver
    
    switch (msg)
    {
    case WM_TOUCH:

        iNumContacts = LOWORD(wParam);
        hInput = (HTOUCHINPUT)lParam;

        pInputs = new (std::nothrow) TOUCHINPUT[iNumContacts];
       
        // Get each touch input info and feed each TOUCHINPUT into the process input handler

        if(pInputs != NULL)
        {
            if(GetTouchInputInfo(hInput, iNumContacts, pInputs, sizeof(TOUCHINPUT)))
            {
               for(int i = 0; i < iNumContacts; i++)
               {
                   // Bring touch input info into client coordinates

                   ptInputs.x = pInputs[i].x/100;	
                   ptInputs.y = pInputs[i].y/100;
                   ScreenToClient(g_hWnd, &ptInputs);
                   pInputs[i].x = ptInputs.x;
                   pInputs[i].y = ptInputs.y;
                   g_ctDriver->ProcessInputEvent(&pInputs[i]);
               }
               g_ctDriver->ProcessChanges();
            }
        }
        
        delete [] pInputs;
        CloseTouchInputHandle(hInput);
        break;
    
    // For each Mouse event build a TOUCHINPUT struct and feed into the process input handler

    case WM_LBUTTONDOWN:

        FillInputData(&tInput, MOUSE_CURSOR_ID, TOUCHEVENTF_DOWN, (DWORD)GetMessageTime(),LOWORD(lParam),HIWORD(lParam));
        g_ctDriver->ProcessInputEvent(&tInput);        
        break;

    case WM_MOUSEMOVE:

        if(LOWORD(wParam) == MK_LBUTTON)
        {
            FillInputData(&tInput, MOUSE_CURSOR_ID, TOUCHEVENTF_MOVE, (DWORD)GetMessageTime(),LOWORD(lParam), HIWORD(lParam));
            g_ctDriver->ProcessInputEvent(&tInput);      
            g_ctDriver->ProcessChanges();
        }
      
        break;

    case WM_LBUTTONUP:

        FillInputData(&tInput, MOUSE_CURSOR_ID, TOUCHEVENTF_UP, (DWORD)GetMessageTime(),LOWORD(lParam), HIWORD(lParam));
        g_ctDriver->ProcessInputEvent(&tInput);
        
        break;

    case WM_DESTROY:
        
        if(g_ctDriver)
        {
            delete g_ctDriver;
        }
        PostQuitMessage(0);
        return 1;

    case WM_SIZE:

        g_iCWidth = LOWORD(lParam);
        g_iCHeight = HIWORD(lParam);
        break;

    case WM_PAINT:
        
        BeginPaint(g_hWnd, &ps);
        g_ctDriver->RenderInitialState(g_iCWidth, g_iCHeight);
        EndPaint(g_hWnd, &ps);
        break;

    case WM_TIMER:
        g_ctDriver->ProcessChanges();
        break;
      
    default:
        return DefWindowProc(hWnd, msg, wParam, lParam);
    }
    return 0;
}
Beispiel #30
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	HWND msgwnd = CreateWindow(L"STATIC", L"Shiftfocus window", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, GetModuleHandle(NULL), 0);

#	define MAKE(x) (RegisterHotKey(msgwnd, x, MOD_CONTROL | MOD_WIN, x) == 0)
	if ((msgwnd == NULL) || MAKE(VK_LEFT)
						 || MAKE(VK_RIGHT)
						 || MAKE(VK_UP)
						 || MAKE(VK_DOWN))
	{
		MessageBox(msgwnd, L"Unable to register hotkeys, exiting.", L"Error", MB_ICONERROR | MB_OK);
		DestroyWindow(msgwnd);
		return 1;
	}

	MSG msg;
	BOOL ret;
	while (0 != (ret = GetMessage(&msg, msgwnd, 0, 0))) {
		if (-1 == ret)
			return 1;

		switch (msg.message) {
		case WM_DESTROY:
			PostQuitMessage(0);
			break;

		case WM_HOTKEY: {
			RECT loc = {};
			HWND fg = GetForegroundWindow();
			HWND desktop = getDesktopWindow();
			GetWindowRect(fg, &loc);
		
			POINT p = {};
			for (
				int distance = 10;
				MonitorFromPoint(p, MONITOR_DEFAULTTONULL);
				distance += 10) {
				
				switch (msg.wParam)
				{
#					define HALF(x,y) (((y)-(x))/2+(x))
					case VK_LEFT:
						p.x=loc.left-distance;
						p.y=HALF(loc.top,loc.bottom);
						break;
					case VK_RIGHT:
						p.x=loc.right+distance;
						p.y=HALF(loc.top,loc.bottom);
						break;
					case VK_UP:
						p.y=loc.top-distance;
						p.x=HALF(loc.left,loc.right);
						break;
					case VK_DOWN:
						p.y=loc.bottom+distance;
						p.x=HALF(loc.left,loc.right);
						break;
					default:
						MessageBeep(MB_ICONERROR);
				}

				HWND n = ChildWindowFromPoint(GetDesktopWindow(), p);
				if (NULL == n)
					MessageBeep(MB_ICONASTERISK);
				else
				{
					if (desktop == n)
						continue;

					if (!SetForegroundWindow(n))
						MessageBeep(MB_ICONERROR);
					break;
				}
			}
		} break;
		}

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}