Ejemplo n.º 1
0
LRESULT player_impl::win_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch (msg)
	{
	case WM_CREATE:
		{
			SetTimer(hwnd, ID_PLAYER_TIMER, 100, NULL);
		}
		break;
	case WM_TIMER:
		{
			if (wparam != ID_PLAYER_TIMER)
				break;
			// 计算显示客户区.
			int more_y = GetSystemMetrics(SM_CYCAPTION)
				+ (GetSystemMetrics(SM_CYBORDER) * 2)
				+ (GetSystemMetrics(SM_CYDLGFRAME) * 2);
			int more_x = (GetSystemMetrics(SM_CXDLGFRAME) * 2)
				+ (GetSystemMetrics(SM_CXBORDER) * 2);

			if (!m_avplay || !m_avplay->m_video_ctx)
				break;

			if (m_avplay && m_avplay->m_video_ctx &&
				(m_avplay->m_video_ctx->width != 0
				|| m_avplay->m_video_ctx->height != 0
				|| m_avplay->m_play_status == playing))
			{
				RECT rc = { 0 };
				GetWindowRect(hwnd, &rc);
				SetWindowPos(hwnd, HWND_NOTOPMOST, rc.left, rc.top,
					m_avplay->m_video_ctx->width + more_x,
					m_avplay->m_video_ctx->height + more_y,
					SWP_FRAMECHANGED);
				KillTimer(hwnd, ID_PLAYER_TIMER);
			}

			// 得到正确的宽高信息.
			m_video_width = m_avplay->m_video_ctx->width;
			m_video_height = m_avplay->m_video_ctx->height;
		}
		break;
	case WM_KEYDOWN:
		if (wparam == VK_F2)
		{
			full_screen(!m_full_screen);
		}
		break;
	case WM_RBUTTONDOWN:
		{
			if (m_avplay && m_avplay->m_play_status == playing)
				pause();
			else if (m_avplay && m_avplay->m_play_status == paused)
				resume();
		}
		break;
	case WM_LBUTTONDOWN:
		{
			RECT rc = { 0 };
			GetWindowRect(hwnd, &rc);
			int width = rc.right - rc.left;
			int xpos = LOWORD(lparam);
			double fact = (double)xpos / width;

			if (m_avplay && (m_avplay->m_play_status == playing
				|| m_avplay->m_play_status == completed)
				&& (fact >= 0.0f && fact <= 1.0f))
				::av_seek(m_avplay, fact);
		}
		break;
// 	case WM_PAINT:
// 		hdc = BeginPaint(hwnd, &ps);
// 		if (m_avplay)
// 			win_paint(hwnd, hdc);
// 		EndPaint(hwnd, &ps);
// 		break;
	case WM_ERASEBKGND:
		{
			return 1;
// 			if (m_video && m_avplay->m_play_status == playing)
// 				return 1;
// 			else
// 				return DefWindowProc(hwnd, msg, wparam, lparam);
		}
	case WM_ACTIVATE:
	case WM_SYNCPAINT:
		break;
	case WM_MOVING:
	case WM_MOVE:
	case WM_SIZE:
		{
			RECT window;
			GetClientRect(hwnd, &window);
			if (m_avplay && m_avplay->m_vo_ctx &&
				m_video->priv)
			{
				m_video->re_size(m_video, LOWORD(lparam), HIWORD(lparam));
			}
			InvalidateRect(hwnd, NULL, TRUE);
		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		break;
	}

	if (m_old_win_proc)
		return CallWindowProc(m_old_win_proc, hwnd, msg, wparam, lparam);// m_old_win_proc(hwnd, msg, wparam, lparam);
	else
		return DefWindowProc(hwnd, msg, wparam, lparam);
}
Ejemplo n.º 2
0
LRESULT CALLBACK wndproc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
  static HWND hwndbutton,hwndbutton1,hwndbutton2,hwndbutton3,hwndedit,hwndedit1,hwndedit2,hwndedit3;
  HDC hdc;
  PAINTSTRUCT ps;
  static HINSTANCE hInstance;
  static int speed=600;
  static int pause=1;
  int line;
  switch(message)
  {
  case WM_CREATE:
	  {
	   //PlaySound(TEXT("1/神话主题曲.wav"),NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
	   color[0]=CreateSolidBrush(RGB(0,0,0));  //白刷
	   color[1]=CreateSolidBrush(RGB(0,255,0)); //绿刷
	   color[2]=CreateSolidBrush(RGB(255,0,0));  //红刷
	   hwndbutton=CreateWindow(TEXT("BUTTON"),TEXT("暂停"),WS_CHILD|WS_VISIBLE,320,140,80,40,hwnd,(HMENU)1,hInstance,NULL);
	   hwndbutton1=CreateWindow(TEXT("BUTTON"),TEXT("退出"),WS_CHILD|WS_VISIBLE,320,200,80,40,hwnd,(HMENU)2,hInstance,NULL);
	   hwndbutton2=CreateWindow(TEXT("BUTTON"),TEXT("新游戏"),WS_CHILD|WS_VISIBLE,320,260,80,40,hwnd,(HMENU)3,hInstance,NULL);
	   hwndbutton3=CreateWindow(TEXT("BUTTON"),TEXT("确定"),WS_CHILD|WS_VISIBLE,320,450,80,30,hwnd,(HMENU)4,hInstance,NULL);
	   hwndedit=CreateWindow(TEXT("EDIT"),TEXT("分数:0"),WS_CHILD|WS_VISIBLE|ES_READONLY,320,320,80,20,hwnd,(HMENU)5,hInstance,NULL);
	   hwndedit1=CreateWindow(TEXT("EDIT"),TEXT("等级:1"),WS_CHILD|WS_VISIBLE|ES_READONLY,320,350,80,20,hwnd,(HMENU)6,hInstance,NULL);
	   hwndedit2=CreateWindow(TEXT("EDIT"),TEXT(""),WS_CHILD|WS_VISIBLE,320,380,80,20,hwnd,(HMENU)7,hInstance,NULL);
       hwndedit3=CreateWindow(TEXT("EDIT"),TEXT(""),WS_CHILD|WS_VISIBLE|ES_READONLY,320,410,80,20,hwnd,(HMENU)8,hInstance,NULL);
	   SetTimer(hwnd,1,speed,NULL);
	   SetTimer(hwnd,2,400,timerProc);
       return 0;
	  }
  case WM_PAINT:
	  {
		hdc=BeginPaint(hwnd,&ps); 
	    hua(hdc);
		load(hdc);
		huabk(hdc,300,0,0,460);
		huabk(hdc,0,0,0,460);
		Init();
		tuxing(hdc,Pos.dir,Pos.sharp,220,20,1);
		tuxing(hdc,Pos.dir,Pos.sharp,0,0,1);
		EndPaint(hwnd,&ps);
	    return 0;
	  }
  case WM_TIMER:
	  { 
		hdc=GetDC(hwnd);
		if(check(Pos.dir,Pos.sharp,Pos.x,Pos.y+20))
		{
		tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,0);
		Pos.y=Pos.y+20;
        tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,1);
		}
	    else
		{
		  if(gameover())
		  {
		  PlaySound(TEXT("1/luodi.wav"),NULL,SND_FILENAME|SND_ASYNC);
		  line=save(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y);
		  if(line==1)
		  {
		  TCHAR fs[256];
		  f+=10;
		  wsprintf(fs,"分数:%d",f);
		  SetDlgItemText(hwnd,5,fs);
		  if(f==100)
		  {
		   TCHAR dj1[256];
           dj++;
		   wsprintf(dj1,"等级:%d",dj);
		   SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==200)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==400)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==800)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		   if(f==1000)
		   {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		   }
		   if(f==2000)
		   {
			KillTimer(hwnd,1);
			MessageBox(NULL,TEXT(""),TEXT(""),MB_OK);
			ZeroMemory(cfk,sizeof(cfk));
			InvalidateRect(hwnd,NULL,FALSE);
		   }
		  }
		  else if(line>=2&&line<4)
		  {
          TCHAR fs[256];
		  f+=20;
		  wsprintf(fs,"分数:%d",f);
		  SetDlgItemText(hwnd,5,fs);
		  if(f==100)
		  {
		   TCHAR dj1[256];
           dj++;
		   wsprintf(dj1,"等级:%d",dj);
		   SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==200)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==400)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==800)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		   if(f==1000)
		   {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		   }
		   if(f==2000)
		   {
			KillTimer(hwnd,1);
			MessageBox(NULL,TEXT(""),TEXT(""),MB_OK);
			ZeroMemory(cfk,sizeof(cfk));
			InvalidateRect(hwnd,NULL,FALSE);
		   }
		  }
		  else if(line>=4&&line<8)
		  {
		  TCHAR fs[256];
		  f+=40;
		  wsprintf(fs,"分数:%d",f);
		  SetDlgItemText(hwnd,5,fs);
		  if(f==100)
		  {
		   TCHAR dj1[256];
           dj++;
		   wsprintf(dj1,"等级:%d",dj);
		   SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==200)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==400)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==800)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		   if(f==1000)
		   {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		   }
		   if(f==2000)
		   {
			KillTimer(hwnd,1);
			MessageBox(NULL,TEXT(""),TEXT(""),MB_OK);
			ZeroMemory(cfk,sizeof(cfk));
			InvalidateRect(hwnd,NULL,FALSE);
		   }
		  }
		  else if(line>=8)
		  {
		  TCHAR fs[256];
		  f+=160;
		  wsprintf(fs,"分数:%d",f);
		  SetDlgItemText(hwnd,5,fs);
		  if(f==100)
		  {
		   TCHAR dj1[256];
           dj++;
		   wsprintf(dj1,"等级:%d",dj);
		   SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==200)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==400)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		  if(f==800)
		  {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		  }
		   if(f==1000)
		   {
		  TCHAR dj1[256];
          dj++;
		  wsprintf(dj1,"等级:%d",dj);
		  SetDlgItemText(hwnd,6,dj1);
		   }
		   if(f==2000)
		   {
			KillTimer(hwnd,1);
			MessageBox(NULL,TEXT(""),TEXT(""),MB_OK);
			ZeroMemory(cfk,sizeof(cfk));
			InvalidateRect(hwnd,NULL,FALSE);
		   }
		  }
          Init();
		  speed=600;
		  SetTimer(hwnd,1,speed,NULL);
		  InvalidateRect(hwnd,0,FALSE);
		  }
		  else
		{
		 KillTimer(hwnd,1);
		 PlaySound(TEXT("1/结束.wav"),NULL,SND_FILENAME|SND_ASYNC);
		 int i=MessageBox(NULL,TEXT(".......@_@是否重来@_@......"),TEXT("提示"),MB_OKCANCEL);
		 if(i==IDOK)
		 {
		  ZeroMemory(cfk,sizeof(cfk));
		  InvalidateRect(hwnd,0,FALSE);
		  SetTimer(hwnd,1,speed,NULL); 
		 }
		}
		}
		ReleaseDC(hwnd,hdc);
	    return 0;
	  }
  case WM_KEYDOWN:
	  {
		hdc=GetDC(hwnd);
		switch(wParam)
	   {
	   case VK_UP:
	   case VK_SPACE:
		   { 
			 if(check(Pos.dir,(Pos.sharp+1)%4,Pos.x,Pos.y))   //同个函数传替的参数值不同,其每个函数返回的值也不同。
			 {
			 PlaySound(TEXT("1/xuanzhuan.wav"),NULL,SND_FILENAME|SND_ASYNC);
			 tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,0);
			 ++Pos.sharp%=4;  //使用两个tuxing函数,第一个的颜色与背景颜色一样,另一个就是本身颜色
			 tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,1);
			 }
		     return 0;
		   }
	   case VK_LEFT:
		   {
			if(check(Pos.dir,Pos.sharp,Pos.x-20,Pos.y))
			{
			PlaySound(TEXT("1/xuanzhuan.wav"),NULL,SND_FILENAME|SND_ASYNC);
			tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,0);
			Pos.x-=20;
			tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,1);
			}
			return 0;
		   }
	   case VK_RIGHT:
		   {
			if(check(Pos.dir,Pos.sharp,Pos.x+20,Pos.y))
			{
			PlaySound(TEXT("1/xuanzhuan.wav"),NULL,SND_FILENAME|SND_ASYNC);
		    tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,0);
			Pos.x+=20;
			tuxing(hdc,Pos.dir,Pos.sharp,Pos.x,Pos.y,1);
			}
			return 0;
		   }
	   case VK_DOWN:
		   {
			PlaySound(TEXT("1/xuanzhuan.wav"),NULL,SND_FILENAME|SND_ASYNC);
		    speed=100;
			SetTimer(hwnd,1,speed,NULL);
		   }
	   }
	   ReleaseDC(hwnd,hdc);
	   return 0;
	  }
  case WM_COMMAND:
	  {
	   switch(LOWORD(wParam))
	   {
	   case 1:
		   {
			 if(gameover())
			 {
			 if(pause)
			 {
			  PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
			  KillTimer(hwnd,1);
			  SetWindowText(hwndbutton,TEXT("继续"));
			 }
             else
			 {
			  PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
			  SetTimer(hwnd,1,speed,NULL);
			  SetWindowText(hwndbutton,TEXT("暂停"));
			  SetFocus(hwnd); //把输入焦点换回到主窗口
			 }
			 ++pause%=2;
			 }
			 return 0;
		   }
	   case 2:
		   {
			PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
			KillTimer(hwnd,1);
			int i=MessageBox(hwnd,TEXT("确定要退出吗?"),TEXT("提示"),MB_OKCANCEL);
			if(i==IDOK)
			{
            KillTimer(hwnd,1);
	        PostQuitMessage(0);
			}
			else
			{
			 PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
			 SetTimer(hwnd,1,speed,NULL);
			}
		    return 0;
		   }
	   case 3:
		   {
			PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
			KillTimer(hwnd,1);
			int i=MessageBox(hwnd,TEXT("确定要重新开始吗?"),TEXT("提示"),MB_OKCANCEL);
			if(i==IDOK)
			{
			ZeroMemory(cfk,sizeof(cfk));
			InvalidateRect(hwnd,NULL,FALSE);
			SetTimer(hwnd,1,speed,NULL); 
			}
			else
			{
			 PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
			 SetTimer(hwnd,1,speed,NULL);
			}
			return 0;
		   }
	   case 4:
		   {
           ZeroMemory(str,sizeof(str));
           GetDlgItemText(hwnd,7,str,sizeof(str)/sizeof(TCHAR));
           SetFocus(hwnd);
		   return 0;
		   }
	   case ID_MENUITEM40001:
		   {
			PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
            KillTimer(hwnd,1);
			MessageBox(hwnd,TEXT("1.游戏简单,不过功能也齐全.\n"
				                 "2.此游戏可能和其他的有点不\n"
								 "  同之处,其他的都是以分数来玩\n"
								 "3.的!而我的不同之处是以时间\n"
								 "  来玩的!根据时间来换取不同的\n"
								 "  音乐!时间越久速度也越快!@_@\n"),TEXT("说明"),MB_OK);
			SetTimer(hwnd,1,speed,NULL);
		    return 0;
		   }
	   case ID_MENUITEM40002:
		   {
			PlaySound(TEXT("1/Pause.wav"),NULL,SND_FILENAME|SND_ASYNC);
		    KillTimer(hwnd,1);
			MessageBox(hwnd,TEXT("通过此游戏的编程,让我知道许多知识.\n"
				                  "特别是POINT结构体,以及数组的使用...\n"  
								  "也要感谢帮助过我的人,特别是我的网友\n"
								  "和她.非常感谢了!!!我会继续努力的!!!"),TEXT("感言"),MB_OK);
			SetTimer(hwnd,1,speed,NULL);
			return 0;
		   }
	   }
	   return 0;
	  }
  case WM_DESTROY:
	  {
	   KillTimer(hwnd,1);
	   KillTimer(hwnd,2);
	   PostQuitMessage(0);
	   return 0;
	  }
  }
  return DefWindowProc(hwnd,message,wParam,lParam);
}
Ejemplo n.º 3
0
void KillCountdownTimer(){
	KillTimer(dialogWindowHandle, 1);
	EstEID_log("pinpad countdown timer killed");
}
Ejemplo n.º 4
0
//
//  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  目的: 处理主窗口的消息。
//
//  WM_COMMAND	- 处理应用程序菜单
//  WM_PAINT	- 绘制主窗口
//  WM_DESTROY	- 发送退出消息并返回
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc;

	LOGBRUSH brush;
	brush.lbStyle = BS_NULL;
	HBRUSH hBrush = CreateBrushIndirect(&brush);

	LOGPEN pen;
	POINT penWidth;
	penWidth.x = 2;
	penWidth.y = 2;

	int color[7][3] = { { 254, 67, 101 }, { 217, 104, 49 }, { 250, 227, 113 }, { 131, 175, 155 }, { 69, 137, 148 }, { 1, 77, 103 }, { 89, 61, 67 } };
	pen.lopnColor = RGB(color[rown][0], color[rown][1], color[rown][2]);
	timess = timess + 1;
	if (timess == TIMESS)
	{
		rown = rown + 1;
		timess = 0;
	}
	if (rown == 6)
		rown = -0;

	pen.lopnStyle = PS_SOLID;
	pen.lopnWidth = penWidth;
	HPEN hPen = CreatePenIndirect(&pen);


	switch (message)
	{
	case WM_TRAY:
		switch (lParam)
		{
		case WM_RBUTTONDOWN:
		{
			//获取鼠标坐标 
			POINT pt; GetCursorPos(&pt);

			//解决在菜单外单击左键菜单不消失的问题 
			SetForegroundWindow(hWnd);

			//使菜单某项变灰 
			//EnableMenuItem(hMenu, ID_SHOW, MF_GRAYED);     

			//显示并获取选中的菜单 
			int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, NULL, hWnd,
				NULL);
			if (cmd == ID_SHOW)
				MessageBox(hWnd, L"Win32 API 实现系统托盘程序", L"托盘程序", MB_OK);
			if (cmd == ID_EXIT)
				PostMessage(hWnd, WM_DESTROY, NULL, NULL);
		}
		break;
		case WM_LBUTTONDOWN:
			MessageBox(hWnd, L"Win32 API 实现系统托盘程序", L"托盘程序", MB_OK);
			break;
		case WM_LBUTTONDBLCLK:
			break;
		}
		break;

	case WM_TIMER:
		ShowTrayMsg();
		KillTimer(hWnd, wParam);
		break;

	case WM_COPYDATA:
		if (wParam == -1 && lParam == -1)
		{
			GetScreenCapture();
			ShowWindow(hWnd, SW_SHOW);
			UpdateWindow(hWnd);
		}


	case WM_COMMAND:
		wmId = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 分析菜单选择:
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;

	case WM_CREATE:
		//GetScreenCapture();
		break;
	case WM_PAINT:
	{
		hdc = BeginPaint(hWnd, &ps);

		HDC memDc = CreateCompatibleDC(hdc);
		HBITMAP bmp = CreateCompatibleBitmap(hdc, screenW, screenH);
		SelectObject(memDc, bmp);

		BitBlt(memDc, 0, 0, screenW, screenH, g_grayMemDc, 0, 0, SRCCOPY);
		SelectObject(memDc, hBrush);
		SelectObject(memDc, hPen);

		if (isDrawing || isSelect)
		{

			BitBlt(memDc, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, g_srcMemDc, rect.left, rect.top, SRCCOPY);
			Rectangle(memDc, rect.left, rect.top, rect.right, rect.bottom);
		}

		BitBlt(hdc, 0, 0, screenW, screenH, memDc, 0, 0, SRCCOPY);

		DeleteObject(bmp);
		DeleteObject(memDc);

		EndPaint(hWnd, &ps);
	}
	break;

	case WM_LBUTTONDOWN:
	{
		if (!isSelect)
		{
			POINT pt;
			GetCursorPos(&pt);
			rect.left = pt.x;
			rect.top = pt.y;
			rect.right = pt.x;
			rect.bottom = pt.y;

			isDrawing = true;
			InvalidateRgn(hWnd, 0, false);
		}
	}
	break;

	case WM_LBUTTONUP:
	{
		if (isDrawing && !isSelect)
		{
			isDrawing = false;
			POINT pt;
			GetCursorPos(&pt);
			rect.right = pt.x;
			rect.bottom = pt.y;

			isSelect = true;

			InvalidateRgn(hWnd, 0, false);
		}
	}
	break;

	case WM_MOUSEMOVE:
	{
		if (isDrawing&& !isSelect)
		{
			POINT pt;
			GetCursorPos(&pt);
			rect.right = pt.x;
			rect.bottom = pt.y;
			InvalidateRgn(hWnd, 0, false);
		}
	}
	break;
	case WM_LBUTTONDBLCLK:
	{
		if (isSelect)
		{
			WriteDatatoClipBoard();
			InvalidateRgn(hWnd, 0, false);
			ShowWindow(hWnd, SW_HIDE);
			//ShowWindow(hWnd, SW_MINIMIZE);



			TCHAR MyDir[_MAX_PATH];
			SHGetSpecialFolderPath(hWnd, MyDir, CSIDL_DESKTOP, 0);	//获取特殊路径,获取桌面路径
			CString  str;
			str.Format(_T("%s"), MyDir);
			CString depart = "\\";
			CString lkuohao = "(";
			CString rkuohao = ")";
			CString name = SHOT_NAME;
			CString cstype = SHOT_TYPE;
			//cstring to char*
			CString strPath = str + depart + name + cstype;
			//char *path = (LPSTR)(LPCTSTR)cstr;

			//CString strPath = L"C:\\Users\\Wayne\\Desktop\\2015年最新软件进展\\call_log.csv";


			int nLength = strPath.GetLength();
			int nBytes = WideCharToMultiByte(CP_ACP, 0, strPath, nLength, NULL, 0, NULL, NULL);
			char* VoicePath = new char[nBytes + 1];
			memset(VoicePath, 0, nLength + 1);
			WideCharToMultiByte(CP_OEMCP, 0, strPath, nLength, VoicePath, nBytes, NULL, NULL);
			VoicePath[nBytes] = 0;

			//strPath    *VoicePath

			int woc = 2;
			CString woca;
			CString cstrn = strPath;

			while (_access(VoicePath, 0) == 0)
			{
				woca.Format(_T("%d"), woc);
				cstrn = strPath + lkuohao + woca + rkuohao + cstype;
				//判断有没有~
				int n2Length = cstrn.GetLength();
				int n2Bytes = WideCharToMultiByte(CP_ACP, 0, cstrn, n2Length, NULL, 0, NULL, NULL);
				VoicePath = new char[n2Bytes + 1];
				memset(VoicePath, 0, n2Length + 1);
				WideCharToMultiByte(CP_OEMCP, 0, cstrn, n2Length, VoicePath, n2Bytes, NULL, NULL);
				VoicePath[n2Bytes] = 0;
				woc++;
			}

			SaveBmp(hBmp, cstrn);	//使用下面的函数

		}
		isSelect = false;

	}
	break;
	case WM_DESTROY:
	{//窗口销毁时删除托盘 
		Shell_NotifyIcon(NIM_DELETE, &nid);

		UNINSPROC    uninstproc;
		uninstproc = (UNINSPROC)GetProcAddress(m_hDll, "UnInstallHook");
		BOOL bResult = uninstproc();

		::FreeLibrary(m_hDll);
		m_hDll = NULL;

		PostQuitMessage(0);
		break;
	}
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Ejemplo n.º 5
0
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int cnt;
    static HDC hdc,hdcMem;
    static PAINTSTRUCT ps;
    static RECT rect;
    static HBRUSH hBrush;
    static HBITMAP hbmMem;

    static HANDLE hOld;

    static int timerSpeed = 1,nrObj = 0;
    static RECT area = {0, 0, 800, 600};

    switch (message)
    {
        case WM_CREATE:
        {
          hdc = GetDC(hwnd);
          GetClientRect(hwnd,&rect);

          SetTimer(hwnd, ID_TIMER, timerSpeed, NULL);
        break;
        }

        case WM_SIZE:
        {
            hdc = GetDC(hwnd);
            GetClientRect(hwnd, &rect);
        break;
        }

        case WM_LBUTTONDOWN:
        {
            POINT coord;
            coord.x = LOWORD(lParam);
            coord.y = HIWORD(lParam);
            cnt=0;
            if (nrObj>0)
            {
                for(int i = 0; i<nrObj; i++)
                {
                    if(abs(coord.x-objs[i]->center.x)<52)
                    {
                        cnt+=1;
                    }
                }
                if(cnt==0)
                {
                    objs[nrObj] = new Circle(coord,2 + coord.x%5);
                    objs[nrObj] -> Color(RGB(coord.x%200, coord.x%150+coord.y%100, coord.y%200));

                    nrObj++;
                }
            }
            else
            {
                objs[nrObj] = new Circle(coord,2 + coord.x%5);
                objs[nrObj] -> Color(RGB(coord.x%200, coord.x%150+coord.y%100, coord.y%200));

                nrObj++;
            }
        break;
        }

         case WM_KEYDOWN:
         {
            switch(wParam)
            {
                case VK_DOWN:
                {
                    timerSpeed+=10;
                break;
                }

                case VK_UP:
                {
                    timerSpeed-=10;

                        if (timerSpeed < 0)
                        {
                            timerSpeed = 1;
                        }
                 break;
                }

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

            KillTimer(hwnd,ID_TIMER);
            SetTimer(hwnd,ID_TIMER,timerSpeed,NULL);
        break;
        }

        case WM_MOUSEWHEEL:
        {
            if((short)HIWORD(wParam)<0)
            {
                timerSpeed+=10;
            }
            else
            {
                timerSpeed-=10;
                if (timerSpeed<0)
                {
                    timerSpeed=1;
                }
            }
            KillTimer(hwnd,ID_TIMER);
            SetTimer(hwnd,ID_TIMER,timerSpeed,NULL);
        break;
        }

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

            hdcMem = CreateCompatibleDC(hdc);
            hbmMem = CreateCompatibleBitmap(hdc, rect.right, rect.bottom);
            hOld = SelectObject(hdcMem, hbmMem);

            for(int i = 0; i<nrObj-1; i++)
            {
                for(int j = i+1; j < nrObj; j++)
                {
                    Interaction(*objs[i],*objs[j]);
                }
            }

            FillRect(hdcMem, &rect,(HBRUSH)GetStockObject(WHITE_BRUSH));

            for(int i = 0; i < nrObj; i++)
            {
                objs[i] -> Move(hdcMem, rect, hBrush);
            }

            BitBlt(hdc, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY);

            SelectObject(hdcMem,hOld);
            DeleteObject(hbmMem);
            DeleteDC(hdcMem);

            EndPaint(hwnd,&ps);

        break;
        }

        case WM_ERASEBKGND:
            return 1;
        break;

        case WM_TIMER:
        {
            InvalidateRect(hwnd,NULL,FALSE);
        break;
        }

        case WM_DESTROY:
        {
            KillTimer(hwnd,ID_TIMER);

            PostQuitMessage (0);
        break;
        }

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}
Ejemplo n.º 6
0
static INT_PTR CALLBACK sttEnterStringDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	EnterStringFormParam *params = (EnterStringFormParam *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadSkinnedIconBig(SKINICON_OTHER_RENAME));
		SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadSkinnedIcon(SKINICON_OTHER_RENAME));
		params = (EnterStringFormParam *)lParam;
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)params);
		SetWindowText(hwndDlg, params->caption);
		{
			RECT rc; GetWindowRect(hwndDlg, &rc);
			switch (params->type) {
			case ESF_PASSWORD:
				params->idcControl = IDC_TXT_PASSWORD;
				params->height = rc.bottom - rc.top;
				break;

			case ESF_MULTILINE:
				params->idcControl = IDC_TXT_MULTILINE;
				params->height = 0;
				rc.bottom += (rc.bottom - rc.top) * 2;
				SetWindowPos(hwndDlg, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOREPOSITION);
				break;

			case ESF_COMBO:
				params->idcControl = IDC_TXT_COMBO;
				params->height = rc.bottom - rc.top;
				if (params->szDataPrefix && params->recentCount)
					ComboLoadRecentStrings(hwndDlg, params);
				break;

			case ESF_RICHEDIT:
				params->idcControl = IDC_TXT_RICHEDIT;
				SendDlgItemMessage(hwndDlg, IDC_TXT_RICHEDIT, EM_AUTOURLDETECT, TRUE, 0);
				SendDlgItemMessage(hwndDlg, IDC_TXT_RICHEDIT, EM_SETEVENTMASK, 0, ENM_LINK);
				params->height = 0;
				rc.bottom += (rc.bottom - rc.top) * 2;
				SetWindowPos(hwndDlg, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOREPOSITION);
				break;
			}
		}
		ShowWindow(GetDlgItem(hwndDlg, params->idcControl), SW_SHOW);
		if (params->ptszInitVal)
			SetDlgItemText(hwndDlg, params->idcControl, params->ptszInitVal);

		if (params->szDataPrefix)
			Utils_RestoreWindowPosition(hwndDlg, NULL, params->szModuleName, params->szDataPrefix);

		SetTimer(hwndDlg, 1000, 50, NULL);

		if (params->timeout > 0) {
			SetTimer(hwndDlg, 1001, 1000, NULL);
			TCHAR buf[128];
			mir_sntprintf(buf, SIZEOF(buf), TranslateT("OK (%d)"), params->timeout);
			SetDlgItemText(hwndDlg, IDOK, buf);
		}

		return TRUE;

	case WM_DESTROY:
		Window_FreeIcon_IcoLib(hwndDlg);
		break;

	case WM_TIMER:
		switch (wParam) {
		case 1000:
			KillTimer(hwndDlg, 1000);
			EnableWindow(GetParent(hwndDlg), TRUE);
			break;

		case 1001:
			TCHAR buf[128];
			mir_sntprintf(buf, SIZEOF(buf), TranslateT("OK (%d)"), --params->timeout);
			SetDlgItemText(hwndDlg, IDOK, buf);

			if (params->timeout < 0) {
				KillTimer(hwndDlg, 1001);
				UIEmulateBtnClick(hwndDlg, IDOK);
			}
		}
		return TRUE;

	case WM_SIZE:
		{
			UTILRESIZEDIALOG urd = { 0 };
			urd.cbSize = sizeof(urd);
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_ENTER_STRING);
			urd.pfnResizer = sttEnterStringResizer;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
		}
		break;

	case WM_GETMINMAXINFO:
		{
			LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
			if (params && params->height)
				lpmmi->ptMaxSize.y = lpmmi->ptMaxTrackSize.y = params->height;
		}
		break;

	case WM_NOTIFY:
		{
			ENLINK *param = (ENLINK *)lParam;
			if (param->nmhdr.idFrom != IDC_TXT_RICHEDIT) break;
			if (param->nmhdr.code != EN_LINK) break;
			if (param->msg != WM_LBUTTONUP) break;

			CHARRANGE sel;
			SendMessage(param->nmhdr.hwndFrom, EM_EXGETSEL, 0, (LPARAM)& sel);
			if (sel.cpMin != sel.cpMax) break; // allow link selection

			TEXTRANGE tr;
			tr.chrg = param->chrg;
			tr.lpstrText = (TCHAR *)mir_alloc(sizeof(TCHAR)*(tr.chrg.cpMax - tr.chrg.cpMin + 2));
			SendMessage(param->nmhdr.hwndFrom, EM_GETTEXTRANGE, 0, (LPARAM)& tr);

			char *tmp = mir_t2a(tr.lpstrText);
			CallService(MS_UTILS_OPENURL, OUF_NEWWINDOW, (LPARAM)tmp);
			mir_free(tmp);
			mir_free(tr.lpstrText);
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_TXT_MULTILINE:
		case IDC_TXT_RICHEDIT:
			if ((HIWORD(wParam) != EN_SETFOCUS) && (HIWORD(wParam) != EN_KILLFOCUS)) {
				SetDlgItemText(hwndDlg, IDOK, TranslateT("OK"));
				KillTimer(hwndDlg, 1001);
			}
			break;

		case IDC_TXT_COMBO:
			if ((HIWORD(wParam) != CBN_SETFOCUS) && (HIWORD(wParam) != CBN_KILLFOCUS)) {
				SetDlgItemText(hwndDlg, IDOK, TranslateT("OK"));
				KillTimer(hwndDlg, 1001);
			}
			break;

		case IDCANCEL:
			if (params->szDataPrefix)
				Utils_SaveWindowPosition(hwndDlg, NULL, params->szModuleName, params->szDataPrefix);

			EndDialog(hwndDlg, 0);
			break;

		case IDOK:
			HWND hWnd = GetDlgItem(hwndDlg, params->idcControl);
			int len = GetWindowTextLength(hWnd)+1;
			params->ptszResult = (LPTSTR)mir_alloc(sizeof(TCHAR)*len);
			GetWindowText(hWnd, params->ptszResult, len);

			if ((params->type == ESF_COMBO) && params->szDataPrefix && params->recentCount)
				ComboAddRecentString(hwndDlg, params);
			if (params->szDataPrefix)
				Utils_SaveWindowPosition(hwndDlg, NULL, params->szModuleName, params->szDataPrefix);

			EndDialog(hwndDlg, 1);
			break;
		}
	}

	return FALSE;
}
Ejemplo n.º 7
0
void CTaskbarNotifier::Show(LPCTSTR pszCaption, int nMsgType, LPCTSTR pszLink, BOOL bAutoClose)
{
	if (nMsgType == TBN_NONOTIFY)
		return;

	LoadConfiguration(m_strConfigFilePath);

	UINT nScreenWidth;
	UINT nScreenHeight;
	UINT nEvents;
	UINT nBitmapSize;
	CRect rcTaskbar;

	m_strCaption = pszCaption;
	m_nActiveMessageType = nMsgType;
	m_strLink = pszLink;

	if (m_bAutoClose) // sets it only if already true, else wait for user action
		m_bAutoClose = bAutoClose;

	if (nMsgType != TBN_NULL && nMsgType != TBN_LOG && nMsgType != TBN_IMPORTANTEVENT)
	{
		// Add element into string list. Max 5 elements.
		while (m_MessageHistory.GetCount() >= 5)
			delete (CTaskbarNotifierHistory*)m_MessageHistory.RemoveHead();
		CTaskbarNotifierHistory* pHistMsg = new CTaskbarNotifierHistory;
		pHistMsg->m_strMessage = m_strCaption;
		pHistMsg->m_nMessageType = nMsgType;
		pHistMsg->m_strLink = m_strLink;
		m_MessageHistory.AddTail(pHistMsg);
	}

	nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
	nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
	HWND hWndTaskbar = ::FindWindow(_T("Shell_TrayWnd"), 0);
	::GetWindowRect(hWndTaskbar, &rcTaskbar);

	// Daniel Lohmann: Calculate taskbar position from its window rect. However, on XP  it may be that 
	// the taskbar is slightly larger or smaller than the screen size. Therefore we allow some tolerance here.
	if (NearlyEqual(rcTaskbar.left, 0, TASKBAR_X_TOLERANCE) && NearlyEqual(rcTaskbar.right, nScreenWidth, TASKBAR_X_TOLERANCE)) {
		// Taskbar is on top or on bottom
		m_nTaskbarPlacement = NearlyEqual(rcTaskbar.top, 0, TASKBAR_Y_TOLERANCE) ? ABE_TOP : ABE_BOTTOM;
		nBitmapSize = m_nBitmapHeight;
	}
	else {
		// Taskbar is on left or on right
		m_nTaskbarPlacement = NearlyEqual(rcTaskbar.left, 0, TASKBAR_X_TOLERANCE) ? ABE_LEFT : ABE_RIGHT;
		nBitmapSize = m_nBitmapWidth;
	}

	// We calculate the pixel increment and the timer value for the showing animation
	// For transparent bitmaps, all animations are disabled.
	DWORD dwTimeToShow = m_bBitmapAlpha ? 0 : m_dwTimeToShow;
	if (dwTimeToShow > m_dwTimerPrecision) {
		nEvents = min((dwTimeToShow / m_dwTimerPrecision) / 2, nBitmapSize); //<<-- enkeyDEV(Ottavio84) -Reduced frames of a half-
		m_dwShowEvents = dwTimeToShow / nEvents;
		m_nIncrementShow = nBitmapSize / nEvents;
	}
	else {
		m_dwShowEvents = m_dwTimerPrecision;
		m_nIncrementShow = nBitmapSize;
	}

	// We calculate the pixel increment and the timer value for the hiding animation
	// For transparent bitmaps, all animations are disabled.
	DWORD dwTimeToHide = m_bBitmapAlpha ? 0 : m_dwTimeToHide;
	if (dwTimeToHide > m_dwTimerPrecision) {
		nEvents = min((dwTimeToHide / m_dwTimerPrecision / 2), nBitmapSize); //<<-- enkeyDEV(Ottavio84) -Reduced frames of a half-
		m_dwHideEvents = dwTimeToHide / nEvents;
		m_nIncrementHide = nBitmapSize / nEvents;
	}
	else {
		m_dwShowEvents = m_dwTimerPrecision;
		m_nIncrementHide = nBitmapSize;
	}

	// Compute init values for the animation
	switch (m_nAnimStatus)
	{
	case IDT_HIDDEN:
		if (m_nTaskbarPlacement == ABE_RIGHT)
		{
			m_nCurrentPosX = rcTaskbar.left;
			m_nCurrentPosY = rcTaskbar.bottom - m_nBitmapHeight;
			m_nCurrentWidth = 0;
			m_nCurrentHeight = m_nBitmapHeight;
		}
		else if (m_nTaskbarPlacement == ABE_LEFT)
		{
			m_nCurrentPosX = rcTaskbar.right;
			m_nCurrentPosY = rcTaskbar.bottom - m_nBitmapHeight;
			m_nCurrentWidth = 0;
			m_nCurrentHeight = m_nBitmapHeight;
		}
		else if (m_nTaskbarPlacement == ABE_TOP)
		{
			m_nCurrentPosX = rcTaskbar.right - m_nBitmapWidth;
			m_nCurrentPosY = rcTaskbar.bottom;
			m_nCurrentWidth = m_nBitmapWidth;
			m_nCurrentHeight = 0;
		}
		else
		{
			// Taskbar is on the bottom or Invisible
			m_nCurrentPosX = rcTaskbar.right - m_nBitmapWidth;
			m_nCurrentPosY = rcTaskbar.top;
			m_nCurrentWidth = m_nBitmapWidth;
			m_nCurrentHeight = 0;
		}
		ShowWindow(SW_SHOWNOACTIVATE);
		SetTimer(IDT_APPEARING, m_dwShowEvents, NULL);
		break;

	case IDT_APPEARING:
		RedrawWindow(&m_rcText);
		break;

	case IDT_WAITING:
		RedrawWindow(&m_rcText);
		KillTimer(IDT_WAITING);
		SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
		break;

	case IDT_DISAPPEARING:
		KillTimer(IDT_DISAPPEARING);
		SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
		if (m_nTaskbarPlacement == ABE_RIGHT)
		{
			m_nCurrentPosX = rcTaskbar.left - m_nBitmapWidth;
			m_nCurrentWidth = m_nBitmapWidth;
		}
		else if (m_nTaskbarPlacement == ABE_LEFT)
		{
			m_nCurrentPosX = rcTaskbar.right;
			m_nCurrentWidth = m_nBitmapWidth;
		}
		else if (m_nTaskbarPlacement == ABE_TOP)
		{
			m_nCurrentPosY = rcTaskbar.bottom;
			m_nCurrentHeight = m_nBitmapHeight;
		}
		else
		{
			m_nCurrentPosY = rcTaskbar.top - m_nBitmapHeight;
			m_nCurrentHeight = m_nBitmapHeight;
		}

		SetWindowPos(&wndTopMost, m_nCurrentPosX, m_nCurrentPosY, m_nCurrentWidth, m_nCurrentHeight, SWP_NOACTIVATE);
		RedrawWindow(&m_rcText);
		break;
	}
}
Ejemplo n.º 8
0
long _EXPORT FAR PASCAL WndProc( HWND hwnd, UINT message, WPARAM wparam,
                                  LPARAM lparam )
