⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win_win32.c

📁 大名鼎鼎的CE下播放软件,TCPPMP的源代码!!!2410下可以流畅的解QVGA的H264,MPEG4等格式.
💻 C
📖 第 1 页 / 共 5 页
字号:
			{
				GetCount = LB_GETCOUNT;
				GetItemData = LB_GETITEMDATA;
				SetCurSel = LB_SETCURSEL;
			}
			else
#endif
			{
				GetCount = CB_GETCOUNT;
				GetItemData = CB_GETITEMDATA;
				SetCurSel = CB_SETCURSEL;
			}

			Count = SendMessage(i->Control,GetCount,0,0);
			for (No=0;No<Count;++No)
				if (SendMessage(i->Control,GetItemData,No,0) == *(int*)Data)
					break;
			if (No==Count)
				No=-1;
			SendMessage(i->Control,SetCurSel,No,0);
			break;
		}
		else
		if (DataDef.Flags & DF_MINMAX)
		{
			if (DataDef.Type == TYPE_TICK)
				Value = *(tick_t*)Data;
			else
				Value = *(int*)Data;

			if (DataDef.Format2 - DataDef.Format1 <= TRACKMAX)
				Value -= DataDef.Format1;
			else
				Value = Scale(Value - DataDef.Format1,TRACKMAX,DataDef.Format2 - DataDef.Format1);
			SendMessage(i->Control,TBM_SETPOS,1,Value);
			break;
		}
		else
		{
			if (DataDef.Flags & DF_PERCENT)
			{
				if (*(int*)Data > 0)
					IntToString(s,TSIZEOF(s),ScaleRound(*(int*)Data,100,PERCENT_ONE),0);
				else
					s[0]=0;
			}
			else
				IntToString(s,TSIZEOF(s),*(int*)Data,0);
			SetWindowText(i->Control,s);
			SendMessage(i->Control,EM_SETSEL,tcslen(s),tcslen(s));
		}
		break;

	case TYPE_STRING:
		SetWindowText(i->Control,Data);
		SendMessage(i->Control,EM_SETSEL,tcslen(s),tcslen(s));
		break;

	case TYPE_TICK:
		if (DataDef.Flags & DF_MSEC)
			stprintf_s(s,TSIZEOF(s),T("%d"),ScaleRound(*(tick_t*)Data,1000,TICKSPERSEC));
		else
			stprintf_s(s,TSIZEOF(s),T("%d"),ScaleRound(*(tick_t*)Data,1,TICKSPERSEC));
		SetWindowText(i->Control,s);
		SendMessage(i->Control,EM_SETSEL,tcslen(s),tcslen(s));
		break;

	case TYPE_FRACTION:
		if (((fraction*)Data)->Num > 0)
			stprintf_s(s,TSIZEOF(s),T("%d"),ScaleRound(((fraction*)Data)->Num,100,((fraction*)Data)->Den));
		else
			s[0] = 0;
		SetWindowText(i->Control,s);
		SendMessage(i->Control,EM_SETSEL,tcslen(s),tcslen(s));
		break;
	}
	p->InUpdate = 0;
}

winunit WinPixelToUnitX(win* p,int Pixel) {	return ScaleRound(Pixel,72,p->LogPixelSX); }
winunit WinPixelToUnitY(win* p,int Pixel) { return ScaleRound(Pixel,72,p->LogPixelSY); }
int WinUnitToPixelX(win* p,winunit Pos) { return ScaleRound(Pos,p->LogPixelSX,72); }
int WinUnitToPixelY(win* p,winunit Pos) { return ScaleRound(Pos,p->LogPixelSY,72); }

void WinProp( win* p, int* x0,int* x1)
{
	*x0 = 2;
	*x1 = p->LabelWidth + *x0;

	if (*x1 > (p->Width*3)/4)
		*x1 = (p->Width*3)/4;

	*x1++;
}

static wincontrol* CreateControl(win* p,int Size)
{
	wincontrol* Control = malloc(Size);
	if (Control)
	{
		wincontrol** i;
		memset(Control,0,Size);
		for (i=&p->Controls;*i;i=&(*i)->Next);
		*i = Control;
	}
	return Control;
}

