总有更好的

 为了便于搜索,这里尽可能保留了论坛上讨论的原文,但是这并不表示本人赞同帖子中的表述方式和观点。

CSDN 讨论总结系列:


ComboBox在datagrid如何模糊查询(.NET技术 C#)


想在datagrid的一列中放一个ComboBox,当输入一个具体值时,能到某一绑定的数据源里面把匹配的的数据用下拉德形式显示出来,也就是实现一个快速筛选的作用。比如说,我输入a,则在下啦列表中出现以a开头的所有记录,再输入b时,在下拉列表中出现以ab开头的所有记录。


prevent unnecessary post backs such like this
use client side javascript and XML HTTP request.

http://weblogs.asp.net/mschwarz/archive/2005/11/11/430267.aspx


如何用宏限制WORD文档打印(其他开发语言 Office开发/ VBA)


A DocumentBeforePrint event procedure looks like this:

  
Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, _Cancel As Boolean)'Your code here End Sub



If you want to prevent printing from occurring in certain circumstances, you can set the Cancel variable to True, e.g.:

  
Private Sub oApp_DocumentBeforePrint(ByVal Doc As Document, _Cancel As Boolean)Dim Result As LongResult = MsgBox("Have you checked the " & "printer for letterhead paper?", vbYesNo)If Result = vbNo Then Cancel = TrueEnd Sub


http://word.mvps.org/FAQs/MacrosVBA/InterceptSavePrint.htm


CTreeCtrl 如何用SetItemData使Item保持额外数据(VC/MFC 界面)


你SetItemData之后将其删除了,这样它引用的就是无效数据了,这样可能会引起程序的崩溃。

You should not delete the item data when it is being used by an item;
handle TVN_DELETEITEM to delete the itemdata when it is no longer used.

BTW, you need to reconsider if you need a tree control at all. Tree control sends several messages for each item. Destroying 40,000 items entails 40,000 TVN_DELETEITEM notifications. Just by sheer numbers that's going to take a while. 40,000 items in a treeview is unusably excessive.

Suggest reading:
http://www.codeproject.com/treectrl/waitingtreectrl.asp
 


在CHTMLView中,取IHTMLWindow2接口时,程序会死掉(VC/MFC HTML/XML )


在CHTMLView中调用IHTMLWindow2,来执行JS代码,可当此view中显示的不是网页,而是word文档内容,或是本地路径的文件夹内容时,程序运行到pIDoc->get_parentWindow(&pIhtmlwindow2);就死掉了,程序进行了get_parentWindow()就出不来了。
 具体代码如下:
   

  
IHTMLDocument2 * pIDoc = (IHTMLDocument2 * ) GetHtmlDocument();HRESULT hr; if (pIDoc == NULL) return FALSE;IHTMLWindow2 * pIhtmlwindow2 = NULL; // = new IHTMLWindow2; hr = pIDoc -> get_parentWindow( & pIhtmlwindow2); if (FAILED(hr)) {pIDoc->Release();return FALSE;}

 


 


 

  
(IHTMLDocument2 * ) GetHtmlDocument();


这个有问题
GetHtmlDocument()返回的不是HtmlDocument,是IDispatch。你可以用如下方法来获取文档的IHTMLDocument2接口

  
CComPtr < IDispatch > spDisp;spDisp.p = CHtmlView::GetHtmlDocument(); CComQIPtr < IHTMLDocument2 > pHTMLDocument2(spDisp);

不过对于你这种情况,GetHtmlDocument()返回的是Word的_Document的IDispatch接口,不是HTMLDocument的,用IHTMLDocument2接口访问当然会出问题。用

  
CComQIPtr < IHTMLDocument2 > pHTMLDocument2(spDisp);


之后判断pHTMLDocument2是否为空。


CFileDialog和SHBrowseForFolder浏览限制(VC/MFC 基础类 )


我如何将CFileDialog和SHBrowseForFolder的对话框浏览的路径限制在E盘?即其它盘屏蔽掉。
如果不能屏蔽的话,当选择别的盘符自动跳回到E盘。


CFileDialog 不行,不过你可以在DoModal之后提示路径不符并且重新显示一个CFileDialog
用SHBrowseForFolder的话可以直接设置BROWSEINFO的pidlRoot成员为E:的pidl。


