コード例 #1
0
ファイル: Main.cpp プロジェクト: mwhooker/CalcCalc
LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	/* Process a Message sent to the Window */
	switch (message)
	{
		case WM_CREATE:
			CreateChildControls(hwnd);
			break;

		case WM_COMMAND:
			if( HIWORD( wParam ) == BN_CLICKED )
			{
				ProcessButtonClick( (char)LOWORD( wParam ) );
			}
			break;

		case WM_DESTROY:
			PostQuitMessage (0); 
			break;
	}
	return DefWindowProc (hwnd, message, wParam, lParam);
}
コード例 #2
0
/*LRESULT CALLBACK FrameWndProc (
	HWND   window,
	UINT   message,
	WPARAM wparam,
	LPARAM lparam)*/
void	FrameDispatchMessage(SDL_Event * e) // process given SDL event
{
	int mysym = e->key.keysym.sym; // keycode
	int mymod = e->key.keysym.mod; // some special keys flags
	int x,y;	// used for mouse cursor position

   switch (e->type) //type of SDL event
   {
     case SDL_ACTIVEEVENT:
	g_bAppActive = e->active.gain; // if gain==1, app is active
        break;

    case SDL_KEYDOWN:
//	    printf("keyb %d is down!\n", mysym);
	    if(mysym >= SDLK_0 && mysym <= SDLK_9 && mymod & KMOD_CTRL) {
		    FrameQuickState(mysym - SDLK_0, mymod);
		    break;
	    }

	    if(mysym < 128 && mysym != SDLK_PAUSE) { // it should be ASCII code?
		if ((g_nAppMode == MODE_RUNNING) || (g_nAppMode == MODE_LOGO) ||
			((g_nAppMode == MODE_STEPPING) && (mysym != SDLK_ESCAPE)))
			{
				KeybQueueKeypress(mysym,ASCII);
			}
			else
			if ((g_nAppMode == MODE_DEBUG) || (g_nAppMode == MODE_STEPPING))
			{
				DebuggerInputConsoleChar(mysym);
			}
			break;
	}
	else {// this is function key?
//		KeybUpdateCtrlShiftStatus(); // if ctrl or shift or alt was pressed?------?
		if ((mysym >= SDLK_F1) && (mysym <= SDLK_F12) && (buttondown == -1))
		{
//			SetUsingCursor(0);	-- for what purpose???
			buttondown = mysym - SDLK_F1;	// special function keys processing

/*			if (fullscreen && (buttonover != -1)) {
				if (buttonover != buttondown)
				EraseButton(buttonover);
				buttonover = -1;
			}
			DrawButton((HDC)0,buttondown);*/
		}
		else if (mysym == SDLK_KP_PLUS) // Gray + - speed up the emulator!
		{
			g_dwSpeed = g_dwSpeed + 2;
			if(g_dwSpeed > SPEED_MAX) g_dwSpeed = SPEED_MAX; // no Maximum tresspassing!
			printf("Now speed=%d\n", (int)g_dwSpeed);
			SetCurrentCLK6502();
		}
		else if (mysym == SDLK_KP_MINUS) // Gray + - speed up the emulator!
		{
			if(g_dwSpeed > SPEED_MIN) g_dwSpeed = g_dwSpeed - 1;// dw is unsigned value!
			//if(g_dwSpeed <= SPEED_MIN) g_dwSpeed = SPEED_MIN; // no Minimum tresspassing!
			printf("Now speed=%d\n", (int)g_dwSpeed);
			SetCurrentCLK6502();
		}
		else if (mysym == SDLK_KP_MULTIPLY) // Gray * - normal speed!
		{
			g_dwSpeed = 10;// dw is unsigned value!
			printf("Now speed=%d\n", (int)g_dwSpeed);
			SetCurrentCLK6502();
		}


		else if (mysym == SDLK_CAPSLOCK) // CapsLock
		{
				KeybToggleCapsLock();
		}
		else if (mysym == SDLK_PAUSE)	// Pause - let us pause all things for the best
		{
			SetUsingCursor(0); // release cursor?
			switch (g_nAppMode)
			{
			case MODE_RUNNING: // go in pause
				g_nAppMode = MODE_PAUSED;
				SoundCore_SetFade(FADE_OUT); // fade out sound?**************
				break;
			case MODE_PAUSED: // go to the normal mode?
				g_nAppMode = MODE_RUNNING;
				SoundCore_SetFade(FADE_IN);  // fade in sound?***************
				break;
			case MODE_STEPPING:
				DebuggerInputConsoleChar( DEBUG_EXIT_KEY );
				break;
			}
			DrawStatusArea(/*(HDC)0,*/DRAW_TITLE);
			if ((g_nAppMode != MODE_LOGO) && (g_nAppMode != MODE_DEBUG))
				VideoRedrawScreen();
			g_bResetTiming = true;
		}
		else if (mysym == SDLK_SCROLLOCK)	// SCROLL LOCK pressed
		{
			g_bScrollLock_FullSpeed = !g_bScrollLock_FullSpeed; // turn on/off full speed?
		}
		else if ((g_nAppMode == MODE_RUNNING) || (g_nAppMode == MODE_LOGO) || (g_nAppMode == MODE_STEPPING))
		{
			// Note about Alt Gr (Right-Alt):
			// . WM_KEYDOWN[Left-Control], then:
			// . WM_KEYDOWN[Right-Alt]
			BOOL autorep  = 0; //previous key was pressed? 30bit of lparam
			BOOL extended = (mysym >= 273); // 24bit of lparam - is an extended key, what is it???
			if ((!JoyProcessKey(mysym ,extended, 1, autorep)) && (g_nAppMode != MODE_LOGO))
				KeybQueueKeypress(mysym, NOT_ASCII);
		}
		else if (g_nAppMode == MODE_DEBUG)
			DebuggerProcessKey(mysym);	// someone should realize debugger for Linapple!?--bb
/*
		if (wparam == VK_F10)
		{
			SetUsingCursor(0);
			return 0;
		}
		break;*/
    }//else
    break;

    case SDL_KEYUP:
//	int mysym = e->key.keysym.sym; // keycode
	if ((mysym >= SDLK_F1) && (mysym <= SDLK_F12) && (buttondown == mysym-SDLK_F1))
	{
		buttondown = -1;
// 			if (fullscreen)
// 				EraseButton(wparam-VK_F1);
// 			else
// 				DrawButton((HDC)0,wparam-VK_F1);
		ProcessButtonClick(mysym-SDLK_F1, mymod); // process function keys - special events
	}
	else
	{	// mysym >= 300 (or 273????)- check for extended key, what is it EXACTLY???
		JoyProcessKey(mysym,(mysym >= 273), 0, 0);
	}
	break;

    case SDL_MOUSEBUTTONDOWN:
	if(e->button.button == SDL_BUTTON_LEFT) {// left mouse button was pressed

	    if (buttondown == -1)
	  {
        x = e->button.x; // mouse cursor coordinates
        y = e->button.y;
        if (usingcursor) // we use mouse cursor for our special needs?
	{
	   KeybUpdateCtrlShiftStatus(); // if either of ALT, SHIFT or CTRL is pressed
	   if (g_bShiftKey | g_bCtrlKey)
	   {
           	 SetUsingCursor(0); // release mouse cursor for user
	   }
          else
	  {
		if (sg_Mouse.Active())
			sg_Mouse.SetButton(BUTTON0, BUTTON_DOWN);
		else
		        JoySetButton(BUTTON0, BUTTON_DOWN);
	  }
	}// we do not use mouse
        else if ( (/*(x < buttonx) &&*/ JoyUsingMouse() && ((g_nAppMode == MODE_RUNNING) ||
		   (g_nAppMode == MODE_STEPPING))) || (sg_Mouse.Active()) )
		{
          		SetUsingCursor(1); // capture cursor
		}
		DebuggerMouseClick( x, y );
      }
//RelayEvent(WM_LBUTTONDOWN,wparam,lparam);
     }//if left mouse button down
     else if(e->button.button == SDL_BUTTON_RIGHT) {
	if (usingcursor)
        {
	     if (sg_Mouse.Active())
		     sg_Mouse.SetButton(BUTTON1, BUTTON_DOWN);
	     else
		     JoySetButton(BUTTON1, BUTTON_DOWN);
        }
     }

      break; // end of MOSEBUTTONDOWN event

    case SDL_MOUSEBUTTONUP:
     if (e->button.button == SDL_BUTTON_LEFT) {// left mouse button was released
     if (usingcursor)
      {
		if (sg_Mouse.Active())
			sg_Mouse.SetButton(BUTTON0, BUTTON_UP);
		else
		    JoySetButton(BUTTON0, BUTTON_UP);
      }
//      RelayEvent(WM_LBUTTONUP,wparam,lparam);
     }
     else if(e->button.button == SDL_BUTTON_RIGHT) {
	     if (usingcursor)
	     {
		     if (sg_Mouse.Active())
			     sg_Mouse.SetButton(BUTTON1, BUTTON_UP);
		     else
			     JoySetButton(BUTTON1, BUTTON_UP);
	     }
     }
     break; // MOUSEBUTTONUP event

    case SDL_MOUSEMOTION:
      x = e->motion.x;// get relative coordinates of mouse cursor
      y = e->motion.y;
      if (usingcursor)
      {
//        DrawCrosshairs(x,y); I do not like those crosshairs, but... --bb
		if (sg_Mouse.Active())
	            sg_Mouse.SetPosition(x, VIEWPORTCX-4, y, VIEWPORTCY-4);
		else
		    JoySetPosition(x, VIEWPORTCX-4, y, VIEWPORTCY-4);
      }
//      RelayEvent(WM_MOUSEMOVE,wparam,lparam);
      break;

    case SDL_USEREVENT:
	if (e->user.code == 1) // should do restart?
		ProcessButtonClick(BTN_RUN, 0);
	break;

   }//switch

//  return DefWindowProc(window,message,wparam,lparam);
}