/*********************************************************************/
{
    static HANDLE   hdlginstance;
    static BOOL     got_watzee_bonus;
    PAINTSTRUCT     ps;
    FARPROC         dlg_proc;
    HDC             hdc;
    POINT           point;
    short           x;
    short           y;
    short           dy;
    short           i;

    switch( message ) {
    case WM_CREATE :
        hdlginstance = ((CREATESTRUCT far *) MK_FP32((void*)lparam))->hInstance;
        x = CharWidth * 22 + CharWidth / 2;
        y = CharHeight * 3;
        dy = CharHeight * 3;
        dy += dy / 7;
       /*  create the check marks for the dice bitmaps, and the ROLL and
           OK buttons  */
        for( i = 0; i < 5; i++, y += dy ) {
            CreateWindow( "BUTTON", "", WS_CHILD|WS_VISIBLE|BS_CHECKBOX,
                          x, y, CharWidth, CharHeight, hwnd,
                          (HMENU)(IDW_DICE1+i),
                          hdlginstance,
                          NULL );
        }
        CreateWindow( "BUTTON", "ROLL", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                      x, CharHeight * 19, 9 * CharWidth / 2 ,
                      CharHeight * 2, hwnd, (HMENU)IDW_ROLL,
                      hdlginstance, NULL );
        CreateWindow( "BUTTON", "OK", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                      x, 43 * CharHeight / 2, 9 * CharWidth / 2,
                      CharHeight * 2, hwnd, (HMENU)IDW_OK,
                      hdlginstance, NULL );
        return( 0 );
    case WMW_START_NEW_GAME :
        dlg_proc = MakeProcInstance( (FARPROC)GetNumPlayersDialogProc, hdlginstance );
        DialogBox( hdlginstance, "GetNumPlayers", hwnd, (DLGPROC)dlg_proc );
        FreeProcInstance( dlg_proc );
        dlg_proc = MakeProcInstance( (FARPROC)GetInitialsDialogProc, hdlginstance );
        DialogBox( hdlginstance, "GetPlayersInitials", hwnd, (DLGPROC)dlg_proc );
        FreeProcInstance( dlg_proc );
        EnableWindow( GetDlgItem( hwnd, IDW_OK ), FALSE );
        EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), TRUE );
        PlayingGameYet = TRUE;
        InvalidateRect( hwnd, NULL, FALSE );
        for( i = 0; i < NumberOfPlayers; i++ ) {
            if( Player[i][IS_COMPUTER] ) break;
        }
        if( i < NumberOfPlayers && !GotTimer ) {
            while( !SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL ) ) {
                if( MessageBox( hwnd, "Too many clocks or timers are active",
                 AppName, MB_ICONEXCLAMATION|MB_RETRYCANCEL ) == IDCANCEL ) {
                    DestroyWindow( hwnd );
                    return( 0 );
                }
            }
            GotTimer = TRUE;
        }
        if( i == 0 ) {
            PCTurn = TRUE;
            EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), FALSE );
        }
        hdc = GetDC( hwnd );
        RollDice( hwnd, hdc );
        GetDiceInfo();
        ReleaseDC( hwnd, hdc );
