Method for processing messages in VB and VC mixing programming

zhaozj2021-02-11  187

Method for processing messages in VB and VC mixing programming

Now more and more people use a mixed programming of VB and VC: Use VB to quickly develop a beautiful interface and peripheral processing programs, and then write various operations of the bottom layer, such as memory operation, Operation of the IO port, etc., VC It is also possible to embed the assembly language for a better operation. The general approach is to compile the VC program into a DLL, declare the functions in the DLL in VB, for example: declare function sendcommand lib "c: / program files / devstudio / wjfprojects / hr0506dllmnsr / debug / hr0506dllmnsr.dll" (cmdnum " AS INTEGER AS Boolean declares, the function SendCommand can be used as a VB's own function. However, how to notify VB in time in time in the VC, such as various underlying states, can also process in time? This is a defect in VB: custom Windows messages cannot be easily handled. For example, two messages are defined in the VC: MW_TAPI_DATACOME, MW_TAPI_BUSY, in the C language, with postmessage (hwnd, mw_tapi_connected, 0,0); statement can easily pass MW_TAPI_CONNECTED messages to the form (form handle is hwnd) ), You can handle it in the primary return function. But to pass this message to VB and let VB processes this message and is not easy. Although in VB5.0 or more, you can define your own events, but it is more troublesome. Here is a simple way to make VB cleverly handle custom messages: 1. First pass the handle of the TextBox control Text1 in the VB form to the DLL (note: the TextBox control in VB has an HWnd property). In VB: 'Declare declared a DLL function Function SendhWnd Lib "c: / program files / devstudio / wjfprojects / Hr0506dllMnsr / debug / Hr0506dllMnsr.dll" ((ByVal hWnd As Long) As Boolean' transfer text1 handle SendhWnd (text1. HWND) VC: // Handle Receive Function DECLSPEC (DLLEXPORT) BOOL gethwnd (hwnd hwnd1) {hWnd = hwnd1; if (hwnd == null) {Return false;} Return true;} 2. In VC API function setWindowText substituted VB PostMessage send messages directly to the control Text1: SetWindowText (hWnd, "MW_TAPI_DATACOME"); 3. processing Text1_Change event message: message handling statements case MW_TAPI_BUSY ': Private Sub Text1_Change () Select case Text1.text case W_TAPI_DATACOME: 'Message Processing Statement Default:' Other Process Statements End Select End Sub The above method is used in the "TAPI remote monitoring system" written in the author. The effect is very good. (Beijing Wu Junfeng)

转载请注明原文地址:https://www.9cbs.com/read-4014.html

New Post(0)