首页
社区
课程
招聘
[求助]关于VC写程序的主窗口的建立
发表于: 2007-2-2 18:04 6304

[求助]关于VC写程序的主窗口的建立

2007-2-2 18:04
6304
VC有对话框设计器,这个没问题,但是程序的主界面不能这样搞,在RegiterClass之后,调用CreateWindow,这样是能创建一个窗口,但是窗口上的那些按钮、Label、Edit怎么创建?难道是在WndProc里面自己写代码创建?那么位置怎么确定?不会是建好编译然后再调整再变异吧,那样的话,下面的Msg处理部分怎么办啊?

[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 217
活跃值: (99)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
程序的主界面当然也可以是对话框.
2007-2-2 19:52
0
雪    币: 216
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
干吗不直接使用MFC呢?
2007-2-2 20:11
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
FHB
4
楼主可以考虑用界面库
2007-2-2 20:48
0
雪    币: 622
活跃值: (294)
能力值: ( LV13,RANK:410 )
在线值:
发帖
回帖
粉丝
5
不喜欢用MFC,主要是调试MFC程序的时候受的打击太大了。。。。
那Dwing,能问下你怎么把涉及好的对话框设置成注主界面?
2007-2-3 09:54
0
雪    币: 297
活跃值: (10)
能力值: ( LV9,RANK:250 )
在线值:
发帖
回帖
粉丝
6
在工程中新建一个资源脚本,把你要加的控件加进去,然后在cpp中写好他们的消息处理函数就可以拉。
比如,用一个对话框,在winmain中一个DialogBox函数就可以拉。
DialogBox(hinstExe,MAKEINTRESOURC,(IDD_DIALOG1),NULL,DialogProc);
这个参数就不解释了吧,关键是最后的对话框的消息处理函数哦。
给个例子吧:)
DWORD WINAPI StartHook(HWND hwnd)
{
	WinExec("HookAll.exe", SW_SHOWNORMAL);
	SendMessage(hwnd,WM_SYSCOMMAND, SC_CLOSE, 0);
	return 0;
}

typedef int (__stdcall * PFN_ENABLENET)(BOOL);


int EnableNet(BOOL bEnable)
{
	HMODULE hMod = LoadLibrary("enblnet.dll");
	if(hMod == NULL)
	{
	    MessageBox(NULL,"Load enblnet.dll failed!", "PFW", 0);
		return -1;
	}
	PFN_ENABLENET pfnEnableNet = (PFN_ENABLENET)GetProcAddress(hMod, "EnableLAN");
	pfnEnableNet(bEnable);
	FreeLibrary(hMod);
	return 0;
}
//////////////////////////////////////////////////////////////////////////
void Dlg3_OnCommandInit(HWND hwnd,UINT wNotifyCode,int wID,HWND hwndCtl)
{
	switch(wID)
	{
	case SC_CLOSE:
		EndDialog(hwnd, wID);
		break;
    case IDC_BUTTON1:
		DWORD dwIndex=GetDlgItemInt(hwnd,IDC_EDIT1,NULL,FALSE);
		SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
		ModifyAcl(hwnd, dwIndex);
		SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
		ModifyAcl(hwnd, 0);
	}
}