//      SetFocus( hwnd );
        return( 0 );
    case WM_COMMAND :
        switch( LOWORD( wparam ) ) {
        case IDM_NEWGAME :
            if( GotTimer ) {
                KillTimer( hwnd, ID_TIMER );
            }
            if( MessageBox( hwnd, "Start New Game:  Are you sure?", "WATZEE",
                            MB_YESNO | MB_ICONEXCLAMATION ) == IDYES ) {
                InitializeGameData();
                InvalidateRect( hwnd, NULL, TRUE );
                SendMessage( hwnd, WMW_START_NEW_GAME, 0, 0 );
            } else if( GotTimer ) {
                SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL );
            }
            break;
        case IDM_OPTIONS :
            if( GotTimer ) {
                KillTimer( hwnd, ID_TIMER );
            }
            dlg_proc = MakeProcInstance( (FARPROC)OptionsDialogProc, hdlginstance );
            DialogBox( hdlginstance, "Options", hwnd, (DLGPROC)dlg_proc );
            FreeProcInstance( dlg_proc );
            if( GotTimer ) {
                SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL );
            }
            break;
        case IDM_EXIT :
            DestroyWindow( hwnd );
            break;
        case IDM_SCORING :
            if( GotTimer ) {
                KillTimer( hwnd, ID_TIMER );
            }
            dlg_proc = MakeProcInstance( (FARPROC)HelpDialogProc, hdlginstance );
            DialogBox( hdlginstance, "WatzeeHelp", hwnd, (DLGPROC)dlg_proc );
            FreeProcInstance( dlg_proc );
            if( GotTimer ) {
                SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL );
            }
            break;
        case IDM_ABOUT :
            if( GotTimer ) {
                KillTimer( hwnd, ID_TIMER );
            }
            dlg_proc = MakeProcInstance( (FARPROC)AboutDialogProc, hdlginstance );
            DialogBox( hdlginstance, "AboutWatzee", hwnd, (DLGPROC)dlg_proc );
            FreeProcInstance( dlg_proc );
            if( GotTimer ) {
                SetTimer( hwnd, ID_TIMER, TIMER_INTERVAL, NULL );
            }
            break;
        case IDW_DICE1 :
        case IDW_DICE2 :
        case IDW_DICE3 :
        case IDW_DICE4 :
        case IDW_DICE5 :
            if( !PCTurn && CurrentRoll < 2 ) {
                SendMessage( hwnd, WMW_DIE_CHECK, wparam, 0 );
            }
            break;
        case IDW_ROLL :
            SendMessage( hwnd, WMW_ROLL, 0, 0 );
            break;
        case IDW_OK :
            SendMessage( hwnd, WMW_OK, 0, 0 );
            break;
        }
        return( 0 );
    case WM_LBUTTONUP :
        if( !PCTurn ) {
            MAKE_POINT( point, lparam );
            if( point.x > CharWidth * 24
             && point.y < CharHeight * 20 ) {
                wparam = GetDieCheck( hwnd, point );
                if( wparam && CurrentRoll < 2 ) {
                    SendMessage( hwnd, WMW_DIE_CHECK, wparam, 0 );
                }
            } else {
                wparam = GetScoreCheck( point );
                if( wparam && Player[CurrentPlayer][wparam] == UNDEFINED ) {
                     SendMessage( hwnd, WMW_SCORE_CHECK, wparam, 0 );
                }
            }
        }
        return( 0 );
    case WMW_DIE_CHECK :
        i = LOWORD( wparam ) - IDW_DICE1;
        Dice[i].is_checked = !Dice[i].is_checked;
        CheckDlgButton( hwnd, wparam, (BOOL)Dice[i].is_checked );
//      SetFocus( hwnd );
        return( 0 );
    case WMW_SCORE_CHECK :
        hdc = GetDC( hwnd );
        if( wparam != LastScoreSelection ) {
            DoScore( hdc, wparam );
            EnableWindow( GetDlgItem( hwnd, IDW_OK ), TRUE );
        }
        ReleaseDC( hwnd, hdc );
//      SetFocus( hwnd );
        return( 0 );
    case WMW_ROLL :
        hdc = GetDC( hwnd );
        if( DieCheckMeansRoll ) {
            for( i = 0; i < 5; i++ ) {
                if( Dice[i].is_checked ) break;
            }
        } else {
            for( i = 0; i < 5; i++ ) {
                if( !Dice[i].is_checked ) break;
            }
        }
        if( i < 5 ) {
            if( LastScoreSelection ) {
                Player[CurrentPlayer][LastScoreSelection] = UNDEFINED;
                WriteScore( hdc, CurrentPlayer, LastScoreSelection );
                DoScoreTotals( hdc );
                LastScoreSelection = 0;
            }
            got_watzee_bonus = FALSE;
            CurrentRoll++;
            RollDice( hwnd, hdc );
            GetDiceInfo();
            if( DiceInfo.got_watzee && Player[CurrentPlayer][WATZEE] == 50 ) {
                got_watzee_bonus = TRUE;
            }
            if( CurrentRoll == 2 ) {
                EnableWindow( GetDlgItem( hwnd, IDW_ROLL ), FALSE );
            }
        }
        ReleaseDC( hwnd, hdc );
//      SetFocus( hwnd );
        return( 0 );
    case WMW_OK :
        hdc = GetDC( hwnd );
        LastScoreSelection = 0;
        if( got_watzee_bonus ) {
            DoScore( hdc, WATZEE_BONUS );
            LastScoreSelection = 0;
            got_watzee_bonus = FALSE;
        }
        NextPlayer( hwnd, hdc );
        ReleaseDC( hwnd, hdc );
//      SetFocus( hwnd );
        return( 0 );
    case WMW_GAME_OVER :
        hdc = GetDC( hwnd );
        WriteScoreOptions( hdc );
        ReleaseDC( hwnd, hdc );
        if( GotTimer ) {
            KillTimer( hwnd, ID_TIMER );
            GotTimer = FALSE;
        }
        if( MessageBox( hwnd, "Another Game ?", "WATZEE", MB_YESNO ) == IDYES ) {
            InitializeGameData();
            InvalidateRect( hwnd, NULL, TRUE );
            SendMessage( hwnd, WMW_START_NEW_GAME, 0, 0 );
        } else {
            DestroyWindow( hwnd );
        }
        return( 0 );
    case WM_TIMER :
        if( PCTurn ) {
            PCPlay( hwnd );
        }
        return( 0 );
    case WM_PAINT :
        hdc = BeginPaint( hwnd, &ps );
        DrawDice( hwnd, hdc );
        DrawScoreCard( hdc );
        WriteScoreOptions( hdc );
        if( PlayingGameYet ) {
            WriteInitials( hdc );
            HighliteName( hdc, CurrentPlayer );
            WriteScores( hdc );
        }
        EndPaint( hwnd, &ps );
        return( 0 );
    case WM_DESTROY :
        {
            HBITMAP     hbm;

            if( GotTimer ) {
                KillTimer( hwnd, ID_TIMER );
            }
            for( i = 0; i < 6; i++ ) {
                hbm = (HBITMAP)GetWindowLong( hwnd, i * sizeof( DWORD ) );
                DeleteObject( hbm );
            }
            PostQuitMessage( 0 );
            return( 0 );
        }
    }
    return( DefWindowProc( hwnd, message, wparam, lparam ) );
}
Ejemplo n.º 9
0
BOOL CALLBACK UruLoginDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
    static LoginDialogParam* pLoginParam;
    static bool showAuthFailed = false;

    switch( uMsg )
    {
        case WM_INITDIALOG:
        {
            s_loginDlgRunning = true;
            _beginthread(StatusCallback, 0, hwndDlg);
            pLoginParam = (LoginDialogParam*)lParam;

            SetWindowText(hwndDlg, "Login");
            SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(gHInst, MAKEINTRESOURCE(IDI_ICON_DIRT)));

            EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);

            SetDlgItemText(hwndDlg, IDC_URULOGIN_USERNAME, pLoginParam->username);
            CheckDlgButton(hwndDlg, IDC_URULOGIN_REMEMBERPASS, pLoginParam->remember ? BST_CHECKED : BST_UNCHECKED);
            if (pLoginParam->remember)
                SetDlgItemText(hwndDlg, IDC_URULOGIN_PASSWORD, FAKE_PASS_STRING);

            SetFocus(GetDlgItem(hwndDlg, pLoginParam->focus));

            if (IS_NET_ERROR(pLoginParam->authError))
            {
                showAuthFailed = true;
            }

            SendMessage(GetDlgItem(hwndDlg, IDC_PRODUCTSTRING), WM_SETTEXT, 0,
                        (LPARAM)plProduct::ProductString().c_str());

            for (int i = 0; i < plLocalization::GetNumLocales(); i++)
            {
                SendMessage(GetDlgItem(hwndDlg, IDC_LANGUAGE), CB_ADDSTRING, 0, (LPARAM)plLocalization::GetLanguageName((plLocalization::Language)i));
            }
            SendMessage(GetDlgItem(hwndDlg, IDC_LANGUAGE), CB_SETCURSEL, (WPARAM)plLocalization::GetLanguage(), 0);

            SetTimer(hwndDlg, AUTH_LOGIN_TIMER, 10, NULL);
            return FALSE;
        }

        case WM_USER_SETSTATUSMSG:
             SendMessage(GetDlgItem(hwndDlg, IDC_STATUS_TEXT), WM_SETTEXT, 0, lParam);
             return TRUE;

        case WM_DESTROY:
        {
            s_loginDlgRunning = false;
            s_statusEvent.Wait();
            KillTimer(hwndDlg, AUTH_LOGIN_TIMER);
            return TRUE;
        }
    
        case WM_NCHITTEST:
        {
            SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, (LONG_PTR)HTCAPTION);
            return TRUE;
        }
    
        case WM_PAINT:
        {
            if (showAuthFailed)
            {
                SetTimer(hwndDlg, AUTH_FAILED_TIMER, 10, NULL);
                showAuthFailed = false;
            }
            return FALSE;
        }
    
        case WM_COMMAND:
        {
            if (HIWORD(wParam) == BN_CLICKED && (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL))
            {
                bool ok = (LOWORD(wParam) == IDOK);
                if (ok)
                {
                    char password[kMaxPasswordLength];

                    GetDlgItemText(hwndDlg, IDC_URULOGIN_USERNAME, pLoginParam->username, kMaxAccountNameLength);
                    GetDlgItemText(hwndDlg, IDC_URULOGIN_PASSWORD, password, kMaxPasswordLength);
                    pLoginParam->remember = (IsDlgButtonChecked(hwndDlg, IDC_URULOGIN_REMEMBERPASS) == BST_CHECKED);

                    plLocalization::Language new_language = (plLocalization::Language)SendMessage(GetDlgItem(hwndDlg, IDC_LANGUAGE), CB_GETCURSEL, 0, 0L);
                    plLocalization::SetLanguage(new_language);

                    SaveUserPass (pLoginParam, password);

                    // Welcome to HACKland, population: Branan
                    // The code to write general.ini really doesn't belong here, but it works... for now.
                    // When general.ini gets expanded, this will need to find a proper home somewhere.
                    {
                        plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini");
                        plString ini_str = plString::Format("App.SetLanguage %s\n", plLocalization::GetLanguageName(new_language));
                        hsStream* gini = plEncryptedStream::OpenEncryptedFileWrite(gipath);
                        gini->WriteString(ini_str);
                        gini->Close();
                        delete gini;
                    }

                    memset(&pLoginParam->authError, 0, sizeof(pLoginParam->authError));
                    bool cancelled = AuthenticateNetClientComm(&pLoginParam->authError, hwndDlg);

                    if (IS_NET_SUCCESS(pLoginParam->authError) && !cancelled)
                        EndDialog(hwndDlg, ok);
                    else {
                        if (!cancelled)
                            ::DialogBoxParam(gHInst, MAKEINTRESOURCE( IDD_AUTHFAILED ), hwndDlg, AuthFailedDialogProc, (LPARAM)pLoginParam);
                        else
                        {
                            NetCommDisconnect();
                        }
                    }
                }
                else
                    EndDialog(hwndDlg, ok);

                return TRUE;
            }
            else if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == IDC_URULOGIN_USERNAME)
            {
                char username[kMaxAccountNameLength];
                GetDlgItemText(hwndDlg, IDC_URULOGIN_USERNAME, username, kMaxAccountNameLength);

                if (StrLen(username) == 0)
                    EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE);
                else
                    EnableWindow(GetDlgItem(hwndDlg, IDOK), TRUE);

                return TRUE;
            }
            else if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_URULOGIN_GAMETAPLINK)
            {
                const char* signupurl = GetServerSignupUrl();
                ShellExecuteA(NULL, "open", signupurl, NULL, NULL, SW_SHOWNORMAL);

                return TRUE;
            }
            break;
        }
    
        case WM_TIMER:
        {
            switch(wParam)
            {
            case AUTH_FAILED_TIMER:
                KillTimer(hwndDlg, AUTH_FAILED_TIMER);
                ::DialogBoxParam(gHInst, MAKEINTRESOURCE( IDD_AUTHFAILED ), hwndDlg, AuthFailedDialogProc, (LPARAM)pLoginParam);
                return TRUE;

            case AUTH_LOGIN_TIMER:
                NetCommUpdate();
                return TRUE;
            }
            return FALSE;
        }
    }
    return FALSE;
}
Ejemplo n.º 10
0
// Remote connection dialog procedure
UINT EmRemoteDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)
{
	WINUI_REMOTE *r = (WINUI_REMOTE *)param;
	CEDAR *c;
	// Validate arguments
	if (hWnd == NULL)
	{
		return 0;
	}

	switch (msg)
	{
	case WM_INITDIALOG:
		RemoteDlgInit(hWnd, r);
		SetTimer(hWnd, 1, 100, NULL);
		break;
	case WM_TIMER:
		switch (wParam)
		{
		case 1:
			KillTimer(hWnd, 1);
			RemoteDlgRefresh(hWnd, r);
			SetTimer(hWnd, 1, 100, NULL);
			break;
		}
		break;
	case WM_COMMAND:
		switch (wParam)
		{
		case R_LOCAL:
			if (IsChecked(hWnd, R_LOCAL) == false)
			{
				SetTextA(hWnd, C_HOSTNAME, "");
				RemoteDlgRefresh(hWnd, r);
				FocusEx(hWnd, C_HOSTNAME);
			}
			else
			{
				SetTextA(hWnd, C_HOSTNAME, "localhost");
				RemoteDlgRefresh(hWnd, r);
				Focus(hWnd, IDOK);
			}
			break;
		case IDCANCEL:
			Close(hWnd);
			break;
		case IDOK:
			RemoteDlgOnOk(hWnd, r);
			break;
		case B_ABOUT:
			c = NewCedar(NULL, NULL);
			About(hWnd, c, _UU("PRODUCT_NAME_ELOGMGR"));
			ReleaseCedar(c);
		}
		switch (LOWORD(wParam))
		{
		case R_LOCAL:
		case C_HOSTNAME:
			RemoteDlgRefresh(hWnd, r);
			break;
		}
		break;
	case WM_CLOSE:
		FreeCandidateList(r->CandidateList);
		EndDialog(hWnd, false);
		break;
	}

	return 0;
}
Ejemplo n.º 11
0
// Window procedure, handles all messages for this program
LRESULT CALLBACK WndProc(	HWND 	hWnd,
							UINT	message,
							WPARAM	wParam,
							LPARAM	lParam)
	{
	static HGLRC hRC;		// Permenant Rendering context
	static HDC hDC;			// Private GDI Device context

	switch (message)
	   	{
		// Window creation, setup for OpenGL
		case WM_CREATE:
			// Store the device context
			hDC = GetDC(hWnd);		

			// Select the pixel format
			SetDCPixelFormat(hDC);		

			// Create the rendering context and make it current
			hRC = wglCreateContext(hDC);
			wglMakeCurrent(hDC, hRC);

			// Create the palette
			hPalette = GetOpenGLPalette(hDC);

			SetupRC(hDC);

			break;

		// Window is being destroyed, cleanup
		case WM_DESTROY:
			// Kill the timer that we created
			KillTimer(hWnd,101);

			glDeleteLists(nFontList, 128);

			// Deselect the current rendering context and delete it
			wglMakeCurrent(hDC,NULL);
			wglDeleteContext(hRC);

			// Delete the palette
			if(hPalette != NULL)
				DeleteObject(hPalette);

			// Tell the application to terminate after the window
			// is gone.
			PostQuitMessage(0);
			break;

		// Window is resized.
		case WM_SIZE:
			// Call our function which modifies the clipping
			// volume and viewport
			ChangeSize(LOWORD(lParam), HIWORD(lParam));
			break;

		// The painting function.  This message sent by Windows 
		// whenever the screen needs updating.
		case WM_PAINT:
			{
			// Call OpenGL drawing code
			RenderScene();

			// Call function to swap the buffers
			SwapBuffers(hDC);

            ValidateRect(hWnd,NULL);
			}
			break;


		// Windows is telling the application that it may modify
		// the system palette.  This message in essance asks the 
		// application for a new palette.
		case WM_QUERYNEWPALETTE:
			// If the palette was created.
			if(hPalette)
				{
				int nRet;

				// Selects the palette into the current device context
				SelectPalette(hDC, hPalette, FALSE);

				// Map entries from the currently selected palette to
				// the system palette.  The return value is the number 
				// of palette entries modified.
				nRet = RealizePalette(hDC);

				// Repaint, forces remap of palette in current window
				InvalidateRect(hWnd,NULL,FALSE);

				return nRet;
				}
			break;

	
		// This window may set the palette, even though it is not the 
		// currently active window.
		case WM_PALETTECHANGED:
			// Don't do anything if the palette does not exist, or if
			// this is the window that changed the palette.
			if((hPalette != NULL) && ((HWND)wParam != hWnd))
				{
				// Select the palette into the device context
				SelectPalette(hDC,hPalette,FALSE);

				// Map entries to system palette
				RealizePalette(hDC);
				
				// Remap the current colors to the newly realized palette
				UpdateColors(hDC);
				return 0;
				}
			break;


        default:   // Passes it on if unproccessed
            return (DefWindowProc(hWnd, message, wParam, lParam));

        }

    return (0L);
	}