SHBrowseForFolder可以用来选择单个文件(BROWSEINFO.ulFlags|=BIF_BROWSEINCLUDEFILES),你也可以考虑重载BOOL CFileDialog::OnFileNameOK
过滤文件:http://msdn.microsoft.com/msdnmag/issues/05/06/CAtWork/default.aspx


如何知道某个网页是已经访问过的(VC/MFC 网络编程)


用CHtmlView写个浏览器,给定一个网页地址字串,如何知道它是不是已经访问过的?

用IE浏览的时候,访问过的地址会变色.如果在自己的程序里,如何判断?一定要做数据库记录比较吗?还是有便捷高效的方法?


IUrlHistoryStg::QueryUrl


将Delphi作为ASP.NET的脚本语言(.NET技术 ASP.NET )


看到下面这篇文章
http://www.aspcool.com/lanmu/browse1.asp?ID=2230&bbsuser=aspnet
想将Delphi做为ASP.NET的脚本语言

使如下代码执行

  
< html > < script language ="Delphi" runat ="server" > procedure ButtonClick(Sender: System.Object; E: EventArgs); begin Message.Text := Edit1.Text; end; script> <body> <form runat="server"> <asp:textbox id="Edit1" runat="server"/> <asp:button text="Click Me!" OnClick="ButtonClick" runat="server"/> form> <p><b><asp:label id="Message" runat="server"/> b> p> body> html>


但是这篇文章使用的是Delphi 7
我想问问大家如何使用Delphi 2006啊
具体就是如何修改以下文件
%systemroot%/Microsoft.net/Framework/v1.1.4322/CONFIG/machine.config
将Delphi作为ASP.NET的脚本语言


you can write code behind pages that inherit from assemblies compiled from Delphi source files.

支持ASP.NET的第一件事是让ASP.NET将Delphi视为脚本语言,让ASP.NET能够为各种ASP文件类型调用Delphi的.NET编译器。

ASP.NET要在IIS虚路径的根目录下寻找web.config文件。下面是ASP.NET中使用Delphi作脚本语言的web.config配制文件内容:

  
< configuration > < system .web > < compilation debug ="true" > < assemblies > < add assembly ="DelphiProvider" /> assemblies><compilers><compiler language="Delphi" extension=".pas" type="Borland.Delphi.DelphiCodeProvider,DelphiProvider" /> compilers> compilation> system.web> configuration>


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconformatofconfigurationfiles.asp


试过几种编码都不能正确显示的一种汉字代码(VC/MFC 硬件/系统 )


一文件的汉字内码为
3D 1B 24 42 4D 7B 31 51 1B 28 42 46 20 39 59 1B 2D 41

绝大多数软件打开显示的都是乱码,改变不同编码,例如 GB2312,UNICODE UTF-8,UNICODE UTF-16,GB18030,GBK,HZ, 也都是乱码, 只有一种软件打开能显示为:
李英F 9Y
经查阅,字符集应是一下某种,但不知如何转化为GB2312 ??
ISO 2022 IR 100/ISO 2022 IR 58/ISO 2022 IR 6/ISO 2022 IR 87


用MultibyteToWideChar和WideCharToMultibyte来转换。ISO-2022-JP的代码页是50221。
参考
http://www.w3.org/International/O-charset-ms.html


ActiveX中关于获取属性的问题(VC/MFC ATL/ActiveX/COM )


建立一个OCX mytest,设置一个属性filetype,在Active Control Test Container中加入mytest control
在Invoke Methods中选择Method Name:filetype(PropPut)设置值,在程序中就能获得filetype的值
但是如果在浏览器中调用

  
< OBJECT style ="LEFT: 0px; TOP: 0px;WIDTH:500PX;HEIGHT:500PX;" classid =clsid:E87C2E03-5EE4-4AC1-91B2-0E48385584D6 VIEWASTEXT > < PARAM NAME ="_Version" VALUE ="6553" > < PARAM NAME ="_ExtentX" VALUE ="2646" > < PARAM NAME ="_ExtentY" VALUE ="1323" > < PARAM NAME ="FILETYPE" VALUE ="*.gif" > OBJECT>

怎么也获取不到FILETYPE属性的值


控件的数据的存储方式是容器决定的。如果容器使用IPersistStreamInit和IPersistStorage 来保存数据,那么COleControl::Serialize会被调用。但是对于你这样使用IPersistPropertyBag来保存数据的情况下,你应该重载COleControl::DoPropExchange。


html 编码的问题,就是把字符串"<"转化为"<" (VC/MFC HTML/XML)


