两个问题

zp19810828csnd 2004-04-10 08:50:01
1.动态创造一组按钮(10),单击每个按钮都响应一个消息?
2.怎样使用socket进行局域网的任意格式文件传输?
每个问题100分,要例程或文章。
不够再加
...全文
21 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhaogaojian 2004-04-11
  • 打赏
  • 举报
回复
关注。。。。。。。。。。。。。。。。
zhujianping_es 2004-04-10
  • 打赏
  • 举报
回复
Well I program a example for you!
#include <afxtempl.h>
#define ID_BUTTON_FRIST 100
#define BUTTON_COUNT 5
class CAaaaaDlg : public CDialog
{
void CAaaaaDlg::CreateButttons(void);
protected:
HICON m_hIcon;
CArray<HWND,HWND> m_arrButton;
..............
//}}AFX_MSG
afx_msg void OnCustomButtonHandler(UINT nID );

DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CAaaaaDlg, CDialog)
//{{AFX_MSG_MAP(CAaaaaDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_BUTTON_FRIST,ID_BUTTON_FRIST+BUTTON_COUNT,OnCustomButtonHandler)
END_MESSAGE_MAP()

// CAaaaaDlg message handlers
void CAaaaaDlg::CreateButttons(void)
{
CRect rect;
GetClientRect(&rect);
rect.bottom=rect.top +30;
rect.right =rect.left+50;
for(int i=0;i<BUTTON_COUNT;i++)
{
CString str;
str.Format("Btn %d",i+1);
HWND hWnd=::CreateWindow("BUTTON",str,WS_VISIBLE|WS_CHILD,rect.left,rect.top,rect.Width(),rect.Height(),this->GetSafeHwnd(),(HMENU)(ID_BUTTON_FRIST+i),::GetModuleHandle(NULL),NULL);
rect.OffsetRect(60,0);
m_arrButton.Add(hWnd);
}
}

BOOL CAaaaaDlg::OnInitDialog()
{
CDialog::OnInitDialog();
..............
// TODO: Add extra initialization here
CreateButttons();
return TRUE; // return TRUE unless you set the focus to a control
}



void CAaaaaDlg::OnDestroy()
{
CDialog::OnDestroy();

for(int n=0;n<m_arrButton.GetSize();n++)
{
HWND h=m_arrButton.GetAt(n);
::DestroyWindow(h);
}
}
void CAaaaaDlg::OnCustomButtonHandler(UINT nID )
{
int n=nID-ID_BUTTON_FRIST+1;
CString str;
str.Format("Button %d Clicked!",n);
AfxMessageBox(str);
}
xuanzg 2004-04-10
  • 打赏
  • 举报
回复
1。
// The code fragment below shows how to use ON_COMMAND_RANGE macro
// to map a contiguous range of command IDs to a single message
// handler function (i.e. OnFileMenuItems() is the sample below). In
// addition, it also shows how to use CheckMenuRadioItem() to check a
// selected menu item and makes it a radio item.
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// ...
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3, OnFileMenuItems)
END_MESSAGE_MAP()

void CMainFrame::OnFileMenuItems(UINT nID)
{
CMenu* mmenu = GetMenu();
CMenu* submenu = mmenu->GetSubMenu(0);
submenu->CheckMenuRadioItem(ID_FILE_MENUITEM1, ID_FILE_MENUITEM3,
nID, MF_BYCOMMAND);
}
_foo 2004-04-10
  • 打赏
  • 举报
回复
第二个http://www.vckbase.com/document/viewdoc/?id=321
_foo 2004-04-10
  • 打赏
  • 举报
回复
1.ON_COMMAND_RANGE

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