static int CreateEnum(win* p, wincontrol* Control, int Left, int Top, int Width, int Height, const datadef* DataDef)
{
	int No;
	int Pos;
	int AddString;
	int ItemData;
	int MaxWidth;
	int FontSize;
	int Plus = 0;

	MaxWidth = WinUnitToPixelX(p,(DataDef->Flags & DF_ENUMSTRING) ? 80:180);
	if (Width > MaxWidth)
		Width = MaxWidth;

	if (p->Smartphone)
	{
		Control->Control = CreateWindow(T("listbox"), NULL, WS_TABSTOP|WS_VISIBLE|WS_CHILD|LBS_NOTIFY|LBS_NOINTEGRALHEIGHT|((DataDef->Flags & DF_ENUMUNSORT)?0:LBS_SORT), 
			Left, Top, Width, Height, p->WndDialog, NULL, p->Module, 0L);

		Control->Edit = CreateWindow(UPDOWN_CLASS, NULL, WS_CHILD|WS_VISIBLE | UDS_HORZ |UDS_ALIGNRIGHT | UDS_ARROWKEYS |  UDS_SETBUDDYINT | UDS_WRAP | UDS_EXPANDABLE, 
			0, 0, 0, 0, p->WndDialog, NULL, p->Module, 0L);

		SendMessage(Control->Edit, UDM_SETBUDDY, (WPARAM)Control->Control, 0);	

		AddString = LB_ADDSTRING;
		ItemData = LB_SETITEMDATA;

		FontSize = PROPSIZE;
		SendMessage(Control->Edit,WM_SETFONT,(WPARAM)WinFont(p,&FontSize,1),0);
	}
	else
	{
		Control->Control = CreateWindow(T("COMBOBOX"), NULL, WS_VSCROLL|WS_TABSTOP|WS_VISIBLE|WS_CHILD|CBS_DROPDOWNLIST|((DataDef->Flags & DF_ENUMUNSORT)?0:CBS_SORT), 
			Left, Top, Width, Height*(p->MenuSmall?10:15), p->WndDialog, NULL, p->Module, 0L);

		Control->ComboBox = 1;
		AddString = CB_ADDSTRING;
		ItemData = CB_SETITEMDATA;
		Plus = 6;

		FontSize = PROPSIZE;
		SendMessage(Control->Control,WM_SETFONT,(WPARAM)WinFont(p,&FontSize,1),0);
	}

	if (DataDef->Flags & DF_ENUMCLASS)
	{
		array List;
		int *i;
		NodeEnumClass(&List,DataDef->Format1);
		for (i=ARRAYBEGIN(List,int);i!=ARRAYEND(List,int);++i)
		{
			Pos = SendMessage(Control->Control,AddString,0,(LPARAM)LangStr(*i,NODE_NAME));
			SendMessage(Control->Control,ItemData,Pos,*i);
		}
		ArrayClear(&List);
	}
	else
	if (DataDef->Flags & DF_ENUMSTRING)
	{
		int Id;
		for (No=0;(Id=LangEnum(DataDef->Format1,No))!=0;++No)
		{
			Pos = SendMessage(Control->Control,AddString,0,(LPARAM)LangStr(DataDef->Format1,Id));
			SendMessage(Control->Control,ItemData,Pos,Id);
		}
	}

	return Plus;
}

static void CreateEditor(win* p, wincontrol* Control, int Left, int Top, int Width, int Height, const datadef* DataDef)
{
	tchar_t Post[32];
	int FontSize;
	int Style = ES_NUMBER;

	if (DataDef->Flags & DF_NEG)
		Style = 0;

	if (DataDef->Type==TYPE_STRING)
		Style = ES_AUTOHSCROLL;

#ifdef TARGET_WIN32
	if ((Width > 32) && DataDef->Type!=TYPE_STRING)
		Width = 32;
#else
	if ((Width > 30) && DataDef->Type!=TYPE_STRING)
		Width = 30;
#endif

	Control->Control = CreateWindow(T("EDIT"), NULL, WS_TABSTOP|WS_VISIBLE|WS_CHILD|Style, 
		WinUnitToPixelX(p,Left), WinUnitToPixelY(p,Top), 
		WinUnitToPixelX(p,Width), WinUnitToPixelY(p,Height), 
		p->WndDialog, NULL, p->Module, 0L);

	FontSize = PROPSIZE;
	SendMessage(Control->Control,WM_SETFONT,(WPARAM)WinFont(p,&FontSize,1),0);

	Control->Editor = 1;
	Post[0] = 0;

	if (DataDef->Flags & DF_KBYTE)
		tcscpy_s(Post,TSIZEOF(Post),T("KB"));
	else	
	if (DataDef->Flags & DF_MHZ)
		tcscpy_s(Post,TSIZEOF(Post),T("Mhz"));
	else	
	if (DataDef->Flags & DF_PERCENT)
		tcscpy_s(Post,TSIZEOF(Post),T("%"));
	else
	if (DataDef->Type == TYPE_TICK)
		tcscpy_s(Post,TSIZEOF(Post),(DataDef->Flags & DF_MSEC) ? T("msec"):T("sec"));

	if (Post[0])
		WinLabel(p,&Top,Left+Width+1,-1,Post,11,0,NULL);
}

