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

📄 mdi for voice.c

📁 五岳鑫电话卡应用开发
💻 C
字号:
#include <windows.h>
#include <string.h>
#include "resource.h"
#include "Voice.h"

HANDLE hInst;

//HMENU hMenu,hMenuDoc;
HMENU hMenu;

//HWND hWndFrame,hWndClient;
HWND hWndFrame;
HWND hChannelWnd,hMessageWnd;

//HWND    ChannelhChildWnd;
//HWND    MessagehChildWnd;

int APIENTRY WinMain(HINSTANCE hInstance,
					 HINSTANCE hPrevInstance,
					 LPSTR lpCmdLine,
					 int nCmdShow)
{
	MSG msg;
	HACCEL hAccel;

	hMenu	 = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MDIMAINMENU));	//主窗口菜单
//	hMenuDoc = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MDIMENUDOC));		//子窗口菜单初始化
	hAccel=LoadAccelerators(hInstance,MAKEINTRESOURCE(IDR_ACCEL));  	//快捷键资源初始化

	if(!hPrevInstance)
	{
		if(!InitApplication(hInstance))
			return(FALSE);
	}

	if(!InitInstance(hInstance,nCmdShow))
		return(FALSE);

	while(GetMessage(&msg,
		NULL,
		0,
		0))
	{
/*		if(!TranslateAccelerator(hWndFrame,hAccel,&msg) && 
			!TranslateMDISysAccel(hWndClient,&msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
*/
		if(!TranslateAccelerator(hWndFrame,hAccel,&msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return(msg.wParam);
}
BOOL InitApplication(HINSTANCE hInstance)
{
////////////////////////////////////////////
//
	WNDCLASS wc;  
//
////////////////////////////////////////////

	wc.style          = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wc.lpfnWndProc    = (WNDPROC) FrameWndProc;
	wc.cbClsExtra     = 0;
	wc.cbWndExtra     = 0;
	wc.hInstance      = hInstance;
	wc.hIcon          = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_BIG));
	wc.hCursor        = LoadCursor(NULL,IDC_ARROW);
	wc.hbrBackground  = GetStockObject(GRAY_BRUSH);  
	wc.lpszMenuName   = NULL;
	wc.lpszClassName  = "WIN_MDI:FRAME";
	if(!RegisterClass(&wc))//注册主窗口
		return FALSE;
/*
	wc.style          = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wc.lpfnWndProc    = (WNDPROC) ChannelWndProc;
	wc.cbClsExtra     = 0;
	wc.cbWndExtra     = sizeof(LOCALHANDLE);
	wc.hInstance      = hInstance;
	wc.hIcon          = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_CHANNEL));
	wc.hCursor        = LoadCursor(NULL,IDC_ARROW);
	wc.hbrBackground  = GetStockObject(WHITE_BRUSH);  
	wc.lpszMenuName   = NULL;
	wc.lpszClassName  = "WIN_MDI:CHANNEL";
	if(!RegisterClass(&wc))//语音通道窗口类

		return FALSE;

	wc.style          = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
	wc.lpfnWndProc    = (WNDPROC) MessageWndProc;
	wc.cbClsExtra     = 0;
	wc.cbWndExtra     = sizeof(LOCALHANDLE);
	wc.hInstance      = hInstance;
	wc.hIcon          = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MESSAGE));
	wc.hCursor        = LoadCursor(NULL,IDC_ARROW);
	wc.hbrBackground  = GetStockObject(WHITE_BRUSH);  
	wc.lpszMenuName   = NULL;
	wc.lpszClassName  = "WIN_MDI:MESSAGE";
	if(!RegisterClass(&wc))//系统信息窗口类
		return FALSE;
*/

	return TRUE;
}