Ejemplo n.º 12
0
// Main dialog procedure
UINT EmMainDlg(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)
{
	NMHDR *n;
	RPC *r = (RPC *)param;
	UINT i;
	char *name;
	// Validate arguments
	if (hWnd == NULL)
	{
		return 0;
	}

	switch (msg)
	{
	case WM_INITDIALOG:
		EmMainInit(hWnd, r);
		break;

	case WM_COMMAND:
		switch (wParam)
		{
		case IDOK:
			// Edit
			i = LvGetSelected(hWnd, L_LIST);
			if (i != INFINITE)
			{
				wchar_t *tmp;
				tmp = LvGetStr(hWnd, L_LIST, i, 0);
				if (tmp != NULL)
				{
					name = CopyUniToStr(tmp);
					EmAdd(hWnd, r, name);
					Free(tmp);
					Free(name);
				}
			}
			break;

		case B_PASSWORD:
			// Admin password
			Dialog(hWnd, D_EM_PASSWORD, EmPasswordDlg, r);
			break;

		case B_LICENSE:
			// Admin password
			Dialog(hWnd, D_EM_LICENSE, EmLicenseDlg, r);
			break;

		case B_ADD:
			// Add
			EmAdd(hWnd, r, NULL);
			EmMainRefresh(hWnd, r);
			break;

		case B_DELETE:
			// Delete
			i = LvGetSelected(hWnd, L_LIST);
			if (i != INFINITE)
			{
				wchar_t *tmp;
				tmp = LvGetStr(hWnd, L_LIST, i, 0);
				if (tmp != NULL)
				{
					RPC_DELETE_DEVICE t;
					wchar_t msg[MAX_SIZE];
					name = CopyUniToStr(tmp);
					UniFormat(msg, sizeof(msg), _UU("EM_DELETE_CONFIRM"), name);
					if (MsgBox(hWnd, MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2, msg) == IDYES)
					{
						Zero(&t, sizeof(t));
						StrCpy(t.DeviceName, sizeof(t.DeviceName), name);
						if (CALL(hWnd, EcDelDevice(r, &t)))
						{
							EmMainRefresh(hWnd, r);
						}
					}
					Free(tmp);
					Free(name);
				}
			}
			break;

		case IDCANCEL:
			Close(hWnd);
			break;
		}
		break;

	case WM_TIMER:
		switch (wParam)
		{
		case 1:
			KillTimer(hWnd, 1);
			EmMainRefresh(hWnd, r);
			SetTimer(hWnd, 1, 1000, NULL);
			break;
		}
		break;

	case WM_NOTIFY:
		n = (NMHDR *)lParam;
		switch (n->code)
		{
		case NM_DBLCLK:
			switch (n->idFrom)
			{
			case L_LIST:
				if (IsEnable(hWnd, IDOK))
				{
					Command(hWnd, IDOK);
				}
				break;
			}
			break;
		case LVN_ITEMCHANGED:
			switch (n->idFrom)
			{
			case L_LIST:
				EmMainUpdate(hWnd, r);
				break;
			}
			break;
		}
		break;

	case WM_CLOSE:
		EndDialog(hWnd, 0);
		break;
	}

	return 0;
}
Ejemplo n.º 13
0
int PopupUpdate(MCONTACT hContact, MEVENT hEvent)
{
	// merge only message popups
	PLUGIN_DATA *pdata = (PLUGIN_DATA*)PopupList[NumberPopupData(hContact, EVENTTYPE_MESSAGE)];

	if (hEvent) {
		pdata->countEvent++;

		pdata->lastEventData->next = (EVENT_DATA_EX *)mir_alloc(sizeof(EVENT_DATA_EX));
		pdata->lastEventData->next->prev = pdata->lastEventData;
		pdata->lastEventData = pdata->lastEventData->next;
		pdata->lastEventData->hEvent = hEvent;
		pdata->lastEventData->number = pdata->lastEventData->prev->number + 1;
		pdata->lastEventData->next = NULL;
		if (!pdata->pluginOptions->bShowON && pdata->countEvent > pdata->pluginOptions->iNumberMsg && pdata->pluginOptions->iNumberMsg)
			pdata->firstShowEventData = pdata->firstShowEventData->next;
		//re-init timer delay
		KillTimer(pdata->hWnd, TIMER_TO_ACTION);
		SetTimer(pdata->hWnd, TIMER_TO_ACTION, pdata->iSeconds * 1000, NULL);
	}

	TCHAR lpzText[MAX_SECONDLINE*2] = _T("\0\0");
	if (pdata->pluginOptions->bShowHeaders)
		mir_sntprintf(lpzText, TranslateT("[b]Number of new message(s): %d[/b]\n"), pdata->countEvent);

	int doReverse = pdata->pluginOptions->bShowON;

	if ((pdata->firstShowEventData != pdata->firstEventData && doReverse) || (pdata->firstShowEventData != pdata->lastEventData && !doReverse))
		mir_sntprintf(lpzText, _T("%s...\n"), lpzText);

	//take the active event as starting one
	EVENT_DATA_EX *eventData = pdata->firstShowEventData;

	int iEvent = 0;
	while (true) {
		if (iEvent)
			eventData = (doReverse) ? eventData->next : eventData->prev;
		iEvent++;

		//get DBEVENTINFO with pBlob if preview is needed (when is test then is off)
		DBEVENTINFO dbe = {0};
		dbe.cbSize = sizeof(dbe);
		dbe.pBlob = NULL;
		dbe.cbBlob = 0;
		if (pdata->pluginOptions->bPreview && eventData->hEvent) {
			dbe.cbBlob = db_event_getBlobSize(eventData->hEvent);
			dbe.pBlob = (PBYTE)mir_alloc(dbe.cbBlob);
		}

		if (eventData->hEvent)
			db_event_get(eventData->hEvent, &dbe);

		if (pdata->pluginOptions->bShowDate || pdata->pluginOptions->bShowTime) {
			TCHAR timestamp[MAX_DATASIZE];
			TCHAR formatTime[MAX_DATASIZE];
			if (pdata->pluginOptions->bShowDate)
				_tcsncpy(formatTime, _T("%Y.%m.%d"), _countof(formatTime));
			else if (pdata->pluginOptions->bShowTime)
				mir_tstrncat(formatTime, _T(" %H:%M"), _countof(formatTime) - mir_tstrlen(formatTime));
			time_t localTime = dbe.timestamp;
			_tcsftime(timestamp, _countof(timestamp), formatTime, localtime(&localTime));
			mir_sntprintf(lpzText, _T("%s[b][i]%s[/i][/b]\n"), lpzText, timestamp);
		}

		// prepare event preview
		TCHAR* szEventPreview = GetEventPreview(&dbe);
		mir_sntprintf(lpzText, _T("%s%s"), lpzText, szEventPreview);
		mir_free(szEventPreview);
		
		if (dbe.pBlob)
			mir_free(dbe.pBlob);
		if (doReverse) {
			if ((iEvent >= pdata->pluginOptions->iNumberMsg && pdata->pluginOptions->iNumberMsg) || !eventData->next)
				break;
		}
		else if ((iEvent >= pdata->pluginOptions->iNumberMsg && pdata->pluginOptions->iNumberMsg) || !eventData->prev)
			break;

		mir_sntprintf(lpzText, _T("%s\n"), lpzText);
	}

	if ((doReverse && eventData->next) || (!doReverse && eventData->prev))
		mir_sntprintf(lpzText, _T("%s\n..."), lpzText);

	PUChangeTextT(pdata->hWnd, lpzText);
	return 0;
}
Ejemplo n.º 14
0
/*
 * set_filter_proc - フィルタ設定のプロシージャ
 */
BOOL CALLBACK set_filter_proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LV_COLUMN lvc;
	FILTER_INFO *fi;
	int i;
	BOOL enable;
#ifdef OP_XP_STYLE
	static long hThemeUp, hThemeDown;