BOOL Dlg3_OnInitDialogInit(HWND hwnd,HWND hwndFocus,LPARAM lParam)
{
//	CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartHook, (LPVOID)hwnd, 0, NULL);
	SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
    ModifyAcl(hwnd, 0);	    
	return(TRUE);
}
BOOL CALLBACK Dialog3ProcInit(
  HWND hwndDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
)
{
	switch(uMsg)
	{
	case WM_INITDIALOG:
		SetWindowLong(hwndDlg,DWL_MSGRESULT,(LONG)Dlg3_OnInitDialogInit(hwndDlg,(HWND)wParam,lParam));
	case WM_COMMAND:
		Dlg3_OnCommandInit(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
		break;
	case WM_SYSCOMMAND:
		Dlg3_OnCommandInit(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
		break;
	}
	return(FALSE);
}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////


void Dlg_OnCommand(HWND hwnd,UINT wNotifyCode,int wID,HWND hwndCtl)
{
	switch(wID)
	{
	case IDCANCEL://最小化
		SendMessage(hwnd,WM_SYSCOMMAND, SC_MINIMIZE, 0);
		break;
	case IDC_BUTTON6://退出程序
		RUNNING = FALSE;
		EndDialog(hwnd,wID);
		Sleep(100);
		break;
	case IDC_BUTTON5://断开网络
		//SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
		EnableNet(FALSE);
		EnableWindow(GetDlgItem(hwnd,IDC_BUTTON7), TRUE);
		EnableWindow(GetDlgItem(hwnd,IDC_BUTTON5), FALSE);
		break;
	case IDC_BUTTON7://连接网络
		//SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
		EnableNet(TRUE);
		EnableWindow(GetDlgItem(hwnd,IDC_BUTTON7), FALSE);
		EnableWindow(GetDlgItem(hwnd,IDC_BUTTON5), TRUE);
		break; 
	case IDC_BUTTON8://清空数据
		SendMessage(GetDlgItem(hwnd,IDC_LIST2), LB_RESETCONTENT, 0, 0);
		break;
	case IDC_BUTTON1://网络状态
		SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
		FindNetHandle(hwnd);
		break;
	case IDC_BUTTON2://网络进程
		WinExec("ProcessInfo.exe", SW_SHOWNORMAL);
		break;
	case IDC_BUTTON3://访问规则
		SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
		QueryAcl(hwnd);
		break;
	case IDC_BUTTON4://修改规则
//		SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_RESETCONTENT, 0, 0);
//		SendMessage(GetDlgItem(hwnd,IDC_LIST1), LB_ADDSTRING,0,(LPARAM)"help\0");
	    DialogBox(NULL,MAKEINTRESOURCE(IDD_DIALOG3),NULL,Dialog3ProcInit);
		break;
	}
}

BOOL Dlg_OnInitDialog(HWND hwnd,HWND hwndFocus,LPARAM lParam)
{
	SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDI_ICON1)));
	SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDI_ICON1)));
	CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)GetTime, NULL, 0, NULL);
	CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Sniffer, hwnd, 0, NULL);
	SendDlgItemMessage(hwnd, IDC_LIST1, LB_SETHORIZONTALEXTENT, 1000, 0); // 设置长度为1000像素的水平滚动条
//	SendDlgItemMessage(hwnd, IDC_LIST1, LB_DIR, DDL_READWRITE | DDL_DIRECTORY | DDL_DRIVES, (LPARAM)"*.*"); // 设置长度为1000像素的水平滚动条
	return(TRUE);
}



BOOL CALLBACK DialogProc(
  HWND hwndDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
)
{
	switch(uMsg)
	{
	case WM_INITDIALOG:
		SetWindowLong(hwndDlg,DWL_MSGRESULT,(LONG)Dlg_OnInitDialog(hwndDlg,(HWND)wParam,lParam));
	case WM_COMMAND:
		Dlg_OnCommand(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
		break;

	}
	return(FALSE);
}


/////////////////////////////////////////////////////////////////
void Dlg_OnCommandInit(HWND hwnd,UINT wNotifyCode,int wID,HWND hwndCtl)
{
	switch(wID)
	{
	case SC_CLOSE:
		EndDialog(hwnd, wID);
		break;
	}
}


BOOL Dlg_OnInitDialogInit(HWND hwnd,HWND hwndFocus,LPARAM lParam)
{
	CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)StartHook, (LPVOID)hwnd, 0, NULL);
	return(TRUE);
}
BOOL CALLBACK DialogProcInit(
  HWND hwndDlg,  // handle to dialog box
  UINT uMsg,     // message
  WPARAM wParam, // first message parameter
  LPARAM lParam  // second message parameter
)
{
	switch(uMsg)
	{
	case WM_INITDIALOG:
		SetWindowLong(hwndDlg,DWL_MSGRESULT,(LONG)Dlg_OnInitDialogInit(hwndDlg,(HWND)wParam,lParam));
	case WM_COMMAND:
		Dlg_OnCommandInit(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
		break;
	case WM_SYSCOMMAND:
		Dlg_OnCommandInit(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
		break;
	}
	return(FALSE);
}


int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int)
{
	if(!AdjustProcessPrivileges(SE_DEBUG_NAME))
		return -1;
	HANDLE CallEvent = CreateEvent(NULL, TRUE, TRUE, "HOOKALL");
	DialogBox(hinstExe,MAKEINTRESOURCE(IDD_DIALOG2),NULL,DialogProcInit);
	DialogBox(hinstExe,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DialogProc);
	ResetEvent(CallEvent);
	CloseHandle(CallEvent);
	return 0;
}
2007-2-3 11:57
0
雪    币: 622
活跃值: (294)
能力值: ( LV13,RANK:410 )
在线值:
发帖
回帖
粉丝
7
谢谢楼上的帮助
2007-2-3 12:00
0
游客
登录 | 注册 方可回帖
返回
//