现在要把字符串中所有这类符号转化为相应的编码字符串.不能用MFC.IL


use InternetCanonicalizeUrl or System::Web::UI::HtmlTextWriter
See also
http://msdn.microsoft.com/library/en-us/vclib/html/vclrfATLServerEncodingReference.asp


security descriptor的具体使用(VC/MFC 基础类)


security descriptor的一般概念我会一点,但是现在我需要完成一个具体的任务:在CreateProcess函数的参数中设置安全选项,要求是让系统中只有该进程的创建者(也就是CreateProcess函数的调用进程)才能完全访问到这个被新创建的进程对象,而假如同一个机器上任意其他第三个用户进程试图使用诸如WriteProcessMemory之类的函数来改写被创建的进程对象的内存区域的时候,会因为权限不够而失败。


Writing to a process address space is controlled by the SecurityDescrptor of the Process Object and by the SeDebug privilege.
By default, you can always debug your own precesses, and, the Administrators are granted the SeDebug privilege. Protecting memory inspection from a debugger is pretty much a lost cause (unless you can leverage natural security-principal restrictions).

A determined person can always read the physical page from a driver/kernel-debugger.

If you want to run a process under user account, but protected from other processes of the same user, you need to make sure the process owner (in its ACL) is something privileged (LOCAL_SYSTEM, LOCAL_SERVICE). A service should start a process with an user token, but with a security descriptor which disallows most access.

SeDebugPrivilege can easily override any DACL if the person has the privilege enabled on their account

默认的权限设置可以在http://www.microsoft.com/technet/security/prodtech/windows2000/w2kccscg/w2kscgcc.mspx
找到
由于权限是基于用户策略的,所以同一用户创建的进程默认具有同样的权限。进程级别的保护可以通过以不同身份执行进程,以及设置进程的用户访问控制列表来做到。
参见
http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.kernel/2004-06/0708.html
在用AdjustTokenPrivileges启用了TOKEN_ADJUST_PRIVILEGES权限之后可以用SetKernelObjectSecurity设置进程的访问权限
参考http://blog.csdn.net/jiangsheng/archive/2004/06/24/25563.aspx


CHtmlView某些情况下无法输入回车的问题(VC/MFC HTML/XML)


载入的页面中嵌有设为编辑模式的层或内嵌框架(DIV contenteditable="true"),则无法响应回车。

找了很久都没有搞定。

看了这个也无效
FAQ:WebBrowser Keystroke Problems
http://www.microsoft.com/mind/0499/faq/faq0499.asp

倒是搜到了这个:<
http://www.maxthon.com/support/history.htm
v 0.4
# Can not press enter in some web html editors and chat rooms
 


in the MFC 6.0 version of the CHTMLView based MFCIE sample, enter key in

