Ejemplo n.º 1
0
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam,
                                   LPARAM lParam) {
  static SERVICE_TABLE_ENTRY service_table[] = {
    {server_name, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
    {NULL, NULL}
  };
  int service_installed;
  char buf[200], *service_argv[] = {__argv[0], NULL};
  POINT pt;
  HMENU hMenu;

  switch (msg) {
    case WM_CREATE:
      if (__argv[1] != NULL &&
          !strcmp(__argv[1], service_magic_argument)) {
        start_mongoose(1, service_argv);
        StartServiceCtrlDispatcher(service_table);
        exit(EXIT_SUCCESS);
      } else {
        start_mongoose(__argc, __argv);
      }
      break;
    case WM_COMMAND:
      switch (LOWORD(wParam)) {
        case ID_QUIT:
          mg_stop(ctx);
          Shell_NotifyIcon(NIM_DELETE, &TrayIcon);
          PostQuitMessage(0);
          break;
        case ID_EDIT_CONFIG:
          edit_config_file();
          break;
        case ID_INSTALL_SERVICE:
        case ID_REMOVE_SERVICE:
          manage_service(LOWORD(wParam));
          break;
      }
      break;
    case WM_USER:
      switch (lParam) {
        case WM_RBUTTONUP:
        case WM_LBUTTONUP:
        case WM_LBUTTONDBLCLK:
          hMenu = CreatePopupMenu();
          AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, server_name);
          AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
          service_installed = manage_service(0);
          snprintf(buf, sizeof(buf), "NT service: %s installed",
                   service_installed ? "" : "not");
          AppendMenu(hMenu, MF_STRING | MF_GRAYED, ID_SEPARATOR, buf);
          AppendMenu(hMenu, MF_STRING | (service_installed ? MF_GRAYED : 0),
                     ID_INSTALL_SERVICE, "Install");
          AppendMenu(hMenu, MF_STRING | (!service_installed ? MF_GRAYED : 0),
                     ID_REMOVE_SERVICE, "Deinstall");
          AppendMenu(hMenu, MF_SEPARATOR, ID_SEPARATOR, "");
          AppendMenu(hMenu, MF_STRING, ID_EDIT_CONFIG, "Edit config file");
          AppendMenu(hMenu, MF_STRING, ID_QUIT, "Exit");
          GetCursorPos(&pt);
          SetForegroundWindow(hWnd);
          TrackPopupMenu(hMenu, 0, pt.x, pt.y, 0, hWnd, NULL);
          PostMessage(hWnd, WM_NULL, 0, 0);
          DestroyMenu(hMenu);
          break;
      }
      break;
  }

  return DefWindowProc(hWnd, msg, wParam, lParam);
}
Ejemplo n.º 2
0
LRESULT CALLBACK WindowProc (HWND   hwnd,
                             UINT   msg,
                             WPARAM wParam,
                             LPARAM lParam)
{
    //these hold the dimensions of the client window area
	  static int cxClient, cyClient;

    switch (msg)
    {
	
		//A WM_CREATE msg is sent when your application window is first
		//created
    case WM_CREATE:
      {
         //to get get the size of the client window first we need  to create
         //a RECT and then ask Windows to fill in our RECT structure with
         //the client window size. Then we assign to cxClient and cyClient 
         //accordingly
			   RECT rect;

			   GetClientRect(hwnd, &rect);

			   cxClient = rect.right;
			   cyClient = rect.bottom;

      }

      break;

    case WM_KEYUP:
      {
        switch(wParam)
        {

        case VK_ESCAPE:
          {
            PostQuitMessage(0);
          }
          
          break;
        }
      }
    
    case WM_PAINT:
      {
 				 PAINTSTRUCT ps;
          
         BeginPaint (hwnd, &ps);

          //Make the bottom part of window a pattern so you can see what
         //the transparency flag does
         HBRUSH PatternBrush = CreateHatchBrush(HS_BDIAGONAL, RGB(0,0,255));

         HBRUSH OldBrush = (HBRUSH)SelectObject(ps.hdc, PatternBrush);

         Rectangle(ps.hdc,0, cyClient/2, cxClient, cyClient);

         //replace the old brush
         SelectObject(ps.hdc, OldBrush);

         //first a demonstration of TextOut
         char* text = "1. I ain't got time to bleed.";
         
         TextOut(ps.hdc, 5, 5, text, strlen(text));

         //now DrawText. First we create a text box
         RECT TextBox;
         TextBox.top = 30;
         TextBox.left = 100;
         TextBox.bottom = 200;
         TextBox.right = cxClient-100;

         //assign some text
         text = "2. You take the blue pill and the story ends.You wake in your bed and believe whatever you want to believe.You take the red pill and you stay in Wonderland and I show you how deep the rabbit-hole goes.";

         //now print the text
         DrawText(ps.hdc, text, strlen(text), &TextBox, DT_WORDBREAK);

         //now to change the colors. First set text to red
          SetTextColor(ps.hdc, RGB(255, 0, 0));

         //background to black
         SetBkColor(ps.hdc, RGB(0, 0, 0));

         TextBox.top = 200;
         TextBox.left = 5;
         TextBox.bottom = 300;
         TextBox.right = cxClient-200;

         text = "3. The greatest trick the devil ever pulled was convincing the world he didn't exist.";
         DrawText(ps.hdc, text, strlen(text), &TextBox, DT_WORDBREAK);

         //now set background to transparent
         SetBkMode(ps.hdc, TRANSPARENT);

         TextBox.top = 300;
         TextBox.left = 100;
         TextBox.bottom = cyClient;
         TextBox.right = cxClient-50;

         text = "4. ...I’m 42 years old. In less than a year I’ll be dead";
         DrawText(ps.hdc, text, strlen(text), &TextBox, DT_WORDBREAK);
         
         EndPaint (hwnd, &ps);
      }

      break;

    //has the user resized the client area?
		case WM_SIZE:
		  {
        //if so we need to update our variables so that any drawing
        //we do using cxClient and cyClient is scaled accordingly
			  cxClient = LOWORD(lParam);
			  cyClient = HIWORD(lParam);
      }

      break;
          
		 case WM_DESTROY:
			 {

         // kill the application, this sends a WM_QUIT message  
				 PostQuitMessage (0);
			 }

       break;

     }//end switch

     //this is where all the messages not specifically handled by our 
		 //winproc are sent to be processed
		 return DefWindowProc (hwnd, msg, wParam, lParam);
}
Ejemplo n.º 3
0
LRESULT CALLBACK MainWndMsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch(uMsg)
	{
	case WM_POWERBROADCAST:
		{
			SYSTEMTIME st;
			GetSystemTime(&st);

			switch(wParam)
			{
			/* Power status has changed. */
			case PBT_APMPOWERSTATUSCHANGE:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMPOWERSTATUSCHANGE %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("1"), MB_OK);

					break;
				}
			/* Operation is resuming automatically from a low-power state. */
			/* This message is sent every time the system resumes. */
			case PBT_APMRESUMEAUTOMATIC:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMRESUMEAUTOMATIC %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("2"), MB_OK);

					break;
				}
			/* Operation is resuming from a low-power state. */
			/* This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key. */
			case PBT_APMRESUMESUSPEND:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMRESUMESUSPEND %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("3"), MB_OK);

					break;
				}
			/* System is suspending operation. */
			case PBT_APMSUSPEND:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMSUSPEND %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("4"), MB_OK);

					break;
				}
			/* A power setting change event has been received. */
			case PBT_POWERSETTINGCHANGE:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_POWERSETTINGCHANGE %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("5"), MB_OK);

					break;
				}
			/* Battery power is low. In Windows Server 2008 and Windows Vista, use PBT_APMPOWERSTATUSCHANGE instead. */
			case PBT_APMBATTERYLOW:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMBATTERYLOW %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("6"), MB_OK);

					break;
				}
			/* OEM-defined event occurred. 
			/* In Windows Server 2008 and Windows Vista, this event is not available because these operating systems support only ACPI; 
			/* APM BIOS events are not supported. */
			case PBT_APMOEMEVENT:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMOEMEVENT %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("7"), MB_OK);

					break;
				}
			/* Request for permission to suspend. In Windows Server 2008 and Windows Vista, use the SetThreadExecutionState function instead. */
			case PBT_APMQUERYSUSPEND:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMQUERYSUSPEND %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("8"), MB_OK);

					break;
				}
			/* Suspension request denied. In Windows Server 2008 and Windows Vista, use SetThreadExecutionState instead. */
			case PBT_APMQUERYSUSPENDFAILED:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMQUERYSUSPENDFAILED %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("9"), MB_OK);

					break;
				}
			/* Operation resuming after critical suspension. In Windows Server 2008 and Windows Vista, use PBT_APMRESUMEAUTOMATIC instead. */
			case PBT_APMRESUMECRITICAL:
				{
					TCHAR szTime[MAX_PATH] = { 0 };
					_stprintf(szTime, TEXT("PBT_APMRESUMECRITICAL %d-%d-%d %d:%d:%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);

					MessageBox(hWnd, szTime, TEXT("10"), MB_OK);

					break;
				}
			default:
				{
					break;
				}
			}
			return 0;
			break;
		}
	case WM_COMMAND:
		{
			if (HIWORD(wParam) == BN_CLICKED) {
				//SendMessage(hWndSpeedMultipleComboBox, CB_SHOWDROPDOWN, (WPARAM) TRUE, 0);
			}

			if ( HIWORD(wParam) == CBN_SELCHANGE) {               
				LRESULT  sel = SendMessage(hWndSpeedMultipleComboBox, CB_GETCURSEL, 0, 0);
				//SetWindowText(hwndStatic, items[sel]);
				//SetFocus(hwnd);
			}

			break;
		}
	case WM_CREATE:
		{
			/* 为窗口添加扩展风格 WS_EX_LAYERED,从而为实现窗口透明做准备 */
			LONG lExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
			lExStyle = lExStyle | WS_EX_LAYERED;
			SetWindowLong(hWnd, GWL_EXSTYLE, lExStyle);

			/* 实现窗口透明 - 设置窗口透明度为 220 */
			SetLayeredWindowAttributes(hWnd, 0, WND_TRANSPARENCY, LWA_ALPHA);


			InitSpeedMultipleComboBox(((LPCREATESTRUCT)lParam)->hInstance, hWnd);

			/* 初始化 Tracker Bar */
			InitSpeedMultipleTrackBar(((LPCREATESTRUCT)lParam)->hInstance, hWnd);

			/* 初始化按钮 */
			InitButton(((LPCREATESTRUCT)lParam)->hInstance, hWnd);


			/* 初始化速度未改变的进程列表框 */
			InitNotSpeedMultipleListView(((LPCREATESTRUCT)lParam)->hInstance, hWnd);

			/* 初始化速度已改变的进程列表框 */
			InitHasSpeedMultipleListView(((LPCREATESTRUCT)lParam)->hInstance, hWnd);

			/* 绑定数据到速度未改变的进程列表框 */
			BindData2NotSpeedMultipleListView(((LPCREATESTRUCT)lParam)->hInstance);

			break;
		}
	case WM_CTLCOLORSTATIC:
		{
			/* 使得静态文本框使用透明背景色 */
			return (DWORD)GetStockObject(NULL_BRUSH);
		}
		/*case WM_COMMAND:
		{
		switch (wParam)
		{
		case ID_BUTTON_INSERT_PROCESS:
		{
		DestroyWindow(hWnd);

		break;
		}
		case ID_BUTTON_REMOVE_PROCESS:
		{
		break;
		}
		case ID_BUTTON_REFRESH_PROCESS:
		{
		break;
		}
		default:
		{
		break;
		}
		}
		break;
		}*/
	case WM_CLOSE:
		{
			DestroyWindow(hWnd);

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

			break;
		}
	default:
		{
			break;
		}
	}

	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