BOOL InitInstance(HINSTANCE hInstance,
				  int nCmdShow)
{
	static HWND hWndClient,hWndFrame;
	static HWND hChannelWnd,hMessageWnd;
	hInst=hInstance;

	hWndFrame=CreateWindow(
		"WIN_MDI:FRAME",
		"海威声讯",
		WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		NULL,
		hMenu,
		hInstance,
		NULL);//创建主窗口

	if(!hWndFrame)
		return(FALSE);

//	hWndClient = GetWindow(hWndFrame,WS_CHILD);   //设置主从关系

	ShowWindow(hWndFrame,nCmdShow);
//	ShowWindow(hWndFrame,SW_MAXIMIZE);

	SetWindowFonts();

	UpdateWindow(hWndFrame);//显示主窗口
	return(TRUE);
}

LRESULT CALLBACK FrameWndProc(HWND hWnd,
							 UINT message,
							 WPARAM wParam,
							 LPARAM lParam)
{
	static HWND hWndClient;
	HWND hWndChild;
//	CLIENTCREATESTRUCT clcr;
//	MDICREATESTRUCT mdi;

	int i;
//	RECT rect;
	char str[100];

	switch(message)
	{
	case WM_CREATE://完成用户窗口的创建
/*		clcr.hWindowMenu	= hMenu;
		clcr.idFirstChild	= 100;

		hWndClient = CreateWindow("MDICLIENT",
			NULL,
			WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
			0,0,
			0,0,
			hWnd,
			NULL,
			hInst,
			(LPSTR) &clcr);
*/
		/*---------------------------------------------
		创建系统信息显示窗口
		---------------------------------------------*/
		/*
		mdi.szClass = "WIN_MDI:MESSAGE";
		mdi.szTitle = "message";
		mdi.hOwner  = hInst;
		mdi.x		= CW_USEDEFAULT;
		mdi.y		= CW_USEDEFAULT;
		mdi.cx		= CW_USEDEFAULT;
		mdi.cy		= CW_USEDEFAULT;
		mdi.style	= 0;
		mdi.lParam	= 0L;

		hMessageWnd	= (HWND)
			(SendMessage(hWndClient,
			WM_MDICREATE,
			0,
			(LONG)(LPMDICREATESTRUCT) &mdi));
		*/
			
		hMessageWnd = CreateWindow("LISTBOX", 
			(LPSTR) MessageTitle,
			MessageWinstyle,
//			0, 
//			0, 
//			300, 
//			400, 
			CW_USEDEFAULT, 
			CW_USEDEFAULT, 
			CW_USEDEFAULT, 
			CW_USEDEFAULT, 
			hWnd, 
			(HMENU) NULL, 
			hInst, 
			NULL);
		
		//Show the window
		//ShowWindow(ChannelhChildWnd, TRUE);
		ShowWindow(hMessageWnd, SW_SHOWNORMAL);
		//Set the font of the created child windows
		SetWindowFonts();

		/*---------------------------------------------
		创建语音通道参数显示窗口
		---------------------------------------------*/
		/*
		mdi.szClass = "WIN_MDI:CHANNEL";
		mdi.szTitle = "voice Channel Status";
		mdi.hOwner  = hInst;
		mdi.x		= CW_USEDEFAULT;
		mdi.y		= CW_USEDEFAULT;
		mdi.cx		= CW_USEDEFAULT;
		mdi.cy		= CW_USEDEFAULT;
		mdi.style	= 0;
		mdi.lParam	= 0L;
		
		hChannelWnd	= (HWND)
			(SendMessage(hWndClient,
			WM_MDICREATE,
			0,
			(LONG)(LPMDICREATESTRUCT) &mdi));
		*/
		//voice Channel Status windows
		hChannelWnd = CreateWindow("LISTBOX", 
			(LPSTR) ChannelTitle,
			ChannelWinstyle,
//			0, 
//			0, 
//			300, 
//			400, 
			CW_USEDEFAULT, 
			CW_USEDEFAULT, 
			CW_USEDEFAULT, 
			CW_USEDEFAULT, 
			hWnd, 
			(HMENU) NULL, 
			hInst, 
			NULL);
		
		//Show the window
		//ShowWindow(ChannelhChildWnd, TRUE);
		ShowWindow(hChannelWnd, SW_SHOWNORMAL);
		//Set the font of the created child windows
		SetWindowFonts();

		for(i = 0; i<MAXCHANNEL;i++)
		{
			wsprintf(str,"Chan:  %d  DTI initialized",i);
			SendMessage(hChannelWnd,LB_ADDSTRING,
				0,(LPARAM) (LPCSTR)str);
		}


		
		//设窗口位置
		SetWindowSIZE((HWND) hWnd,(HWND) hChannelWnd,(HWND) hMessageWnd);
		
		break;

	case WM_COMMAND://主窗口消息响应
		switch(LOWORD(wParam))
		{
		case IDM_NEWWINDOW://创建子窗口
/*
			mdi.szClass = "WIN_MDI:CHANNEL";
			mdi.szTitle = "语音通道";
			mdi.hOwner  = hInst;
			mdi.x		= CW_USEDEFAULT;
			mdi.y		= CW_USEDEFAULT;
			mdi.cx		= CW_USEDEFAULT;
			mdi.cy		= CW_USEDEFAULT;
			mdi.style	= 0;
			mdi.lParam	= 0L;
			
			hWndChild	= (HWND) 
				(SendMessage(hWndClient,
				WM_MDICREATE,
				0,
				(LONG)(LPMDICREATESTRUCT) &mdi));
			break;
			*/
			break;
			
		case IDM_EXIT:
			SendMessage(hWnd,WM_CLOSE,0,0L);
			break;

		case IDM_MDITILE:  //并列子窗口
			//SendMessage(hWndClient,WM_MDITILE,0,0L);//并列子窗口

			//设窗口位置
			SetWindowSIZE((HWND) hWnd,(HWND) hChannelWnd,(HWND) hMessageWnd);
			break;

		case IDM_MDICASCADE://叠置子窗口
			SendMessage(hWndClient,WM_MDICASCADE,0,0L);
			break;

		case IDM_MDICONARRANGE://排列子窗口图标
			SendMessage(hWndClient,WM_MDIICONARRANGE,0,0L);
			break;

		case IDM_MDINEXT://激活下一个子窗口
			SendMessage(hWndClient,WM_MDINEXT,0,0L);
			break;

		case IDM_MDIDESTROY://关闭当前活动窗口
			hWndChild = (HWND) SendMessage(
				hWndClient,WM_MDIGETACTIVE,0,0L);

			SendMessage(hWndClient,
				WM_MDINEXT,
				(WPARAM) hWndChild,
				0L);		
			
			SendMessage(hWndClient,WM_MDIDESTROY,
				(WPARAM)(HWND)hWndChild,
				0L);
			break;

		case IDM_DESTROYALLCHILD://关闭所有子窗口
			
			/* hide the MDI client window to avoid multiple repaints */
		
			xf_CloseAllChildren (hWndClient);
			ShowWindow(hWndClient,SW_SHOW);
			break;

		case IDM_ABOUT:
			DialogBox(hInst,MAKEINTRESOURCE(ABOUT),hWnd,(DLGPROC)About);
			break;
		default:
			hWndChild	= (HWND) SendMessage(
				hWndClient,WM_MDIGETACTIVE,0,0L);
			if(IsWindow(hWndChild))
				SendMessage(hWndChild,WM_COMMAND,wParam,lParam);
			break;
			
		}
		break;
/*---------------------------------------------
		case WM_PAINT:
			//设窗口位置
			SetWindowSIZE((HWND) hWndClient,(HWND) hChannelWnd,(HWND) hMessageWnd);
			break;
---------------------------------------------*/

		case WM_CLOSE:
        /* don't close if any children cancel the operation */
		xf_CloseAllChildren (hWndClient);

  	    DestroyWindow (hWnd);
	    break;

	case WM_QUERYENDSESSION:
	    /*	Before session ends, check that all files are saved */
		xf_CloseAllChildren (hWndClient);
		break;

	case WM_DESTROY:
	    PostQuitMessage (0);
	    break;
	default:
	    return DefFrameProc (hWnd,hWndClient,message,wParam,lParam);
    }
    return 0;
}
/*
LRESULT CALLBACK ChannelWndProc(HWND hWnd,
							 UINT message,
							 WPARAM wParam,
							 LPARAM lParam)
{
	static HWND hWndClient,hWndFrame;
	int i;
	RECT rect;
	char str[100];

	switch(message)
	{
	case WM_CREATE:
		hWndClient = GetParent(hWnd);
		hWndFrame = GetParent(hWndClient);
		GetClientRect(hChannelWnd,&rect);

//voice Channel Status windows
		ChannelhChildWnd = CreateWindow("LISTBOX", 
			(LPSTR) NULL,
			WS_CHILD | WS_VSCROLL | LBS_NOTIFY,
			0, 
			0, 
			300, 
			400, 
			hWnd, 
			(HMENU) NULL, 
			hInst, 
			NULL);
		
		//Show the window
		//ShowWindow(ChannelhChildWnd, TRUE);
		ShowWindow(ChannelhChildWnd, SW_SHOWNORMAL);
		//Set the font of the created child windows
		SetWindowFonts();
		//INIT CHANNEL
		for(i = 0; i<MAXCHANNEL;i++)
		{
			wsprintf(str,"Chan:  %d  DTI initialized",i);
			SendMessage(ChannelhChildWnd,LB_ADDSTRING,
				0,(LPARAM) (LPCSTR)str);
		}
		break;


	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		default:
			return 0L;
		}
	case WM_MDIACTIVATE:
		if(lParam)
			SendMessage(hWndClient,WM_MDISETMENU,(WPARAM) hMenuDoc,0);
		else
			SendMessage(hWndClient,WM_MDISETMENU,(WPARAM) hMenu,0);
		DrawMenuBar(hWndFrame);
		return 0L;

	case WM_QUERYENDSESSION:
	case WM_CLOSE:
	case WM_DESTROY:
		//!!!!!!向frame窗口发送消息
		SetWindowSIZE((HWND) hWndClient,(HWND) hChannelWnd,(HWND) hMessageWnd);
		break;

	}
	return (DefMDIChildProc(hWnd,message,wParam,lParam));
}
*/
/*
LRESULT CALLBACK MessageWndProc(HWND hWnd,
							 UINT message,
							 WPARAM wParam,
							 LPARAM lParam)
{
	static HWND hWndClient,hWndFrame;
	switch(message)
	{
	case WM_CREATE:
		hWndClient = GetParent(hWnd);
		hWndFrame = GetParent(hWndClient);
		break;


	case WM_COMMAND:
		switch(LOWORD(wParam))
		{
		default:
			return 0L;
		}
	case WM_MDIACTIVATE:
		if(lParam)
			SendMessage(hWndClient,WM_MDISETMENU,(WPARAM) hMenuDoc,0);
		else
			SendMessage(hWndClient,WM_MDISETMENU,(WPARAM) hMenu,0);
		DrawMenuBar(hWndFrame);
		return 0L;

	case WM_QUERYENDSESSION:
	case WM_CLOSE:
	case WM_DESTROY:
		//!!!!!!向frame窗口发送消息
		SendMessage(hWndFrame,WM_MDIDESTROY,(WPARAM)(HWND) hWnd,0L);
		break;

	}
	return (DefMDIChildProc(hWnd,message,wParam,lParam));
}
*/
BOOL APIENTRY About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam)
{
	switch(message)
	{
	case WM_INITDIALOG:
		return(TRUE);
	case WM_COMMAND:
		if(LOWORD(wParam)==IDOK||LOWORD(wParam)==IDCANCEL)
		{
			EndDialog(hDlg,TRUE);
			return(TRUE);
		}
		break;
	}
	return(FALSE);
}
/****************************************************************************
 *									    *
 *  FUNCTION   : xf_CloseAllChildren ()					    *
 *									    *
 *  PURPOSE    : Destroys all MDI child windows.			    *
 *									    *
 ****************************************************************************/