#endif	// OP_XP_STYLE

	switch (uMsg) {
	case WM_INITDIALOG:
#ifdef OP_XP_STYLE
		// XP
		hThemeUp = open_theme(GetDlgItem(hDlg, IDC_BUTTON_UP), L"SCROLLBAR");
		hThemeDown = open_theme(GetDlgItem(hDlg, IDC_BUTTON_DOWN), L"SCROLLBAR");
#endif	// OP_XP_STYLE
		if (option.filter_all_action == FILTER_ACTION_ADD) {
			CheckDlgButton(hDlg, IDC_RADIO_ALL_ADD, 1);
		} else {
			CheckDlgButton(hDlg, IDC_RADIO_ALL_IGNORE, 1);
		}

		// リストビューのカラムの設定
		i = 0;
		lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;

		lvc.fmt = LVCFMT_LEFT;
		lvc.cx = 150;
		lvc.pszText = message_get_res(IDS_FILTER_LIST_NAME);
		lvc.iSubItem = i++;
		ListView_InsertColumn(GetDlgItem(hDlg, IDC_LIST_FILTER), lvc.iSubItem, &lvc);

		lvc.fmt = LVCFMT_LEFT;
		lvc.cx = 100;
		lvc.pszText = message_get_res(IDS_FILTER_LIST_ACTION);
		lvc.iSubItem = i++;
		ListView_InsertColumn(GetDlgItem(hDlg, IDC_LIST_FILTER), lvc.iSubItem, &lvc);

		lvc.fmt = LVCFMT_RIGHT;
		lvc.cx = 80;
		lvc.pszText = message_get_res(IDS_FILTER_LIST_SIZE);
		lvc.iSubItem = i++;
		ListView_InsertColumn(GetDlgItem(hDlg, IDC_LIST_FILTER), lvc.iSubItem, &lvc);

		// リストビューのスタイルの設定
		SetWindowLong(GetDlgItem(hDlg, IDC_LIST_FILTER), GWL_STYLE,
			GetWindowLong(GetDlgItem(hDlg, IDC_LIST_FILTER), GWL_STYLE) | LVS_SHOWSELALWAYS);
		SendDlgItemMessage(hDlg, IDC_LIST_FILTER, LVM_SETEXTENDEDLISTVIEWSTYLE, 0,
			LVS_EX_ONECLICKACTIVATE | LVS_EX_FULLROWSELECT |
			SendDlgItemMessage(hDlg, IDC_LIST_FILTER, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0));

		for (i = 0; i < option.filter_cnt; i++) {
			listview_set_filter(GetDlgItem(hDlg, IDC_LIST_FILTER), option.filter_info + i, TRUE);
		}
		SendMessage(hDlg, WM_LV_EVENT, LVN_ITEMCHANGED, 0);

		if (*cmd_filter != TEXT('\0')) {
			SetTimer(hDlg, ID_ADD_TIMER, 1, NULL);
		}
		break;

	case WM_DESTROY:
		listview_free_filter(GetDlgItem(hDlg, IDC_LIST_FILTER));
#ifdef OP_XP_STYLE
		// XP
		if (hThemeUp != 0 && hThemeDown != 0) {
			close_theme(hThemeUp);
			close_theme(hThemeDown);
		}
#endif	// OP_XP_STYLE
		break;

	case WM_DRAWITEM:
		switch ((UINT)wParam) {
		case IDC_BUTTON_UP:
			i = DFCS_SCROLLUP;
			break;

		case IDC_BUTTON_DOWN:
			i = DFCS_SCROLLDOWN;
			break;

		default:
			return FALSE;
		}
		// ボタンの描画
#ifdef OP_XP_STYLE
		if (hThemeUp != 0 && hThemeDown != 0) {
			draw_theme_scroll((LPDRAWITEMSTRUCT)lParam, i, (i == DFCS_SCROLLUP) ? hThemeUp : hThemeDown);
		} else {
			draw_scroll_sontrol((LPDRAWITEMSTRUCT)lParam, i);
		}
#else	// OP_XP_STYLE
		draw_scroll_sontrol((LPDRAWITEMSTRUCT)lParam, i);
#endif	// OP_XP_STYLE
		break;

#ifdef OP_XP_STYLE
	case WM_THEMECHANGED:
		// テーマの変更
		if (hThemeUp != 0 && hThemeDown != 0) {
			close_theme(hThemeUp);
			close_theme(hThemeDown);
		}
		hThemeUp = open_theme(GetDlgItem(hDlg, IDC_BUTTON_UP), L"SCROLLBAR");
		hThemeDown = open_theme(GetDlgItem(hDlg, IDC_BUTTON_DOWN), L"SCROLLBAR");
		break;
#endif	// OP_XP_STYLE

	case WM_NOTIFY:
		if (listview_notify_proc(hDlg, lParam, GetDlgItem(hDlg, IDC_LIST_FILTER)) == 0) {
			return OptionNotifyProc(hDlg, uMsg, wParam, lParam);
		}
		break;

	case WM_LV_EVENT:
		switch (wParam) {
		case LVN_ITEMCHANGED:
			enable = (ListView_GetSelectedCount(GetDlgItem(hDlg, IDC_LIST_FILTER)) <= 0) ? FALSE : TRUE;
			EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_UP), enable);
			EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_DOWN), enable);
			EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_EDIT), enable);
			EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_DELETE), enable);
			break;
		}
		break;

	case WM_TIMER:
		switch (wParam) {
		case ID_ADD_TIMER:
			KillTimer(hDlg, wParam);
			if ((i = filter_get_index(cmd_filter, 0)) == -1) {
				// 追加
				SendMessage(hDlg, WM_COMMAND, IDC_BUTTON_ADD, 0);
			} else {
				ListView_SetItemState(GetDlgItem(hDlg, IDC_LIST_FILTER), i,
					LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
				// 編集
				SendMessage(hDlg, WM_COMMAND, IDC_BUTTON_EDIT, 0);
			}
			break;
		}
		break;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDC_BUTTON_UP:
			if ((i = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_FILTER), -1, LVNI_SELECTED)) == -1) {
				break;
			}
			if (i == 0) {
				break;
			}
			listview_move_item(GetDlgItem(hDlg, IDC_LIST_FILTER), i, -1);
			SetFocus(GetDlgItem(hDlg, LOWORD(wParam)));
			break;

		case IDC_BUTTON_DOWN:
			if ((i = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_FILTER), -1, LVNI_SELECTED)) == -1) {
				break;
			}
			if (i == ListView_GetItemCount(GetDlgItem(hDlg, IDC_LIST_FILTER)) - 1) {
				break;
			}
			listview_move_item(GetDlgItem(hDlg, IDC_LIST_FILTER), i, 1);
			SetFocus(GetDlgItem(hDlg, LOWORD(wParam)));
			break;

		case IDC_BUTTON_ADD:
			DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER_SET), hDlg, set_filter_item_proc, 0);
			break;

		case IDC_BUTTON_EDIT:
			if ((i = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_FILTER), -1, LVNI_SELECTED)) == -1) {
				break;
			}
			DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DIALOG_FILTER_SET), hDlg, set_filter_item_proc,
				listview_get_lparam(GetDlgItem(hDlg, IDC_LIST_FILTER), i));
			listview_set_text(GetDlgItem(hDlg, IDC_LIST_FILTER), i);
			break;

		case IDC_BUTTON_DELETE:
			if ((i = ListView_GetNextItem(GetDlgItem(hDlg, IDC_LIST_FILTER), -1, LVNI_SELECTED)) == -1) {
				break;
			}
			if (MessageBox(hDlg, message_get_res(IDS_OPTION_DELETE), WINDOW_TITLE, MB_ICONQUESTION | MB_YESNO) == IDNO) {
				break;
			}
			if ((fi = (FILTER_INFO *)listview_get_lparam(GetDlgItem(hDlg, IDC_LIST_FILTER), i)) != NULL) {
				mem_free(&fi->format_name);
				ini_free_format_name(fi->fn, fi->fn_cnt);
				mem_free(&fi);
			}
			ListView_DeleteItem(GetDlgItem(hDlg, IDC_LIST_FILTER), i);
			ListView_SetItemState(GetDlgItem(hDlg, IDC_LIST_FILTER), i,
				LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
			break;

		case IDOK:
			for (i = 0; i < option.filter_cnt; i++) {
				mem_free(&((option.filter_info + i)->format_name));
				ini_free_format_name((option.filter_info + i)->fn, (option.filter_info + i)->fn_cnt);
			}
			mem_free(&option.filter_info);

			option.filter_all_action = IsDlgButtonChecked(hDlg, IDC_RADIO_ALL_IGNORE);
			option.filter_info = listview_get_filter(GetDlgItem(hDlg, IDC_LIST_FILTER), &option.filter_cnt);
			listview_free_filter(GetDlgItem(hDlg, IDC_LIST_FILTER));
			prop_ret = 1;
			break;

		case IDPCANCEL:
			break;
		}
		break;

	default:
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 15
0
BOOL CDlgPpro::DestroyWindow() 
{
	KillTimer(STATE_TIMER);
	KillTimer(AUTOSEAT_TIMER);
	return CDialog::DestroyWindow();
}
Ejemplo n.º 16
0
Archivo: snake.cpp Proyecto: qhw/Snake
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc,hMemDC;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
	
	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				case IDM_UP:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_UP,0);
					break;
				case IDM_LEFT:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_LEFT,0);
					break;
				case IDM_RIGHT:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_RIGHT,0);
					break;
				case IDM_DOWN:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_DOWN,0);
					break;
				case IDM_START_PAUSE:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_SPACE,0);
					break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_CREATE:
			m = 20;
			n = 15;
			for(i = 0; i < n_body; i++)
			{
				Position[i].x = m-i;
				Position[i].y = n;
				Matrix[Position[i].x][Position[i].y] = 1;
			}
			CreateFood();
			CreateUI(hWnd);
			SetTimer(hWnd,100,speed,NULL);
				break;
		case WM_KEYDOWN:
			switch(wParam)
			{
			case VK_UP:
				//KillTimer(hWnd,100);
				if(direction != 2 && n>0 && CheckOver(hWnd,m,n-1))
				{
					
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					n--;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].y = n;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}
					CreateFood();
					direction = 0;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			case VK_LEFT:
			//	KillTimer(hWnd,100);
				if(direction != 1 && m>0 && CheckOver(hWnd,m-1,n))
				{
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					m--;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].x = m;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}	
					CreateFood();
					direction = 3;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			case VK_RIGHT:
				//KillTimer(hWnd,100);
				if(direction != 3 && m<39 && CheckOver(hWnd,m+1,n))
				{
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					m++;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].x = m;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}	
					CreateFood();
					direction = 1;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			case VK_SPACE:
				if(start_or_pause)
				{
					KillTimer(hWnd,100);
					start_or_pause = false;
				}else
				{
					SetTimer(hWnd,100,speed,NULL);
					start_or_pause = true;
				}
				break;
			case VK_DOWN:
			//	KillTimer(hWnd,100);
				if(direction != 0 && n<31 && CheckOver(hWnd,m,n+1) )
				{
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					n++;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].y = n;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}
					CreateFood();
					direction = 2;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			
			//GetClientRect(hWnd, &rt);
			hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
			hBmp  =   LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
			hMemDC  =  CreateCompatibleDC(hdc);   
			hBmpOld  =   (HBITMAP)SelectObject(hMemDC,hBmp);

			//Matrix[10][10] = 1;
			
			for(i = 0; i < 40; i++)
				for(j =0; j <32; j++)
				{
						rt.left = i * 16;
					rt.top = 24 + j *16;
					switch(Matrix[i][j])
					{
						case 0:
							{
								rt.right = rt.left + 16;
								rt.bottom = rt.top + 16 ;
								FillRect(hdc,&rt,hbr);
							}
							break;
						case 1:
							{
								hBmp  =   LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
								hMemDC  =  CreateCompatibleDC(hdc);   
								hBmpOld  =   (HBITMAP)SelectObject(hMemDC,hBmp);
								BitBlt(hdc,rt.left,rt.top,16,16,hMemDC,0,0,SRCCOPY);
								SelectObject(hMemDC, hBmpOld);   
								DeleteObject(hBmp);   
								DeleteObject(hMemDC); 
							}
							break;
						case 2:
							{
								hBmp  =   LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
								hMemDC  =  CreateCompatibleDC(hdc);   
								hBmpOld  =   (HBITMAP)SelectObject(hMemDC,hBmp);
								BitBlt(hdc,rt.left,rt.top,16,16,hMemDC,0,0,SRCCOPY);
								SelectObject(hMemDC, hBmpOld);   
								DeleteObject(hBmp);   
								DeleteObject(hMemDC); 
							}
							break;
					}
				}
			SelectObject(hMemDC, hBmpOld);   
			DeleteObject(hBmp);   
			DeleteObject(hMemDC); 
			EndPaint(hWnd, &ps);
			break;
		case WM_TIMER:
			//KillTimer(hWnd,100);
			switch(direction)
			{
			case 0://UP
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(n>0)
				{
					n--;
				}
				else
				{
					//MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}
				Position[0].y = n;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			case 1://RIGHT
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(m<39)
					m++;
				else
				{
					//MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}
				Position[0].x = m;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			case 2://DOWN
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(n<31)
				  n++;
				else
				{
				//	MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false ;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}	
				Position[0].y = n;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			case 3://LEFT
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(m>0)
					m--;
				else
				{
					//MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}
				Position[0].x = m;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			}
			//SetTimer(hWnd,100,500,NULL);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
Ejemplo n.º 17
0
static LRESULT CALLBACK MButtonWndProc(HWND hwndDlg, UINT msg,  WPARAM wParam, LPARAM lParam)
{
	MButtonCtrl* bct =  (MButtonCtrl *)GetWindowLongPtr(hwndDlg, 0);
	switch(msg) {
	case WM_NCCREATE:
		SetWindowLongPtr(hwndDlg, GWL_STYLE, GetWindowLongPtr(hwndDlg, GWL_STYLE) | BS_OWNERDRAW);
		bct = ( MButtonCtrl* )mir_calloc(sizeof(MButtonCtrl));
		if (bct==NULL) return FALSE;
		bct->hwnd = hwndDlg;
		bct->stateId = PBS_NORMAL;
		bct->hFont = ( HFONT )GetStockObject(DEFAULT_GUI_FONT);
		LoadTheme(bct);
		if (SUCCEEDED(CoCreateInstance(CLSID_AccPropServices, NULL, CLSCTX_SERVER, 
			IID_IAccPropServices, (void**)&bct->pAccPropServices))) 
		{
			// Annotating the Role of this object to be PushButton
			SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON);
		} 
		else 
			bct->pAccPropServices = NULL;
		SetWindowLongPtr(hwndDlg, 0, (LONG_PTR)bct);
		if (((CREATESTRUCT *)lParam)->lpszName) SetWindowText(hwndDlg, ((CREATESTRUCT *)lParam)->lpszName);
		return TRUE;

	case WM_DESTROY:
		if (bct) {
			if (bct->pAccPropServices) {
				bct->pAccPropServices->Release();
				bct->pAccPropServices = NULL;
			}
			if (bct->hwndToolTips) {
				TOOLINFO ti = {0};
				ti.cbSize = sizeof(ti);
				ti.uFlags = TTF_IDISHWND;
				ti.hwnd = bct->hwnd;
				ti.uId = (UINT_PTR)bct->hwnd;
				if (SendMessage(bct->hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti)) {
					SendMessage(bct->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
				}
				if ( SendMessage(bct->hwndToolTips, TTM_GETTOOLCOUNT, 0, (LPARAM)&ti) == 0 ) {
					int idx;
					TTooltips tt;
					tt.ThreadId = GetCurrentThreadId();
			        
                    EnterCriticalSection(&csTips);
					if ( List_GetIndex( &lToolTips, &tt, &idx ) ) {
						mir_free( lToolTips.items[idx] );
						List_Remove( &lToolTips, idx );
						DestroyWindow( bct->hwndToolTips );
					}
			        LeaveCriticalSection(&csTips);
					
                    bct->hwndToolTips = NULL;
				}
			}
			if (bct->arrow) IconLib_ReleaseIcon(bct->arrow, 0);
			DestroyTheme(bct);
		}
		break;	// DONT! fall thru

    case WM_NCDESTROY:
		mir_free(bct);
        break;

	case WM_SETTEXT:
		bct->cHot = 0;
		if ( lParam != 0 ) {
			TCHAR *tmp = ( TCHAR* )lParam;
			while (*tmp) {
				if (*tmp=='&' && *(tmp+1)) {
					bct->cHot = _tolower(*(tmp+1));
					break;
				}
				tmp++;
			}
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;

	case WM_KEYUP:
		if (bct->stateId!=PBS_DISABLED && wParam == VK_SPACE) {
			if (bct->pushBtn) {
				if (bct->pbState) {
					bct->pbState = 0;
					bct->stateId = PBS_NORMAL;
				}
				else {
					bct->pbState = 1;
					bct->stateId = PBS_PRESSED;
				}
				InvalidateRect(bct->hwnd, NULL, TRUE);
			}
			SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
			return 0;
		}
		break;

	case WM_SYSKEYUP:
		if (bct->stateId!=PBS_DISABLED && bct->cHot && bct->cHot == tolower((int)wParam)) {
			if (bct->pushBtn) {
				if (bct->pbState) {
					bct->pbState = 0;
					bct->stateId = PBS_NORMAL;
				}
				else {
					bct->pbState = 1;
					bct->stateId = PBS_PRESSED;
				}
				InvalidateRect(bct->hwnd, NULL, TRUE);
			}
			SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
			return 0;
		}
		break;

	case WM_THEMECHANGED:
		// themed changed, reload theme object
		LoadTheme(bct);
		InvalidateRect(bct->hwnd, NULL, TRUE); // repaint it
		break;

	case WM_SETFONT: // remember the font so we can use it later
		bct->hFont = (HFONT)wParam; // maybe we should redraw?
		break;

	case WM_NCPAINT:
	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdcPaint;

		hdcPaint = BeginPaint(hwndDlg, &ps);
		if (hdcPaint) {
			PaintWorker(bct, hdcPaint);
			EndPaint(hwndDlg, &ps);
		}
		break;
	}
	case BM_SETIMAGE:
	{
		HGDIOBJ hnd = NULL;
		if (bct->hIcon) hnd = bct->hIcon;
		else if (bct->hBitmap) hnd = bct->hBitmap;

		if (wParam == IMAGE_ICON) {
			bct->hIcon = (HICON)lParam;
			bct->hBitmap = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		else if (wParam == IMAGE_BITMAP) {
			bct->hBitmap = (HBITMAP)lParam;
			bct->hIcon = NULL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		return (LRESULT)hnd;
	}
	case BM_GETIMAGE:
		if (bct->hIcon) return (LRESULT)bct->hIcon;
		else if (bct->hBitmap) return (LRESULT)bct->hBitmap;
		else return 0;
	case BM_SETCHECK:
		if (!bct->pushBtn) break;
		if (wParam == BST_CHECKED) {
			bct->pbState = 1;
               bct->stateId = PBS_PRESSED;
		}
		else if (wParam == BST_UNCHECKED) {
			bct->pbState = 0;
               bct->stateId = PBS_NORMAL;
		}
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BM_GETCHECK:
		if (bct->pushBtn) {
			return bct->pbState?BST_CHECKED:BST_UNCHECKED;
		}
		return 0;
	case BUTTONSETARROW: // turn arrow on/off
		if (wParam) {
			if (!bct->arrow) {
				bct->arrow = LoadSkinIcon(SKINICON_OTHER_DOWNARROW);
				SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_BUTTONDROPDOWN);
			}
		}
		else {
			if (bct->arrow) {
				IconLib_ReleaseIcon(bct->arrow, 0);
				bct->arrow = NULL;
				SetHwndPropInt(bct, OBJID_CLIENT, CHILDID_SELF, PROPID_ACC_ROLE, ROLE_SYSTEM_PUSHBUTTON);
			}
		}
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONSETDEFAULT:
		bct->defbutton = wParam?1:0;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONSETASPUSHBTN:
		bct->pushBtn = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONSETASFLATBTN:
		bct->flatBtn = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;
	case BUTTONADDTOOLTIP:
		if ( wParam ) {
			TOOLINFO ti = {0};
			if ( !bct->hwndToolTips ) {
				int idx;
				TTooltips tt;
				tt.ThreadId = GetCurrentThreadId();
			    
                EnterCriticalSection(&csTips);
				if ( List_GetIndex( &lToolTips, &tt, &idx )) {
					bct->hwndToolTips = ((TTooltips*)lToolTips.items[idx])->hwnd;
				} else {
					TTooltips *ptt = ( TTooltips* )mir_alloc( sizeof(TTooltips) );
					ptt->ThreadId = tt.ThreadId;
					ptt->hwnd = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, _T(""), TTS_ALWAYSTIP, 0, 0, 0, 0, NULL, NULL, hMirandaInst, NULL);
					List_Insert( &lToolTips, ptt, idx );
					bct->hwndToolTips = ptt->hwnd;
				}
    			LeaveCriticalSection(&csTips);
			}
			ti.cbSize = sizeof(ti);
			ti.uFlags = TTF_IDISHWND;
			ti.hwnd = bct->hwnd;
			ti.uId = (UINT_PTR)bct->hwnd;
			if (SendMessage(bct->hwndToolTips, TTM_GETTOOLINFO, 0, (LPARAM)&ti))
				SendMessage(bct->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)&ti);
			ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS;
			ti.uId = (UINT_PTR)bct->hwnd;
			#if defined( _UNICODE )
				if ( lParam & BATF_UNICODE )
					ti.lpszText = mir_wstrdup( TranslateW(( WCHAR* )wParam ));
				else
					ti.lpszText = LangPackPcharToTchar(( char* )wParam );
			#else
				ti.lpszText = Translate(( char* )wParam );
			#endif
			if (bct->pAccPropServices) {
				wchar_t *tmpstr = mir_t2u(ti.lpszText);
				bct->pAccPropServices->SetHwndPropStr(bct->hwnd, OBJID_CLIENT, 
					CHILDID_SELF, PROPID_ACC_DESCRIPTION, tmpstr);
				mir_free(tmpstr);
			}
			SendMessage( bct->hwndToolTips, TTM_ADDTOOL, 0, (LPARAM)&ti);
			#if defined( _UNICODE )
				mir_free( ti.lpszText );
			#endif
		}
		break;
	case WM_SETFOCUS: // set keybord focus and redraw
		bct->focus = 1;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_KILLFOCUS: // kill focus and redraw
		bct->focus = 0;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_WINDOWPOSCHANGED:
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_ENABLE: // windows tells us to enable/disable
		bct->stateId = wParam?PBS_NORMAL:PBS_DISABLED;
		InvalidateRect(bct->hwnd, NULL, TRUE);
		break;

	case WM_MOUSELEAVE: // faked by the WM_TIMER
		if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_NORMAL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;

	case WM_LBUTTONDOWN:
		if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
			bct->stateId = PBS_PRESSED;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		break;

	case WM_LBUTTONUP:
    {
        int showClick = 0;
		if (bct->pushBtn) {
			if (bct->pbState) bct->pbState = 0;
			else bct->pbState = 1;
		}
		if (bct->stateId!=PBS_DISABLED) { // don't change states if disabled
            if (bct->stateId==PBS_PRESSED)
                showClick = 1;
			if (msg==WM_LBUTTONUP) bct->stateId = PBS_HOT;
			else bct->stateId = PBS_NORMAL;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
        if (showClick) // Tell your daddy you got clicked.
            SendMessage(GetParent(hwndDlg), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndDlg), BN_CLICKED), (LPARAM)hwndDlg);
		break;
    }
	case WM_MOUSEMOVE:
		if (bct->stateId == PBS_NORMAL) {
			bct->stateId = PBS_HOT;
			InvalidateRect(bct->hwnd, NULL, TRUE);
		}
		// Call timer, used to start cheesy TrackMouseEvent faker
		SetTimer(hwndDlg,BUTTON_POLLID,BUTTON_POLLDELAY,NULL);
		break;
	case WM_TIMER: // use a timer to check if they have did a mouseout
		if (wParam == BUTTON_POLLID) {
			RECT rc;
			POINT pt;
			GetWindowRect(hwndDlg,&rc);
			GetCursorPos(&pt);
			if(!PtInRect(&rc,pt)) { // mouse must be gone, trigger mouse leave
				PostMessage(hwndDlg,WM_MOUSELEAVE,0,0L);
				KillTimer(hwndDlg,BUTTON_POLLID);
		}	}
		break;

	case WM_ERASEBKGND:
		return 1;
	}
	return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
Ejemplo n.º 18
0
/** @brief wndProc
  *
  * @TODO: document this function
  */
LRESULT TaskArea::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_TIMER:
		if (wParam == m_dragTimer)
		{
			if (m_dragTask)
			{
				SendMessage(hBlackboxWnd, BB_BRINGTOFRONT, 0,  (LPARAM)m_dragTask->GetTaskWnd());
				m_dragTask = NULL;
			}
			KillTimer(barWnd, m_dragTimer);
		}
		break;
	case BB_RECONFIGURE:
		readSettings();
		populateTasks();
		break;
	case BB_BROADCAST:
	{
		LPCSTR msg_string = (LPCSTR)lParam;
		LPCSTR element = NULL;
		msg_string += 1;
		if (!strnicmp(msg_string, m_pluginPrefix, strlen(m_pluginPrefix)))
		{
			msg_string += strlen(m_pluginPrefix) + 1;
			if (!strnicmp(msg_string, m_itemPrefix, strlen(m_itemPrefix)))
			{
				msg_string += strlen(m_itemPrefix) + 1;
				if ((element = "Stretch") && !strnicmp(msg_string, element, strlen(element)))
				{
					//msg_string += strlen(element);
					//m_iconSize = atoi(msg_string);
					//s_settingsManager.WriteSetting(m_pluginPrefix, "Tasks", element);
					//populateTasks();
					//PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0);
				}
			}
			else if (!strnicmp(msg_string, m_basePrefix.c_str(), m_basePrefix.size()))
			{
				if (itemList.size())
				{
					itemList.front()->wndProc(hWnd, msg, wParam, lParam);
				}
				PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0);
				configMenu(NULL, true);
				return 0;
			}
		}
	}
	break;
	case BB_TASKSUPDATE:
		switch (lParam)
		{
		case TASKITEM_FLASHED:
		case TASKITEM_ACTIVATED:
			Collection::wndProc(hWnd, msg, wParam, lParam);
			RedrawWindow(barWnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT);
			return 0;
		case TASKITEM_ADDED:

			if (std::find_if(itemList.begin(), itemList.end(), bind2nd(TaskIsHWnd(), reinterpret_cast<HWND>(wParam))) == itemList.end())
			{
				Task *newTask = new Task(reinterpret_cast<HWND>(wParam), vertical);
				itemList_t::iterator insertLoc = itemList.end();
				if (vertical && stretchTaskarea)
				{
					insertLoc--;
				}
				itemList.insert(insertLoc, newTask);
				if (stretchTaskarea)
				{
					calculateSizes(true);
					RedrawWindow(barWnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT);
				}
				else
				{
					PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0);
				}
			}
			break;

		case TASKITEM_REMOVED:
		{
			itemList.remove_if(bind2nd(TaskIsHWnd(), reinterpret_cast<HWND>(wParam)));
			if (stretchTaskarea)
			{
				calculateSizes(true);
				RedrawWindow(barWnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT);
			}
			else
			{
				PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0);
			}
			break;
		}
		//populateTasks();
		}
		break;
	}
	return Collection::wndProc(hWnd, msg, wParam, lParam);
}
Ejemplo n.º 19
0
LPARAM OnClientSockMsg(WPARAM wParam, LPARAM lParam)
{
	switch (WSAGETSELECTEVENT(lParam))
	{
		case FD_CONNECT:
		{
			DWORD dwThreadIDForMsg = 0;

			if (CheckSocketError(lParam))
			{
				dwThreadIDForMsg = 0;

				if (InitThread(ThreadFuncForMsg))
				{
					KillTimer(g_hMainWnd, _ID_TIMER_CONNECTSERVER);
				
					SetTimer(g_hMainWnd, _ID_TIMER_KEEPALIVE, 5000, (TIMERPROC)OnTimerProc);

					InsertLogMsg(IDS_CONNECT_LOGINSERVER);
					SendMessage(g_hStatusBar, SB_SETTEXT, MAKEWORD(1, 0), (LPARAM)_TEXT("Connected"));
				}
			}
			else
			{
				closesocket(g_csock);
				g_csock = INVALID_SOCKET;

				SetTimer(g_hMainWnd, _ID_TIMER_CONNECTSERVER, 10000, (TIMERPROC)OnTimerProc);
			}

			break;
		}
		case FD_CLOSE:
		{
			closesocket(g_csock);
			g_csock = INVALID_SOCKET;

			OnCommand(IDM_STOPSERVICE, 0);

			break;
		}
		case FD_READ:
		{
			int		nSocket = 0;
			char	*pszFirst = NULL, *pszEnd = NULL;

			UINT nRecv = 0;

			ioctlsocket((SOCKET)wParam, FIONREAD, (u_long *)&nRecv);

			if (nRecv)
			{
				char *pszPacket = new char[nRecv + 1];

				nRecv = recv((SOCKET)wParam, pszPacket, nRecv, 0);

				pszPacket[nRecv] = '\0';

				if (!(g_xMsgQueue.PushQ((BYTE *)pszPacket)))
					InsertLogMsg(_TEXT("[INFO] Not enough queue(g_xMsgQueue) buffer."));
			}

			break;
		}
	}

	return 0L;
}
Ejemplo n.º 20
0
int TCFormatVolume (volatile FORMAT_VOL_PARAMETERS *volParams)
{
	int nStatus;
	PCRYPTO_INFO cryptoInfo = NULL;
	HANDLE dev = INVALID_HANDLE_VALUE;
	DWORD dwError;
	char header[TC_VOLUME_HEADER_EFFECTIVE_SIZE];
	unsigned __int64 num_sectors, startSector;
	fatparams ft;
	FILETIME ftCreationTime;
	FILETIME ftLastWriteTime;
	FILETIME ftLastAccessTime;
	BOOL bTimeStampValid = FALSE;
	BOOL bInstantRetryOtherFilesys = FALSE;
	char dosDev[TC_MAX_PATH] = { 0 };
	char devName[MAX_PATH] = { 0 };
	int driveLetter = -1;
	WCHAR deviceName[MAX_PATH];
	uint64 dataOffset, dataAreaSize;
	LARGE_INTEGER offset;
	BOOL bFailedRequiredDASD = FALSE;
	HWND hwndDlg = volParams->hwndDlg;

	FormatSectorSize = volParams->sectorSize;

	if (FormatSectorSize < TC_MIN_VOLUME_SECTOR_SIZE
		|| FormatSectorSize > TC_MAX_VOLUME_SECTOR_SIZE
		|| FormatSectorSize % ENCRYPTION_DATA_UNIT_SIZE != 0)
	{
		Error ("SECTOR_SIZE_UNSUPPORTED", hwndDlg);
		return ERR_DONT_REPORT; 
	}

	/* WARNING: Note that if Windows fails to format the volume as NTFS and the volume size is
	less than the maximum FAT size, the user is asked within this function whether he wants to instantly
	retry FAT format instead (to avoid having to re-create the whole container again). If the user
	answers yes, some of the input parameters are modified, the code below 'begin_format' is re-executed 
	and some destructive operations that were performed during the first attempt must be (and are) skipped. 
	Therefore, whenever adding or modifying any potentially destructive operations below 'begin_format',
	determine whether they (or their portions) need to be skipped during such a second attempt; if so, 
	use the 'bInstantRetryOtherFilesys' flag to skip them. */

	if (volParams->hiddenVol)
	{
		dataOffset = volParams->hiddenVolHostSize - TC_VOLUME_HEADER_GROUP_SIZE - volParams->size;
	}
	else
	{
		if (volParams->size <= TC_TOTAL_VOLUME_HEADERS_SIZE)
			return ERR_VOL_SIZE_WRONG;

		dataOffset = TC_VOLUME_DATA_OFFSET;
	}

	dataAreaSize = GetVolumeDataAreaSize (volParams->hiddenVol, volParams->size);

	num_sectors = dataAreaSize / FormatSectorSize;

	if (volParams->bDevice)
	{
		StringCbCopyA ((char *)deviceName, sizeof(deviceName), volParams->volumePath);
		ToUNICODE ((char *)deviceName, sizeof(deviceName));

		driveLetter = GetDiskDeviceDriveLetter (deviceName);
	}

	VirtualLock (header, sizeof (header));

	nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
				     header,
				     volParams->ea,
					 FIRST_MODE_OF_OPERATION_ID,
				     volParams->password,
				     volParams->pkcs5,
					  volParams->pim,
					 NULL,
				     &cryptoInfo,
					 dataAreaSize,
					 volParams->hiddenVol ? dataAreaSize : 0,
					 dataOffset,
					 dataAreaSize,
					 0,
					 volParams->headerFlags,
					 FormatSectorSize,
					 FALSE);

	if (nStatus != 0)
	{
		burn (header, sizeof (header));
		VirtualUnlock (header, sizeof (header));
		return nStatus;
	}

