Eric's profileMastersPhotosBlogListsMore ![]() | Help |
|
|
April 15 Outlook Watchdog - prevent your outlook from being closed... ;) People in our office usually feel disappointed that they usually close outlook by accident and complain about why Microsoft does not provide such kind of an option. It's just a small piece of cake, isn't it? If that does exist, I would like to hear that from you; ) Then I started to look for something that might help from the web today... But unluckily, many people are complaining but few of them get a good solution for that? By googling, googling, ... I finally found one called AddsForOutlookInst.exe, but it's not free and costs 70$ or so. Then, I was considering to make one myself. It's just a job regarding how to prevent a window from being closed. First of all, I took a look at the Visual Studio Tools for Office and would like to develop an Outlook addin. Unluckily once again, the Outlook application does not provide any facilities to prevent its main window from being closed. So I give up that choice immediately and just planned to use windows hook techniques to achieve the purposes. Windows hook is an amazing technique if are properly used. A good example is the cursor transation in morden dictionary tools, such as KingSoft or YouDao, etc. Actually windows hook is more or less used in every windows applications to manage complicated user scenarios. The solution, I called "Outlook Watchdog", is shown as below: HHOOK hOutlookWatchdogHook = NULL; BOOL OUTLOOKWATCHDOGHOOKAPI OutlookWatchdog_SetHooks() { HMODULE hMod = GetModuleHandle( _T("OutlookWatchdogHook.dll") ); if (!hMod) return FALSE; hOutlookWatchdogHook = SetWindowsHookEx( WH_CBT, OutlookWatchdogHookProc, hMod, 0 ); return NULL != hOutlookWatchdogHook; } LRESULT CALLBACK OutlookWatchdogHookProc( int nCode, WPARAM wParam, LPARAM lParam ) { if (nCode == HCBT_SYSCOMMAND && wParam == SC_CLOSE) { HWND hWnd = FindWindow( _T("rctrl_renwnd32"), NULL ); if (hWnd == GetActiveWindow()) { static TCHAR wndText[80]; ZeroMemory( wndText, sizeof(wndText) ); GetWindowText(hWnd, wndText, 80); if (_tcsstr( wndText, _T("- Microsoft Outlook") )) // hard code here for testing outlook main window. { if (IDNO == MessageBox( hWnd, _T("Exiting outlook is not a good idea for now;) Do you want to continue? "), _T("Exit Outlook"), MB_YESNO | MB_ICONEXCLAMATION | MB_DEFBUTTON2 )) { ShowWindow( hWnd, SW_SHOWMINIMIZED ); return 1; } } } } return 0; } void OUTLOOKWATCHDOGHOOKAPI OutlookWatchdog_KillHooks() { if (hOutlookWatchdogHook) { UnhookWindowsHookEx( hOutlookWatchdogHook ); hOutlookWatchdogHook = NULL; } } It's trivial to use windows hook techniques. Just one thing I want to remind of here that you'd better use "WH_CBT" windows hook type. I have tried other types, for example, WH_CALLWNDPROC, WH_GETMESSAGE. However, you could not modify the message for WH_CALLWNDPROC, and modifying the message for WH_GETMESSAGE does not work. I just don't know why... maybe someone could help point out that. Finally, if someone needs the executable file from me, just go ahead, it's free. ;) Thanks Eric April 14 mshtml deployment for your .NET applications One of the component we have recently delivered depends upon the mshtml a little bit. However, mshtml might not be installed properly in some environment. (For us, it worked well in our pre-production environment, however did work in the production environment. ) Basically, if your operating system has installed all the updates, basically it works. In other cases, you could deploy the mshtml manually. Mshtml.dll exposes its functionalities via COM interfaces, and generally you could locate the COM server and type library at %systemroot%\system32\mshtml.dll/tlb. On the other hand, .NET applications call mshtml via COM Interop service, so that we need the COM Interop assemblies installed property. The following shows two ways to simply deploy the mshtml so that your application
that directly or indirectly depends on it could work as expected. 1. Download the Primary Interop Assemblies redistribution packages for Office system from Microsoft. Use the links below for Office 2003 and 2007 respectively. http://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-8ba0-d36d67e0f4ad&displaylang=en and http://www.microsoft.com/downloads/details.aspx?FamilyID=59daebaa-bed4-4282-a28c-b864d8bfa513&displaylang=en. Extract the files from the downloaded exe, and run the *.msi (e.g., o2007pia.msi) to installed it. After that, the COM Interop assemblies will be installed and registered. 2. If you're using Visual Studio 2005+, you could find the Microsoft.msthml.dll assembly from %Program Files%\Microsoft.NET\Primary Interop Assemblies. Then, copy the dll (Microsoft.mshtml.dll) to the target machine, run the following command to install it to the GAC. gacutil.exe /i %path%Microsoft.mshtml.dll Note: if you take a look at the list when you add a .NET assembly reference, you will notice other loactions where Microsoft.mshtml.dll could be present as well, for example, C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office11 or C:\Program Files\Microsoft Visual Studio 9.0\Visual Studio Tools for Office\PIA\Office12. Don't use them, because gacutil requires the assembly to be strong name signed in order to install it to the GAC and the assemblies you found in other locations are delay signed or test signed and cannot be used for deployment. #Q.E.D December 12 Jeffrey Richter Invented the new asynchronous programming style using C# Iterator. Jeffrey Richter (well... the expert in many areas...) ... has introduced his new asynchronous programming paradigm by using c# iterators. Amazing. you guys could check it out from http://channel9.msdn.com/posts/Charles/Jeffrey-Richter-and-his-AsyncEnumerator/. Or download the video from http://mschnlnine.vo.llnwd.net/d1/ch9/9/8/8/6/4/4/JeffRichterAsync.wmv. Get more information about his "PowerThreading" from http://wintellect.com/PowerThreading.aspx. I strongly recommend this reading. Enjoy! December 03 Windows Live released so many babies...Wow, as I have just noticed, Windows Live has changed its face, which is more lovely now ;)
Previously, Spaces or Messenger should be the center point if we could imagine other windows live services as points on a big circle. Now, this has changed to your "profile", much similar to what we have already seen on facebook or other SNS services. Actually, there was a long story about the profile. The profile was called MSN Profile or MSN member directory when it came w/ the MSN brand at the beginning, then when spaces was released, it was integrated into spaces as a module or part on your space and shared by other windows live services such as Hotmail, Messenger, and so on. Now, you guys might notice if you took a look at your space that the profile has been once again moved out of space and links to the new Windows Live Profile Experience personal potal page at http://profile.live.com. From your profile page, you could get all of the updated information from people in your network (Yes, it's more like a real network now), and you can "post a note" to any updated parts on that, for example, you can leave a note on your friends' messenger personal messages which itself is no longer a single one but all of the these that're typed... and from your profile page you could get to any service that are surrouding you (e.g., SkyDrive, Photos, Mail, etc. ), and you can turn back anywhere. So, windows live releases a better user experience, even a better idea.
Well, Hotmail is much faster now and its speed issue was primarily why I switched my personal email to Gmail. But I like hotmail, because of the clean email box name.... ;) October 13 Find friends?Find or invite friends is a "MUST" feature for majority of the SNS services, which could help make your service known to people in the world. From developers' point of view, there might be some ones that have been seeking for general solutions for this over time. Basically, there're several methods to achieve such kind of purpose according to the "source" of the "contacts/friends", say, MSN (GTalk) contacts, or Email contacts:
The first one above is the most trusted one because the service has no opportunity to record your email (account) and password, and facebook is now using the Windows Live Contacts API but has done hard work to make it fit the facebook look and feel. Basically, the Windows Live Contacts API is difficult for use and made adapted to your service's look and feel, however Google Contacts API and Yahoo! Address Book API are much easier to use. People that're interested in this can jump to the links below:
Even though the second method seems too "heavy" for this purpose, it's indeed used by some SNS services currently, for example, kaixin.com and yiqi.com if I could still remember that. DotMSN is an open source library that can be used to develop MSN robots on Microsoft .NET platform, and there are similar open source stuff that are developed for other tools and platforms, e.g., PHP, Python, etc. Such kind of libraries are safe to use because they're all based on MSNP (Microsoft Notification Protocol, http://en.wikipedia.org/wiki/MSNP) and MSNP itself is backward compatible except for some special cases. Luma QQ is a famous QQ client written in Java and could run on Linux, however, the development has stopped because of some legal issues w/ Tencent. The major phenomenon of using this method may be that your MSN or QQ (likely, not sure) will be made offline. I prefer to the third one and have worked out the solutions for the MSN contacts and major Email services including Hotmail, Gmail, Netease (126, 163), Sina, Yahoo!, 263, etc. (Note: MSN contacts is the same as Hotmail contacts only if the Hotmail account is also used as the MSN account, and exactly different otherwise). Most of the work regard this method is investigating the HTTP(s) communication betweent the client and server, and simulating that on behalf of the user after that. A general class hierarchy might look like below:
The significant advantage of the method is that you could work out a uniform architecture for the contacts API above which can be easily extended (actually, nearly none of the Email ISPs in China publishes public APIs), however the disadvantage is that it's not safe because the "protocols" might be changing over time in the future and to overcome the risks you need some automating tests that run for them from time to time. And... if the verification code is need for signin the service (e.g., QQ), this method does not work at all unless... ;) so, you could mix up the methods above according to your estimation of them. Hope it helpful for guys that're looking for solutions of this and comments are also appreciated... #end October 08 Getting Started : XmlHttpRequest - IXmlHttpRequest is exposed either by Javascript itself in Mozilla browsers as a class or by ActiveX object in Microsoft Internet Explorer 4.0 or above.The interface IXMLHTTPRequest interface members are listed below:
HRESULT put_onreadystatechange(Idispatch *pReadyStateSink);
HRESULT get_readyState(long *plState); HRESULT get_responseBody(VARIANT *pvarBody); HRESULT get_responseStream(VARIANT *pvarBody); HRESULT get_responseText(BSTR *pbstrBody); HRESULT get_responseXML(Idispatch **ppBody); HRESULT get_status(long *plStatus); HRESULT get_statusText(BSTR *pbstrStatus); HRESULT abort(void); HRESULT getAllResponseHeaders(BSTR *pbstrHeaders); HRESULT getResponseHeader(BSTR bstrHeader, BSTR *pbstrValue); HRESULT open(BSTR bstrMethod, BSTR bstrUrl, VARIANT varAsync,VARIANT bstrUser, VARIANT bstrPassword); HRESULT send(VARIANT varBody); HRESULT setRequestHeader(BSTR bstrHeader, BSTR bstrValue); In javascript,the relevant properties and methods are almost the same as the above,except that the properties does not have the get or put prefix and can be accessed without brackets.Then i'll explain something more about the frequently used properties and methods: 1.onreadystatechange use this property to register callback function for the request,which will be called once the response is ok or http connection is time out,where you can receive the response data and make the concrete process according to the response.In javascript,you should set this property with a function pointer either the function pointer variable or the function literal,for e.g.: var oXmlHttpRequest = CreateXmlHttpRequest(...); // create the XMLHTTPRequest interface reference
function OnReadyStateChange_Callback(variant) { ... } oXmlHttpRequest.onreadystatechange = OnReadyStateChange_Callback; or oXmlHttpRequest.onreadystatechange = function(variant) {...}; or oXmlHttpRequest.onreadystatechange = new Function(...) { "..." }; 2.responseText,responseXML standing for the response from the server,where responseText is the plain-text formatted string while the responseXML is the XMLDocument object that can be used to parse the structured response result,especially the MIME type text/xml is set onto the HTTP request. 3.status the HTTP response code,including 200,500,etc. 4.open(sMethod,sUrl,bAsync,sUser,sPwd) Method that is used to initialize and open the HTTP connection and request,where sMethod : the HTTP method name(i.e.,POST,GET,PROPFIND,etc.) sUrl : the URL to request bAsync : boolean indicating the synchronization model sUser : userName if required sPwd : password if required 5.send(content) Method that is used to send additional data to the requested URL,usually used for HTTP POST query strings. Remote Scripting - AJAX compared to RPC/COM,Web Service and Remoting ...Recently,i've taken some look at the hot word - AJAX,which is short for Asynchronous JavaScript And XML.I previously mentioned it as a new popular technology,however,i've made some mistakes,since it's not but a grouping of technologies such as standards based presentation HTML,CSS,Javascript and DOM,XmlHttpRequest XML/XSLT and HTTP protocol.Thus,once you understand these traditional terms,you can easily accept the AJAX concept.So what's on earth the AJAX?Have you experienced RPC,COM ever before?Hmmm,you might think of them quite old terms,then what about Remoting(a.k.a.Java RMI)?If either,i dare say you must not be strange with Web Service,right?So the AJAX is much similar to all of the terms i mentioned,to some degree.First I want to talk something about the AJAX in details.Previously,if you want to get some resources from the web server,you should send a new HTTP request and then get the response to/from the web server,in which way,the page is reloaded and refreshed,e.g.,clicking a link causing the browser to load the pages or some other type of resoruces and render everything again.Now,you can jump over the round trip to make the direct http request at the background asynchrously and register the callbacks in order to receive the notifications where you get the response data and do some necessary things to the existing page using DOM manipulating methods,without to refresh the whole page.The AJAX is based on the XmlHttpRequest Object exposed either by the Javascript itself in Mozilla Browsers or via Microsoft ActiveX object in Internet Explorer(see the discussion in my next blog entry).Using XmlHttpRequest,you can call the remote methods in Javascript.So in this way,AJAX is much like RPC,Remoting and Web service,since all of them can be used to call remote methods,i.e.,cross-boundary method call.The differences are which protocol they are using as the underlying communication mechanism and how the marshalling and unmashalling is done between the caller and callee.the following is a overview for the differences:
If you guys have some interesting in those technologies,you can do addtional some research on them,then you can get an improvement on many aspects.AJAX itself is very interesting and quite useful for you to improve the interactivity of your web application and the rich user interface related.To get more information,click the following links:
|
|
|