Ejemplo n.º 4
0
LRESULT CALLBACK GameApplication::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if (hwnd!=GameApplication::pApp->GetAppWindow())
		return  DefWindowProc ( hwnd, msg, wParam, lParam );

	if ( GameApplication::pApp == NULL )
		return DefWindowProc ( hwnd, msg, wParam, lParam );

	POINT pt;
	LONG delta;
	USHORT active, minimized;

	switch ( msg )
	{
	case WM_PAINT:
		if ( !GameApplication::pApp->Paint( hwnd, wParam, lParam ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam );
		break;
	case WM_KEYDOWN:
		if ( !GameApplication::pApp->KeyDown ( wParam, lParam ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_KEYUP:
		if ( !GameApplication::pApp->KeyUp ( wParam, lParam ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_MOUSEMOVE:
		pt.x = ( short ) LOWORD ( lParam );
		pt.y = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseMove ( pt, LOWORD( wParam) ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam );
		break;
	case WM_MOUSEWHEEL:
		delta = ( short ) HIWORD ( wParam );
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseWheelMove ( pt, LOWORD ( wParam ), delta ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam );
		break;
	case WM_LBUTTONDOWN:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseButtonDown ( pt, LOWORD ( wParam ), 0 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_LBUTTONDBLCLK:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseDoubleClick ( pt, LOWORD ( wParam ), 0 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_LBUTTONUP:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseButtonUp ( pt, LOWORD ( wParam ), 0 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_RBUTTONDOWN:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseButtonDown ( pt, LOWORD ( wParam ), 1 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_RBUTTONDBLCLK:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseDoubleClick ( pt, LOWORD ( wParam ), 1 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_RBUTTONUP:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseButtonUp ( pt, LOWORD ( wParam ), 1 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_MBUTTONDOWN:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseButtonDown ( pt, LOWORD ( wParam ), 2 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_MBUTTONDBLCLK:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseDoubleClick ( pt, LOWORD ( wParam ), 2 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_MBUTTONUP:
		pt.x   = ( short ) LOWORD ( lParam );
		pt.y   = ( short ) HIWORD ( lParam );
		if ( !GameApplication::pApp->MouseButtonUp ( pt, LOWORD ( wParam ), 2 ) )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		break;
	case WM_DESTROY:
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				PostQuitMessage( 0 );
			break;
	case WM_ACTIVATE:
		active    = LOWORD ( wParam );
		minimized = HIWORD ( wParam );
		if ( ( active == WA_ACTIVE ) || ( active == WA_CLICKACTIVE ) )
		{
			if ( minimized ) // Needed???
				ShowWindow ( hwnd, SW_RESTORE );
		if ( !GameApplication::pApp->AppActivate () )
			if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
				return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		}
		else
		{
			if ( !GameApplication::pApp->AppDeactivate () )
				if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
					return DefWindowProc ( hwnd, msg, wParam, lParam ); 
		}
		break;
	default: 
		if ( !GameApplication::pApp->ProcessMessage ( msg, wParam, lParam ) )
			return DefWindowProc ( hwnd, msg, wParam, lParam );
	}
	return 0;
}
Ejemplo n.º 5
0
static LRESULT CALLBACK
SDL_Assertion_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
    case WM_CREATE:
    {
        /* !!! FIXME: all this code stinks. */
        const SDL_assert_data *data = SDL_Windows_AssertData;
        char buf[1024];
        const int w = 100;
        const int h = 25;
        const int gap = 10;
        int x = gap;
        int y = 50;
        int len;
        int i;
        static const struct {
            const char *name;
            SDL_assert_state state;
        } buttons[] = {
            {"Abort", SDL_ASSERTION_ABORT },
            {"Break", SDL_ASSERTION_BREAK },
            {"Retry", SDL_ASSERTION_RETRY },
            {"Ignore", SDL_ASSERTION_IGNORE },
            {"Always Ignore", SDL_ASSERTION_ALWAYS_IGNORE },
        };

        len = (int) SDL_snprintf(buf, sizeof (buf),
                                 "Assertion failure at %s (%s:%d), triggered %u time%s:\r\n  '%s'",
                                 data->function, data->filename, data->linenum,
                                 data->trigger_count, (data->trigger_count == 1) ? "" : "s",
                                 data->condition);
        if ((len < 0) || (len >= sizeof (buf))) {
            buf[sizeof (buf) - 1] = '\0';
        }

        CreateWindowA("STATIC", buf,
                      WS_VISIBLE | WS_CHILD | SS_LEFT,
                      x, y, 550, 100,
                      hwnd, (HMENU) 1, NULL, NULL);
        y += 110;

        for (i = 0; i < (sizeof (buttons) / sizeof (buttons[0])); i++) {
            CreateWindowA("BUTTON", buttons[i].name,
                          WS_VISIBLE | WS_CHILD,
                          x, y, w, h,
                          hwnd, (HMENU) buttons[i].state, NULL, NULL);
            x += w + gap;
        }
        break;
    }

    case WM_COMMAND:
        SDL_Windows_AssertChoice = ((SDL_assert_state) (LOWORD(wParam)));
        SDL_Windows_AssertData = NULL;
        break;

    case WM_DESTROY:
        SDL_Windows_AssertData = NULL;
        break;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}
Ejemplo n.º 6
0
LRESULT OSD::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
    return DefWindowProc(hWnd, message, wParam, lParam);
}
Ejemplo n.º 7
0
//***************************************************************************
CSize  CGuiToolBarWnd::CalcSize(TBBUTTON* pData, int nCount)
{
	ASSERT(pData != NULL && nCount > 0);
	BOOL bDrow=FALSE;
	int  nNumDrow=0;
	CPoint cur(0,0);
	CSize sizeResult(0,0);
	CClientDC dc(this);
	int xSizeMin=32;
	if(m_dwStyle & CBRS_FLOATING )  
		SetSizes(m_sizeButton, m_sizeImage);
	if (bVertDocked)
	 ::SendMessage(m_hWnd, TB_SETMAXTEXTROWS, 0, 0);
	else
	 ::SendMessage(m_hWnd, TB_SETMAXTEXTROWS, 1, 0);
	//CFont* m_fontOld=dc.SelectObject(&m_cfont);
//	SetRealSize();
	DWORD dwExtendedStyle = DefWindowProc(TB_GETEXTENDEDSTYLE, 0, 0);
	for (int i = 0; i < nCount; i++)
	{
		
		if ((pData[i].fsStyle &  TBSTYLE_SEP) &&(pData[i].idCommand!=0))
		{
		    if (bVertDocked)
			{
				 CWnd * pWnd =GetDlgItem(pData[i].idCommand);
				 ASSERT_VALID(pWnd);
				 pWnd->ShowWindow( SW_HIDE   );
				 pData[i].fsState |= TBSTATE_HIDDEN;
				 continue;
				
			}
			else
			{
				
					CWnd * pWnd =GetDlgItem(pData[i].idCommand);
					ASSERT_VALID(pWnd);
					pData[i].fsState &= ~TBSTATE_HIDDEN;
					pWnd->ShowWindow( SW_SHOW   );
					
								
			}
		}
		
		int cySep = pData[i].iBitmap;
		cySep = cySep * 2 / 3;
		CRect rci;
		GetItemRect(i, &rci);
		int cx=rci.Width();
		xSizeMin=min(xSizeMin,cx);
		if (pData[i].fsStyle & TBSTYLE_SEP)
		{
			// a separator represents either a height or width
			if (pData[i].fsState & TBSTATE_WRAP)
				sizeResult.cy = max(cur.y + m_sizeButton.cy + cySep, sizeResult.cy);
			else
				sizeResult.cx = max(cur.x + pData[i].iBitmap, sizeResult.cx);
		}
		else
		{
			// check for dropdown style, but only if the buttons are being drawn
			if ((pData[i].fsStyle & TBSTYLE_DROPDOWN) &&
				(dwExtendedStyle & TBSTYLE_EX_DRAWDDARROWS))
			{
				// add size of drop down
				cx += (_afxDropDownWidth);
				nNumDrow++;
				bDrow=TRUE;
			}
			sizeResult.cx = max(cur.x + cx, sizeResult.cx);
			sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy);
		}

			

		if (pData[i].fsStyle & TBSTYLE_SEP)
			cur.x += pData[i].iBitmap;
		else
			cur.x += cx - CX_OVERLAP;

		if (pData[i].fsState & TBSTATE_WRAP)
		{
			cur.x = 0;
			cur.y += m_sizeButton.cy;
			if (pData[i].fsStyle & TBSTYLE_SEP)
				cur.y += cySep;
		}
	}
	if (bDrow == TRUE)
	{
		
		if (bVertDocked)
		{
			sizeResult.cx-=_afxDropDownWidth;
			sizeResult.cy+=_afxDropDownWidth-2;//*nNumDrow;
		}
		else
		{
			sizeResult.cx-=_afxDropDownWidth*nNumDrow;
		}
	}
	else
	{
		if (bVertDocked)
			sizeResult.cy+=_afxDropDownWidth/2;
	}
	return sizeResult;
}
Ejemplo n.º 8
0
LRESULT WinParent::MainWindowLoop(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	// 	for (std::map<HWND, OGLWindow*>::iterator it=m_childArr.begin(); it!=m_childArr.end(); ++it)
	// 	{
	// // 		if (message == WM_KEYUP || it->first == hWnd)
	// // 		{
	// 			child = it->second;
	// /*		}*/
	// 	}
	// 	OGLWindow *child = NULL;
	// 	for (std::map<HWND, OGLWindow*>::iterator it=m_childMap.begin(); it!=m_childMap.end(); ++it)
	// 	{
	//  		if (message == WM_KEYUP || it->first == hWnd)
	//  		{
	// 			child = it->second;
	// 		}
	// 
	switch(message)
	{
	case WM_CREATE:
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_PAINT:
		m_childArr[m_curChild]->Display();
		break;
	case WM_SIZE:
		{
			if (m_curChild < 0) break;
			int nWidth = LOWORD(lParam);
			int nHight = HIWORD(lParam);
			m_childArr[m_curChild]->Reshape(nWidth, nHight);
			m_childArr[m_curChild]->Show();
		}
		break;
	case WM_KEYUP:
		switch(wParam)
		{
		case VK_ESCAPE:
			exit(EXIT_SUCCESS);
			break;
		case VK_F2:
			{
				int nWidth = m_childArr[m_curChild]->getWidth();
				int nHight = m_childArr[m_curChild]->getHeight();
				m_childArr[m_curChild]->Hide();
				m_curChild--;
				if (m_curChild < 0)
					m_curChild = EXAMPLES_QTY-1;
				SetWindowText(m_hwnd, m_childArr[m_curChild]->getTitle());
				m_childArr[m_curChild]->Reshape(nWidth, nHight);
				m_childArr[m_curChild]->Show();
			}
			break;
		case VK_F3:
			{
				int nWidth = m_childArr[m_curChild]->getWidth();
				int nHight = m_childArr[m_curChild]->getHeight();
				m_childArr[m_curChild]->Hide();
				m_curChild++;
				if (m_curChild >= EXAMPLES_QTY)
					m_curChild = 0;
				SetWindowText(m_hwnd, m_childArr[m_curChild]->getTitle());
				m_childArr[m_curChild]->Reshape(nWidth, nHight);
				m_childArr[m_curChild]->Show();
			}
			break;
		default:
			m_childArr[m_curChild]->keyboard(wParam, 0, 0);
			break;
		}
		break;
	case WM_SIZING:
		{
// 			if (m_curChild < 0) break;
// 			int nWidth = LOWORD(lParam);
// 			int nHight = HIWORD(lParam);
// 			m_childArr[m_curChild]->Reshape(nWidth, nHight);
// 			m_childArr[m_curChild]->Show();
		}
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
Ejemplo n.º 9
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;
    PAINTSTRUCT ps;
    HDC hdc;

#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
    static SHACTIVATEINFO s_sai;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP
	
    switch (message) 
    {
        case WM_COMMAND:
            wmId    = LOWORD(wParam); 
            wmEvent = HIWORD(wParam); 
            // Parse the menu selections:
            switch (wmId)
            {
#ifndef WIN32_PLATFORM_WFSP
                case IDM_HELP_ABOUT:
                    DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, About);
                    break;
#endif // !WIN32_PLATFORM_WFSP
#ifndef SHELL_AYGSHELL
                case IDM_FILE_EXIT:
                    DestroyWindow(hWnd);
                    break;
#endif // !SHELL_AYGSHELL
#ifdef WIN32_PLATFORM_WFSP
                case IDM_OK:
                    DestroyWindow(hWnd);
                    break;
#endif // WIN32_PLATFORM_WFSP
#ifdef WIN32_PLATFORM_PSPC
                case IDM_OK:
                    SendMessage (hWnd, WM_CLOSE, 0, 0);				
                    break;
#endif // WIN32_PLATFORM_PSPC
                default:
                    return DefWindowProc(hWnd, message, wParam, lParam);
            }
            break;
        case WM_CREATE:
#ifndef SHELL_AYGSHELL
            g_hWndCommandBar = CommandBar_Create(g_hInst, hWnd, 1);
            CommandBar_InsertMenubar(g_hWndCommandBar, g_hInst, IDR_MENU, 0);
            CommandBar_AddAdornments(g_hWndCommandBar, 0, 0);
#endif // !SHELL_AYGSHELL
#ifdef SHELL_AYGSHELL
            SHMENUBARINFO mbi;

            memset(&mbi, 0, sizeof(SHMENUBARINFO));
            mbi.cbSize     = sizeof(SHMENUBARINFO);
            mbi.hwndParent = hWnd;
            mbi.nToolBarId = IDR_MENU;
            mbi.hInstRes   = g_hInst;

            if (!SHCreateMenuBar(&mbi)) 
            {
                g_hWndMenuBar = NULL;
            }
            else
            {
                g_hWndMenuBar = mbi.hwndMB;
            }

#ifndef WIN32_PLATFORM_WFSP
            // Initialize the shell activate info structure
            memset(&s_sai, 0, sizeof (s_sai));
            s_sai.cbSize = sizeof (s_sai);
#endif // !WIN32_PLATFORM_WFSP
#endif // SHELL_AYGSHELL
            break;
        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            
            // TODO: Add any drawing code here...
            
            EndPaint(hWnd, &ps);
            break;
        case WM_DESTROY:
#ifndef SHELL_AYGSHELL
            CommandBar_Destroy(g_hWndCommandBar);
#endif // !SHELL_AYGSHELL
#ifdef SHELL_AYGSHELL
            CommandBar_Destroy(g_hWndMenuBar);
#endif // SHELL_AYGSHELL
            PostQuitMessage(0);
            break;

#if defined(SHELL_AYGSHELL) && !defined(WIN32_PLATFORM_WFSP)
        case WM_ACTIVATE:
            // Notify shell of our activate message
            SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
            break;
        case WM_SETTINGCHANGE:
            SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
            break;
#endif // SHELL_AYGSHELL && !WIN32_PLATFORM_WFSP

        default:
            return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Ejemplo n.º 10
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND h;
	static int aps = 0;
	switch (msg)
	{
	case WM_CLOSE:
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		{
		case ID_button1:
		{
						   int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), hwnd, AboutDlgProc);
						   if (ret == -1) MessageBox(hwnd, "Eroare creare dialog", "Eroare", MB_OK | MB_ICONERROR);
						   break;
		}
		case ID_button2:
		{
						   if (siteslist->curent != NULL)
						   {
							   int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG2), hwnd, dlg);
							   if (ret == -1) MessageBox(hwnd, "Eroare creare dialog", "Eroare", MB_OK | MB_ICONERROR);
						   }
						   else MessageBox(hwnd, "Nu exista niciun site in lista!", "Atentionare", MB_OK|MB_ICONEXCLAMATION);
						   break;
		}
		case ID_button3:
		{
						   if (siteslist->curent != NULL)
						   {
							   int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG3), hwnd, dlg2);
							   if (ret == -1) MessageBox(hwnd, "Eroare creare dialog", "Eroare", MB_OK | MB_ICONERROR);
						   }
						   else MessageBox(hwnd, "Nu exista niciun site in lista!", "Atentionare", MB_OK | MB_ICONEXCLAMATION);
						   break;
		}
		case ID_button_ex:
		{
							 DestroyWindow(hwnd);
							 break;
		}
		}
		default:
			break;
		}
	case WM_CREATE:
	{
					  ////////Buton adaugare site
					  h = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Adauga site", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 10, 90, 40, hwnd, (HMENU)ID_button1, NULL, NULL);
					  if (h == NULL) MessageBox(hwnd, "Butonul1 nu a fost creat", "Eroare", MB_OK | MB_ICONERROR);

					  /////////////Buton afisare site
					  h = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Afiseaza site", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 60, 90, 40, hwnd, (HMENU)ID_button2, NULL, NULL);
					  if (h == NULL) MessageBox(hwnd, "Butonul2 nu a fost creat", "Eroare", MB_OK | MB_ICONERROR);

					  /////////////Buton cautare produs
					  h = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "Cauta produs", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 110, 90, 40, hwnd, (HMENU)ID_button3, NULL, NULL);
					  if (h == NULL) MessageBox(hwnd, "Butonul3 nu a fost creat", "Eroare", MB_OK | MB_ICONERROR);

					  ///////Buton exit
					  h = CreateWindowEx(WS_EX_WINDOWEDGE, "BUTTON", "EXIT", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, 10, 160, 90, 40, hwnd, (HMENU)ID_button_ex, NULL, NULL);
					  if (h == NULL) MessageBox(hwnd, "Butonul exit nu a fost creat", "Eroare", MB_OK | MB_ICONERROR);
	}
	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;
}
Ejemplo n.º 11
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static BOOL bOpened = FALSE ;
     HDC         hdc ;
     HMENU       hMenu ;
     int         i, iNumDevs, iPitchBend, cxClient, cyClient ;
     MIDIOUTCAPS moc ;
     PAINTSTRUCT ps ;
     SIZE        size ;
     TCHAR       szBuffer [16] ;
     
     switch (message)
     {
     case WM_CREATE:
               // Get size of capital letters in system font
          
          hdc = GetDC (hwnd) ;
          
          GetTextExtentPoint (hdc, TEXT ("M"), 1, &size) ;
          cxCaps = size.cx ;
          cyChar = size.cy ;
          
          ReleaseDC (hwnd, hdc) ;
          
               // Initialize "Volume" scroll bar
          
          SetScrollRange (hwnd, SB_HORZ, 1, 127, FALSE) ;
          SetScrollPos   (hwnd, SB_HORZ, iVelocity, TRUE) ;
          
               // Initialize "Pitch Bend" scroll bar
          
          SetScrollRange (hwnd, SB_VERT, 0, 16383, FALSE) ;
          SetScrollPos   (hwnd, SB_VERT, 8192, TRUE) ;
          
               // Get number of MIDI output devices and set up menu
          
          if (0 == (iNumDevs = midiOutGetNumDevs ()))
          {
               MessageBeep (MB_ICONSTOP) ;
               MessageBox (hwnd, TEXT ("No MIDI output devices!"),
                                 szAppName, MB_OK | MB_ICONSTOP) ;
               return -1 ;
          }
          SetMenu (hwnd, CreateTheMenu (iNumDevs)) ;
          return 0 ;
          
     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
          
          xOffset = (cxClient - 25 * 3 * cxCaps / 2) / 2 ;
          yOffset = (cyClient - 11 * cyChar) / 2 + 5 * cyChar ;
          return 0 ;
          
     case WM_COMMAND:
          hMenu = GetMenu (hwnd) ;
          
              // "Open" menu command
          
          if (LOWORD (wParam) == IDM_OPEN && !bOpened)
          {
               if (midiOutOpen (&hMidiOut, iDevice, 0, 0, 0))
               {
                    MessageBeep (MB_ICONEXCLAMATION) ;
                    MessageBox (hwnd, TEXT ("Cannot open MIDI device"),
                                szAppName, MB_OK | MB_ICONEXCLAMATION) ;
               }
               else
               {
                    CheckMenuItem (hMenu, IDM_OPEN,  MF_CHECKED) ;
                    CheckMenuItem (hMenu, IDM_CLOSE, MF_UNCHECKED) ;
                    
                    MidiSetPatch (hMidiOut, iChannel, iVoice) ;
                    bOpened = TRUE ;
               }
          }
          
               // "Close" menu command
          
          else if (LOWORD (wParam) == IDM_CLOSE && bOpened)
          {
               CheckMenuItem (hMenu, IDM_OPEN,  MF_UNCHECKED) ;
               CheckMenuItem (hMenu, IDM_CLOSE, MF_CHECKED) ;
               
                    // Turn all keys off and close device
               
               for (i = 0 ; i < 16 ; i++)
                    MidiOutMessage (hMidiOut, 0xB0, i, 123, 0) ;
               
               midiOutClose (hMidiOut) ;
               bOpened = FALSE ;
          }
          
               // Change MIDI "Device" menu command
          
          else if (LOWORD (wParam) >= IDM_DEVICE - 1 && 
                   LOWORD (wParam) <  IDM_CHANNEL)
          {
               CheckMenuItem (hMenu, IDM_DEVICE + iDevice, MF_UNCHECKED) ;
               iDevice = LOWORD (wParam) - IDM_DEVICE ;
               CheckMenuItem (hMenu, IDM_DEVICE + iDevice, MF_CHECKED) ;
               
                    // Close and reopen MIDI device
               
               if (bOpened)
               {
                    SendMessage (hwnd, WM_COMMAND, IDM_CLOSE, 0L) ;
                    SendMessage (hwnd, WM_COMMAND, IDM_OPEN,  0L) ;
               }
          }
          
               // Change MIDI "Channel" menu command
          
          else if (LOWORD (wParam) >= IDM_CHANNEL && 
                   LOWORD (wParam) <  IDM_VOICE)
          {
               CheckMenuItem (hMenu, IDM_CHANNEL + iChannel, MF_UNCHECKED);
               iChannel = LOWORD (wParam) - IDM_CHANNEL ;
               CheckMenuItem (hMenu, IDM_CHANNEL + iChannel, MF_CHECKED) ;
               
               if (bOpened)
                    MidiSetPatch (hMidiOut, iChannel, iVoice) ;
          }
          
               // Change MIDI "Voice" menu command
          
          else if (LOWORD (wParam) >= IDM_VOICE)
          {
               CheckMenuItem (hMenu, IDM_VOICE + iVoice, MF_UNCHECKED) ;
               iVoice = LOWORD (wParam) - IDM_VOICE ;
               CheckMenuItem (hMenu, IDM_VOICE + iVoice, MF_CHECKED) ;
               
               if (bOpened)
                    MidiSetPatch (hMidiOut, iChannel, iVoice) ;
          }
          
          InvalidateRect (hwnd, NULL, TRUE) ;
          return 0 ;
          
          // Process a Key Up or Key Down message
          
     case WM_KEYUP:
     case WM_KEYDOWN:
          hdc = GetDC (hwnd) ;
          
          if (bOpened)
               ProcessKey (hdc, message, lParam) ;
          
          ReleaseDC (hwnd, hdc) ;
          return 0 ;
          
          // For Escape, turn off all notes and repaint
          
     case WM_CHAR:
          if (bOpened && wParam == 27)
          {
               for (i = 0 ; i < 16 ; i++)
                    MidiOutMessage (hMidiOut, 0xB0, i, 123, 0) ;
               
               InvalidateRect (hwnd, NULL, TRUE) ;
          }
          return 0 ;
          
          // Horizontal scroll: Velocity
          
     case WM_HSCROLL:
          switch (LOWORD (wParam))
          {
          case SB_LINEUP:         iVelocity -= 1 ;  break ;
          case SB_LINEDOWN:       iVelocity += 1 ;  break ;
          case SB_PAGEUP:         iVelocity -= 8 ;  break ;
          case SB_PAGEDOWN:       iVelocity += 8 ;  break ;
          case SB_THUMBPOSITION:  iVelocity = HIWORD (wParam) ;  break ;
          default:                return 0 ;
          }
          iVelocity = max (1, min (iVelocity, 127)) ;
          SetScrollPos (hwnd, SB_HORZ, iVelocity, TRUE) ;
          return 0 ;
          
          // Vertical scroll:  Pitch Bend
     
     case WM_VSCROLL:
          switch (LOWORD (wParam))
          {
          case SB_THUMBTRACK:    iPitchBend = 16383 - HIWORD (wParam) ;  break ;
          case SB_THUMBPOSITION: iPitchBend = 8191 ;                     break ;
          default:               return 0 ;
          }
          iPitchBend = max (0, min (iPitchBend, 16383)) ;
          SetScrollPos (hwnd, SB_VERT, 16383 - iPitchBend, TRUE) ;
          
          if (bOpened)
               MidiPitchBend (hMidiOut, iChannel, iPitchBend) ;
          return 0 ;
     
     case WM_PAINT:
          hdc = BeginPaint (hwnd, &ps) ;
          
          for (i = 0 ; i < NUMSCANS ; i++)
               if (key[i].xPos != -1)
                    DrawKey (hdc, i, FALSE) ;
               
          midiOutGetDevCaps (iDevice, &moc, sizeof (MIDIOUTCAPS)) ;
          wsprintf (szBuffer, TEXT ("Channel %i"), iChannel + 1) ;
     
          TextOut (hdc, cxCaps, 1 * cyChar, 
                        bOpened ? TEXT ("Open") : TEXT ("Closed"),
                        bOpened ? 4 : 6) ;
          TextOut (hdc, cxCaps, 2 * cyChar, moc.szPname,
                        lstrlen (moc.szPname)) ;
          TextOut (hdc, cxCaps, 3 * cyChar, szBuffer, lstrlen (szBuffer)) ;
          TextOut (hdc, cxCaps, 4 * cyChar,
                        fam[iVoice / 8].inst[iVoice % 8].szInst,
               lstrlen (fam[iVoice / 8].inst[iVoice % 8].szInst)) ;
     
          EndPaint (hwnd, &ps) ;
          return 0 ;
               
     case WM_DESTROY :
          SendMessage (hwnd, WM_COMMAND, IDM_CLOSE, 0L) ;
          PostQuitMessage (0) ;
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Ejemplo n.º 12
0
/* Main window procedure */
static LRESULT CALLBACK
WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch(uMsg) {
        case WM_NOTIFY:
            return HandleNotify(hwnd, (NMHDR*) lParam);

        case WM_SIZE:
            if(wParam == SIZE_RESTORED  ||  wParam == SIZE_MAXIMIZED)
                HandleResize(hwnd, LOWORD(lParam), HIWORD(lParam));
            return 0;

        case WM_SETFOCUS:
            SetFocus(hwndHtml);
            return 0;

        case WM_COMMAND:
            switch(LOWORD(wParam)) {
                case IDM_BACK:    SendMessage(hwndHtml, MC_HM_GOBACK, TRUE, 0); break;
                case IDM_FORWARD: SendMessage(hwndHtml, MC_HM_GOBACK, FALSE, 0); break;
            }
            break;

        case WM_CREATE:
        {
            HIMAGELIST tbImgList;
            TBBUTTON tbButtons[2];

            /* Create the html control */
            hwndHtml = CreateWindow(MC_WC_HTML, INITIAL_URL, WS_CHILD | WS_VISIBLE | WS_TABSTOP,
                                    0, 0, 0, 0, hwnd, (HMENU) ID_HTML, hInst, NULL);

            /* Create toolbar control. It provides the 'back' and 'forward'
             * buttons for walking the browser history. */
            hwndToolbar = CreateWindow(TOOLBARCLASSNAME, NULL, WS_CHILD | WS_BORDER | WS_VISIBLE,
                                    0, 0, 0, 0, hwnd, (HMENU) ID_TOOLBAR, hInst, NULL);
            SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
            memset(tbButtons, 0, sizeof(tbButtons));
            tbButtons[0].iBitmap = 0;
            tbButtons[0].idCommand = IDM_BACK;
            tbButtons[0].fsStyle = BTNS_BUTTON;
            tbButtons[1].iBitmap = 1;
            tbButtons[1].idCommand = IDM_FORWARD;
            tbButtons[1].fsStyle = BTNS_BUTTON;
            SendMessage(hwndToolbar, TB_ADDBUTTONS, 2, (LPARAM) tbButtons);
            tbImgList = ImageList_LoadImage(hInst, _T("toolbar"), 24, 1, RGB(255,0,255),
                                    IMAGE_BITMAP, LR_CREATEDIBSECTION);
            SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM) tbImgList);

            /* Create status control. We show status info the HTML control
             * sends to us via WM_NOTIFY. */
            hwndStatus = CreateWindow(STATUSCLASSNAME, NULL, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
                                    0, 0, 0, 0, hwnd, (HMENU) ID_STATUS, hInst, NULL);
            return 0;
        }

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

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Ejemplo n.º 13
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HDC hDC;
	PAINTSTRUCT Ps;


	switch (msg)
	{

	case WM_PAINT:
	{	HFONT	    font;
	hDC = BeginPaint(hwnd, &Ps);

	HPEN hLinePen;
	COLORREF qLineColor;
	qLineColor = RGB(255, 0, 0);
	hLinePen = CreatePen(PS_SOLID, 7, qLineColor);
	{
		int x1 = 10, x2 = 10, x3 = 1260, x4 = 680;

		font = CreateFont(3, 3, 0, 0,
			FW_NORMAL, FALSE, FALSE, FALSE,
			ANSI_CHARSET, OUT_DEFAULT_PRECIS,
			CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
			DEFAULT_PITCH | FF_ROMAN,
			"Times New Roman");
		SelectObject(hDC, font);
		TextOut(hDC, 1320, 689, "Johnny", 6);
		DeleteObject(font);
		
		HBRUSH      NewBrush;	
		POINT       Pt[4];
		NewBrush = CreateSolidBrush(RGB(255, 255, 255));
		SelectObject(hDC, NewBrush);
		Pt[0].x = x1; Pt[0].y = x2;
		Pt[1].x = x3; Pt[1].y = x2;
		Pt[2].x = x3; Pt[2].y = x4;
		Pt[3].x = x1; Pt[3].y = x4;
		Polygon(hDC, Pt, 4);
		DeleteObject(NewBrush);		

	}
	EndPaint(hwnd, &Ps);
	break; }

	case WM_LBUTTONDOWN:
	{	if (ok_start == 1)
	{
		wchar_t waCoord[20];
		wsprintf((LPSTR)waCoord, ("(%i, %i)"), LOWORD(lParam), HIWORD(lParam));
		int msg_return = MessageBox(hwnd, (LPCSTR)waCoord, ("Ai ales coordonatele:"), MB_OKCANCEL);
		{	if (msg_return == IDOK)
		{
			poz_x = LOWORD(lParam);
			poz_y = HIWORD(lParam);
			hDC = BeginPaint(hwnd, &Ps);
			hDC = GetWindowDC(hwnd);
			if ((poz_x<10 || poz_y<10 || poz_x>1260 || poz_y>680))
			{ 
				poz_x = poz_y = 0; 
				MessageBox(NULL,
					(LPCSTR)"Alege un punct din zona incadrata!",
					"Atentie!!!",
					MB_ICONERROR);
				break;
			}
			TextOut(hDC, poz_x + 7, poz_y + 23, "x", 1);

			/*   char v[7];
			   itoa(poz_x, v, 10);

			   TextOut(hDC, poz_x + 7, poz_y + 23, v, lung_nr(poz_x));
			   TextOut(hDC, poz_x + 38, poz_y + 23, ";", 1);
			   itoa(poz_y, v, 10);
			   TextOut(hDC, poz_x + 40, poz_y + 23, v, lung_nr(poz_y));
			   EndPaint(hwnd, &Ps);*/
			ReleaseDC(hwnd, hDC);
		}
		if (msg_return == IDCANCEL)
		{
			int poz_x = 0;
			int poz_y = 0;
		}

		}

	}
	else MessageBox(NULL,
		(LPCSTR)"Nu ai citit instructiunile!",
		"Atentie!!!",
		MB_ICONERROR);
	break;
	}
	case WM_CREATE:
	{HICON hIcon;
	
	hIcon = (HICON)LoadImage(NULL, "tr.ico", IMAGE_ICON, 16, 16,0);

		CreateWindowEx(NULL,
		"BUTTON",
		"Start!",
		WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		1265,
		10,
		80,
		24,
		hwnd,
		(HMENU)IDC_MAIN_BUTTON,
		GetModuleHandle(NULL),
		NULL);
	CreateWindowEx(NULL,
		"BUTTON",
		"Localizare",
		WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		1265,
		50,
		80,
		24,
		hwnd,
		(HMENU)IDC_LOCATE_BUTTON,
		GetModuleHandle(NULL),
		NULL);
	CreateWindowEx(NULL,
		"BUTTON",
		"Adresa",
		WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		1265,
		90,
		80,
		24,
		hwnd,
		(HMENU)IDC_ADRESS_BUTTON,
		GetModuleHandle(NULL),
		NULL);
	CreateWindowEx(NULL,
		"BUTTON",
		"Instructiuni",
		WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
		1265,
		130,
		80,
		24,
		hwnd,
		(HMENU)IDC_HELP_BUTTON,
		GetModuleHandle(NULL),
		NULL);


	}
		break;
	case WM_COMMAND:
	{ switch (wParam)
	{
	case IDC_MAIN_BUTTON:
	{	HFONT	    font;
	hDC = BeginPaint(hwnd, &Ps);
	hDC = GetWindowDC(hwnd);
	root = radacina("coord.txt");
	poz_x = 0; poz_y = 0;
	afisare_arbore(root, hDC);
	ok_start = 1;
	EndPaint(hwnd, &Ps);
	ReleaseDC(hwnd, hDC);
	break; }

	case IDC_HELP_BUTTON:
	{	
	MessageBox(NULL,
		(LPCSTR)fisier_help("ajutor.txt"),
		"Ajutor",
		MB_ICONINFORMATION);
	break; }
	case IDC_LOCATE_BUTTON:
	{if (poz_x != 0 && poz_y != 0)

	{
		MessageBox(NULL,
			(LPCSTR)nume_localizare(root, poz_x, poz_y),
			"Zona in care te aflii este:",
			MB_ICONINFORMATION);
	}
	else MessageBox(NULL,
		(LPCSTR)"Nu ai selectat un punct din zona incadrata!\nAlege mai intai un punct din zona incadrata!",
		"Atentie!!!",
		MB_ICONERROR);
	}	break;
	
	case IDC_ADRESS_BUTTON:
	{if (poz_x != 0 && poz_y != 0)

	{
		MessageBox(NULL,
			(LPCSTR)nume_adresa(root, poz_x, poz_y),
			"Adresa zonei in care te aflii este:",
			MB_ICONINFORMATION);
	}
	 else MessageBox(NULL,
		(LPCSTR)"Nu ai selectat un punct din zona incadrata!\nAlege mai intai un punct din zona incadrata!",
		"Atentie!!!",
		MB_ICONERROR);
	}
	break; }
	}break;
	case WM_DESTROY:
		PostQuitMessage(WM_QUIT);
		break;

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
	}
	return 0;


}
Ejemplo n.º 14
0
LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWORD lParam)
{
    switch (uMsg)
    {
    case WM_CREATE:
    {
        //record class for future usage
        LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
        CMainGui * _this = (CMainGui *)lpcs->lpCreateParams;
        SetProp(hWnd, "Class", _this);

        _this->m_hMainWindow = hWnd;
        _this->CreateStatusBar();

        //Move the Main window to the location last executed from or center the window
        int X = (GetSystemMetrics(SM_CXSCREEN) - _this->Width()) / 2;
        int	Y = (GetSystemMetrics(SM_CYSCREEN) - _this->Height()) / 2;

        g_Settings->LoadDword(UserInterface_MainWindowTop, (uint32_t &)Y);
        g_Settings->LoadDword(UserInterface_MainWindowLeft, (uint32_t &)X);

        _this->SetPos(X, Y);

        _this->ChangeWinSize(640, 480);
    }
    break;
    case WM_SYSCOMMAND:
        switch (wParam) {
        case SC_SCREENSAVE:
        case SC_MONITORPOWER:
        {
            CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
            if (_this &&
                    _this->bCPURunning() &&
                    !g_Settings->LoadBool(GameRunning_CPU_Paused) &&
                    g_Settings->LoadDword(Setting_DisableScrSaver))
            {
                return 0;
            }
        }
        break;
        case SC_MAXIMIZE:
        {
            CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
            if (_this)
            {
                if (_this->RomBrowserVisible())
                {
                    _this->RomBrowserMaximize(true);
                }
            }
        }
        break;
        }
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
        break;
    case WM_MOVE:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");

        if (!_this->m_bMainWindow ||
                !_this->m_Created ||
                _this->m_AttachingMenu ||
                _this->m_MakingVisible ||
                IsIconic(hWnd) ||
                _this->ShowingRomBrowser())
        {
            break;
        }

        if (IsZoomed(hWnd))
        {
            if (_this->RomBrowserVisible())
            {
                // save that browser is maximized
            }
            break;
        }

        //get the current position of the window
        RECT WinRect;
        GetWindowRect(hWnd, &WinRect);

        //save the location of the window
        if (_this->RomBrowserVisible())
        {
            _this->m_SaveRomBrowserPos = true;
            _this->m_SaveRomBrowserTop = WinRect.top;
            _this->m_SaveRomBrowserLeft = WinRect.left;
        }
        else
        {
            _this->m_SaveMainWindowPos = true;
            _this->m_SaveMainWindowTop = WinRect.top;
            _this->m_SaveMainWindowLeft = WinRect.left;
        }
        KillTimer(hWnd, Timer_SetWindowPos);
        SetTimer(hWnd, Timer_SetWindowPos, 1000, NULL);
    }
    if (CGuiSettings::bCPURunning() && g_BaseSystem)
    {
        if (g_Plugins->Gfx() && g_Plugins->Gfx()->MoveScreen)
        {
            WriteTrace(TraceGFXPlugin, TraceDebug, "Starting");
            g_Plugins->Gfx()->MoveScreen((int)(short)LOWORD(lParam), (int)(short)HIWORD(lParam));
            WriteTrace(TraceGFXPlugin, TraceDebug, "Done");
        }
    }
    break;
    case WM_TIMER:
        if (wParam == Timer_SetWindowPos)
        {
            KillTimer(hWnd, Timer_SetWindowPos);
            CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
            _this->SaveWindowLoc();
            break;
        }
        break;
    case WM_SIZE:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this) {
            _this->Resize(wParam, LOWORD(lParam), HIWORD(lParam));
        }
        if (_this)
        {
            if (wParam == SIZE_MAXIMIZED)
            {
                if (_this->RomBrowserVisible())
                {
                    _this->RomBrowserMaximize(true);
                }
            }
            _this->ResizeRomList(LOWORD(lParam), HIWORD(lParam));
        }
        if (_this)
        {
            if (wParam == SIZE_RESTORED && _this->RomBrowserVisible())
            {
                _this->RomBrowserMaximize(false);
            }
        }
    }
    break;
    case WM_NOTIFY:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this == NULL || !_this->RomBrowserVisible() || !_this->RomListNotify(wParam, lParam))
        {
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
        }
    }
    break;
    case WM_DRAWITEM:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this)
        {
            if (!_this->RomListDrawItem(wParam, lParam))
            {
                return DefWindowProc(hWnd, uMsg, wParam, lParam);
            }
        }
    }
    break;
    case WM_PAINT:
    {
        //			CMainGui * _this = (CMainGui *)GetProp(hWnd,"Class");
        //			CN64System * System  = _this->m_System;

        //			if (bCPURunning() && Settings->Load(CPU_Paused)) {
        //				CPlugins * Plugins = System->Plugins();
        //				if (Plugins->Gfx()->DrawScreen) {
        //					Plugins->Gfx()->DrawScreen();
        //				}
        //			}
        ValidateRect(hWnd, NULL);
    }
    break;
    case WM_KEYUP:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");

        if (_this->m_bMainWindow && bCPURunning())
        {
            if (g_BaseSystem)
            {
                if (g_Plugins && g_Plugins->Control()->WM_KeyUp) {
                    g_Plugins->Control()->WM_KeyUp(wParam, lParam);
                }
            }
        }
    }
    break;
    case WM_KEYDOWN:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");

        if (_this->m_bMainWindow && bCPURunning())
        {
            if (g_BaseSystem)
            {
                if (g_Plugins && g_Plugins->Control()->WM_KeyDown)
                {
                    g_Plugins->Control()->WM_KeyDown(wParam, lParam);
                }
            }
        }
    }
    break;
    case WM_SETFOCUS:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this->RomBrowserVisible())
        {
            PostMessage(hWnd, WM_BROWSER_TOP, 0, 0);
            break;
        }

        if (_this->m_bMainWindow && bCPURunning() && bAutoSleep())
        {
            if (g_BaseSystem)
            {
                g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_AppGainedFocus);
            }
        }
    }
    break;
    case WM_KILLFOCUS:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this->RomBrowserVisible())
        {
            break;
        }

        if (_this->m_bMainWindow && bCPURunning() && bAutoSleep())
        {
            if (g_BaseSystem)
            {
                g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_AppLostFocus);
            }
        }
    }
    break;
    case WM_ACTIVATEAPP:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        DWORD fActive = (BOOL)wParam;

        if (fActive && _this->RomBrowserVisible())
        {
            PostMessage(hWnd, WM_BROWSER_TOP, 0, 0);
        }
        if (_this->m_bMainWindow && bCPURunning())
        {
            if (!fActive && g_Settings->LoadBool(UserInterface_InFullScreen))
            {
                Notify().WindowMode();
                if (bAutoSleep() && g_BaseSystem)
                {
                    //System->ExternalEvent(PauseCPU_AppLostActiveDelayed );
                }
                break;
            }
            if (bAutoSleep() || fActive)
            {
                if (g_BaseSystem)
                {
                    g_BaseSystem->ExternalEvent(fActive ? SysEvent_ResumeCPU_AppGainedActive : SysEvent_PauseCPU_AppLostActive);
                }
            }
        }
    }
    break;
    case WM_HIDE_CUROSR:
        if (!wParam)
        {
            while (ShowCursor(FALSE) >= 0) {
                Sleep(0);
            }
        }
        else
        {
            while (ShowCursor(TRUE) < 0) {
                Sleep(0);
            }
        }
        break;
    case WM_MAKE_FOCUS:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        _this->BringToTop();
    }
    break;
    case WM_BROWSER_TOP:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        _this->RomBrowserToTop();
    }
    break;
    case WM_RESET_PLUGIN:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this->m_ResetInfo != NULL)
        {
            g_Notify->BreakPoint(__FILE__, __LINE__);
        }
        _this->m_ResetInfo = (RESET_PLUGIN *)lParam;
        _this->m_ResetPlugins = true;
    }
    break;
    case WM_GAME_CLOSED:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        Notify().WindowMode();
        if (g_Settings->LoadDword(RomBrowser_Enabled))
        {
            _this->ShowRomBrowser();
        }
        _this->RefreshMenu();
        _this->MakeWindowOnTop(false);
        _this->SetStatusText(0, L"");
        _this->SetStatusText(1, L"");
    }
    break;
    case WM_COMMAND:
    {
        CMainGui * _this = (CMainGui *)GetProp(hWnd, "Class");
        if (_this == NULL) {
            break;
        }

        switch (LOWORD(wParam)) {
        case ID_POPUPMENU_PLAYGAME:
            g_BaseSystem->RunFileImage(_this->CurrentedSelectedRom());
            break;
        case ID_POPUPMENU_ROMDIRECTORY:
            _this->SelectRomDir();
            break;
        case ID_POPUPMENU_REFRESHROMLIST:
            _this->RefreshRomBrowser();
            break;
        case ID_POPUPMENU_ROMINFORMATION:
        {
            RomInformation Info(_this->CurrentedSelectedRom());
            Info.DisplayInformation(hWnd);
        }
        break;
        case ID_POPUPMENU_EDITSETTINGS:
        case ID_POPUPMENU_EDITCHEATS:
        {
            CN64Rom Rom;
            Rom.LoadN64Image(_this->CurrentedSelectedRom(), true);
            Rom.SaveRomSettingID(true);

            if (LOWORD(wParam) == ID_POPUPMENU_EDITSETTINGS)
            {
                CSettingConfig SettingConfig(true);
                SettingConfig.Display(hWnd);
            }

            if (LOWORD(wParam) == ID_POPUPMENU_EDITCHEATS)
            {
                CCheatsUI * cheatUI = new CCheatsUI;
                g_cheatUI = cheatUI;
                cheatUI->SelectCheats(hWnd, true);
                if (g_cheatUI == cheatUI)
                {
                    g_cheatUI = NULL;
                }
            }

            if (g_Rom)
            {
                g_Rom->SaveRomSettingID(false);
            }
            else
            {
                Rom.ClearRomSettingID();
            }
        }
        break;
        default:
            if (_this->m_Menu)
            {
                if (LOWORD(wParam) > 5000 && LOWORD(wParam) <= 5100)
                {
                    if (g_Plugins->RSP())
                    {
                        g_Plugins->RSP()->ProcessMenuItem(LOWORD(wParam));
                    }
                }
                else if (LOWORD(wParam) > 5100 && LOWORD(wParam) <= 5200)
                {
                    if (g_Plugins->Gfx())
                    {
                        WriteTrace(TraceGFXPlugin, TraceDebug, "Starting");
                        g_Plugins->Gfx()->ProcessMenuItem(LOWORD(wParam));
                        WriteTrace(TraceGFXPlugin, TraceDebug, "Done");
                    }
                }
                else if (LOWORD(wParam) > 5200 && LOWORD(wParam) <= 5300)
                {
                    if (g_Plugins->Gfx() && g_Plugins->Gfx()->OnRomBrowserMenuItem != NULL)
                    {
                        CN64Rom Rom;
                        if (!Rom.LoadN64Image(_this->CurrentedSelectedRom(), true))
                        {
                            break;
                        }
                        Rom.SaveRomSettingID(true);
                        g_Notify->DisplayMessage(0, "");
                        BYTE * RomHeader = Rom.GetRomAddress();
                        WriteTrace(TraceGFXPlugin, TraceDebug, "OnRomBrowserMenuItem - Starting");
                        g_Plugins->Gfx()->OnRomBrowserMenuItem(LOWORD(wParam), hWnd, RomHeader);
                        WriteTrace(TraceGFXPlugin, TraceDebug, "OnRomBrowserMenuItem - Done");
                        if (g_Rom)
                        {
                            g_Rom->SaveRomSettingID(false);
                        }
                        else
                        {
                            g_Settings->SaveString(Game_IniKey, "");
                        }
                    }
                }
                else if (_this->m_Menu->ProcessMessage(hWnd, HIWORD(wParam), LOWORD(wParam)))
                {
                    return true;
                }
            }
        }
    }
    break;
    case WM_DROPFILES:
    {
        char filename[MAX_PATH];

        HDROP hDrop = (HDROP)wParam;
        DragQueryFile(hDrop, 0, filename, sizeof(filename));
        DragFinish(hDrop);

        CN64System::RunFileImage(filename);
    }
    break;
    case WM_DESTROY:
        WriteTrace(TraceUserInterface, TraceDebug, "WM_DESTROY - start");
        {
            CMainGui   * _this = (CMainGui *)GetProp(hWnd, "Class");
            if (_this->m_bMainWindow)
            {
                Notify().WindowMode();
            }
            _this->m_hMainWindow = NULL;
            WriteTrace(TraceUserInterface, TraceDebug, "WM_DESTROY - 1");
            if (_this->m_bMainWindow)
            {
                _this->SaveRomListColoumnInfo();
                WriteTrace(TraceUserInterface, TraceDebug, "WM_DESTROY - 2");
                _this->SaveWindowLoc();
            }
        }
        WriteTrace(TraceUserInterface, TraceDebug, "WM_DESTROY - 3");
        RemoveProp(hWnd, "Class");
        WriteTrace(TraceUserInterface, TraceDebug, "WM_DESTROY - 4");
        PostQuitMessage(0);
        WriteTrace(TraceUserInterface, TraceDebug, "WM_DESTROY - Done");
        break;
    default:
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    return TRUE;
}
Ejemplo n.º 15
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    
    PAINTSTRUCT ps;
    HDC hdc;
    
    switch (message) 
    {
    case WM_CREATE:
        {
            if (!hmWnd)
                hmWnd = hWnd;

            hdc = GetDC(hWnd);
            CBIT = GetDeviceCaps(hdc, BITSPIXEL);    
            CBYTE = CBIT/8;
            ReleaseDC(hWnd, hdc);
            
            buffer = malloc(width*height*CBYTE);
            bmp.bmType = 0;
            bmp.bmWidth = width;
            bmp.bmHeight = height;
            bmp.bmWidthBytes = width*CBYTE;
            bmp.bmPlanes = 1;
            bmp.bmBitsPixel = CBIT;
            bmp.bmBits = buffer;
            
            if (CBYTE == 4)
                fmt = COLOR_FORMAT_BGRA;
            else if (CBYTE == 3)
                fmt = COLOR_FORMAT_BGR;
            else if (CBYTE == 2)
                fmt = COLOR_FORMAT_RGB565;

            ps_initialize();

            canvas = ps_canvas_create_with_data(buffer, fmt, width, height, width*CBYTE);
            context = ps_context_create(canvas, 0);
            on_init(context, width, height);    
        }
        break;
    case WM_PAINT:
        {
            HDC mdc;
            HGDIOBJ h;
            hdc = BeginPaint(hWnd, &ps);
            
            on_draw(context);
            
            mdc = CreateCompatibleDC(hdc);
            hbmp = CreateBitmapIndirect(&bmp);
            h = SelectObject(mdc, hbmp);
            BitBlt(hdc, 0, 0, width, height, mdc, 0, 0, SRCCOPY);
            SelectObject(mdc, h);
            DeleteObject(hbmp);
            DeleteDC(mdc);
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_TIMER:
        on_timer();
        break;
    case WM_SIZE:
        {
            ps_canvas* old_canvas = 0;
            width = LOWORD(lParam);
            height = HIWORD(lParam);
            free(buffer);

            if (width < 1)
                width = 1;
            if (height < 1)
                height = 1;

            buffer = malloc(width*height*CBYTE);
            bmp.bmType = 0;
            bmp.bmWidth = width;
            bmp.bmHeight = height;
            bmp.bmWidthBytes = width*CBYTE;
            bmp.bmPlanes = 1;
            bmp.bmBitsPixel = CBIT;
            bmp.bmBits = buffer;

            canvas = ps_canvas_create_with_data(buffer, fmt, width, height, width*CBYTE);
            old_canvas = ps_context_set_canvas(context, canvas);
            ps_canvas_unref(old_canvas);
            on_size(width, height);
        }
        break;
    case WM_ERASEBKGND:
        break;
    case WM_LBUTTONDOWN:
            on_mouse_event(LEFT_BUTTON_DOWN, (int)wParam, LOWORD(lParam), HIWORD(lParam));
        break;
    case WM_MOUSEMOVE:
            on_mouse_event(MOUSE_MOVE, (int)wParam, LOWORD(lParam), HIWORD(lParam));
        break;
    case WM_KEYDOWN:
            on_key_event(KEY_EVENT_DOWN, (int)wParam);
        break;
    case WM_KEYUP:
            on_key_event(KEY_EVENT_UP, (int)wParam);
        break;
    case WM_DESTROY:
        {
            on_term(context);
            ps_context_unref(context);
            ps_canvas_unref(canvas);
            ps_shutdown();
            free(buffer);
            PostQuitMessage(0);
        }
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}
Ejemplo n.º 16
0
LRESULT D3DApp::msgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	// WM_ACTIVATE is sent when the window is activated or deactivated.  
	// We pause the game when the window is deactivated and unpause it 
	// when it becomes active.  
	case WM_ACTIVATE:
		if( LOWORD(wParam) == WA_INACTIVE )
		{
			mAppPaused = true;
			mTimer.stop();
		}
		else
		{
			mAppPaused = false;
			mTimer.start();
		}
		return 0;

	// WM_SIZE is sent when the user resizes the window.  
	case WM_SIZE:
		// Save the new client area dimensions.
		mClientWidth  = LOWORD(lParam);
		mClientHeight = HIWORD(lParam);
		if( md3dDevice )
		{
			if( wParam == SIZE_MINIMIZED )
			{
				mAppPaused = true;
				mMinimized = true;
				mMaximized = false;
			}
			else if( wParam == SIZE_MAXIMIZED )
			{
				mAppPaused = false;
				mMinimized = false;
				mMaximized = true;
				onResize();
			}
			else if( wParam == SIZE_RESTORED )
			{
				
				// Restoring from minimized state?
				if( mMinimized )
				{
					mAppPaused = false;
					mMinimized = false;
					onResize();
				}

				// Restoring from maximized state?
				else if( mMaximized )
				{
					mAppPaused = false;
					mMaximized = false;
					onResize();
				}
				else if( mResizing )
				{
					// If user is dragging the resize bars, we do not resize 
					// the buffers here because as the user continuously 
					// drags the resize bars, a stream of WM_SIZE messages are
					// sent to the window, and it would be pointless (and slow)
					// to resize for each WM_SIZE message received from dragging
					// the resize bars.  So instead, we reset after the user is 
					// done resizing the window and releases the resize bars, which 
					// sends a WM_EXITSIZEMOVE message.
				}
				else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
				{
					onResize();
				}
			}
		}
		return 0;

	// WM_EXITSIZEMOVE is sent when the user grabs the resize bars.
	case WM_ENTERSIZEMOVE:
		mAppPaused = true;
		mResizing  = true;
		mTimer.stop();
		return 0;

	// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
	// Here we reset everything based on the new window dimensions.
	case WM_EXITSIZEMOVE:
		mAppPaused = false;
		mResizing  = false;
		mTimer.start();
		onResize();
		return 0;
 
	// WM_DESTROY is sent when the window is being destroyed.
	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;

	// The WM_MENUCHAR message is sent when a menu is active and the user presses 
	// a key that does not correspond to any mnemonic or accelerator key. 
	case WM_MENUCHAR:
        // Don't beep when we alt-enter.
        return MAKELRESULT(0, MNC_CLOSE);

	// Catch this message so to prevent the window from becoming too small.
	case WM_GETMINMAXINFO:
		((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
		((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200; 
		return 0;
	}

	return DefWindowProc(mhMainWnd, msg, wParam, lParam);
}
Ejemplo n.º 17
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    node *current = NULL;
    node *nodes;
    unsigned short tag;

    switch (msg)
        {
        case WM_CREATE:
            if (experimental_mouse) {
                SetTimer(hwnd, TIMER_UPDATE_MOUSE, 500, NULL); // Poll for mouse position
            }
            break;

        case WM_CLOSE:
            {
                ClipCursor(0); // Release Cursor Lock
                DeregisterShellHookWindow(hwnd);
                UnregisterHotkeys(hwnd);
                if (experimental_mouse) {
                    KillTimer(hwnd, TIMER_UPDATE_MOUSE); // Mouse Poll Timer
                }
                for (tag=0; tag<TAGS; tag++) {
                    nodes = tags[tag].nodes;
                    for (current = nodes; current;) {
                        node *next = current->next;
                        RestoreWindow(current->hwnd);
                        RemoveNode(current->hwnd, tag);
                        current = next;
                    }
                    DestroyWindow(hwnd);
                }
            }
            break;

        case WM_DESTROY:
            PostQuitMessage(WM_QUIT);
            break;

        case WM_HOTKEY:
            if (wParam >= KEY_TOGGLE_T1 && wParam < (KEY_TOGGLE_T1 + TAGS)) {
                ToggleTag(wParam - KEY_TOGGLE_T1);
                break;
            } else if (wParam >= KEY_SWITCH_T1 && wParam < (KEY_SWITCH_T1 + TAGS)) {
                MinimizeTag(current_tag);
                current_tag = wParam - KEY_SWITCH_T1;
                ArrangeWindows();
                break;
            }

            current = tags[current_tag].current_window;

            switch (wParam)
                {
                case KEY_PREV_TAG:
                    if (current_tag > 0) {
                        MinimizeTag(current_tag);
                        --current_tag;
                        ArrangeWindows();
                    }
                    break;

                case KEY_NEXT_TAG:
                    if (current_tag < TAGS) {
                        MinimizeTag(current_tag);
                        ++current_tag;
                        ArrangeWindows();
                    }
                    break;

                case KEY_SELECT_UP:
                    if (current) {
                        tags[current_tag].current_window = GetNextNode();
                        FocusCurrent();
                    }
                    break;

                case KEY_SELECT_DOWN:
                    if (current) {
                        tags[current_tag].current_window = GetPreviousNode();
                        FocusCurrent();
                    }
                    break;

                case KEY_MOVE_MAIN:
                    SwapWindowWithNode(tags[current_tag].nodes);
                    ArrangeWindows();
                    break;

                case KEY_EXIT:
                    PostMessage(hwnd, WM_CLOSE, 0, 0);
                    break;

                case KEY_MARGIN_LEFT:
                    margin -= 20;
                    ArrangeWindows();
                    break;

                case KEY_MARGIN_RIGHT:
                    margin += 20;
                    ArrangeWindows();
                    break;

                case KEY_IGNORE:
                    if (!disableNext) {
                        disableNext = 1;
                    } else {
                        disableNext = 0;
                    }
                    break;

                case KEY_MOUSE_LOCK:
                    if (lockMouse) {
                        lockMouse = 0;
                        ClipCursor(0);
                    } else {
                        lockMouse = 1;
                        FocusCurrent();
                    }
                    break;

                case KEY_TILING_MODE:
                    tags[current_tag].tilingMode = (tags[current_tag].tilingMode + 1) % 3;
                    ArrangeWindows();
                    break;

                case KEY_MOVE_UP:
                    if (current) {
                        SwapWindowWithNode(GetNextNode());
                        ArrangeWindows();
                    }
                    break;

                case KEY_MOVE_DOWN:
                    if (current) {
                        SwapWindowWithNode(GetPreviousNode());
                        ArrangeWindows();
                    }
                    break;

                case KEY_DISP_CLASS:
                    {
                        LPSTR temp = (LPSTR)malloc(sizeof(TCHAR) * 128);
                        GetClassName(GetForegroundWindow(), temp, 128);
                        MessageBox(NULL, temp, "Window Class", MB_OK);
                        free(temp);
                    }
                    break;

                case KEY_TILE:
                    if (IsGoodWindow(GetForegroundWindow())) {
                        AddNode(GetForegroundWindow(), current_tag);
                        ArrangeWindows();
                    }
                    break;

                case KEY_UNTILE:
                    FullRemoveNode(GetForegroundWindow());
                    ArrangeWindows();
                    break;

                case KEY_INC_AREA:
                    tags[current_tag].masterarea_count++;
                    ArrangeWindows();
                    break;

                case KEY_DEC_AREA:
                    tags[current_tag].masterarea_count--;
                    ArrangeWindows();
                    break;

                case KEY_CLOSE_WIN:
                    PostMessage(GetForegroundWindow(), WM_CLOSE, 0, 0);
                    break;
                }
            break;

        case WM_TIMER:
            switch (wParam)
                {
                case TIMER_UPDATE_MOUSE:
                    UpdateMousePos(hwnd);
                    break;
                }
            break;

        default:
            if (msg == shellhookid) { // Handle the Shell Hook message
                switch (wParam)
                    {
                    case HSHELL_WINDOWCREATED:
                        if (IsGoodWindow((HWND)lParam)) {
                            AddNode((HWND)lParam, current_tag);
                            ArrangeWindows();
                            FocusCurrent();
                        }
                        break;

                    case HSHELL_WINDOWDESTROYED:
                        FullRemoveNode((HWND)lParam);
                        ArrangeWindows();
                        FocusCurrent();
                        break;

                    case HSHELL_RUDEAPPACTIVATED:
                    case HSHELL_WINDOWACTIVATED:
                        {
                            node *found = FindNode((HWND)lParam, current_tag);
                            if (found) {
                                tags[current_tag].current_window = current = found;
                                FocusCurrent();
                            }
                        }
                        break;
                    }
            } else {
                return DefWindowProc(hwnd, msg, wParam, lParam);
            }
        }
    return 0;
}
Ejemplo n.º 18
0
LRESULT CALLBACK outwnd_handler(HWND hwnd,UINT msg,WPARAM wParam, LPARAM lParam)
{
	
	switch(msg)	{
	case WM_ACTIVATEAPP:
		// The application z-ordering has change
		// foreground application wParm will be
		OutputActive = (BOOL)wParam;
		break;

	case WM_CREATE:	{
			SCROLLINFO si;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_RANGE | SIF_POS;
			si.nMin = 0;
			si.nMax = max_scroll_pos;
			si.nPos = max_scroll_pos;
			SetScrollInfo(hwnd, SB_VERT, &si, 1 );
		}
		break;

	case WM_TIMER:
		if (scroll_wait)
			PostMessage(hwnd, WM_MOUSEMOVE, 0, last_mousemove);

		if ( Outwnd_changed )	{
			RECT client;
			GetClientRect(hOutputWnd, &client);
			client.top = client.bottom - nTextHeight;
			InvalidateRect(hOutputWnd,&client,0);
		}

		scroll_wait = 0;
		break;

	case WM_COMMAND:	{
		int z;

		z = LOWORD(wParam);
		if (z >= ID_FILTER && z < ID_FILTER + outwnd_filter_count)
		{
			z -= ID_FILTER;
			outwnd_filter[z]->state = !outwnd_filter[z]->state;

			if ( !stricmp( outwnd_filter[z]->name, "error" ) )	{
				outwnd_filter[z]->state = 1;
			} else if ( !stricmp( outwnd_filter[z]->name, "general" ) )	{
				outwnd_filter[z]->state = 1;
			} else if ( !stricmp( outwnd_filter[z]->name, "warning" ) )	{
				outwnd_filter[z]->state = 1;
			}
			save_filter_info();
			break;
		}

		switch (z)
		{
			case ID_COPY:
				outwnd_copy_marked_selection(hwnd);
				break;

			/*
			case ID_FIND:
				if (DialogBox(GetModuleHandle(NULL), "FIND_DIALOG", hOutputWnd,
					(int (__stdcall *)(void)) find_dlg_handler) == IDOK)
				{
					find_text_in_outwindow(mprintf_last_line, 0);
				}

				break;
				*/
		}
		break;
	}

	case WM_RBUTTONDOWN:	{
			HMENU h_menu = CreatePopupMenu();
			HMENU h_sub_menu = CreatePopupMenu();
			POINT pt;
			int i;

			for (i=0; i<outwnd_filter_count; i++)
			{
				UINT flags = MFT_STRING;	//MF_GRAYED;

				if ( !stricmp( outwnd_filter[i]->name, "error" ) )	{
					flags |= MF_GRAYED;
				} else if ( !stricmp( outwnd_filter[i]->name, "general" ) )	{
					flags |= MF_GRAYED;
				} else if ( !stricmp( outwnd_filter[i]->name, "warning" ) )	{
					flags |= MF_GRAYED;
				}

				if (outwnd_filter[i]->state)
					AppendMenu(h_sub_menu, flags | MF_CHECKED, ID_FILTER + i, outwnd_filter[i]->name);
				else
					AppendMenu(h_sub_menu, flags, ID_FILTER + i, outwnd_filter[i]->name);
			}

			AppendMenu(h_menu, MFT_STRING, ID_COPY, "&Copy\tEnter");
			AppendMenu(h_menu, MFT_STRING, ID_FIND, "&Find Text");
			AppendMenu(h_menu, MF_POPUP, (unsigned int) h_sub_menu, "Filter &Messages");
			pt.x = LOWORD(lParam);
			pt.y = HIWORD(lParam);
			ClientToScreen(hwnd, &pt);

			TrackPopupMenu(h_menu, 0, pt.x, pt.y, 0, hwnd, NULL);
			DestroyMenu(h_menu);
			break;
		}
		
	case WM_LBUTTONDOWN:
		fix_marking_coords(marking_started_x, marking_started_y, lParam);
		SetCapture(hwnd);  // monopolize mouse
		marking_active = 1;
		outwnd_update_marking(lParam, hwnd);
		break;

	case WM_MOUSEMOVE:
		last_mousemove = lParam;
		if (marking_active){
			outwnd_update_marking(lParam, hwnd);
		}
		break;

	case WM_LBUTTONUP:
		if (marking_active)
		{
			ReleaseCapture();
			marking_active = 0;
			outwnd_update_marking(lParam, hwnd);
		}
		break;
	
	case WM_VSCROLL:	{
			SCROLLINFO si;
			int vpos = GetScrollPos( hwnd, SB_VERT );
			int old_vpos=vpos;
			switch (LOWORD(wParam))	{
			case SB_LINEDOWN:
				vpos++;
				break;
			case SB_LINEUP:
				vpos--;
				break;
			case SB_THUMBPOSITION:
				vpos = HIWORD(wParam);
				break;
			case SB_THUMBTRACK:
				vpos = HIWORD(wParam);
				break;
			case SB_PAGEDOWN:
				vpos += nCharRows;
				break;
			case SB_PAGEUP:
				vpos -= nCharRows;
				break;
			}
			if ( vpos < 0 ) vpos = 0;
			else if ( vpos > max_scroll_pos ) vpos = max_scroll_pos;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_POS;
			si.nPos = vpos;
			SetScrollInfo(hwnd, SB_VERT, &si, 1 );
			ScrollWindow(hwnd,0,(old_vpos-vpos)*nTextHeight,NULL,NULL);
			UpdateWindow(hOutputWnd);
			//InvalidateRect(hOutputWnd,NULL,0);
		}
		break;

	case WM_KEYDOWN:	{
			SCROLLINFO si;
			int vpos = GetScrollPos( hwnd, SB_VERT );
			int old_vpos=vpos;
			int nVirtKey = (int) wParam;  // virtual-key code
			switch(nVirtKey)	{
			case VK_DOWN:
			case VK_RIGHT:
				vpos++;
				break;
			case VK_UP:
			case VK_LEFT:
				vpos--;
				break;
			case VK_NEXT:
				vpos += nCharRows;
				break;
			case VK_PRIOR:
				vpos -= nCharRows;
				break;
			case VK_END:
				vpos = 0;
				break;
			case VK_HOME:
				vpos = max_scroll_pos;
				break;
			case VK_RETURN:
				outwnd_copy_marked_selection(hwnd);
				break;
			case UP_FAST:  // special value we define
				vpos -= 5;
				break;
			case DOWN_FAST:  // special value we define
				vpos += 5;
				break;
			}
			
			if ( vpos < 0 ) vpos = 0;
			else if ( vpos > max_scroll_pos ) vpos = max_scroll_pos;
			si.cbSize = sizeof(SCROLLINFO);
			si.fMask = SIF_POS;
			si.nPos = vpos;
			SetScrollInfo(hwnd, SB_VERT, &si, 1 );
			ScrollWindow(hwnd, 0, (old_vpos-vpos)*nTextHeight, NULL, NULL);
			UpdateWindow(hOutputWnd);
			//InvalidateRect(hOutputWnd,NULL,0);
		}
		break;

	case WM_SIZE:
		InvalidateRect(hOutputWnd,NULL,0);
		break;

	case WM_PAINT:
		outwnd_paint(hwnd);
		break;

	case WM_DESTROY:
		outwnd_disabled = 1;
		PostQuitMessage(0);
		break;

	default:
		return DefWindowProc(hwnd, msg, wParam, lParam);
		break;
	}

	return 0;
}
Ejemplo n.º 19
0
CSize  CGuiToolBarWnd::CalcLayout(DWORD dwMode, int nLength)
{
	ASSERT_VALID(this);
	ASSERT(::IsWindow(m_hWnd));
	if (dwMode & LM_HORZDOCK)
		ASSERT(dwMode & LM_HORZ);
	
	if (dwMode & LM_HORZ)
		bVertDocked=FALSE;
	else
		bVertDocked=TRUE;
	int nCount;
	TBBUTTON* pData = NULL;
	CSize sizeResult(0,0);

	//BLOCK: Load Buttons
	{
		nCount = DefWindowProc(TB_BUTTONCOUNT, 0, 0);
		if (nCount != 0)
		{
			int i;
			pData = new TBBUTTON[nCount];
			for (i = 0; i < nCount; i++)
				_GetButton(i, &pData[i]);
		}
	}

	if (nCount > 0)
	{
		if (!(m_dwStyle & CBRS_SIZE_FIXED))
		{
			BOOL bDynamic = m_dwStyle & CBRS_SIZE_DYNAMIC;

			if (bDynamic && (dwMode & LM_MRUWIDTH))
				SizeToolBar(pData, nCount, m_nMRUWidth);
			else if (bDynamic && (dwMode & LM_HORZDOCK))
				SizeToolBar(pData, nCount, 32767);
			else if (bDynamic && (dwMode & LM_VERTDOCK))
				SizeToolBar(pData, nCount, 0);
			else if (bDynamic && (nLength != -1))
			{
				CRect rect; rect.SetRectEmpty();
				CalcInsideRect(rect, (dwMode & LM_HORZ));
				BOOL bVert = (dwMode & LM_LENGTHY);
				int nLen = nLength + (bVert ? rect.Height() : rect.Width());

				SizeToolBar(pData, nCount, nLen, bVert);
			}
			else if (bDynamic && (m_dwStyle & CBRS_FLOATING))
				SizeToolBar(pData, nCount, m_nMRUWidth);
			else
				SizeToolBar(pData, nCount, (dwMode & LM_HORZ) ? 32767 : 0);
		}

		sizeResult = CalcSize(pData, nCount);

		if (dwMode & LM_COMMIT)
		{
			_AFX_CONTROLPOS* pControl = NULL;
			int nControlCount = 0;
			BOOL bIsDelayed = m_bDelayedButtonLayout;
			m_bDelayedButtonLayout = FALSE;

			for (int i = 0; i < nCount; i++)
				if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
					nControlCount++;

			if (nControlCount > 0)
			{
				pControl = new _AFX_CONTROLPOS[nControlCount];
				nControlCount = 0;

				for(int i = 0; i < nCount; i++)
				{
					if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
					{
						pControl[nControlCount].nIndex = i;
						pControl[nControlCount].nID = pData[i].idCommand;

						CRect rect;
						GetItemRect(i, &rect);
						ClientToScreen(&rect);
						pControl[nControlCount].rectOldPos = rect;

						nControlCount++;
					}
				}
			}

			if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
				m_nMRUWidth = sizeResult.cx;
			for (i = 0; i < nCount; i++)
				_SetButton(i, &pData[i]);

			if (nControlCount > 0)
			{
				for (int i = 0; i < nControlCount; i++)
				{
					CWnd* pWnd = GetDlgItem(pControl[i].nID);
					if (pWnd != NULL)
					{
						CRect rect;
						pWnd->GetWindowRect(&rect);
						CPoint pt = rect.TopLeft() - pControl[i].rectOldPos.TopLeft();
						GetItemRect(pControl[i].nIndex, &rect);
						pt = rect.TopLeft() + pt;
						pWnd->SetWindowPos(NULL, pt.x, pt.y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
					}
				}
				delete[] pControl;
			}
			m_bDelayedButtonLayout = bIsDelayed;
		}
		delete[] pData;
	}

	//BLOCK: Adjust Margins
	{
		CRect rect; rect.SetRectEmpty();
		CalcInsideRect(rect, (dwMode & LM_HORZ));
		sizeResult.cy -= rect.Height();
		sizeResult.cx -= rect.Width();

		CSize size = CControlBar::CalcFixedLayout((dwMode & LM_STRETCH), (dwMode & LM_HORZ));
		sizeResult.cx = max(sizeResult.cx, size.cx);
		sizeResult.cy = max(sizeResult.cy, size.cy);
	}
	return sizeResult;
}
Ejemplo n.º 20
0
LRESULT CALLBACK MainLoop::WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

    if( uMsg == WM_CLOSE )
        PostQuitMessage(0);
    switch( uMsg )
    {
    case WM_SIZE:
      current_main_loop->ResizeWindow();
     break;
    case WM_CLOSE:
        exit(0);

    case WM_KEYUP:
        if( wParam < 256 )
            current_main_loop->keys[ wParam ]= false;
        break;

    case WM_SETFOCUS:
        current_main_loop->use_mouse= true;
        ShowCursor( false );
        break;
    case WM_KILLFOCUS:
        current_main_loop->use_mouse= false;
        ShowCursor( true );
        break;

    case WM_KEYDOWN:
    {
        if( wParam < 256 )
            current_main_loop->keys[ wParam ]= true;

		switch( wParam )
		{
            case KEY(' '):
            current_main_loop->player->Jump();
            break;

           /* case KEY('M'):
            ShowCursor( current_main_loop->use_mouse );
            current_main_loop->use_mouse = !current_main_loop->use_mouse;
            break;*/

			case VK_ESCAPE:
			exit(0);
            break;

			default:
                 if( wParam <= 57 && wParam>= 49 )
                    current_main_loop->player->SetWeapon( wParam - 49 );
			break;
		}

      
    }//key down
    break;

    case WM_LBUTTONDOWN://shot button
           // current_main_loop->player->Shot();
            current_main_loop->mouse_keys[0]= true;
            break;
     case WM_LBUTTONUP://shot button
         current_main_loop->mouse_keys[0]= false;
         break;
     case WM_RBUTTONUP:
         current_main_loop->renderer->Zoom();
         break;

        case WM_MOUSEWHEEL:
            if( GET_WHEEL_DELTA_WPARAM(wParam) > 0 )
                current_main_loop->player->PreviousWeapon();
            else
                current_main_loop->player->NextWeapon();
        break;

#ifdef MRPG_DEBUG
        printf( "key: %d\n", wParam );
#endif
        break;


    default:
        break;
    }

    return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
Ejemplo n.º 21
0
static LRESULT CALLBACK ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	const char *cmdString;
	static qboolean s_timePolarity;

	switch (uMsg)
	{
	case WM_ACTIVATE:
		if ( LOWORD( wParam ) != WA_INACTIVE )
		{
			SetFocus( s_wcd.hwndInputLine );
		}

		if ( com_viewlog && ( com_dedicated && !com_dedicated->integer ) )
		{
			// if the viewlog is open, check to see if it's being minimized
			if ( com_viewlog->integer == 1 )
			{
				if ( HIWORD( wParam ) )		// minimized flag
				{
					Cvar_Set( "viewlog", "2" );
				}
			}
			else if ( com_viewlog->integer == 2 )
			{
				if ( !HIWORD( wParam ) )		// minimized flag
				{
					Cvar_Set( "viewlog", "1" );
				}
			}
		}
		break;

	case WM_CLOSE:
		if ( ( com_dedicated && com_dedicated->integer ) )
		{
			cmdString = CopyString( "quit" );
			Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, (void *)cmdString );
		}
		else if ( s_wcd.quitOnClose )
		{
			PostQuitMessage( 0 );
		}
		else
		{
			Sys_ShowConsole( 0, qfalse );
			Cvar_Set( "viewlog", "0" );
		}
		return 0;
	case WM_CTLCOLORSTATIC:
		if ( ( HWND ) lParam == s_wcd.hwndBuffer )
		{
			SetBkColor( ( HDC ) wParam, RGB( 0, 0, 0 ) );
			SetTextColor( ( HDC ) wParam, RGB( 249, 249, 000 ) );
			return ( long ) s_wcd.hbrEditBackground;
		}
		else if ( ( HWND ) lParam == s_wcd.hwndErrorBox )
		{
			if ( s_timePolarity & 1 )
			{
				SetBkColor(   ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) );
				SetTextColor( ( HDC ) wParam, RGB( 0xff, 0x00, 0x00 ) );
			}
			else
			{
				SetBkColor(   ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) );
				SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x00, 0x00 ) );
			}
			return ( long ) s_wcd.hbrErrorBackground;
		}
		return FALSE;
		break;

	case WM_COMMAND:
		if ( wParam == COPY_ID )
		{
			SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 );
			SendMessage( s_wcd.hwndBuffer, WM_COPY, 0, 0 );
		}
		else if ( wParam == QUIT_ID )
		{
			if ( s_wcd.quitOnClose )
			{
				PostQuitMessage( 0 );
			}
			else
			{
				cmdString = CopyString( "quit" );
				Sys_QueEvent( 0, SE_CONSOLE, 0, 0, strlen( cmdString ) + 1, (void *)cmdString );
			}
		}
		else if ( wParam == CLEAR_ID )
		{
			SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 );
			SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, ( LPARAM ) "" );
			UpdateWindow( s_wcd.hwndBuffer );
		}
		break;
	case WM_CREATE:
		s_wcd.hbrEditBackground =  CreateSolidBrush( RGB( 0x00, 0x00, 0x00 ) );
		s_wcd.hbrErrorBackground = CreateSolidBrush( RGB( 0x80, 0x80, 0x80 ) );
		SetTimer( hWnd, 1, 1000, NULL );
		break;
	case WM_ERASEBKGND:
	    return DefWindowProc( hWnd, uMsg, wParam, lParam );
	case WM_TIMER:
		if ( wParam == 1 )
		{
			s_timePolarity = (qboolean)!s_timePolarity;
			if ( s_wcd.hwndErrorBox )
			{
				InvalidateRect( s_wcd.hwndErrorBox, NULL, FALSE );
			}
		}
		break;
    }

    return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
