I have been a daunting programmer for Windows API programming and have no confidence or perseverance to learn. However, Windows programmers may encounter or use Windows APIs more or less. Whether you are Java or netProgramBoth of them indirectly use the win api. The two runtime environments only encapsulate the win api in a different layer.
Proficient in. Net interoperability: Describes P/invoke, C ++ InterOP, and COM InterOP in depth. I read five or six pages each time because the book is a bit boring. If you want to learn about interoperability or win api programming, read it.
The following are two instances I have used and viewed:
1. dynamic display window
# Region Animation startup form
[Dllimportattribute ( " User32.dll " )]
Private Static E Xtern Bool Animatewindow (intptr hwnd, Int Dwtime, Int Dwflags );
/*
1. aw_slide: This type is used by default. This type is ignored when the aw_center effect is used.
2. aw_active: Activation window. This effect cannot be used when aw_hide effect is used.
3. aw_blend: fade-in effect
4. aw_hide: Hide the window
5. aw_center: when used with the aw_hide effect, the effect overlaps the number of windows, and the window is extended separately.
6. aw_hor_positive: display the window from left to right
7. aw_hor_negative: display window from right to left
8. aw_ver_positve: display window from top to bottom
9. aw_ver_negative: display the window from bottom to top
*/
Public Const Int32 aw_hor_positive = Zero X 00000001 ;
Public Const Int32 aw_hor_negative = Zero X 00000002 ;
Public Const Int32 aw_ver_positive = Zero X 00000004 ;
Public Const Int32 aw_ver_negative = Zero X 00000008 ;
Public Const Int32 aw_center = Zero X 00000010 ;
Public Const Int32 aw_hide = Zero X 00010000 ;
Public Const Int32 aw_activate = Zero X 00020000 ;
Public Const Int32 aw_slide = Zero X 00040000 ;
Public Const Int32 aw_blend = Zero X 00080000 ;
// Dynamic close form
Private Void Xformmain_formclosed ( Object Sender, formclosedeventargs E)
{
// Dynamic close form
Animatewindow ( This . Handle, 800 , Aw_slide + Aw_hide + Aw_center );
}
# Endregion
Public Xformmain ()
{
Initializecomponent ();
// Animation startup
Animatewindow ( This . Handle, 800 , Aw_slide + Aw_center );
}
User32.dll exists in c: \ windows \ system32. Call the animatewindow function to display the window dynamically. You can view msdn to obtain detailed instructions for this method.
2. Two solutions to automatically convert vs2005 Chinese Input Method to full-width
From: http://www.cnblogs.com/name-lh/archive/2006/04/13/374337.html
// Two solutions for automatic conversion of vs2005 Chinese Input Method to full-width mode ----- 2 ----- use the inherited method
//Recently, when using vs2005 for a project, I have been suffering from the bug that the vs2005 Input Method automatically switches to the full angle.
//Microsoft gave us a solution. However, I have to package all my projects as products. Microsoft is still confused.
//This bug provides a solution. What should I do? I can endure the hard work of switching back and forth with this input method, and the user experience will not repeat us.
//If this is not the case, let us all go to Microsoft to get rid of the bad news!
//You can't just hand over the product. You have to do it yourself. Below I will use two methods to implement the bug of how to avoid the input method.
// First, create an independent class as follows:
// The method for using this class is:
// Modify the inheritance relationships of all forms. For example, you have a form class:
// Public partial class form1: imeform
// {
// // ...
// }
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. collections;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
Using System. runtime. interopservices;
Namespace Controls. Windows
{
Public Class Imeform: system. Windows. Forms. Form
{
// Declare some API functions
[Dllimport ( " Imm32.dll " )]
Public Static Extern Intptr immgetcontext (intptr hwnd );
[Dllimport ( " Imm32.dll " )]
Public Static Extern Bool Immgetopenstatus (intptr himc );
[Dllimport ( " Imm32.dll " )]
Public Static Extern Bool Immsetopenstatus (intptr himc, Bool B );
[Dllimport ( " Imm32.dll " )]
Public Static Extern Bool Immgetconversionstatus (intptr himc, Ref Int Lpdw, Ref Int Lpdw2 );
[Dllimport ( " Imm32.dll " )]
Public Static Extern Int Immsimulatehotkey (intptr hwnd, Int Lnghotkey );
Private Const Int Ime_cmode_fullshape = 0x8 ;
Private Const Int Ime_chotkey_shape_toggle = 0x11 ;
// Reload onactivated form
Protected Override Void Onactivated (eventargs E)
{
Base . Onactivated (E );
Intptr hime = Immgetcontext ( This . Handle );
If (Immgetopenstatus (hime )) // If the input method is enabled
{
Int Imode = 0 ;
Int Isentence = 0 ;
Bool Bsuccess = Immgetconversionstatus (hime, Ref Imode, Ref Isentence ); // Retrieving input method information
If (Bsuccess)
{
If (Imode & Ime_cmode_fullshape) > 0 ) // If it is a fullwidth
Immsimulatehotkey ( This . Handle, ime_chotkey_shape_toggle ); // Convert to halfwidth
}
}
}
}
}
This problem was previously encountered in vs2005 development, but MS has provided patches and will not occur again. We just want to see how to use the three methods of imm32.dll.
The above two examples show us how to use win api programming, involving query of Function Methods and query of constant-defined values. Function query mainly uses msdn, which is the most authoritative. For Constant Value queries, you can use online gadgets. Win api programming tools recommended: http://bbs.eyuyan.com/TopicOther.asp? T = 5 & boardid = 124 & id = 202857 & page = 1, among which API constant query 1.0 and easy-to-use API companion are better