begin_format:

	if (volParams->bDevice)
	{
		/* Device-hosted volume */

		DWORD dwResult;
		int nPass;

		if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev), devName, sizeof(devName), FALSE) != 0)
			return ERR_OS_ERROR;

		if (IsDeviceMounted (devName))
		{
			if ((dev = DismountDrive (devName, volParams->volumePath)) == INVALID_HANDLE_VALUE)
			{
				Error ("FORMAT_CANT_DISMOUNT_FILESYS", hwndDlg);
				nStatus = ERR_DONT_REPORT; 
				goto error;
			}

			/* Gain "raw" access to the partition (it contains a live filesystem and the filesystem driver 
			would otherwise prevent us from writing to hidden sectors). */

			if (!DeviceIoControl (dev,
				FSCTL_ALLOW_EXTENDED_DASD_IO,
				NULL,
				0,   
				NULL,
				0,
				&dwResult,
				NULL))
			{
				bFailedRequiredDASD = TRUE;
			}
		}
		else if (IsOSAtLeast (WIN_VISTA) && driveLetter == -1)
		{
			// Windows Vista doesn't allow overwriting sectors belonging to an unformatted partition 
			// to which no drive letter has been assigned under the system. This problem can be worked
			// around by assigning a drive letter to the partition temporarily.

			char szDriveLetter[] = { 'A', ':', 0 };
			char rootPath[] = { 'A', ':', '\\', 0 };
			char uniqVolName[MAX_PATH+1] = { 0 };
			int tmpDriveLetter = -1;
			BOOL bResult = FALSE;

			tmpDriveLetter = GetFirstAvailableDrive ();
 
			if (tmpDriveLetter != -1)
			{
				rootPath[0] += (char) tmpDriveLetter;
				szDriveLetter[0] += (char) tmpDriveLetter;

				if (DefineDosDevice (DDD_RAW_TARGET_PATH, szDriveLetter, volParams->volumePath))
				{
					bResult = GetVolumeNameForVolumeMountPoint (rootPath, uniqVolName, MAX_PATH);

					DefineDosDevice (DDD_RAW_TARGET_PATH|DDD_REMOVE_DEFINITION|DDD_EXACT_MATCH_ON_REMOVE,
						szDriveLetter,
						volParams->volumePath);

					if (bResult 
						&& SetVolumeMountPoint (rootPath, uniqVolName))
					{
						// The drive letter can be removed now
						DeleteVolumeMountPoint (rootPath);
					}
				}
			}
		}

		// For extra safety, we will try to gain "raw" access to the partition. Note that this should actually be
		// redundant because if the filesystem was mounted, we already tried to obtain DASD above. If we failed,
		// bFailedRequiredDASD was set to TRUE and therefore we will perform pseudo "quick format" below. However, 
		// for extra safety, in case IsDeviceMounted() failed to detect a live filesystem, we will blindly
		// send FSCTL_ALLOW_EXTENDED_DASD_IO (possibly for a second time) without checking the result.

		DeviceIoControl (dev,
			FSCTL_ALLOW_EXTENDED_DASD_IO,
			NULL,
			0,   
			NULL,
			0,
			&dwResult,
			NULL);


		// If DASD is needed but we failed to obtain it, perform open - 'quick format' - close - open 
		// so that the filesystem driver does not prevent us from formatting hidden sectors.
		for (nPass = (bFailedRequiredDASD ? 0 : 1); nPass < 2; nPass++)
		{
			int retryCount;

			retryCount = 0;

			// Try exclusive access mode first
			// Note that when exclusive access is denied, it is worth retrying (usually succeeds after a few tries).
			while (dev == INVALID_HANDLE_VALUE && retryCount++ < EXCL_ACCESS_MAX_AUTO_RETRIES)
			{
				dev = CreateFile (devName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

				if (retryCount > 1)
					Sleep (EXCL_ACCESS_AUTO_RETRY_DELAY);
			}

			if (dev == INVALID_HANDLE_VALUE)
			{
				// Exclusive access denied -- retry in shared mode
				dev = CreateFile (devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
				if (dev != INVALID_HANDLE_VALUE)
				{
					if (IDNO == MessageBoxW (volParams->hwndDlg, GetString ("DEVICE_IN_USE_FORMAT"), lpszTitle, MB_YESNO|MB_ICONWARNING|MB_DEFBUTTON2))
					{
						nStatus = ERR_DONT_REPORT; 
						goto error;
					}
				}
				else
				{
					handleWin32Error (volParams->hwndDlg, SRC_POS);
					Error ("CANT_ACCESS_VOL", hwndDlg);
					nStatus = ERR_DONT_REPORT; 
					goto error;
				}
			}

			if (volParams->hiddenVol || bInstantRetryOtherFilesys)
				break;	// The following "quick format" operation would damage the outer volume

			if (nPass == 0)
			{
				char buf [2 * TC_MAX_VOLUME_SECTOR_SIZE];
				DWORD bw;

				// Perform pseudo "quick format" so that the filesystem driver does not prevent us from 
				// formatting hidden sectors
				memset (buf, 0, sizeof (buf));

				if (!WriteFile (dev, buf, sizeof (buf), &bw, NULL))
				{
					nStatus = ERR_OS_ERROR; 
					goto error;
				}

				FlushFileBuffers (dev);
				CloseHandle (dev);
				dev = INVALID_HANDLE_VALUE;
			}
		}

		if (DeviceIoControl (dev, FSCTL_IS_VOLUME_MOUNTED, NULL, 0, NULL, 0, &dwResult, NULL))
		{
			Error ("FORMAT_CANT_DISMOUNT_FILESYS", hwndDlg);
			nStatus = ERR_DONT_REPORT; 
			goto error;
		}
	}
	else
	{
		/* File-hosted volume */

		dev = CreateFile (volParams->volumePath, GENERIC_READ | GENERIC_WRITE,
			(volParams->hiddenVol || bInstantRetryOtherFilesys) ? (FILE_SHARE_READ | FILE_SHARE_WRITE) : 0,
			NULL, (volParams->hiddenVol || bInstantRetryOtherFilesys) ? OPEN_EXISTING : CREATE_ALWAYS, 0, NULL);

		if (dev == INVALID_HANDLE_VALUE)
		{
			nStatus = ERR_OS_ERROR; 
			goto error;
		}

		DisableFileCompression (dev);

		if (!volParams->hiddenVol && !bInstantRetryOtherFilesys)
		{
			LARGE_INTEGER volumeSize;
			volumeSize.QuadPart = dataAreaSize + TC_VOLUME_HEADER_GROUP_SIZE;

			if (volParams->sparseFileSwitch && volParams->quickFormat)
			{
				// Create as sparse file container
				DWORD tmp;
				if (!DeviceIoControl (dev, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &tmp, NULL))
				{
					nStatus = ERR_OS_ERROR; 
					goto error;
				}
			}

			// Preallocate the file
			if (!SetFilePointerEx (dev, volumeSize, NULL, FILE_BEGIN)
				|| !SetEndOfFile (dev)
				|| SetFilePointer (dev, 0, NULL, FILE_BEGIN) != 0)
			{
				nStatus = ERR_OS_ERROR;
				goto error;
			}
		}
	}

	if (volParams->hiddenVol && !volParams->bDevice && bPreserveTimestamp)
	{
		if (GetFileTime ((HANDLE) dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime) == 0)
			bTimeStampValid = FALSE;
		else
			bTimeStampValid = TRUE;
	}

	KillTimer (volParams->hwndDlg, TIMER_ID_RANDVIEW);

	/* Volume header */

	// Hidden volume setup
	if (volParams->hiddenVol)
	{
		LARGE_INTEGER headerOffset;

		// Check hidden volume size
		if (volParams->hiddenVolHostSize < TC_MIN_HIDDEN_VOLUME_HOST_SIZE || volParams->hiddenVolHostSize > TC_MAX_HIDDEN_VOLUME_HOST_SIZE)
		{		
			nStatus = ERR_VOL_SIZE_WRONG;
			goto error;
		}

		// Seek to hidden volume header location
		
		headerOffset.QuadPart = TC_HIDDEN_VOLUME_HEADER_OFFSET;

		if (!SetFilePointerEx ((HANDLE) dev, headerOffset, NULL, FILE_BEGIN))
		{
			nStatus = ERR_OS_ERROR;
			goto error;
		}
	}
	else if (bInstantRetryOtherFilesys)
	{
		// The previous file system format failed and the user wants to try again with a different file system.
		// The volume header had been written successfully so we need to seek to the byte after the header.

		LARGE_INTEGER offset;
		offset.QuadPart = TC_VOLUME_DATA_OFFSET;
		if (!SetFilePointerEx ((HANDLE) dev, offset, NULL, FILE_BEGIN))
		{
			nStatus = ERR_OS_ERROR;
			goto error;
		}
	}

	if (!bInstantRetryOtherFilesys)
	{
		// Write the volume header
		if (!WriteEffectiveVolumeHeader (volParams->bDevice, dev, header))
		{
			nStatus = ERR_OS_ERROR;
			goto error;
		}

		// To prevent fragmentation, write zeroes to reserved header sectors which are going to be filled with random data
		if (!volParams->bDevice && !volParams->hiddenVol)
		{
			byte buf[TC_VOLUME_HEADER_GROUP_SIZE - TC_VOLUME_HEADER_EFFECTIVE_SIZE];
			DWORD bytesWritten;
			ZeroMemory (buf, sizeof (buf));

			if (!WriteFile (dev, buf, sizeof (buf), &bytesWritten, NULL))
			{
				nStatus = ERR_OS_ERROR;
				goto error;
			}

			if (bytesWritten != sizeof (buf))
			{
				nStatus = ERR_PARAMETER_INCORRECT;
				goto error;
			}
		}
	}

	if (volParams->hiddenVol)
	{
		// Calculate data area position of hidden volume
		cryptoInfo->hiddenVolumeOffset = dataOffset;

		// Validate the offset
		if (dataOffset % FormatSectorSize != 0)
		{
			nStatus = ERR_VOL_SIZE_WRONG; 
			goto error;
		}

		volParams->quickFormat = TRUE;		// To entirely format a hidden volume would be redundant
	}

	/* Data area */
	startSector = dataOffset / FormatSectorSize;

	// Format filesystem

	switch (volParams->fileSystem)
	{
	case FILESYS_NONE:
	case FILESYS_NTFS:

		if (volParams->bDevice && !StartFormatWriteThread())
		{
			nStatus = ERR_OS_ERROR; 
			goto error;
		}

		nStatus = FormatNoFs (hwndDlg, startSector, num_sectors, dev, cryptoInfo, volParams->quickFormat);

		if (volParams->bDevice)
			StopFormatWriteThread();

		break;
		
	case FILESYS_FAT:
		if (num_sectors > 0xFFFFffff)
		{
			nStatus = ERR_VOL_SIZE_WRONG; 
			goto error;
		}

		// Calculate the fats, root dir etc
		ft.num_sectors = (unsigned int) (num_sectors);

#if TC_MAX_VOLUME_SECTOR_SIZE > 0xFFFF
#error TC_MAX_VOLUME_SECTOR_SIZE > 0xFFFF
#endif

		ft.sector_size = (uint16) FormatSectorSize;
		ft.cluster_size = volParams->clusterSize;
		memcpy (ft.volume_name, "NO NAME    ", 11);
		GetFatParams (&ft); 
		*(volParams->realClusterSize) = ft.cluster_size * FormatSectorSize;

		if (volParams->bDevice && !StartFormatWriteThread())
		{
			nStatus = ERR_OS_ERROR; 
			goto error;
		}

		nStatus = FormatFat (hwndDlg, startSector, &ft, (void *) dev, cryptoInfo, volParams->quickFormat);

		if (volParams->bDevice)
			StopFormatWriteThread();

		break;

	default:
		nStatus = ERR_PARAMETER_INCORRECT; 
		goto error;
	}

	if (nStatus != ERR_SUCCESS)
		goto error;

	// Write header backup
	offset.QuadPart = volParams->hiddenVol ? volParams->hiddenVolHostSize - TC_HIDDEN_VOLUME_HEADER_OFFSET : dataAreaSize + TC_VOLUME_HEADER_GROUP_SIZE;

	if (!SetFilePointerEx ((HANDLE) dev, offset, NULL, FILE_BEGIN))
	{
		nStatus = ERR_OS_ERROR;
		goto error;
	}

	nStatus = CreateVolumeHeaderInMemory (hwndDlg, FALSE,
		header,
		volParams->ea,
		FIRST_MODE_OF_OPERATION_ID,
		volParams->password,
		volParams->pkcs5,
		volParams->pim,
		cryptoInfo->master_keydata,
		&cryptoInfo,
		dataAreaSize,
		volParams->hiddenVol ? dataAreaSize : 0,
		dataOffset,
		dataAreaSize,
		0,
		volParams->headerFlags,
		FormatSectorSize,
		FALSE);

	if (!WriteEffectiveVolumeHeader (volParams->bDevice, dev, header))
	{
		nStatus = ERR_OS_ERROR;
		goto error;
	}

	// Fill reserved header sectors (including the backup header area) with random data
	if (!volParams->hiddenVol)
	{
		nStatus = WriteRandomDataToReservedHeaderAreas (hwndDlg, dev, cryptoInfo, dataAreaSize, FALSE, FALSE);

		if (nStatus != ERR_SUCCESS)
			goto error;
	}

#ifndef DEBUG
	if (volParams->quickFormat && volParams->fileSystem != FILESYS_NTFS)
		Sleep (500);	// User-friendly GUI
#endif

error:
	dwError = GetLastError();

	burn (header, sizeof (header));
	VirtualUnlock (header, sizeof (header));

	if (dev != INVALID_HANDLE_VALUE)
	{
		if (!volParams->bDevice && !volParams->hiddenVol && nStatus != 0)
		{
			// Remove preallocated part before closing file handle if format failed
			if (SetFilePointer (dev, 0, NULL, FILE_BEGIN) == 0)
				SetEndOfFile (dev);
		}

		FlushFileBuffers (dev);

		if (bTimeStampValid)
			SetFileTime (dev, &ftCreationTime, &ftLastAccessTime, &ftLastWriteTime);

		CloseHandle (dev);
		dev = INVALID_HANDLE_VALUE;
	}

	if (nStatus != 0)
	{
		SetLastError(dwError);
		goto fv_end;
	}

	if (volParams->fileSystem == FILESYS_NTFS)
	{
		// Quick-format volume as NTFS
		int driveNo = GetLastAvailableDrive ();
		MountOptions mountOptions;
		int retCode;

		ZeroMemory (&mountOptions, sizeof (mountOptions));

		if (driveNo == -1)
		{
			MessageBoxW (volParams->hwndDlg, GetString ("NO_FREE_DRIVES"), lpszTitle, ICON_HAND);
			MessageBoxW (volParams->hwndDlg, GetString ("FORMAT_NTFS_STOP"), lpszTitle, ICON_HAND);

			nStatus = ERR_NO_FREE_DRIVES;
			goto fv_end;
		}

		mountOptions.ReadOnly = FALSE;
		mountOptions.Removable = FALSE;
		mountOptions.ProtectHiddenVolume = FALSE;
		mountOptions.PreserveTimestamp = bPreserveTimestamp;
		mountOptions.PartitionInInactiveSysEncScope = FALSE;
		mountOptions.UseBackupHeader = FALSE;

		if (MountVolume (volParams->hwndDlg, driveNo, volParams->volumePath, volParams->password, volParams->pkcs5, volParams->pim, FALSE, FALSE, TRUE, &mountOptions, FALSE, TRUE) < 1)
		{
			MessageBoxW (volParams->hwndDlg, GetString ("CANT_MOUNT_VOLUME"), lpszTitle, ICON_HAND);
			MessageBoxW (volParams->hwndDlg, GetString ("FORMAT_NTFS_STOP"), lpszTitle, ICON_HAND);
			nStatus = ERR_VOL_MOUNT_FAILED;
			goto fv_end;
		}

		if (!IsAdmin () && IsUacSupported ())
			retCode = UacFormatNtfs (volParams->hwndDlg, driveNo, volParams->clusterSize);
		else
			retCode = FormatNtfs (driveNo, volParams->clusterSize);

		if (retCode != TRUE)
		{
			if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
				MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);

			if (dataAreaSize <= TC_MAX_FAT_SECTOR_COUNT * FormatSectorSize)
			{
				if (AskErrYesNo ("FORMAT_NTFS_FAILED_ASK_FAT", hwndDlg) == IDYES)
				{
					// NTFS format failed and the user wants to try FAT format immediately
					volParams->fileSystem = FILESYS_FAT;
					bInstantRetryOtherFilesys = TRUE;
					volParams->quickFormat = TRUE;		// Volume has already been successfully TC-formatted
					volParams->clusterSize = 0;		// Default cluster size
					goto begin_format;
				}
			}
			else
				Error ("FORMAT_NTFS_FAILED", hwndDlg);

			nStatus = ERR_DONT_REPORT;
			goto fv_end;
		}

		if (!UnmountVolumeAfterFormatExCall (volParams->hwndDlg, driveNo))
			MessageBoxW (volParams->hwndDlg, GetString ("CANT_DISMOUNT_VOLUME"), lpszTitle, ICON_HAND);
	}

