1.GotoDlgCtrl(GetDlgItem(IDC_examnum));
GetDlgItem():返回一个指定控件或子窗口的指针
GetDlgItem(ID)->SetFocus()
SetFocus:Sets the input focus to the window.
GotoDlgCtrl:Sets the keyboard focus to a control in the dialog box.
2.int num=m_choose.GetCurSel();
CComboBox::GetCurSel
返回组合框中列表框中当前选中的项的下标。如果没有选中项,则返回CB_ERR。
3.m_choose.AddString("题目一");
m_choose.AddString("题目二");
m_choose.AddString("题目三");
MFC中,下拉列表的insertstring和addstring 区别:前者是插入指定位置,后者是按顺序添加
addstring("AAAAAA")
addstring("BBBBBB")
addstring("CCCCCC")
addstring("DDDDDD")
insertstring(1,"XXXXXX")
结果;
AAAAAA
XXXXXX
BBBBBB
CCCCCC
DDDDDD
4.MFC播放MP3文件。
#include "mmsystem.h"
#pragma comment(lib, "winmm.lib")
MCI_OPEN_PARMS op;
op.dwCallback=NULL;
op.lpstrAlias=NULL;
op.lpstrDeviceType=_T("MPEGAudio"); //设备类型,大多数文件可以这样设置
op.lpstrElementName=_T("D:\\1.mp3") ;//文件路径
op.wDeviceID=NULL; //打开设备成功以后保存这个设备号备用
UINT rs; //接受函数返回结果
rs=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT ,(DWORD)&op);//发送命令打开设备,成功返回0,否则返回错误号,第三个参数这里必须
MCI_OPEN_ELEMENT
if(rs==0) //设备打开成功就播放文件
{
MCI_PLAY_PARMS pp;
pp.dwCallback=NULL;
pp.dwFrom=0; //开始播放的位置
mciSendCommand(op.wDeviceID,MCI_PLAY,MCI_WAIT,(DWORD)&pp);//播放文件,如果第三个参数设为MCI_WAIT则程序窗口会被阻塞,为了避免这种情况可以设为MCI_NOTIFY ,这两个标志的详细区别请见MSDN,区别不小哦。
}
最后别望了在WM_CLOSE消息处理过程中发送MCI_CLOSE命令关闭设备,写成这样:
MCI_GENERIC_PARMS gp;
gp.dwCallback=NULL;
mciSendCommand(op.wDeviceID,MCI_CLOSE,MCI_WAIT,(DWORD)&gp);
红色部分未验证
5.UINT SetTimer(UINT nIDEvent,UINT nElapse,void(CALLBACK EXPORT *lpfnTimer)(HWND,UINT ,YINT ,DWORD))
6.EnableWindow():
GetDlgItem(IDC_write)->EnableWindow(TRUE);
GetDlgItem(IDC_send)->EnableWindow(1);
GetDlgItem(IDC_print)->EnableWindow(1);
GetDlgItem(IDC_start)->EnableWindow(0);
PDF *p= PDF_new(); //新建PDFLib对象
PDF_set_parameter( p,"license","X600605-009100-4E7661-329E0C");//除水印
int font;
PDF_begin_document(p,"test.pdf", 0, ""); //新建一个PDF文件
/* This line is required to avoid problems on Japanese systems */
PDF_set_parameter(p,"hypertextencoding", "host");
//给PDF文档添加属性
PDF_set_info(p, "Creator", "法院速录测试系统");
PDF_set_info(p, "Author", "FLZ");
PDF_set_info(p, "Title", "法院速录测试结果");
PDF_begin_page_ext(p, a4_width, a4_height, ""); //新建一个页面
font = PDF_load_font(p, "STSong-Light", 0, "GB-EUC-H", ""); //查询详细信息加载字体。
PDF_setfont(p, font, 12);
PDF_set_text_pos(p, 50, 700); //从哪里开始写
PDF_show(p, "成绩单");
PDF_continue_text(p,"");//换行
PDF_continue_text(p,"");//换行
PDF_continue_text(p,"准考证:");
PDF_show(p,m_examnum);
PDF_continue_text(p,"");//换行
PDF_continue_text(p,"身份证:");
PDF_show(p,m_num);
PDF_end_page_ext(p, ""); //关闭页面
PDF_end_document(p, ""); //关闭PDF文件
PDF_delete(p); //释放PDFLib对象
$pdfdoc
,
float$width
,
float$height
,
string$optlist
)
Adds a new page to the document, and specifies various options. The parameterswidth
andheight
are the dimensions of the new page in points. 成功时返回TRUE
, 或者在失败时返回FALSE
。
$pdfdoc
,
int$font
,
string$keyword
,
string$optlist
)
Queries detailed information about a loaded font.
查询详细信息加载字体。
http://php.net/manual/zh/function.pdf-info-font.php关于PDF的函数,特别全
$pdfdoc
,
int$font
,
float$fontsize
)
Sets the current font in the specified size
, using a font
handle returned by PDF_load_font(). 成功时返回TRUE
, 或者在失败时返回FALSE
。
设置当前的字体在指定的大小,使用一个字体处理返回的PDF_load_font()
$p
,
float $x
,
float $y
)
Sets the position for text output on the page. 成功时返回TRUE
, 或者在失败时返回 FALSE
。
设置页面上的文本输出位置
$p
,
string $key
,
string $value
)
Sets some PDFlib parameter with string type. 成功时返回 TRUE
, 或者在失败时返回 FALSE
。
设置一些PDFlib的字符串类型参数
$pdfdoc
,
string $fontname
,
string $encoding
,
string $optlist
)
Searches for a font and prepares it for later use.
8.
HBRUSH CMy0121120829Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何特性
if (nCtlColor == CTLCOLOR_STATIC)
{
switch (pWnd->GetDlgCtrlID())
{
case IDC_Time:
pDC->SetTextColor(RGB(255,0,0));//设置画笔的颜色,设置红色的文本
default:
break;
}
}
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
pDC 包含了子窗口的显示设备环境的指针。可能是临时的。
pWnd消息发送者指针
nCtlColor 包含了下列值,指定了控件的类型:
CTLCOLOR_BTN 按钮控件 ·
CTLCOLOR_DLG 对话框 ·
CTLCOLOR_EDIT 编辑控件 ·
CTLCOLOR_LISTBOX 列表框控件
CTLCOLOR_MSGBOX 消息框
CTLCOLOR_STATIC 静态控件等
pWnd:一般表示指向CWnd类的一个指针
MFC使用一个CBT钩子来监视窗口的创建,当pWnd的窗口句柄创建时,_AfxCbtFilterHook将被调用,这个函数的用意已经非常明显,将新创建的窗口句柄附加到pWnd,并为pWnd指定窗口过程。这个函数较长,我就不列代码了,只是将大概的几点列举如下:
通过CWnd::Attach将句柄附加给pWnd,Attach还做了另一件事,建立pWnd与句柄的哈唏表,这是为了后面处理消息时可以找到正确的CWnd对象。哈唏表在MFC中大量地被使用
op.lpstrDeviceType=_T("MPEGAudio"); //设备类型,大多数文件可以这样设置
//if(num==CB_ERR)
//{
// MessageBox("请您选择考试编号!","法院速录测试系统");
// return;
//}
CString strFileName;
strFileName.Format(".//%d.mp3",num+1);
op.lpstrElementName=strFileName;
op.wDeviceID=NULL; //打开设备成功以后保存这个设备号备用
UINT rs; //接受函数返回结果
//发送命令打开设备,成功返回0,否则返回错误号,第三个参数这里必须MCI_OPEN_ELEMENT
rs=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT,(DWORD)&op);
mciSendCommand(NULL,MCI_SET,MCI_SET_DOOR_OPEN,NULL);//开光驱
mciSendCommand(op.wDeviceID,MCI_PLAY,MCI_NOTIFY,(DWORD)&op);
见:http://baike.baidu.com/view/4189925.htm?fr=aladdin
MCI_OPEN_PARMS是一结构体类型,其结构体定义为
typedef struct {
DWORD_PTR dwCallback;
MCIDEVICEID wDeviceID;//设别ID
LPCTSTR lpstrDeviceType;//设备类型
LPCTSTR lpstrElementName;//文件名
LPCTSTR lpstrAlias;//别名
} MCI_OPEN_PARMS;
dwCallback
The low-order word specifies a window handle used for the MCI_NOTIFY flag.
wDeviceID
Identifier returned to application.
lpstrDeviceType
Name or constant identifier of the device type. (The name of the device is typically obtained from the registry or SYSTEM.INI file.) If this member is a constant, it can be one of the values listed in MCI Device Types.
lpstrElementName
Device element (often a path).
lpstrAlias
Optional device alias.
The MCI_PLAY_PARMS structure contains positioning information for the MCI_PLAY command.
typedef struct
{
DWORD_PTR dwCallback;
DWORD dwFrom;
DWORD dwTo;
} MCI_PLAY_PARMS;
Members
dwCallback
The low-order word specifies a window handle used for the MCI_NOTIFY flag.
dwFrom
Position to play from.
dwTo
Position to play to.
绝对路径:是从盘符开始的路径,形如 C:\windows\system32\cmd.exe 相对路径:是从当前路径开始的路径,假如当前路径为C:\windows 要描述上述路径,只需输入 system32\cmd.exe 实际上,严格的相对路径写法应为 .\system32\cmd.exe 其中,.表示当前路径,在通道情况下可以省略,只有在特殊的情况下不能省略。 假如当前路径为c:\program files 要调用上述命令,则需要输入 ..\windows\system32\cmd.exe 其中,..为父目录。 当前路径如果为c:\program files\common files 则需要输入 ..\..\windows\system32\cmd.exe 另外,还有一种不包含盘符的特殊绝对路径,形如 \windows\system32\cmd.exe 无论当前路径是什么,会自动地从当前盘的根目录开始查找指定的程序。
见:http://blog.163.com/gl_jiang@126/blog/static/76100972201008104914805/
16.CString::SetAt 替换
举个例子:
CString str = _T("012335678");
str.SetAt( 4, '4' );
此时 str = _T("012345678");
17.MCI的命令消息接口,所有MCI命令消息都是通过mciSendCommand函数发送的,函数声明为:
MCIERROR mciSendCommand(
MCIDEVICEID wIDDevice, //设备的ID,在打开设备时不用该参数
UINT uMsg, //命令消息
DWORD fdwCommand, //命令消息的标志
DWORD dwParam //指向包含命令消息参数的结构
); //若成功则返回0,否则返回错误码
见:http://lxxavr.blog.163.com/blog/static/1402991472011920114056820/
18.MCI_WAIT是播放完后再去返回,不能立刻停止播放音乐。
――The Wait Flag MCI 命令在执行时一般会立即返回执行结果,即使有些命令执行要花上几分钟才能完成。 你可以使用 "wait" (MCI_WAIT) flag 来指定设备等待,直到请求命令完成再返回到应用程序控制。
MCI_NOTIFY
――The Notify Flag The "notify" (MCI_NOTIFY) flag 指示设备完成一次操作后 (邮寄)post 一个 MM_MCINOTIFY 信息。 我们可以在MM_MCINOTIFY 的处理函数来做一些相应的处理工作: 是否completed successfully, failed, or was superseded or aborted(成功完成,失败或被取代或中止) 等等,
19.
自动换行问题
方法一
1.ProPerties->Styles->Multiline 打钩&& Horizontal scroll不打钩
Multiline属性并不是代表换行 而是能接受多行文本.
2.Edit控件属性里
把Multiline和Want Return两项都选成True
如果想使 超过边界(一定字数)自动换行显示 (实际上还是一行)
则Edit控件属性里 Multiline 选成True ,Auto HScroll(主动产生程度滚动条)选成False(不打钩)
3.m_String = m_String + sNewString + "\r\n"
方法二:(当EDIT映射到一EDIT时)
m_Edit.SetSel(-1, -1);
m_Edit.ReplaceSel(sNewString+"\r\n");