Ejemplo n.º 22
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	static BOOL bAlarm = FALSE;

	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	//if( message == CMouseHook::UWM_DRAGEEND)
	//{
	//	SetCapture(NULL);
	//	SetCursor(LoadCursor(NULL,IDC_ARROW));
	//	CMouseHook::StopHook();
	//	if( g_pChessBoard )
	//	{
	//		g_pChessBoard->GetGameWindow();
	//	}
	//}

	switch (message)
	{
	case WM_ACTIVATEAPP:
		g_bActive = wParam;
		break;
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// Parse the menu selections:
		switch (wmId)
		{
		case IDM_CAPTURE:
			break;
		case IDM_ABOUT:
			//test();
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hwnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hwnd);
			break;
		case IDM_SEC5:
			AppEnv::nThinkTime = 5;			
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC5, MF_CHECKED);
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC10, MF_UNCHECKED);
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC30, MF_UNCHECKED);
			break;
		case IDM_SEC10:
			AppEnv::nThinkTime = 10;
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC5, MF_UNCHECKED);
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC10, MF_CHECKED);
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC30, MF_UNCHECKED);
			break;
		case IDM_SEC30:
			AppEnv::nThinkTime = 30;
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC5, MF_UNCHECKED);
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC10, MF_UNCHECKED);
			CheckMenuItem(GetMenu(g_hWndMain), IDM_SEC30, MF_CHECKED);
			break;
		case IDM_AUTOPLAY:
			AppEnv::bAutoPlay = !AppEnv::bAutoPlay ;
			if(AppEnv::bAutoPlay )
				CheckMenuItem(GetMenu(g_hWndMain), IDM_AUTOPLAY, MF_CHECKED);
			else
				CheckMenuItem(GetMenu(g_hWndMain), IDM_AUTOPLAY, MF_UNCHECKED);			
		default:
			return DefWindowProc(g_hWndMain, message, wParam, lParam);
		}
		break;

	case WM_PAINT:
		hdc = BeginPaint(hwnd, &ps);

		if ( g_pMainSurface  )
		{
			g_pMainSurface->FastBlt(hdc);
		}

		EndPaint(hwnd, &ps);
		break;
	case WM_LBUTTONDOWN:
		//SetCapture(hwnd);
		//SetCursor(LoadCursor(NULL,IDC_CROSS));
		//CMouseHook::StartHook(hwnd);
		break;
	//case WM_KEYUP:
	//		vk = (int) wParam;

	//		switch( vk )
	//		{
	//		case VK_RETURN:
	//			if ( g_pChessEngine)
	//			{
	//				if ( g_pChessEngine->GetState() == CChessEngine::BusyWait )
	//					g_pChessEngine->SendCommand("stop");
	//			}
	//			//DumpBoradHash();
	//			break;
	//		}
		break;
	case WM_TIMER:
		switch( wParam )
		{
		case APPUPDATE_TIMER:
			if (!AppLoop()) {
			    DestroyWindow(hwnd);
			}
			doUpdate();

			return 0;

		}
		break;
	case WM_DESTROY:
		if(g_bInitialized)
		{
			ExitApp();
		}

		doRelease();

		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}
