WPF sends and receives Windows messages

Source: Internet
Author: User
Windows messages sent and received by WPF

 

 

[System. Security. suppressunmanagedcodesecurity]

[Dllimport ("user32.dll", charset = charset. Auto)]

Public static extern bool peekmessage (out message MSG, intptr hwnd, uint messagefiltermin, uint messagefiltermax, uint flags );

[Dllimport ("user32.dll", entrypoint = "sendmessagea")]

Private Static extern int sendmessage (intptr hwnd, int wmsg, intptr wparam, string lparam );

[Dllimport ("user32.dll", charset = charset. Unicode)]

Public static extern intptr postmessage (intptr hwnd, int wmsg, intptr wparam, intptr lparam );

 

Intptr hwnd;

 

Private void windowloaded (Object sender, eventargs E)

{

 

Hwnd = new windowinterophelper (this). Handle;

Hwndsource. fromhwnd (hwnd). addhook (New hwndsourcehook (wndproc ));

 

}

// Receives Windows messages

 

Private intptr wndproc (intptr hwnd, int MSG, intptr wparam, intptr lparam, ref bool handled)

{

Int wm_user = 0x0400 + 111;

If (MSG = wm_user)

{

// Decodetouch (wparam, lparam );

String dicom_file = marshal. ptrtostringansi (wparam );

Handled = true;

F_opendicom (dicom_file );

 

}

Return intptr. zero;

}

// Send a Windows message

Private void f_send_msg (string filepath)

{

 

Intptr hwnd_ifc;

Int wm_user = 0x0400 + 111;

Hwnd_ifc = hwnd; // find the form handle with the title frmpassive.

 

Unicodeencoding encode = new unicodeencoding ();

Char [] chars = encode. getchars (encode. getbytes (filepath ));

Message MSG;

 

MSG = message. Create (hwnd_ifc, wm_user, Marshal. stringtohglobalansi (filepath), new intptr (0 ));

Postmessage (msg. hwnd, MSG. MSG, MSG. wparam, MSG. lparam );

 

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.