fv_end:
	dwError = GetLastError();

	if (dosDev[0])
		RemoveFakeDosName (volParams->volumePath, dosDev);

	crypto_close (cryptoInfo);

	SetLastError (dwError);
	return nStatus;
}
Ejemplo n.º 21
0
void CTaskbarNotifier::OnTimer(UINT nIDEvent)
{
	switch (nIDEvent)
	{
	case IDT_APPEARING:
		m_nAnimStatus = IDT_APPEARING;
		switch (m_nTaskbarPlacement)
		{
		case ABE_BOTTOM:
			if (m_nCurrentHeight < m_nBitmapHeight)
			{
				m_nCurrentPosY -= m_nIncrementShow;
				m_nCurrentHeight += m_nIncrementShow;
			}
			else
			{
				KillTimer(IDT_APPEARING);
				SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
				m_nAnimStatus = IDT_WAITING;
			}
			break;

		case ABE_TOP:
			if (m_nCurrentHeight < m_nBitmapHeight)
				m_nCurrentHeight += m_nIncrementShow;
			else
			{
				KillTimer(IDT_APPEARING);
				SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
				m_nAnimStatus = IDT_WAITING;
			}
			break;

		case ABE_LEFT:
			if (m_nCurrentWidth < m_nBitmapWidth)
				m_nCurrentWidth += m_nIncrementShow;
			else
			{
				KillTimer(IDT_APPEARING);
				SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
				m_nAnimStatus = IDT_WAITING;
			}
			break;

		case ABE_RIGHT:
			if (m_nCurrentWidth < m_nBitmapWidth)
			{
				m_nCurrentPosX -= m_nIncrementShow;
				m_nCurrentWidth += m_nIncrementShow;
			}
			else
			{
				KillTimer(IDT_APPEARING);
				SetTimer(IDT_WAITING, m_dwTimeToStay, NULL);
				m_nAnimStatus = IDT_WAITING;
			}
			break;
		}
		SetWindowPos(&wndTopMost, m_nCurrentPosX, m_nCurrentPosY, m_nCurrentWidth, m_nCurrentHeight, SWP_NOACTIVATE);
		break;

	case IDT_WAITING:
		KillTimer(IDT_WAITING);
		if (m_bAutoClose)
			SetTimer(IDT_DISAPPEARING, m_dwHideEvents, NULL);
		break;

	case IDT_DISAPPEARING:
		m_nAnimStatus = IDT_DISAPPEARING;
		switch (m_nTaskbarPlacement)
		{
		case ABE_BOTTOM:
			if (m_nCurrentHeight > 0)
			{
				m_nCurrentPosY += m_nIncrementHide;
				m_nCurrentHeight -= m_nIncrementHide;
			}
			else
			{
				KillTimer(IDT_DISAPPEARING);
				Hide();
			}
			break;

		case ABE_TOP:
			if (m_nCurrentHeight > 0)
				m_nCurrentHeight -= m_nIncrementHide;
			else
			{
				KillTimer(IDT_DISAPPEARING);
				Hide();
			}
			break;

		case ABE_LEFT:
			if (m_nCurrentWidth > 0)
				m_nCurrentWidth -= m_nIncrementHide;
			else
			{
				KillTimer(IDT_DISAPPEARING);
				Hide();
			}
			break;

		case ABE_RIGHT:
			if (m_nCurrentWidth > 0)
			{					 
				m_nCurrentPosX += m_nIncrementHide;
				m_nCurrentWidth -= m_nIncrementHide;
			}
			else
			{
				KillTimer(IDT_DISAPPEARING);
				Hide();
			}
			break;
		}
		SetWindowPos(&wndTopMost, m_nCurrentPosX, m_nCurrentPosY, m_nCurrentWidth, m_nCurrentHeight, SWP_NOACTIVATE);
		break;
	}

	CWnd::OnTimer(nIDEvent);
}
Ejemplo n.º 22
0
/******************************************************************************
* CounterPaneProc *
*-----------------*
*   Description:
*       Handles messages specifically for the counter (order) pane.
*
******************************************************************************/
LRESULT CounterPaneProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
    HRESULT hr;
    
    switch ( message )
    {
        case WM_ESPRESSOORDER:
        {
            ID_TEXT *pulIds = (ID_TEXT *) lParam;
            _ASSERTE( pulIds );
            if ( pulIds == NULL )
            {
                return 0;
            }
            KillTimer( hWnd, 0 );
            int i = 0, ilen = 0;
            TCHAR szTempBuf[NORMAL_LOADSTRING];
            TCHAR szSpace[] =  _T(" ");
            int iTemplen;
            
            g_szCounterDisplay[0] = '\0';

            // Sort the array
            while ( 0 != pulIds[i].ulId )
            {
                i++;
            }
            for ( int j = 0; j < i; j++ )
            {
                int iminIndex = j;               
                for ( int k = j; k < i; k++ )
                {
                    if ( pulIds[iminIndex].ulId > pulIds[k].ulId )
                    {
                        iminIndex = k;
                    }
                }
                ULONG ulId = pulIds[iminIndex].ulId;
                WCHAR *pwstr = pulIds[iminIndex].pwstrCoMemText;
                pulIds[iminIndex].pwstrCoMemText = pulIds[j].pwstrCoMemText;
                pulIds[j].pwstrCoMemText = pwstr;
                pulIds[iminIndex].ulId = pulIds[j].ulId;
                pulIds[j].ulId = ulId;
            }
            
            i = 0;
            // Put in the first order words if we actually have an order
            if ( 0 != pulIds[0].ulId )
            {
                iTemplen = LoadString( g_hInst, IDS_ORDERBEGIN, szTempBuf, NORMAL_LOADSTRING );                
                _tcscat_s( g_szCounterDisplay + ilen, _countof(g_szCounterDisplay) - ilen, szTempBuf );
                ilen += iTemplen;
            }
            while ( i < MAX_ID_ARRAY && 0 != pulIds[i].ulId )
            {
                CW2T pTempStr( pulIds[i].pwstrCoMemText );

                iTemplen = lstrlen( pTempStr );
                // We'll quit now so we dont overrun the buffer
                if ( ilen + iTemplen >= MAX_LOADSTRING )
                {
                    break;
                }
                if ( i > 0 )
                {
                    _tcscat_s( g_szCounterDisplay + ilen, _countof(g_szCounterDisplay) - ilen, szSpace );
                    ilen += 1;
                }
                _tcscat_s( g_szCounterDisplay, _countof(g_szCounterDisplay), pTempStr );
                ilen += iTemplen;
                i++;
            }
            // Put the thank you on this order
            if ( 0 < i )
            {
                iTemplen = LoadString( g_hInst, IDS_ORDEREND, szTempBuf, NORMAL_LOADSTRING );                
                if ( ilen + iTemplen < MAX_LOADSTRING )
                {
                    _tcscat_s( g_szCounterDisplay + ilen, _countof(g_szCounterDisplay) - ilen, szTempBuf );
                    ilen += iTemplen;
                }
            }

            InvalidateRect( hWnd, NULL, TRUE );
            SetTimer( hWnd, 0, TIMEOUT, NULL );

            // Delete the CoTaskMem we were given initially by ISpPhrase->GetText
            i = 0;
            while ( i < MAX_ID_ARRAY && 0 != pulIds[i].ulId )
            {
                CoTaskMemFree( pulIds[i].pwstrCoMemText );
                i++;
            }
            delete [] pulIds;
            return ( 1 );
        }
        case WM_PAINT:
            CounterPanePaint( hWnd, g_szCounterDisplay );
            return ( 1 );

        case WM_INITPANE:
            LoadString( g_hInst, IDS_PLEASEORDER, g_szCounterDisplay, MAX_LOADSTRING );
            // Set the rule recognizing an espresso order to active, now that we are ready for it
            g_cpCmdGrammar->SetRuleIdState( VID_EspressoDrinks, SPRS_ACTIVE );
            // Set our interests to include false recognitions
            hr = g_cpRecoCtxt->SetInterest( SPFEI(SPEI_RECOGNITION)|SPFEI(SPEI_FALSE_RECOGNITION),
                                                    SPFEI(SPEI_RECOGNITION)|SPFEI(SPEI_FALSE_RECOGNITION) );
            _ASSERTE( SUCCEEDED( hr ) );

            return ( 1 );

        case WM_TIMER:
            // Revert back to 'go ahead and order' message
            LoadString( g_hInst, IDS_PLEASEORDER, g_szCounterDisplay, MAX_LOADSTRING );
            InvalidateRect( hWnd, NULL, TRUE );
            KillTimer( hWnd, 0 );
            return ( 1 );

        case WM_GOTOOFFICE:
            KillTimer( hWnd, 0 );
            // Set the rule recognizing an espresso order to inactive
            // since you cant order from the office
            g_cpCmdGrammar->SetRuleIdState( VID_EspressoDrinks, SPRS_INACTIVE );
            // Set our interests to include only recognitions
            hr = g_cpRecoCtxt->SetInterest( SPFEI(SPEI_RECOGNITION),SPFEI(SPEI_RECOGNITION) );
            _ASSERTE( SUCCEEDED( hr ) );
            
            // Set the right message handler and repaint
            g_fpCurrentPane = OfficePaneProc;
            PostMessage( hWnd, WM_INITPANE, NULL, NULL );
            InvalidateRect( hWnd, NULL, TRUE );
            return ( 1 );

        case WM_DIDNTUNDERSTAND:
            KillTimer( hWnd, 0 );
            LoadString( g_hInst, IDS_DIDNTUNDERSTAND, g_szCounterDisplay, MAX_LOADSTRING );
            InvalidateRect( hWnd, NULL, TRUE );
            SetTimer( hWnd, 0, TIMEOUT, NULL );
            return ( 1 );

    }
    return ( 0 );
}
Ejemplo n.º 23
0
LRESULT APIENTRY DD_WindowProc(HWND hWnd, UINT msg, UINT wParam, LONG lParam)
{
	GF_Event evt;
	DDContext *ctx;
	GF_VideoOutput *vout = (GF_VideoOutput *) GetWindowLong(hWnd, GWL_USERDATA);

	if (!vout) return DefWindowProc (hWnd, msg, wParam, lParam);
	ctx = (DDContext *)vout->opaque;

	switch (msg) {
	case WM_SIZE:
		/*always notify GPAC since we're not sure the owner of the window is listening to these events*/
		evt.type = GF_EVENT_SIZE;
		evt.size.width = LOWORD(lParam);
		evt.size.height = HIWORD(lParam);
		vout->on_event(vout->evt_cbk_hdl, &evt);
		break;
	case WM_CLOSE:
		if (hWnd==ctx->os_hwnd) {
			evt.type = GF_EVENT_QUIT;
			vout->on_event(vout->evt_cbk_hdl, &evt);
		}
		return 1;
	case WM_DESTROY:
		if (ctx->owns_hwnd || (hWnd==ctx->fs_hwnd)) {
			PostQuitMessage (0);
		} else if (ctx->orig_wnd_proc) {
			/*restore window proc*/
			SetWindowLong(ctx->os_hwnd, GWL_WNDPROC, ctx->orig_wnd_proc);
			ctx->orig_wnd_proc = 0L;
		}
		break;
	case WM_ACTIVATE:
#if 1
		if (ctx->fullscreen && (LOWORD(wParam)==WA_INACTIVE) && (hWnd==ctx->fs_hwnd)) {
			evt.type = GF_EVENT_SHOWHIDE;
			vout->on_event(vout->evt_cbk_hdl, &evt);
		}
#endif
		break;

	case WM_SETCURSOR:
		if (ctx->cur_hwnd==hWnd) DD_SetCursor(vout, ctx->cursor_type);
		return 1;
	case WM_ERASEBKGND:
		//InvalidateRect(ctx->cur_hwnd, NULL, TRUE);
		//break;
	case WM_PAINT:
		if (ctx->cur_hwnd==hWnd) {
			evt.type = GF_EVENT_REFRESH;
			vout->on_event(vout->evt_cbk_hdl, &evt);
		}
		break;
	case WM_KILLFOCUS:
		if (hWnd==ctx->os_hwnd) ctx->has_focus = 0;
		break;

	case WM_MOUSEMOVE:
		if (ctx->cur_hwnd!=hWnd) break;
		if (ctx->last_mouse_pos != lParam) {
			ctx->last_mouse_pos = lParam;
			DD_SetCursor(vout, (ctx->cursor_type==GF_CURSOR_HIDE) ? ctx->cursor_type_backup : ctx->cursor_type);
			evt.type = GF_EVENT_MOUSEMOVE;
			DD_GetCoordinates(lParam, &evt);
			vout->on_event(vout->evt_cbk_hdl, &evt);
			mouse_start_timer(ctx, hWnd, vout);
		}
		break;

	case WM_TIMER:
		if (wParam==10) {
			if (ctx->fullscreen && (ctx->cursor_type!=GF_CURSOR_HIDE)) {
				if (gf_sys_clock() > MOUSE_HIDE_TIMEOUT + ctx->last_mouse_move) {
					ctx->cursor_type_backup = ctx->cursor_type;
					DD_SetCursor(vout, GF_CURSOR_HIDE);
					KillTimer(hWnd, ctx->timer);
					ctx->timer = 0;
				}
			}
		}
		break;
	case WM_LBUTTONDOWN:
	case WM_LBUTTONDBLCLK:
		grab_mouse(ctx, vout);
		evt.type = GF_EVENT_MOUSEDOWN;
		DD_GetCoordinates(lParam, &evt);
		evt.mouse.button = GF_MOUSE_LEFT;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		if (!ctx->has_focus && (hWnd==ctx->os_hwnd)) {
			ctx->has_focus = 1;
			SetFocus(ctx->os_hwnd);
		}
		break;
	case WM_LBUTTONUP:
		release_mouse(ctx, hWnd, vout);
		evt.type = GF_EVENT_MOUSEUP;
		DD_GetCoordinates(lParam, &evt);
		evt.mouse.button = GF_MOUSE_LEFT;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		break;
	case WM_RBUTTONDOWN:
	case WM_RBUTTONDBLCLK:
		grab_mouse(ctx, vout);
		evt.type = GF_EVENT_MOUSEDOWN;
		DD_GetCoordinates(lParam, &evt);
		evt.mouse.button = GF_MOUSE_RIGHT;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		if (!ctx->has_focus && (hWnd==ctx->os_hwnd)) {
			ctx->has_focus = 1;
			SetFocus(ctx->os_hwnd);
		}
		break;
	case WM_RBUTTONUP:
		release_mouse(ctx, hWnd, vout);
		evt.type = GF_EVENT_MOUSEUP;
		DD_GetCoordinates(lParam, &evt);
		evt.mouse.button = GF_MOUSE_RIGHT;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		mouse_start_timer(ctx, hWnd, vout);
		break;
	case WM_MBUTTONDOWN:
	case WM_MBUTTONDBLCLK:
		grab_mouse(ctx, vout);
		evt.type = GF_EVENT_MOUSEDOWN;
		evt.mouse.button = GF_MOUSE_MIDDLE;
		DD_GetCoordinates(lParam, &evt);
		vout->on_event(vout->evt_cbk_hdl, &evt);
		if (!ctx->has_focus && (hWnd==ctx->os_hwnd)) {
			ctx->has_focus = 1;
			SetFocus(ctx->os_hwnd);
		}
		break;
	case WM_MBUTTONUP:
		release_mouse(ctx, hWnd, vout);
		evt.type = GF_EVENT_MOUSEUP;
		DD_GetCoordinates(lParam, &evt);
		evt.mouse.button = GF_MOUSE_MIDDLE;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		mouse_start_timer(ctx, hWnd, vout);
		break;
	case WM_MOUSEWHEEL: 
		if (ctx->cur_hwnd==hWnd) {
			DD_SetCursor(vout, (ctx->cursor_type==GF_CURSOR_HIDE) ? ctx->cursor_type_backup : ctx->cursor_type);
			evt.type = GF_EVENT_MOUSEWHEEL;
			DD_GetCoordinates(lParam, &evt);
			evt.mouse.wheel_pos = FLT2FIX( ((Float) (s16) HIWORD(wParam)) / WHEEL_DELTA );
			vout->on_event(vout->evt_cbk_hdl, &evt);
			mouse_start_timer(ctx, hWnd, vout);
		}
		return 1;

	/*there's a bug on alt state (we miss one event)*/
	case WM_SYSKEYDOWN:
	case WM_SYSKEYUP:
	case WM_KEYUP:
	case WM_KEYDOWN:
		w32_translate_key(wParam, lParam, &evt.key);
		evt.type = ((msg==WM_SYSKEYDOWN) || (msg==WM_KEYDOWN)) ? GF_EVENT_KEYDOWN : GF_EVENT_KEYUP;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		break;

	case WM_CHAR:
		evt.type = GF_EVENT_TEXTINPUT;
		evt.character.unicode_char = wParam;
		vout->on_event(vout->evt_cbk_hdl, &evt);
		break;
	}
	return DefWindowProc (hWnd, msg, wParam, lParam);
}
Ejemplo n.º 24
0
/******************************************************************************
* WndProc *
*---------*
*   Description:
*       Main window procedure.
*
******************************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
    {
        case WM_CREATE:
            // Try to initialize, quit with error message if we can't
            if ( FAILED( InitSAPI( hWnd ) ) )
            {
                const int iMaxTitleLength = 64;
                TCHAR tszBuf[ MAX_PATH ];
                LoadString( g_hInst, IDS_FAILEDINIT, tszBuf, MAX_PATH );
                TCHAR tszName[ iMaxTitleLength ];
                LoadString( g_hInst, IDS_APP_TITLE, tszName, iMaxTitleLength );

                MessageBox( hWnd, tszBuf, tszName, MB_OK|MB_ICONWARNING );
                return( -1 );
            }
            break;
            
        // This is our application defined window message to let us know that a
        // speech recognition event has occurred.
        case WM_RECOEVENT:
            ProcessRecoEvent( hWnd );
            break;

        case WM_ERASEBKGND:
            EraseBackground( (HDC) wParam );
            return ( 1 );

        case WM_GETMINMAXINFO:
        {
            LPMINMAXINFO lpMM = (LPMINMAXINFO) lParam;

            lpMM->ptMaxSize.x = MINMAX_WIDTH;
            lpMM->ptMaxSize.y = MINMAX_HEIGHT;
            lpMM->ptMinTrackSize.x = MINMAX_WIDTH;
            lpMM->ptMinTrackSize.y = MINMAX_HEIGHT;
            lpMM->ptMaxTrackSize.x = MINMAX_WIDTH;
            lpMM->ptMaxTrackSize.y = MINMAX_HEIGHT;
            return ( 0 );
        }

        // Release remaining SAPI related COM references before application exits
        case WM_DESTROY:
            KillTimer( hWnd, 0 );
            CleanupGDIObjects();
            CleanupSAPI();
            PostQuitMessage(0);
            break;

        default:
        {
            _ASSERTE( g_fpCurrentPane );
            if ( g_fpCurrentPane == NULL)
            {
                return 0;
            }
            // Send unhandled messages to pane specific procedure for potential action
            LRESULT lRet = (*g_fpCurrentPane)(hWnd, message, wParam, lParam);
            if ( 0 == lRet )
            {
                lRet = DefWindowProc(hWnd, message, wParam, lParam);
            }
            return ( lRet );
        }
   }
   return ( 0 );
}
Ejemplo n.º 25
0
Archivo: hotkey.c Proyecto: now/purels
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case LM_GETREVID:
		{
			char *buf = (char *) lParam;

			if (wParam == 0)
			{
				strcpy(buf, "hotkey.dll: ");
				strcat(buf, &rcsRevision[11]);
				buf[strlen(buf)-1] = '\0';
			}
			else if (wParam == 1)
			{
				strcpy(buf, &rcsId[1]);
				buf[strlen(buf)-1] = '\0';
			} else
			{
				strcpy(buf, "");
			}
			return strlen(buf);

		}
	case WM_ENDSESSION:
	case WM_QUERYENDSESSION:
		return SendMessage(parent,message,wParam,lParam);
	case WM_SYSCOMMAND:
		{
		switch (wParam)
			{
			case SC_CLOSE:
				PostMessage(parent,WM_KEYDOWN,LM_SHUTDOWN,0);
				return 0;
			default:
				return DefWindowProc(hwnd,message,wParam,lParam);
			}
		}

	case WM_CREATE:
		{
			int i;

			for (i=0;i<numHotkeys;i++)
			{
				RegisterHotKey(hwnd,i,hotkeys[i].sub,hotkeys[i].ch);
			}
			if (GetRCBool("HotkeyNoWinKeyPopup",FALSE)){
				if (!RegisterHotKey(hwnd, GlobalAddAtom("LWIN_KEY"),MOD_WIN, VK_LWIN)){
					MessageBox(NULL,"Error registering Win Key",szAppName,MB_OK);
				}
				if (!RegisterHotKey(hwnd, GlobalAddAtom("RWIN_KEY"),MOD_WIN, VK_RWIN)){
					MessageBox(NULL,"Error registering Win Key",szAppName,MB_OK);
				}
			}
			if (GetRCBool("LSNoShellWarning", FALSE) && GetRCBool("ExplorerNoWarn", FALSE)){
				if (!RegisterHotKey(hwnd, GlobalAddAtom("CTL_ESC"),MOD_CONTROL,VK_ESCAPE)){
					MessageBox(NULL,"Error registering Ctrl+Esc",szAppName,MB_OK);
				}
			} 
		}
		return 0;

	case WM_DESTROY:
		UnregisterHotKey(hwnd, GlobalFindAtom("LWIN_KEY"));
		UnregisterHotKey(hwnd, GlobalFindAtom("RWIN_KEY"));
		UnregisterHotKey(hwnd, GlobalFindAtom("CTL_ESC"));
		GlobalDeleteAtom(GlobalFindAtom("LWIN_KEY"));
		GlobalDeleteAtom(GlobalFindAtom("RWIN_KEY"));
		GlobalDeleteAtom(GlobalFindAtom("CTL_ESC"));
		return 0;

	case WM_ERASEBKGND: 
		return 0;

	case WM_PAINT:  
		return 0;

	case WM_HOTKEY:
		{
			if (wParam <  (WPARAM) numHotkeys)
			{
				int num = wParam;

				if (lstrlen(hotkeys[num].szCommand))
				{
					if (hotkeys[num].szCommand[0] == '!') {
						KillTimer(hwnd, 1);
						ParseBangCommand(hwnd, hotkeys[num].szCommand, hotkeys[num].szParameters);
					} else {
			            char workDirectory[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR];

						_splitpath(hotkeys[num].szCommand, drive, dir, NULL, NULL);
						strcpy(workDirectory, drive);
						strcat(workDirectory, dir);

						LSExecuteEx(GetDesktopWindow(), NULL, hotkeys[num].szCommand, hotkeys[num].szParameters, workDirectory, SW_SHOWNORMAL);

						KillTimer(hwnd, 1);
						/*
						SHELLEXECUTEINFO si;
						char workDirectory[MAX_PATH];
						char drive[_MAX_DRIVE];
						char dir[_MAX_DIR];
		
						_splitpath(hotkeys[num].szCommand, drive, dir, NULL, NULL);
						strcpy(workDirectory, drive);
						strcat(workDirectory, dir);
						memset(&si, 0, sizeof(si));
						si.cbSize = sizeof(SHELLEXECUTEINFO);
						si.lpDirectory = workDirectory;
						si.lpVerb = NULL;
						si.nShow = 1;
						si.fMask = SEE_MASK_DOENVSUBST;
						si.lpFile = hotkeys[num].szCommand;
						si.lpParameters = hotkeys[num].szParameters;
						ShellExecuteEx(&si);
						*/
					}
				}
			}
			else
			{
				char szCommand[1024];

				if (GlobalGetAtomName((ATOM)wParam, szCommand, 1024) > 0)
				{
					if (!strcmp(szCommand, "CTL_ESC"))
						SendMessage(parent, LM_POPUP, 0, 0);
					else if (!strcmp(szCommand, "REINIT") && GetRCBool("HotkeyLoadExplorerKeys", TRUE)) {
						drizzt_FreeHotKeys();
						drizzt_InitHotKeys();
					} else if (!strcmp(szCommand, "LWIN_KEY")) {
						SetTimer(hwnd, 1, 750, NULL);
					} else if (!strcmp(szCommand, "RWIN_KEY")) {
						SetTimer(hwnd, 1, 750, NULL);
					} else {
						KillTimer(hwnd, 1);
						if (GetRCBool("HotkeyLoadExplorerKeys", TRUE)){
							drizzt_execute(szCommand, NULL, NULL);
						}
					}
				}
			}

			break;
		}
	case WM_TIMER:
		if (wParam == 1) {
			ParseBangCommand(hwnd, "!Popup", NULL);
			KillTimer(hwnd, 1);
		}
	}
	return DefWindowProc(hwnd,message,wParam,lParam);
}
Ejemplo n.º 26
0
void CUpdaterDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	switch(nIDEvent){
		case IDT_START_CHECK:
			{
				KillTimer(IDT_START_CHECK);
				notYetShow = false;
				if(cup.downloadList()){
					
					if(m_nLanguage){
						cs_stat.SetWindowText(_T("Updating to latest SPlayer..."));

						csCurTask.SetWindowText(_T("Current Task: Updating..."));

						cszSizeTotal.SetWindowText(  CString(L"Fize: ") + getShortSize(cup.iSVPCU_TOTAL_FILEBYTE) );

						csTotalProgress.SetWindowText( CString(L"Decompressed: ") + getShortSize(cup.iSVPCU_CURRENT_FILEBYTE_DONE) );
					}else{
						cs_stat.SetWindowText(_T("正在更新到射手播放器的最新版本..."));

						csCurTask.SetWindowText(_T("当前任务: 正在更新..."));
						
						cszSizeTotal.SetWindowText(  CString(L"文件大小: ") + getShortSize(cup.iSVPCU_TOTAL_FILEBYTE) );

						csTotalProgress.SetWindowText( CString(L"已解压: ") + getShortSize(cup.iSVPCU_CURRENT_FILEBYTE_DONE) );
					}

					SetTimer(IDT_REAL_START_CHECK, 800, NULL);


					SetTimer(IDT_SHOW_INTRO,3500, NULL);

					
				}else{
					if(m_nLanguage){
						cs_stat.SetWindowText(_T("You already have latest version, there is no need to update.\r\nUpdater will exit in 30 sec."));
						csCurTask.SetWindowText(_T("Current Task: Closing..."));
					}else{
						cs_stat.SetWindowText(_T("您已经拥有最新版的射手播放器,目前无需升级。\r\n升级程序将在30秒后退出"));
						csCurTask.SetWindowText(_T("当前任务:正在准备关闭..."));
					}
					SetTimer(IDT_CLOSE_DLG, 30000, NULL);
				}

			}
			break;
		case IDT_SHOW_INTRO:
			if(cup.bWaiting && rand() % 2 == 1){
					if(m_nLanguage){
						cs_stat.SetWindowText( _T("Exit SPlayer or reboot to finish update."));
					}else
						cs_stat.SetWindowText( _T("关闭播放器或重新启动完成本次更新"));

			}else
				cs_stat.SetWindowText(szaIntro.GetAt( rand() % szaIntro.GetCount() ));

			break;
		case IDT_REAL_START_CHECK:
			{
				
				KillTimer(IDT_REAL_START_CHECK);
				//cb_backgd.EnableWindow(true);
				AfxBeginThread(ThreadCheckUpdate , (LPVOID)&cup);
				if(m_nLanguage){
					csCurTask.SetWindowText(_T("Current Task: Downloading..."));
				}else
					csCurTask.SetWindowText(_T("当前任务: 正在下载..."));
				iTimeStart = time(NULL);
				SetTimer(IDT_REFRESH_STAT, 700, NULL);
			}
			break;
		case IDT_REFRESH_STAT:
			{
				CString szTmp;
				

				if(cup.iSVPCU_TOTAL_FILEBYTE < cup.iSVPCU_TOTAL_FILEBYTE_DONE + cup.iSVPCU_CURRENT_FILEBYTE_DONE){
					cup.iSVPCU_TOTAL_FILEBYTE = cup.iSVPCU_TOTAL_FILEBYTE_DONE + cup.iSVPCU_CURRENT_FILEBYTE_DONE;
				}
				if (cup.iSVPCU_TOTAL_FILEBYTE  <= 0){
					cup.iSVPCU_TOTAL_FILEBYTE = 1;
				}
				double progress = 0;
				if(cup.iSVPCU_TOTAL_FILEBYTE){
					progress = (double)( cup.iSVPCU_TOTAL_FILEBYTE_DONE + cup.iSVPCU_CURRENT_FILEBYTE_DONE ) * 100/ (cup.iSVPCU_TOTAL_FILEBYTE);
				}
				//szTmp.Format( _T("射手影音自动更新程序\n文件:%d/%d 下载:%0.2f%%") , cup.iSVPCU_CURRETN_FILE , cup.iSVPCU_TOTAL_FILE ,progress );
				//SVP_LogMsg(szTmp);

				if(cup.bWaiting){
					if(m_nLanguage){
						szTmp = _T("To be polite, we don't KILL any running program. Pleas exit SPlayer or reboot to finish update.");
						csCurTask.SetWindowText(_T("Current: Trying to overwrite..."));
					}else{
						szTmp = _T("出于礼貌,升级程序不会强行关闭正在运行中的程序。请您关闭播放器或重新启动后将自动更新到最新版本");
						csCurTask.SetWindowText(_T("当前任务:正在覆盖..."));
					}
					cs_stat.SetWindowText(szTmp);


					if(m_firstDown == 80){
						ShowWindow(SW_MINIMIZE);
						ShowWindow(SW_HIDE);
					}
					m_firstDown+=10;

				}
				wcscpy_s(tnid.szTip, szTmp);

//szTmp.Format( _T("正在下载文件: %s (%d / %d)") , cup.szCurFilePath , cup.iSVPCU_CURRETN_FILE , cup.iSVPCU_TOTAL_FILE);
				if(!cup.bWaiting){
					
					double downloadedTotal = cup.iSVPCU_TOTAL_FILEBYTE_DONE + cup.iSVPCU_CURRENT_FILEBYTE_DONE;
					UINT timeNowNow = time(NULL);
					if( timeNowNow  - iTimeStart){
						double speed = downloadedTotal / ( timeNowNow  - iTimeStart);
						CString szBufSpeed;
						if(m_nLanguage){
							szBufSpeed.Format( _T("Speed: %s/sec") , getShortSize(speed) );
						}else
							szBufSpeed.Format( _T("速度: %s/秒") , getShortSize(speed) );
						szSpeed.SetWindowText(szBufSpeed);
					}

					if(m_nLanguage){
						csTotalProgress.SetWindowText( CString(L"Decompressed: ") + getShortSize(downloadedTotal) );
					}else
						csTotalProgress.SetWindowText( CString(L"已解压: ") + getShortSize(downloadedTotal) );

					prg_total.SetPos(int(progress * 10));
					
				}
				//SetWindowText(szTmp);

				//szTmp.Format( _T("总进度:%0.2f%%") , progress);
				

				
				//Shell_NotifyIcon(NIM_MODIFY,&tnid);

				if(cup.bSVPCU_DONE){
					KillTimer(IDT_REFRESH_STAT);
					if(m_nLanguage){
						szTmp = (L"You have finished updating to latest version of SPlayer.\r\nUpdater will exit in 30 sec.");
						csCurTask.SetWindowText(_T("Current Task: Finished"));
					}else{
						szTmp = _T("射手影音播放器已经更新到最新版本!\r\n本程序将在半分钟内关闭");
						csCurTask.SetWindowText(_T("当前任务: 更新已结束"));
					}
					cs_stat.SetWindowText(szTmp);

					if(m_firstDown%10 == 8){
						ShowWindow(SW_MINIMIZE);
						ShowWindow(SW_HIDE);
					}
					m_firstDown++;
					KillTimer(IDT_SHOW_INTRO);

					//cb_backgd.SetWindowText(_T("关闭"));
					SetTimer(IDT_CLOSE_DLG, 15000, NULL);
				}
			}
			break;
		case IDT_CLOSE_DLG:
			KillTimer(IDT_CLOSE_DLG);
			Shell_NotifyIcon(NIM_DELETE, &tnid); 
			OnOK();
			break;
	}
	CDialog::OnTimer(nIDEvent);
}
Ejemplo n.º 27
0
BOOL CHyperLink::DestroyWindow() 
  {
      KillTimer(m_nTimerID);
      return CStatic::DestroyWindow();
  }