Ejemplo n.º 23
0
LRESULT CALLBACK WindowProc( HWND   hWnd,
                             UINT   msg,
                             WPARAM wParam,
                             LPARAM lParam )
{
	if( TwEventWin(hWnd, msg, wParam, lParam) ) // send event message to AntTweakBar
	{return 0;} // event has been handled by AntTweakBar
   
	static POINT ptLastMousePosit;
    static POINT ptCurrentMousePosit;
    static bool bMousing;
    
    switch( msg )
    {
        case WM_KEYDOWN:
        {
            switch( wParam )
            {
                case VK_ESCAPE:
                    PostQuitMessage(0);
                    break;

				case VK_F1:
					g_bHandleWindowResize = !g_bHandleWindowResize;
					break;
            }
        }
        break;

        case WM_LBUTTONDOWN:
        {
            ptLastMousePosit.x = ptCurrentMousePosit.x = LOWORD (lParam);
            ptLastMousePosit.y = ptCurrentMousePosit.y = HIWORD (lParam);
            bMousing = true;
        }
        break;

        case WM_LBUTTONUP:
        {
            bMousing = false;
        }
        break;

        case WM_MOUSEMOVE:
        {
            ptCurrentMousePosit.x = LOWORD (lParam);
            ptCurrentMousePosit.y = HIWORD (lParam);

            if( bMousing )
            {
				float spinX, spinY;
				g_app->getSpin (&spinX, &spinY);
                spinX -= (ptCurrentMousePosit.x - ptLastMousePosit.x);
                spinY -= (ptCurrentMousePosit.y - ptLastMousePosit.y);
				g_app->setSpin(spinX, spinY);
            }

            ptLastMousePosit.x = ptCurrentMousePosit.x;
            ptLastMousePosit.y = ptCurrentMousePosit.y;
        }
        break;

        case WM_SIZE:
        {
			if( g_bHandleWindowResize == true )
			{
				// If the device is not NULL and the WM_SIZE message is not a
				// SIZE_MINIMIZED event, resize the device's swap buffers to match
				// the new window size.
				if( g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED )
				{
					cleanupDX();

					g_d3dpp.BackBufferWidth  = LOWORD(lParam);
					g_d3dpp.BackBufferHeight = HIWORD(lParam);

					HRESULT hr = g_pd3dDevice->Reset( &g_d3dpp );

                    if( hr == D3DERR_INVALIDCALL )
                    {
                        MessageBox( NULL,
							"Call to Reset() failed with D3DERR_INVALIDCALL!",
                            "ERROR", MB_OK | MB_ICONEXCLAMATION );
                    }

					setupDX();
				}
			}
        }
        break;

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

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

	// done
    return 0;
}
Ejemplo n.º 24
0
LRESULT CALLBACK WndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	C_Window* win = (C_Window*)((void*)GetWindowLongPtr(wnd, GWLP_USERDATA));
	//if(win!=0 && win->m_oldp != 0)
	//{
	//	win->m_oldp(wnd, msg, wParam, lParam);
	//}

	if(msg == WM_SIZE)
	{
		win->OnResize();
	}
	else if(msg ==  WM_ACTIVATE)
	{
		if(LOWORD(wParam)) win->OnFocus();
		if(!LOWORD(wParam)) win->OnLostFocus();
	}
	else if(msg ==  WM_PAINT)
	{
		win->OnPaint();
	}
	else if(msg ==  WM_CLOSE || msg ==  WM_DESTROY)
	{
		win->OnClose();
	}
	else if(msg ==  WM_SHOWWINDOW)
	{
		win->OnVisible();
	}
	else if(msg ==  WM_LBUTTONDOWN || msg ==  WM_RBUTTONDOWN || msg ==  WM_MBUTTONDOWN || msg ==  WM_XBUTTONDOWN)
	{
		unsigned int button = 0;
		switch(msg)
		{
		case WM_LBUTTONDOWN:
			button = KEY_LBUTTON;
			break;
		case WM_RBUTTONDOWN:
			button = KEY_RBUTTON;
			break;
		case WM_MBUTTONDOWN:
			button = KEY_MBUTTON;
			break;
		case WM_XBUTTONDOWN:
			if(HIWORD(wParam) == XBUTTON1)
			{
				button = KEY_XBUTTON1;
			}
			else if(HIWORD(wParam) == XBUTTON2)
			{
				button = KEY_XBUTTON2;
			}
			break;
		}
		win->MouseDown(button, LOWORD(wParam), PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
	}
	else if(msg ==  WM_LBUTTONUP || msg ==  WM_RBUTTONUP || msg ==  WM_MBUTTONUP || msg ==  WM_XBUTTONUP)
	{
		unsigned int button = 0;
		switch(msg)
		{
		case WM_LBUTTONUP:
			button = KEY_LBUTTON;
			break;
		case WM_RBUTTONUP:
			button = KEY_RBUTTON;
			break;
		case WM_MBUTTONUP:
			button = KEY_MBUTTON;
			break;
		case WM_XBUTTONUP:
			if(HIWORD(wParam) == XBUTTON1)
			{
				button = KEY_XBUTTON1;
			}
			else if(HIWORD(wParam) == XBUTTON2)
			{
				button = KEY_XBUTTON2;
			}
			break;
		}
		win->MouseUp(button, LOWORD(wParam), PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
	}
	else if(msg ==  WM_LBUTTONDBLCLK || msg ==  WM_RBUTTONDBLCLK || msg ==  WM_MBUTTONDBLCLK || msg ==  WM_XBUTTONDBLCLK)
	{
		unsigned int button = 0;
		switch(msg)
		{
		case WM_LBUTTONDBLCLK:
			button = KEY_LBUTTON;
			break;
		case WM_RBUTTONDBLCLK:
			button = KEY_RBUTTON;
			break;
		case WM_MBUTTONDBLCLK:
			button = KEY_MBUTTON;
			break;
		case WM_XBUTTONDBLCLK:
			if(HIWORD(wParam) == XBUTTON1)
			{
				button = KEY_XBUTTON1;
			}
			else if(HIWORD(wParam) == XBUTTON2)
			{
				button = KEY_XBUTTON2;
			}
			break;
		}
		win->MouseDblClick(button, LOWORD(wParam), PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
	}
	else if(msg ==  WM_MOUSEMOVE)
	{
		win->MouseMove(PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
	}
	else if(msg ==  WM_MOUSEWHEEL)
	{
		win->MouseWheel( short(HIWORD(wParam)) / WHEEL_DELTA, LOWORD(wParam), PointI(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
	}
	else if(msg ==  WM_KEYDOWN)
	{
		win->KeyDown(wParam);
		if(isascii(wParam) && wParam != VK_RETURN && wParam != VK_DELETE && wParam != VK_CLEAR && wParam != VK_TAB)
		{
			win->KeyChar(static_cast<wchar_t>(wParam));
		}
	}
	else if(msg ==  WM_KEYUP)
	{
		win->KeyUp(wParam);
	}
	else if(msg ==  WM_CHAR)
	{
		win->KeyChar(static_cast<wchar_t>(wParam));
	}

	return DefWindowProc(wnd, msg, wParam, lParam);
}
Ejemplo n.º 25
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;

	switch (message) 
	{
	case WM_CBLBUTTONCLICKED:
		switch(wParam)
		{// begin wParam
		case 1:
			DisplayStatus("AM Productions Caption pressed - Going to http://am-productions.yi.org/");
			ShellExecute(NULL,"open","http://am-productions.yi.org/",NULL,NULL,SW_SHOWNORMAL);
			break;
		case 2:
			cbExtra.New(8,
			(HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP5),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS|LR_DEFAULTCOLOR),
			(HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP6),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS|LR_DEFAULTCOLOR),
			"Caption 8",1);
			DisplayStatus("Caption 2 pressed - Created Caption 8 and inserted it at index 1");
			break;
		case 3:
			cbExtra.Delete(3);
			DisplayStatus("Caption 3 pressed - Deleted Caption 3");
			break;
		case 4:
			DisplayStatus("Caption 4 pressed");
			break;
		case 7:
			DisplayStatus("Caption 7 pressed");
			break;
		case 8:
			cbExtra.Replace(8,7,
			(HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP5),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS|LR_DEFAULTCOLOR),
			(HBITMAP)LoadImage(hInst,MAKEINTRESOURCE(IDB_BITMAP6),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS|LR_DEFAULTCOLOR),
			"Caption 7");
			DisplayStatus("Caption 8 pressed - Replaced Caption 8 with Caption 7");
			break;
		}// end wParam
		break;
		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:
				   DestroyWindow(hWnd);
				   break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
Ejemplo n.º 26
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam) {
	
	HDC ContextHandle;
	PAINTSTRUCT PaintStructure;
	RECT ClientRectangle;
	LPCWSTR MyText = L"Done with Pride and Prejudice by me!";
	TCHAR text[] = L"Done with Pride and Prejudice by me!";
	
	COLORREF TextColor = RGB(100, 100, 100);
	HBRUSH brush = CreateSolidBrush(RGB(176, 23, 31));
	HFONT fontCorbel;
	
	HWND TextBox;
	switch (Msg)
	{

		case WM_CREATE:
			{
				LPCWSTR button01_ID = L"BUTTON";
				LPCWSTR button01_text = L"DEFAULT";
				HWND button01 = CreateWindowEx(WS_EX_WINDOWEDGE, button01_ID, button01_text, BS_DEFPUSHBUTTON | WS_VISIBLE | WS_BORDER | WS_CHILD, 5, 5, 85, 25, hwnd, (HMENU)BUTTON_01, NULL, NULL);
	
				LPCWSTR button02_ID = L"BUTTON";
				LPCWSTR button02_text = L"CUSTOM";
				HWND button02 = CreateWindowEx(NULL, button02_ID, button02_text, BS_DEFPUSHBUTTON | WS_VISIBLE | WS_BORDER | WS_CHILD, 5, 35, 85, 25, hwnd, (HMENU)BUTTON_02, NULL, NULL);
				
				TextBox = CreateWindow(TEXT("EDIT"), TEXT("DEFAULT STYLE"), WS_VISIBLE | WS_CHILD| WS_BORDER | ES_AUTOHSCROLL, 
					
					5, 65, 200, 20, hwnd, (HMENU) NULL, NULL, NULL);
				
				}
			break;
		case WM_PAINT:
			ContextHandle = BeginPaint(hwnd, &PaintStructure);
			GetClientRect(hwnd, &ClientRectangle);
			DrawText(ContextHandle, MyText, -1,
				&ClientRectangle, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
			
			EndPaint(hwnd, &PaintStructure);

			return 0;
		case WM_COMMAND:
			
			{
				switch (wParam) {
			
					case BUTTON_01:
						
						SetClassLongPtr(hwnd, GCLP_HBRBACKGROUND, (ULONG)brush);
						RedrawWindow(hwnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME);
						MessageBox(NULL, L"Background color changed", L"ATENTION", NULL);
						break;
					case BUTTON_02:
						
						break;
				}	
			}

			break;
		
		case WM_CLOSE:
			{
				if (MessageBox(hwnd, L"Do you want to exit?", L"Exit", MB_OKCANCEL)==IDOK)
					DestroyWindow(hwnd);
			}
			
			break;
			
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hwnd, Msg, wParam, lParam);
	}
	return 0;
}
Ejemplo n.º 27
0
static LRESULT WINAPI ConWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	//char *cmdString;
	static bool s_timePolarity;

	switch (uMsg)
	{
	case WM_ACTIVATE:
		if ( LOWORD( wParam ) != WA_INACTIVE )
		{
			SetFocus( s_wcd.hwndInputLine );
		}

		break;
    case WM_CLOSE:
        DestroyWindow(hWnd);
    break;
    case WM_DESTROY:
        PostQuitMessage(0);
    break;

	//case WM_CLOSE:
	//	PostQuitMessage( 0 );
	//	return 0;
	case WM_CTLCOLORSTATIC:
		if ( ( HWND ) lParam == s_wcd.hwndBuffer )
		{
			SetBkColor( ( HDC ) wParam, RGB( 0x00, 0x00, 0xB0 ) );
			SetTextColor( ( HDC ) wParam, RGB( 0xff, 0xff, 0x00 ) );
			return ( long ) s_wcd.hbrEditBackground;
		}
		else if ( ( HWND ) lParam == s_wcd.hwndErrorBox )
		{
			if ( s_timePolarity & 1 )
			{
				SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) );
				SetTextColor( ( HDC ) wParam, RGB( 0xff, 0x0, 0x00 ) );
			}
			else
			{
				SetBkColor( ( HDC ) wParam, RGB( 0x80, 0x80, 0x80 ) );
				SetTextColor( ( HDC ) wParam, RGB( 0x00, 0x0, 0x00 ) );
			}
			return ( long ) s_wcd.hbrErrorBackground;
		}
		break;

	case WM_COMMAND:
		if ( wParam == COPY_ID )
		{
			SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 );
			SendMessage( s_wcd.hwndBuffer, WM_COPY, 0, 0 );
		}
		else if ( wParam == QUIT_ID )
		{
			//PostQuitMessage( 0 );
	        DestroyWindow(hWnd);
		}
		else if ( wParam == CLEAR_ID )
		{
			SendMessage( s_wcd.hwndBuffer, EM_SETSEL, 0, -1 );
			SendMessage( s_wcd.hwndBuffer, EM_REPLACESEL, FALSE, ( LPARAM ) "" );
			UpdateWindow( s_wcd.hwndBuffer );
		}
		break;
	case WM_CREATE:
//		s_wcd.hbmLogo = LoadBitmap( g_wv.hInstance, MAKEINTRESOURCE( IDB_BITMAP1 ) );
//		s_wcd.hbmClearBitmap = LoadBitmap( g_wv.hInstance, MAKEINTRESOURCE( IDB_BITMAP2 ) );
		s_wcd.hbrEditBackground = CreateSolidBrush( RGB( 0x00, 0x00, 0xB0 ) );
		s_wcd.hbrErrorBackground = CreateSolidBrush( RGB( 0x80, 0x80, 0x80 ) );
		SetTimer( hWnd, 1, 1000, NULL );
		break;
//	case WM_ERASEBKGND:
//	    return DefWindowProc( hWnd, uMsg, wParam, lParam );
	case WM_TIMER:
		if ( wParam == 1 )
		{
			s_timePolarity = !s_timePolarity;
			if ( s_wcd.hwndErrorBox )
			{
				InvalidateRect( s_wcd.hwndErrorBox, NULL, FALSE );
			}
		}
		break;
    }

    return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