wincontrol* WinPropNative(win* p, node* Node, int No)
{
	wincontrol* Control = CreateControl(p,sizeof(wincontrol));
	if (Control)
	{
		Control->Pin.Node = Node;
		Control->Pin.No = No;
	}
	return Control;
}

wincontrol* WinPropValue(win* p, winunit* DlgTop, node* Node, int No)
{
	int FontSize;
	int Height,Width;
	int Gap = WinUnitToPixelX(p,2);
	int Top = WinUnitToPixelY(p,*DlgTop);
	int Left;
	winunit x,x0,x1,y1,y2;
	wincontrol* Control;
	datadef DataDef;

	if (!NodeDataDef(Node,No,&DataDef))
		return NULL;

	Control = WinPropNative(p,Node,No);
	if (!Control)
		return NULL;

	if (DataDef.Flags & DF_SHORTLABEL)
	{
		if (p->Smartphone)
			x1 = 36;
		else
			x1 = 48;
		x0 = 2;
		Width = x1-x0-2; 
	}
	else
	if ((DataDef.Flags & DF_CHECKLIST) && DataDef.Type==TYPE_BOOL)
	{
		x0 = 4+PROPSIZE;
		x1 = 2;
		Width = -1;
	}
	else
	{
		WinProp(p,&x0,&x1);
		Width = x1-x0-2;
	}

	if (DataDef.Flags & DF_NOWRAP)
		Width = -1;

	y1 = *DlgTop;
	if (DataDef.Type != TYPE_RESET)
		WinLabel(p,&y1,x0,Width,DataDef.Name,PROPSIZE,0,Control);
	else
		x1 = x0;

	y2 = *DlgTop + PROPSIZE+1;
	Width = WinUnitToPixelX(p,PROPSIZE+1);
	Height = WinUnitToPixelY(p,PROPSIZE+1);
	Left = WinUnitToPixelX(p,x1);

	switch (DataDef.Type)
	{
	case TYPE_RESET:
		Control->Control = CreateWindow(T("BUTTON"),NULL,WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_NOTIFY,
			Left+Gap,Top,Width*5,WinUnitToPixelY(p,PROPSIZE+2), p->WndDialog, NULL, p->Module, NULL);

		y2 += 2;
		FontSize = PROPSIZE;
		SendMessage(Control->Control,WM_SETFONT,(WPARAM)WinFont(p,&FontSize,0),0);
		SetWindowText(Control->Control,DataDef.Name);
		break;

	case TYPE_HOTKEY:
		x = (Width*7)/2;
		Control->Edit = CreateWindow(T("EDIT"),NULL,ES_READONLY|ES_AUTOHSCROLL|WS_VISIBLE|WS_CHILD,
			Left,Top,x,Height, p->WndDialog, NULL, p->Module, NULL );

		Control->Control = CreateWindow(T("BUTTON"),NULL,WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_NOTIFY,
			Left+x+Gap,Top,(Width*5)/2,WinUnitToPixelY(p,PROPSIZE+2), p->WndDialog, NULL, p->Module, NULL);

		FontSize = PROPSIZE;
		SendMessage(Control->Edit,WM_SETFONT,(WPARAM)WinFont(p,&FontSize,1),0);

		FontSize = PROPSIZE;
		SendMessage(Control->Control,WM_SETFONT,(WPARAM)WinFont(p,&FontSize,0),0);

		y2 += 2;
		break;

	case TYPE_BOOL:
		Control->Control = CreateWindow(T("BUTTON"),NULL,WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_CHECKBOX|BS_NOTIFY,
			Left,Top,Width,Height,p->WndDialog,NULL,p->Module,NULL);
		break;

	case TYPE_INT:
		if (DataDef.Flags & (DF_ENUMCLASS|DF_ENUMSTRING))
		{
			y2 += CreateEnum(p,Control,Left,Top,WinUnitToPixelX(p,p->Width-x1),Height,&DataDef);
			break;
		}
		else
		if (DataDef.Flags & DF_MINMAX)
		{
			int Interval;

			Width = p->Width-x1;
			if (Width > 100)
				Width = 100;
			if (Width < 65 && !(DataDef.Flags & DF_NOWRAP))
			{
				y2 = y1 + PROPSIZE+1;
				x1 = x0;
				Width = p->Width-x1;
				if (Width > 200)
					Width = 200;
				Left = WinUnitToPixelX(p,x1);
				Top = WinUnitToPixelY(p,y1);
			}

			Control->Control = CreateWindowEx( 
				0,                    
				TRACKBAR_CLASS,       
				NULL,   
				WS_TABSTOP|WS_CHILD | WS_VISIBLE | TBS_HORZ|TBS_BOTH|TBS_NOTICKS|TBS_FIXEDLENGTH, 
				Left,Top,    
				WinUnitToPixelX(p,Width), Height,   
				p->WndDialog,	
				NULL,						
				p->Module,                     
				NULL); 

			Interval = DataDef.Format2 - DataDef.Format1;
			if (Interval > TRACKMAX)
				Interval = TRACKMAX;

			SendMessage(Control->Control, TBM_SETRANGE, FALSE,MAKELONG(0,Interval));
			SendMessage(Control->Control, TBM_SETPAGESIZE,0,Interval/32);
			SendMessage(Control->Control, TBM_SETLINESIZE,0,Interval/32);
			SendMessage(Control->Control, TBM_SETTHUMBLENGTH, WinUnitToPixelY(p,TRACKTHUMB),0);
			break;
		}
		// no break

	case TYPE_STRING:
	case TYPE_TICK:
	case TYPE_FRACTION:
		CreateEditor(p,Control,x1,*DlgTop,p->Width-x1,PROPSIZE+1,&DataDef);
		y2 += 1;
		break;
	}
	SetWindowLong(Control->Control,GWL_USERDATA,(LONG)Control);
	WinControlUpdate(p,Control);
	*DlgTop = y1>y2?y1:y2;
	return Control;
}