VOID NEAR PASCAL xf_CloseAllChildren (HWND hWndClient)
{
	HWND hWndChild;
	ShowWindow(hWndClient,SW_HIDE);
	
	hWndChild	= (HWND) SendMessage(
		hWndClient,WM_MDIGETACTIVE,0,0L);
	while(IsWindow(hWndChild))
	{
		SendMessage(hWndClient,
			WM_MDINEXT,
			(WPARAM) hWndChild,
			0L);		
		//释放窗口数据
		//.............
		
		SendMessage(hWndClient,WM_MDIDESTROY,
			(WPARAM)(HWND)hWndChild,
			0L);
		hWndChild = (HWND) SendMessage(
			hWndClient,WM_MDIGETACTIVE,0,0L);
	}
	return;
}
/****************************************************************
*	Name		: SetWindowFonts
*	Input Parms	: None.
*	Description	: Sets the font of the created windows.  Each
*				: child window created should have a call here.
*****************************************************************/
void SetWindowFonts(void)
{
	HANDLE handle;

	/*	Get the handle to the stock font ANSI_VAR_FONT */
	handle = GetStockObject(ANSI_VAR_FONT);

	/*	This Message uses the above handle to the ANSI VAR FONT
		for the child windows specified in the call.  One of these 
		messages should be sent for each child window created.

		By setting LPARAM to TRUE, the window is redrawn immediately
		with the new font. */
	//SendMessage(D4XhChildWnd, WM_SETFONT, (WPARAM)handle, (LPARAM)TRUE);
   	SendMessage(hWndFrame, WM_SETFONT, (WPARAM)handle, (LPARAM)TRUE);
}
/****************************************************************
*	Name		: SetWindowSIZE
*	Input Parms	: None.
*	Description	: Sets the RECT of the created windows and MDI windows.  
*				: 
*****************************************************************/
void SetWindowSIZE(HWND _hWnd,HWND _hChannelWnd,HWND _hMessageWnd)
{
	RECT RectWnd;
	
	GetClientRect(_hWnd,&RectWnd);
//	GetWindowRect(_hWnd,&RectWnd);

	MoveWindow(_hChannelWnd,
		CHILD_WND_FREE_WIDTH,
		CHILD_WND_FREE_HEIGHT,
		(RectWnd.right-RectWnd.left)/2 - CHILD_WND_FREE_WIDTH-10,
		RectWnd.bottom - RectWnd.top - CHILD_WND_FREE_HEIGHT-15,
		TRUE);

	MoveWindow(_hMessageWnd,
		(RectWnd.right-RectWnd.left)/2 + CHILD_WND_FREE_WIDTH-10,
		CHILD_WND_FREE_HEIGHT,
		(RectWnd.right-RectWnd.left)/2 - CHILD_WND_FREE_WIDTH-10,
		RectWnd.bottom - RectWnd.top - CHILD_WND_FREE_HEIGHT-15,
		TRUE);
	
	return;
}
void Msg_display(LPSTR string)
{
	int index;
    
	SendMessage(hMessageWnd, LB_ADDSTRING, (WPARAM)0, (LPARAM)string);
	index = SendMessage (hMessageWnd, LB_GETCARETINDEX, 0,0);
    if (index>200) {
	   SendMessage (hMessageWnd, LB_DELETESTRING, (WPARAM)0, 0);
	}
	SendMessage(hMessageWnd, LB_SETCARETINDEX, (WPARAM)++index, (LPARAM)FALSE);
/*
	SendMessage(MainhWnd, LB_ADDSTRING, (WPARAM)0, (LPARAM)string);
	index = SendMessage (MainhWnd, LB_GETCARETINDEX, 0,0);
    if (index>200) {
	   SendMessage (MainhWnd, LB_DELETESTRING, (WPARAM)0, 0);
	}	SendMessage(MainhWnd, LB_SETCARE
TINDEX, (WPARAM)++index, (LPARAM)FALSE);

*/
}

⌨️ 快捷键说明

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