Ejemplo n.º 28
0
LRESULT CALLBACK ButtonWndHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{   
	int t;
	BUTTONOBJ * st;
	st=NULL;
	for (t=0;(t<GLOBAL.objects)&&(st==NULL);t++)
		if (objects[t]->type==OB_BUTTON)
		{	st=(BUTTONOBJ *)objects[t];
		    if (st->displayWnd!=hWnd) st=NULL;
		}

	if (st==NULL) return DefWindowProc( hWnd, message, wParam, lParam );
	
	switch( message ) 
	{	case WM_DESTROY:
		 break;
		case WM_MOUSEACTIVATE:
   	      st->redraw=1;
		  close_toolbox();
		  actobject=st;
		  SetWindowPos(hWnd,HWND_TOP,0,0,0,0,SWP_DRAWFRAME|SWP_NOMOVE|SWP_NOSIZE);
		  InvalidateRect(ghWndDesign,NULL,TRUE);
		break;

		case WM_LBUTTONDOWN:
			{  int actx,acty,minpoint,i;
			   float actdist,mindist;
			   actx=(int)LOWORD(lParam);
			   acty=(int)HIWORD(lParam);
			   printf("button pressed in wnd %ld at: %ld, %ld\n",hWnd, actx,acty);
			   // if (distance (actx, acty, NAVI_X+170, NAVI_Y+33) < NAVI_SELECTDISTANCE) SendMessage(hWnd, WM_KEYDOWN, KEY_BACKSPACE,0); 
			   switch (st->buttonfunction) {
				   case BUTTONFUNCTION_PLAYSESSION:
						SendMessage(ghWndStatusbox,WM_COMMAND,IDC_RUNSESSION,0);
					break;
				   case BUTTONFUNCTION_STOPSESSION:
						SendMessage(ghWndStatusbox,WM_COMMAND,IDC_STOPSESSION,0);
					break;
				   case BUTTONFUNCTION_ENDSESSION:
						SendMessage(ghWndStatusbox,WM_COMMAND,IDC_ENDSESSION,0);
					break;
				   case BUTTONFUNCTION_VAL1VAL2:
				   case BUTTONFUNCTION_VAL1INV:
						st->state=STATE_PRESSED;
					break;
				   case BUTTONFUNCTION_TOGGLEVAL:
						st->togglecount=!(st->togglecount);
					break;
				   case BUTTONFUNCTION_TOGGLE1SEC:
						st->state=STATE_PRESSED;
						st->togglecount=1;
					break;
				   case BUTTONFUNCTION_DEVSETTINGS:
						SendMessage(ghWndMain,WM_COMMAND,IDM_DEVICESETTINGS,0);
					break;
				   case BUTTONFUNCTION_APPSETTINGS:
						SendMessage(ghWndMain,WM_COMMAND,IDM_SETTINGS,0);
					break;
			   }
			}
			break;

		case WM_GETMINMAXINFO:
		{
			MINMAXINFO* mmi = (MINMAXINFO*)lParam;
			//mmi->ptMaxSize.x = 10;
			//mmi->ptMaxSize.y = 10;
			mmi->ptMinTrackSize.x = 5;
			mmi->ptMinTrackSize.y = 5;
			//mmi->ptMaxTrackSize.x = 10;
			//mmi->ptMaxTrackSize.y = 10;
			return 0;
		}
		case WM_SIZE: 
		case WM_MOVE:
			{
  			  WINDOWPLACEMENT  wndpl;
			  GetWindowPlacement(st->displayWnd, &wndpl);
  	 	      st->redraw=TRUE;

			  if (GLOBAL.locksession) {
				  wndpl.rcNormalPosition.top=st->top;
				  wndpl.rcNormalPosition.left=st->left;
				  wndpl.rcNormalPosition.right=st->right;
				  wndpl.rcNormalPosition.bottom=st->bottom;
				  SetWindowPlacement(st->displayWnd, &wndpl);


				  //if (st->displayborder) SetWindowLong(st->displayWnd, GWL_STYLE, (WS_CLIPSIBLINGS| WS_CHILD | WS_CAPTION | WS_THICKFRAME )&~WS_SIZEBOX);
				  // else SetWindowLong(st->displayWnd, GWL_STYLE, 0);
				  SetWindowLong(st->displayWnd, GWL_STYLE, GetWindowLong(st->displayWnd, GWL_STYLE)&~WS_SIZEBOX);
				 // if (st->displayborder) SetWindowLong(st->displayWnd, GWL_STYLE, GetWindowLong(st->displayWnd, GWL_STYLE)&~WS_SIZEBOX);
				 // else SetWindowLong(st->displayWnd, GWL_STYLE, 0);
			  }
			  else {
				  st->top=wndpl.rcNormalPosition.top;
				  st->left=wndpl.rcNormalPosition.left;
				  st->right=wndpl.rcNormalPosition.right;
				  st->bottom=wndpl.rcNormalPosition.bottom;
				  st->redraw=TRUE; 
				  st->redraw=TRUE;
				  // SetWindowLong(st->displayWnd, GWL_STYLE, (WS_CLIPSIBLINGS| WS_CHILD | WS_CAPTION | WS_THICKFRAME | WS_SIZEBOX));
				  SetWindowLong(st->displayWnd, GWL_STYLE, GetWindowLong(st->displayWnd, GWL_STYLE) | WS_SIZEBOX);
			  }
			  update_border(st->displayWnd,st->displayborder);

			  InvalidateRect(hWnd,NULL,TRUE);
			}
			break;

		case WM_ERASEBKGND:
			st->redraw=1;
			return 0;

		case WM_PAINT:
			draw_button(st);
  	    	break;
		default:
			return DefWindowProc( hWnd, message, wParam, lParam );
    } 
    return 0;
}
Ejemplo n.º 29
0
LRESULT CALLBACK notificationWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;
	RECT rc = {0};
	UINT notify_duration = 0;
	static BOOL is_fading_out = FALSE;
	static HHOOK hook_mouse_over = NULL;
	static NotifyNotification notification_data_copy = {L"", L"", ICON_INFO};

	switch (message)
	{
	case WM_LIBNOTIFYSHOW:
		/* close if already running */
		if(IsWindowVisible(hWnd))
		{
			SendMessage(hWnd, WM_LIBNOTIFYCLOSE, 0, 0);
		}
		/* guarded by CS to make sure notification_data doesn't get corrupted
		   when this code and notify_notification_update is running in parallel */
		{
			EnterCriticalSection(&thread_guard);
			NotifyNotification *notification_data = (NotifyNotification*) lParam;
			if(notification_data &&
			   notification_data->body &&
			   notification_data->summary)
			{
				notification_data_copy = *notification_data;
			}
			else
			{
				LeaveCriticalSection(&thread_guard);
				break;
			}
			LeaveCriticalSection(&thread_guard);
		}

		/* deduce the allowed text width from the max width; see geometry for rationale */
		rc.right = notification_window_width_max - (icon_size + (icon_padding * 3));

		hdc = GetDC(hWnd);
		if(hdc)
		{
			HRGN hRgn = NULL;
			HGDIOBJ hOldFont = SelectObject(hdc, (HGDIOBJ) font_body);
			if(hOldFont)
			{
				DrawText(hdc,
						 notification_data_copy.body,
						 -1,
						 &rc,
						 DT_CALCRECT | DT_WORDBREAK |
						 DT_EDITCONTROL | DT_NOCLIP |
						 DT_NOPREFIX | DT_EXTERNALLEADING);

				SelectObject(hdc, hOldFont);
			}

			ReleaseDC(hWnd, hdc);
			if(!hOldFont) return 0;	/* exit if font selection failed */

			/* calculate the actual bounding rectangle from the DrawText output */
			notify_wnd.notification_window_height = notify_wnd.summary_body_divider +
													rc.bottom +
													(icon_padding * 3);
			notify_wnd.notification_window_width = rc.right + icon_size + (icon_padding * 3);

			/* word count * milliseconds per word */
			notify_duration = word_count(notification_data_copy.body) * milliseconds_per_word;

			/* in case the calculation renders too low a value, replace it with a de facto minimum */
			notify_duration = MAX(notify_duration, min_notification_timeout);

			/* get the screen area uncluttered by the taskbar */
			if(SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0))
			{
				LONG window_x = 0, window_y = 0;

				/* system tray @ right bottom */
				if((rc.bottom != GetSystemMetrics(SM_CYSCREEN)) ||
					(rc.right != GetSystemMetrics(SM_CXSCREEN)))
				{
					window_x = rc.right -
							   (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) -
							   notify_wnd.notification_window_width;
					window_y = rc.bottom -
							   (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) -
							   notify_wnd.notification_window_height;
				}
				else if(rc.left != 0)	/* left bottom */
				{
					window_x = rc.left +
							   (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor);
					window_y = rc.bottom -
							   (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor) -
							   notify_wnd.notification_window_height;
				}
				else					/* right top */
				{
					window_x = rc.right -
							   (GetSystemMetrics(SM_CXSCREEN) / window_offset_factor) -
							   notify_wnd.notification_window_width;
					window_y = rc.top +
							   (GetSystemMetrics(SM_CYSCREEN) / window_offset_factor);
				}

				/* resize and reposition the window */
				MoveWindow(hWnd,
						   window_x,
						   window_y,
						   notify_wnd.notification_window_width,
						   notify_wnd.notification_window_height,
						   TRUE);

				/* set the new positions to be used by the mouse over hook */
				notify_wnd.notification_window_rect.left = window_x;
				notify_wnd.notification_window_rect.top = window_y;
				notify_wnd.notification_window_rect.right = window_x + notify_wnd.notification_window_width;
				notify_wnd.notification_window_rect.bottom = window_y + notify_wnd.notification_window_height;

				/* make it as a rounded rect. */
				hRgn = CreateRoundRectRgn(0,
										  0,
										  notify_wnd.notification_window_width,
										  notify_wnd.notification_window_height,
										  rounded_rect_edge,
										  rounded_rect_edge);
				SetWindowRgn(hWnd, hRgn, TRUE);

				/* since bRedraw is set to TRUE in SetWindowRgn invalidation isn't required */
				/*InvalidateRect(hWnd, NULL, TRUE);*/

				/* show the window and set the timers for animation and overall visibility */
				ShowWindow(hWnd, SW_SHOWNOACTIVATE);

				SetTimer(hWnd, TIMER_ANIMATION, fade_duration, NULL);
				SetTimer(hWnd, TIMER_NOTIFICATION, notify_duration, NULL);
			}
		}
		break;
	case WM_LIBNOTIFYCLOSE:
		/* clean up and reset flags */
		{
			if(hook_mouse_over)
			{
				UnhookWindowsHookEx(hook_mouse_over);
				hook_mouse_over = NULL;
			}

			KillTimer(hWnd, TIMER_ANIMATION);
			KillTimer(hWnd, TIMER_NOTIFICATION);
			is_fading_out = FALSE;

			ShowWindow(hWnd, SW_HIDE);
		}
		break;
	case WM_PAINT:
		if((L'\0' != notification_data_copy.body[0]) &&
		   (L'\0' != notification_data_copy.summary[0]))
		{
			hdc = BeginPaint(hWnd, &ps);

			SetTextColor(hdc, RGB(255, 255, 255));
			SetBkMode(hdc, TRANSPARENT);

			HGDIOBJ hOldFont = SelectObject(hdc, (HGDIOBJ) font_summary);

			if(hOldFont)
			{
				/* set the padding as left offset and center the icon horizontally */
				DrawIcon(hdc,
						 icon_padding,
						 (notify_wnd.notification_window_height / 2) - (icon_size / 2),
						 notification_icons[notification_data_copy.icon_req]);

				/* calculate and DrawText for both summary and body
				   based on the geometry given above */
				rc.left = icon_size + (icon_padding * 2);
				rc.right = notify_wnd.notification_window_width - icon_padding;
				rc.top = icon_padding;
				rc.bottom = notify_wnd.summary_body_divider + (icon_padding * 2);

				DrawText(hdc,
						 notification_data_copy.summary,
						 -1,
						 &rc,
						 DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX);

				if(SelectObject(hdc, (HGDIOBJ) font_body))
				{
					rc.top = rc.bottom;
					rc.bottom = notify_wnd.notification_window_height - icon_padding;

					DrawText(hdc,
							 notification_data_copy.body,
							 -1,
							 &rc,
							 DT_WORDBREAK | DT_EDITCONTROL |
							 DT_NOCLIP | DT_NOPREFIX |
							 DT_EXTERNALLEADING);
				}

				SelectObject(hdc, hOldFont);
			}

			EndPaint(hWnd, &ps);
		}
		break;
	case WM_LIBNOTIFYEXIT:
		if(hook_mouse_over)
		{
			UnhookWindowsHookEx(hook_mouse_over);
			hook_mouse_over = NULL;
		}

		KillTimer(notify_wnd.notification_window, TIMER_ANIMATION);
		KillTimer(notify_wnd.notification_window, TIMER_NOTIFICATION);
		PostQuitMessage(0);
		break;
	case WM_TIMER:
		if(IsWindowVisible(hWnd))
		{
			if(wParam == TIMER_ANIMATION)	/* notification animation timer */
			{
				if(is_fading_out)
				{
					if(notify_wnd.notification_window_alpha > 5)
					{
						notify_wnd.notification_window_alpha -= 25;
					}
					else
					{
						/* once fully faded out, self destroy and reset the flags */
						KillTimer(hWnd, TIMER_ANIMATION);
						is_fading_out = FALSE;
						notify_wnd.notification_window_alpha = 0;
						SendMessage(hWnd, WM_LIBNOTIFYCLOSE, 0, 0);
					}
				}
				else
				{
					if(notify_wnd.notification_window_alpha < 250)
					{
						notify_wnd.notification_window_alpha += 25;
					}
					else
					{
						/* self destory as alpha reaches the maximum */
						KillTimer(hWnd, TIMER_ANIMATION);
						notify_wnd.notification_window_alpha = 255;

						/* set the mouse over hook once the window is fully visible */
						hook_mouse_over = SetWindowsHookEx(WH_MOUSE_LL,
														   mouse_over_hook_proc,
														   (HINSTANCE) GetModuleHandle(NULL),
														   0);
					}
				}
				/* for all the above cases set the newly calculated alpha */
				SetLayeredWindowAttributes(notify_wnd.notification_window,
										   0,
										   notify_wnd.notification_window_alpha,
										   LWA_ALPHA);
			}
			else	/* notification duration timer */
			{
				/* self destruct once timed out */
				KillTimer(hWnd, TIMER_NOTIFICATION);

				/* kill the hook set by animation timer */
				if(hook_mouse_over)
				{
					UnhookWindowsHookEx(hook_mouse_over);
					hook_mouse_over = NULL;
				}

				/* start fading out sequence */
				is_fading_out = TRUE;
				SetTimer(hWnd, TIMER_ANIMATION, fade_duration, NULL);
			}
		}
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}

	return 0;
}
Ejemplo n.º 30
0
static LRESULT CALLBACK TrayCBWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (uMsg == WM_TASKBARCREATED)
	{
		InitTrayIcon();
		return 0;
	}
	switch (uMsg)
	{
		case WM_TRAY_NOTIFY:
			switch(lParam)
			{
				case WM_LBUTTONDBLCLK:
					PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_TRAY_HIDESHOW, 0), 0);
					break;
				case WM_RBUTTONUP:
				{
					SetForegroundWindow(hWnd);
					POINT pt = { 0 };
					GetCursorPos(&pt);
					TrackPopupMenu(hTrayMenu, 0, pt.x, pt.y, 0, hWnd, 0);
					PostMessage(hWnd, WM_NULL, 0, 0);
					break;
				}
			}
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case IDM_TRAY_HIDESHOW:
					if (IsWindowVisible(hMainWnd))
					{
						//ShowWindow(hMainWnd, SW_HIDE);
						CloseWindow(hMainWnd);
					}
					else
					{
						ShowWindow(hMainWnd, SW_RESTORE);
						SetForegroundWindow(hMainWnd);
					}
					break;
				default:
					PostMessage(hMainWnd, WM_COMMAND, wParam, lParam);
					break;
			}
			break;
		case WM_INITMENUPOPUP:
			SendMessage(hMainWnd, WM_INITMENUPOPUP, 0, 0);
			break;
		case WM_MEASUREITEM:
		{
			if (!dwNoOwnerDrawMenu)
			{
				LPMEASUREITEMSTRUCT pMIS = (LPMEASUREITEMSTRUCT)lParam;
				if (pMIS->CtlType == ODT_MENU)
				{
					return pEBMenuTray->MeasureItem(wParam, lParam);
				}
			}
			return FALSE;
		}
		case WM_DRAWITEM:
		{
			if (!dwNoOwnerDrawMenu)
			{
				LPDRAWITEMSTRUCT pDIS = (LPDRAWITEMSTRUCT)lParam;
				if (pDIS->CtlType == ODT_MENU)
				{
					return pEBMenuTray->DrawItem(wParam, lParam);
				}
			}
			return FALSE;
		}
		default:
			return DefWindowProc(hWnd, uMsg, wParam, lParam);
	}
	return 0;
}