Archive for the ‘平台’ Category

Hello, kernel!

hello,Kernel!

注意几处:

1. Linux是大小写敏感的,文中的Makefile文件不能写成makefile。

2. 安装命令 sudo insmod HelloKernel.ko,卸载命令sudo rmmod HelloKernel.ko。

3. 查看内核输出命令应该是dmesg,而不是dmsg。

ListView

list-view controls中一个item代表一行,设置这行的信息通过subitem。

Each item can have one or more subitems. A subitem is a string that, in report view, is displayed in a column separate from the item's icon and label. All items in a list-view control have the same number of subitems. The number of subitems is determined by the number of columns in the list-view control. When you add a column to a list-view control, you specify its associated subitem index. The iItem member is the zero-based index of the item. The iSubItem member is the one-based index of a subitem or zero if the structure contains information about an item. To change the attributes of a list-view item, use the LVM_SETITEM message, specifying the address of an LVITEM structure. The mask member of this structure specifies the item attributes you want to change. For example, to change only the text of an item or subitem, use the LVM_SETITEMTEXT message.

Report (details) view: Each item appears on its own line, with information arranged in columns. The leftmost column is always left justified and contains the small icon and label. Subsequent columns contain subitems as specified by the application.

示例代码:

HWND hWnd = GetDlgItem(hDlg, IDC_LIST1);
ListView_SetExtendedListViewStyle(hWnd, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES);
LVCOLUMN lvc = {0};
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvc.fmt = LVCFMT_CENTER;
lvc.cx = 20;
lvc.iSubItem = 0;
lvc.pszText = TEXT("");
ListView_InsertColumn(hWnd, 0, &lvc);
lvc.cx = 100;
lvc.iSubItem = 1;
lvc.pszText = TEXT("编号");
ListView_InsertColumn(hWnd, 1, &lvc);
LVITEM lvi = {0};
lvi.mask = LVIF_TEXT;
lvi.iItem = 0;
lvi.iSubItem = 0;
lvi.pszText = TEXT("");
ListView_InsertItem(hWnd, &lvi);
ListView_SetItemText(hWnd, 0, 1, TEXT("1"));
lvi.iItem = 1;
ListView_InsertItem(hWnd, &lvi);
ListView_SetItemText(hWnd, 1, 1, TEXT("2"));

 

 

 

 

 

 

 

 

 

 

参考资料:http://msdn.microsoft.com/en-us/library/bb774737(v=VS.85).aspx

MFC ODBC与Access

今天帮人调试程序,遇到了MFC ODBC与Access数据库相关的问题,记录下。

之前从未真正使用过ODBC与Access数据库,下面是一点理解:ODBC和JDBC一样,是一层统一的封装,由各个数据库厂商提供统一的接口。你可以使用ODBC的统一接口,因为它具有通用性,稍加修改就能移植到不同数据库。当然,你也可以使用数据库厂商提供的单独的库。

与Access数据库连接,本质是与其数据库文件打交道,格式为.mdb。可以通过COM或者MFC本身的ODBC支持来实现连接。

COM实现连接:http://6520874.blog.163.com/blog/static/7258271920113845626128/

MFC项目向导中有对ODBC的支持,首先要在控制面板--->管理工具中配置数据源(ODBC)。

配置时有三种DSN(Data Source Name,数据源名称),需要根据具体情况及其提示进行配置,添加Microsoft Access Driver相关的数据库.mdb文件。

MFC项目向导会自动生成相关的CxxxSet类对ODBC进行支持。

在这里有趣的是,VC6.0的对话框编辑器中提供了相应的ActiveX控件ADODC和DATAGRID对ODBC进行了视图支持,但VS2005中确没有。具体的解决方案是:http://zhidao.baidu.com/question/210849183.html

在调试的过程中,因为项目的具体要求,还遇到了一点问题。该项目的主窗口即m_pMainWnd是含有以上两个控件的View,不是Dlg。现在需要先有登录对话框进行登录后才能出现主窗口。

在InitInstance中进行修改如下:
// The one and only window has been initialized, so show and update it.
//m_pMainWnd->ShowWindow(SW_SHOW);
//m_pMainWnd->UpdateWindow();
CLoginDlg dlg;
dlg.DoModal();
return TRUE;

然后在登录对话框的登录成功处有如下代码:
AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
AfxGetApp()->m_pMainWnd->UpdateWindow();
CDialog::OnOK();

结果发现主窗口依然出现,并且CLoginDlg的构造函数中AfxOleInit处出现断言错误。注释掉后,断言错误消失。

于是注释掉InitInstance中如下代码:
//// Parse command line for standard shell commands, DDE, file open
//CCommandLineInfo cmdInfo;
//ParseCommandLine(cmdInfo);

//// Dispatch commands specified on the command line
//if (!ProcessShellCommand(cmdInfo))
// return FALSE;

结果发现会在ShowWindow(SW_SHOW)处出现断言错误,具体出现在winocc.cpp ShowWindow中的ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));处。

经过调试发现m_pMainWnd为NULL。也就是说在ProcessShellCommand后m_pMainWnd才会有正确的赋值。参考:http://apps.hi.baidu.com/share/detail/15714628

最终解决方案:相关函数的调用延迟到CLoginDlg的登录处理函数中,如下:
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
AfxGetApp()->ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line
if (!AfxGetApp()->ProcessShellCommand(cmdInfo))
return ;

// The one and only window has been initialized, so show and update it.
AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
AfxGetApp()->m_pMainWnd->UpdateWindow();
CDialog::OnOK();

SendMessage、PostMessage原理

SendMessage、PostMessage原理

Win7安装方法

各种Windows 7安装方法大汇总

无觅相关文章插件,快速提升流量