bool_t WinNoHotKey(int HotKey)
{
	int Model = QueryPlatform(PLATFORM_MODEL);
	if (Model == MODEL_TOSHIBA_E800) // record button mapping works on E800...
		return 0;

	HotKey &= ~HOTKEY_KEEP;
	if (((HotKey & HOTKEY_MASK) == 0xC5 || HotKey == VK_ESCAPE || HotKey == VK_F1 || 
		 HotKey == VK_F2 || HotKey == VK_F3 || HotKey == VK_F4 ||
		 HotKey == VK_F6 || HotKey == VK_F7) && 
		(QueryPlatform(PLATFORM_TYPENO) == TYPE_POCKETPC ||
		 QueryPlatform(PLATFORM_TYPENO) == TYPE_SMARTPHONE))
		return 1; // record, softkey1,2, talk, end, volume up/odwn

	return 0;
}

bool_t WinEssentialKey(int HotKey)
{
	HotKey &= ~HOTKEY_KEEP;
	return 
		HotKey == 0x86 || //action
		HotKey == VK_RETURN ||
		HotKey == VK_LEFT || // (need to be essential for D-pad rotation support too!)
		HotKey == VK_RIGHT ||
		HotKey == VK_UP ||
		HotKey == VK_DOWN; // should use normal WM_KEYDOWN event for them
}

static void AddButton(win* p,int Pos,int Id,int Bitmap,tchar_t* Name,bool_t Check)
{
	TBBUTTON Button;
	memset(&Button,0,sizeof(Button));
	Button.iBitmap = p->BitmapNo + Bitmap;
	Button.idCommand = Id;
	Button.fsState = TBSTATE_ENABLED;
	Button.fsStyle = (BYTE)((Check ? TBSTYLE_CHECK : TBSTYLE_BUTTON) | TBSTYLE_AUTOSIZE | BTNS_SHOWTEXT);
	Button.dwData = 0;
	Button.iString = 0;

	if (Id<0)
	{
		Button.idCommand = 0;
		Button.fsStyle = TBSTYLE_SEP;

		if (!p->AygShellTB && !(p->Flags & WIN_DIALOG) && GetSystemMetrics(SM_CXSCREEN)<=240)
			return;
	}

	if (p->WndTB)
	{
		SendMessage(p->WndTB,TB_INSERTBUTTON,Pos,(LPARAM)&Button);

		if (Name && Id>0)
		{
			TBBUTTONINFO Button;
			Button.cbSize = sizeof(Button);
			Button.dwMask = TBIF_TEXT;
			Button.pszText = Name;
			SendMessage(p->WndTB,TB_SETBUTTONINFO,Id,(LPARAM)&Button);
		}
	}
}