Ejemplo n.º 28
0
/***************************************************
~CUGNoteType - Destructor
	Clean up all allocated resources
****************************************************/
CUGNoteType::~CUGNoteType(){

	if(m_timerID != 0)
		KillTimer(m_ctrl->m_hWnd,m_timerID);
}
Ejemplo n.º 29
0
//----------------------------------------------------------------------
BOOL CALLBACK x_DialogProc(HWND hDlgWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam) { 
  UINT uiTimerID; 
  int iRes;
 
  switch (uiMsg) {

    case WM_COMMAND: 
      if (HIWORD(wParam) == BN_CLICKED) { 
        switch (LOWORD(wParam)) { 
          case IDC_CMD_EXIT:  // Exit button
            PostMessage( hDlgWnd, WM_CLOSE, 0, 0);
            return TRUE;
          case IDC_CMD_START:  // Start button
            g_CmdStart();
            return TRUE;
          case IDC_CMD_STOP:  // Stop button
            g_CmdStop();
            return TRUE;

          // Hide/show log window
          case IDC_CHK_SHOWLOG: 
            // Retrieve the state of the check box. 
            iRes = SendDlgItemMessage( hDlgWnd, IDC_CHK_SHOWLOG, BM_GETCHECK, 0, 0); 
            if( iRes == BST_CHECKED ) CP_printfShow();
            if( iRes == BST_UNCHECKED ) CP_printfHide();
            return TRUE; 

        } // switch
      }  // if BN_CLICKED
      break;

    case WM_TIMER:
      OnTimer( hDlgWnd );
      return TRUE;

    case WM_DESTROY:
      PostQuitMessage(0);
      return TRUE;

    case WM_CLOSE:
      KillTimer( hDlgWnd, TIMER_ID);
      g_Release_OptoTrack();
      DestroyWindow (hDlgWnd);
      return TRUE;

    case WM_INITDIALOG:
      g_hWnd = hDlgWnd;

      SetWindowText(hDlgWnd, x_szTitle);
      SendMessage(hDlgWnd, WM_SETICON, ICON_BIG, 
                  (LPARAM)LoadIcon(x_hInstance, MAKEINTRESOURCE(IDI_ICON_APPL)));
      SendMessage(hDlgWnd, WM_SETICON, ICON_SMALL, 
                 (LPARAM)LoadImage(x_hInstance, MAKEINTRESOURCE(IDI_ICON_APPL), IMAGE_ICON, 16, 16, 0));
      ShowWindow(hDlgWnd, SW_SHOW); 
  
      uiTimerID = SetTimer( hDlgWnd,  TIMER_ID,  TIMER_PERIOD_MS,  NULL ); 
 
      if ( uiTimerID == 0){ 
        CP_printf("Error: could not create timer!"); // don't exit we are still functional
      } 

      iRes = g_Init_OptoTrack( );
      if( iRes != 0 ) { 
        MessageBox( NULL, "Error: g_Init_OptoTrack() failed.", x_szTitle, MB_OK);
        PostMessage( hDlgWnd, WM_CLOSE, 0, 0);
        return TRUE;
      }

      return TRUE;
  } // switch (uiMsg)

  return FALSE;       // did not process a message 
} 
Ejemplo n.º 30
0
LRESULT CTrayIcon::OnTrayIconNotify(WPARAM wParam, LPARAM lParam)
{
	UNREFERENCED_PARAMETER(wParam);

	// prevent reentrancy
	static BOOL bInNotify = FALSE;

	if (bInNotify || !GetParent()->IsWindowEnabled())
		return 0L;

	CAutoFlag af(bInNotify, TRUE);
	BOOL bNotify = TRUE;

	GetCursorPos(&m_nm.ptAction);

	switch (lParam)
	{
	case WM_MOUSEMOVE:
	case WM_LBUTTONDOWN:
		bNotify = FALSE;
		break;

	case WM_LBUTTONUP:
		if (m_nPrevMsg == WM_LBUTTONDOWN) // start a timer to test for double click
		{
			UINT nDelay = GetDoubleClickTime();
			SetTimer(TIMER_SINGLECLK, nDelay, NULL);
		}

		bNotify = FALSE; // we'll handle it in OnTimer
		break;

	case WM_LBUTTONDBLCLK:
		// if we got here then the timer has not yet been tripped so it's a double click
		if (m_nPrevMsg == WM_LBUTTONUP)
		{
			KillTimer(TIMER_SINGLECLK);
			m_nm.hdr.code = NM_DBLCLK;
		}
		break;

	case WM_RBUTTONDOWN:
		bNotify = FALSE;
		break;

	case WM_RBUTTONUP:
		if (m_nPrevMsg == WM_RBUTTONDOWN)
			m_nm.hdr.code = NM_RCLICK;
		else
			bNotify = FALSE;
		break;

	case WM_RBUTTONDBLCLK:
		m_nm.hdr.code = NM_RDBLCLK;
		break;

	case WM_MBUTTONDOWN:
	case WM_MBUTTONUP:
	case WM_MBUTTONDBLCLK:
		bNotify = FALSE;
		break;

	case NIN_BALLOONUSERCLICK:
	case NIN_BALLOONTIMEOUT:
		if (m_bTemporaryIcon)
		{
			m_bTemporaryIcon = FALSE;
			ShowTrayIcon(FALSE);
		}
		bNotify = FALSE;
		break;

	default:
		bNotify = FALSE;
		break;
	}

	if (lParam != WM_MOUSEMOVE)
		m_nPrevMsg = lParam;

	if (!bNotify)
		return TRUE;

	LRESULT lr = GetParent()->SendMessage(WM_NOTIFY, GetDlgCtrlID(),
									(LPARAM)&m_nm);

	return lr;
}