get swallowed. You can fix this by adding a TranslateMessage call

   
BOOL CMfcieView ::PreTranslateMessage(MSG * pMsg) { // TODO: Add your specialized code here and/or call thebase class if (pMsg- >message == WM_KEYDOWN && (pMsg- >wParam ==VK_RETURN | | pMsg- >wParam == VK_ESCAPE)) { ::TranslateMessage(pMsg); } return CHtmlView::PreTranslateMessage(pMsg);}



The problem occurs only when MFCIE is showing web page with a DHTML editor which has the focus. Otherwise CHtmlView intercepts enter key correctly even when the TranslateMessage call is absent. http://www.microsoft.com/mind/0499/faq/faq0499.asp suggested calling Win 32 API IsDialogMessage(), which is even worse. IDocHostUIHandler::TranslateAccelerator (and presumablly, IOleInPlaceActiveObject::TranslateAccelerator) is called and get ignored somewhere inside the web browser control. I can not reproduce this in MFC 7, but I can not find how it got fixed after WinDiffing the mfc sources, either.
 


DOS窗口下不能正常显示Unicode(VC/MFC ATL/ActiveX/COM)


_putts(_T("English汉字/n"));
我用Unicode格式输出的字符串,遇到汉字就结束了。
改成下面:
_tprintf_s(_T("%s/n"), _T("English汉字"));
其中汉字全变成了“?”

如果不能直接解决,请问怎么把Unicode转成ANSI?


use WideCharToMultiByte() to convert the unicode strings to MBCS before you print them to console with printf().

Alternatively, you might try changing the console code page with chcp or programatically (SetConsoleCP, SetConsoleOutputCP, SetFileApisToANSI). By default console uses OEM codepage.


绑定表达式的问题(.NET技术 ASP.NET)


本人在DataList里加了一个HyperLinker的控件
NavigateUrl属性希望设置成fittingsbyproducer.aspx?pro=***
注:当前页面不是fittingsbyproducer.aspx
其中***需要从数据源中读取ProducerID字段数据,我写不好,望各位指教


 

   
private void DataGridResult_ItemCreated( object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {//只处理列表项if(e.Item.ItemType ==ListItemType.Item||e.Item.ItemType == ListItemType.AlternatingItem){//查找模板生成的控件并且修改其目标System.Web.UI.WebControls.HyperLink hl=(HyperLink)e.Item.FindControl("HyperLinkTopic");//注意对不同的数据源,e.Item.DataItem的类型也不同System.Data.DataRowView rec=(System.Data.DataRowView)e.Item.DataItem;if(rec!=null){//编码会造成查询时内存溢出的日文片假名hl.Text=srwbbs.Global.JDecode(rec["Topic"].ToString());//根据参数和值建立目标URLNameValueCollection nvc=new NameValueCollection();nvc["ID"]=rec["ID"].ToString();nvc["BoardID"]=rec["BoardID"].ToString();string strURL="http://allgames.gamesh.com/srwbbs/topic.asp";strURL+=srwbbs.Global.BuildQueryString(nvc).ToString();//设置目标hl.NavigateUrl=strURL;}}} // 从字符串:值的集合建立URL的参数字符串 static public string BuildQueryString(NameValueCollection values) { StringBuilder sb = new StringBuilder(); for (int i =0; i < values.Count; ++ i) { sb.Append(i == 0 ? "?" : "&"); sb.Append(values.Keys[i]); sb.Append("="); sb.Append(HttpUtility.UrlEncode(values[i])); } return sb.ToString(); }

进程间通讯问题(VC/MFC 进程/线程/DLL )


在进程A中NEW 了一个套接字,然后启动进程B。
通过共享内存等方法能否实现在B中使用A中套接字来发送和接受数据。


http://support.microsoft.com/default.aspx?scid=kb;en-us;150523


关于WebBrowser编辑中的自动换行问题(VC/MFC HTML/XML)


程序中使用了一个内嵌的WebBrowser,可编辑,现在问题是在WebBrowser中编辑文字时不会自动换行,即会出现HScroll bar,要回车才换行。有没有人知道如何可以使WebBrowser编辑器能自动换行,而不出现HScroll bar


use IHTMLDocument2::get_body, IHTMLElement::get_style, QueryInterface for IHTMLStyle3, and call IHTMLStyle3::wordWrap with break-word


如何修改本地安全策略(.NET技术 VC.NET)


You can modify local policies using WMI in Windows XP/2003.
No such support in Windows 2000 or earlier.
Reference
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/TechRef/4dca53ac-435b-45f7-9f5c-1cb77b7a6a39.mspx

You can also use DumpSec (http://www.somarsoft.com) instead.

You can do a call-out to the Win2k resource kit tool ntrights.exe for this:


ntrights.exe +r SeServiceLogonRight -u username


How to Set Logon User Rights with the Ntrights.exe Utility
http://support.microsoft.com/?kbid=279664 


How to: Determine NTRIGHTS Names and Meanings
http://support.microsoft.com/?kbid=245207
 

Ntrights.exe is also in the free Win2k3 resource kit (it very well might work
on Win2k as well):


Windows Server 2003 Resource Kit Tools
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&DisplayLang=en


(The kit will install on WinXP or later, but you can copy Ntrights.exe to a
Win2k computer and try it out if necessary)


Or you can create your own program, an account can also be granted the user
right programmatically through the Local Security Authority (LSA) API calls.


132958 How to Manage User Privileges Programmatically in Windows NT
http://support.microsoft.com/default.aspx?scid=kb;EN-US;132958


读取表格内容(VC/MFC HTML/XML )


获得这样的内容(bstrSrc):  

   
< td class ="gridbodynobgColor" > 2200601883 td>


 
那么请问如何只得到2200601883呢。  

   
VARIANT varIndex, var2; VariantInit( & varIndex); VariantInit( & var2); varIndex.vt = VT_I4; varIndex.lVal = i; CComPtr < IDispatch > pDisp3; pCollection3 -> item(varIndex,var2, & pDisp3); IHTMLElement * pElem3; pDisp3 -> QueryInterface(IID_IHTMLElement,(LPVOID * ) & pElem3);

 
到这一步已经能获得通过  

   
BSTR bstrSrc; pElem3 -> get_outerHTML( & bstrSrc);

我自己想这样做:  

   
IHTMLTableCell * pTableCell = NULL; pElem3 -> QueryInterface(IID_IHTMLTableCell,(LPVOID * ) & pTableCell);


 
这里如何做我就不知道了。  
pTableCell->????  


 

query  for  IHTMLElement  and call get_innerText to  get  the text,  or  for IHTMLDOMNode  to  get  access  a child text  node


如何获得本地所有ODBC数据源名(Delphi 数据库相关)


用BDE中的TSession组件可以用如下方法获得本地所有ODBC数据源名
Session1.GetAliasNames(Listbox1.items)
但是这样的话,程序发布的时候,需要打包BDE,程序本身很小,一打包就会变很大了,有没有什么其他方法可以获得本地所有数据源名啊,ADO可以吗?API怎么实现?


...Extract the ODBC System Data Sources?
uses
Registry;

   
procedure TForm1.Button1Click(Sender: TObject);varn: Integer;List: TStringList;Reg: TRegistry;beginReg : = TRegistry.Create; try Reg.RootKey : = HKEY_CURRENT_USER;Reg.LazyWrite : = False;Reg.OpenKey( ' Software/ODBC/ODBC.INI/ODBC Data Sources ' , False);List : = TStringList.Create;Reg.GetValueNames(List);ListBox1.Clear; for n : = 0 to List.Count - 1 do ListBox1.Items.Add(List.Strings[n]);Reg.CloseKey; finally Reg.Free;end;end;

但是用Session1.GetAliasNames(Listbox1.items)的话,还能取得数据库别名,用读注册表的方法不可以,有什么更好的方法吗?

An application can call SQLDataSources multiple times to retrieve all data source names. The Driver Manager retrieves this information from the system information. When there are no more data source names, the Driver Manager returns SQL_NO_DATA. If SQLDataSources is called with SQL_FETCH_NEXT immediately after it returns SQL_NO_DATA, it will return the first data source name. For information about how an application uses the information returned by SQLDataSources, see Choosing a Data Source or Driver.

If SQL_FETCH_NEXT is passed to SQLDataSources the very first time it is called, it will return the first data source name.

The driver determines how data source names are mapped to actual data sources.


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcsqldatasources.asp


令人头疼的MessageBox::Show (.NET技术 VC.NET )


想用弹出对话框显示String字符串,

   
String * fmt = S " asdf " ;MessageBox::Show( " ssss " );

但这样不行,错误信息:
d:/CARTTRAIN/Form1.h(208) : error C2653: “MessageBoxA” : 不是类或命名空间名称
d:/CARTTRAIN/Form1.h(208) : error C2660: “System::Windows::Forms::Control::Show” : 函数不接受 1 个参数

当然 MessageBox(NULL,("asdf"),0,0); 是可以的,但是想用MessageBox::Show( "ssss" );这种格式。


原因可能是我包含了两个类所引起的,#include "DataArray.h".........,因为去掉所有与包含的类相关的内容,去掉上面的#include就ok,但是我必须要包含这个类,请问该如何解决?


在包含DataArray.h之后
#undef MessageBox


怎样在"EDIT框"编辑时自动切换为全角/半角的输入法(VC/MFC 基础类)


 

   
hWnd = GetDlgItem(EDIT控件ID) -> m_hWnd;HIMChImc;DWORDdwConvMode, dwSentMode;hImc = ImmGetContext(hWnd);ImmGetConversionStatus(hImc, & dwConvMode, & dwSentMode);ImmSetConversionStatus(hImc, dwConvMode | IME_CMODE_FULLSHAPE, dwSentMode)



参照上面代码,可以设置为全角
dwConvMode | IME_CMODE_FULLSHAPE改为dwConvMode & ~IME_CMODE_FULLSHAPE
可以设置为半角


用vb.net和asp.net怎么实现程序自动将网页下载到本地硬盘中(.NET技术 VB.NET)


比方说我想自动把RSS里的新闻都下载到硬盘里,如果网页中有图片以及js等,因其放在其它文件中,所以用以上代码得不到,请问,如何实现像IE另存为网页一样,把整个网页拷贝下来


http://www.codeproject.com/aspnet/aspnethtml2mht.asp




  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值