static int FindButton(win* p,int Id)
{
	if (p->WndTB)
	{
		int i;
		int n=SendMessage(p->WndTB,TB_BUTTONCOUNT,0,0);
		for (i=0;i<n;++i)
		{
			TBBUTTON Button;
			SendMessage(p->WndTB,TB_GETBUTTON,i,(LPARAM)&Button);
			if (Button.idCommand == Id)
				return i;
		}
	}
	return -1;
}

void WinDeleteButton(win* p,int Id)
{
	int No = FindButton(p,Id);
	if (No>=0)
		SendMessage(p->WndTB,TB_DELETEBUTTON,No,0);
}

void WinAddButton(win* p,int Id,int Bitmap,tchar_t* Name,bool_t Check)
{
	if (p->WndTB)
		AddButton(p,SendMessage(p->WndTB,TB_BUTTONCOUNT,0,0),Id,Bitmap,Name,Check);
}

win* WinGetObject(HWND Wnd)
{
	return (win*) GetWindowLong(Wnd,GWL_USERDATA);
}

void WinSetObject(HWND Wnd,win* p)
{
	SetWindowLong(Wnd,GWL_USERDATA,(LONG)p);
}

void WinRegisterHotKey(win* p,int Id,int HotKey)
{
#if defined(NDEBUG) || defined(TARGET_WINCE)
	int Mod = MOD_KEYUP;
	HotKey &= ~HOTKEY_KEEP;
	//if (WinNoHotKey(HotKey)) return; //don't force, some devices support those hotkeys
	if (HotKey & HOTKEY_ALT) Mod |= MOD_ALT;
	if (HotKey & HOTKEY_SHIFT) Mod |= MOD_SHIFT;
	if (HotKey & HOTKEY_CTRL) Mod |= MOD_CONTROL;
	if (HotKey & HOTKEY_WIN) Mod |= MOD_WIN;
	HotKey &= HOTKEY_MASK;
	if (FuncUnregisterFunc1)
		FuncUnregisterFunc1(Mod,HotKey);
	RegisterHotKey(p->Wnd,Id,Mod,HotKey);
#endif
}

void WinUnRegisterHotKey(win* p,int Id)
{
#if defined(NDEBUG) || defined(TARGET_WINCE)
	UnregisterHotKey(p->Wnd,Id);
#endif
}

wincontrol* WinPropLabel(win* p, winunit* Top, const tchar_t* LockedMsg, const tchar_t* Value)
{
	wincontrol* Control;
	int x0,x1;
	int y2=*Top,y1=*Top;
	WinProp(p,&x0,&x1);
	Control = WinLabel(p,&y2,x1,-1,Value,PROPSIZE,LABEL_BOLD,NULL);
	if (Control && !(p->Flags & WIN_NOTABSTOP))
		Control->Disabled = 0; // tab stop
	WinLabel(p,&y1,x0,x1-x0-2,LockedMsg,PROPSIZE,0,Control);
	*Top = y1>y2 ? y1:y2;
	return Control;
}

static void WinUpdateScroll(win* p);
static void WinNext(win* p,bool_t Prev);

int WinKeyState(int Key)
{
	if (GetKeyState(VK_CONTROL)<0) Key |= HOTKEY_CTRL;
	if (GetKeyState(VK_SHIFT)<0) Key |= HOTKEY_SHIFT;
	if (GetKeyState(VK_MENU)<0) Key |= HOTKEY_ALT;
	if (GetKeyState(VK_LWIN)<0 || GetKeyState(VK_RWIN)<0) Key |= HOTKEY_WIN;
	//if (Key >= 0xC1 && Key <= 0xCF)	Key |= HOTKEY_WIN; // h3800 ???
	return Key;
}

void WinAllKeys(bool_t State)
{
	if (FuncAllKeys)
		FuncAllKeys(State);
}

void* WinCursorArrow()
{
#if defined(TARGET_WINCE)
	return NULL;
#else
	return LoadCursor(NULL,IDC_ARROW);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -