简体   繁体   中英

How to use the SendMessage/PostMessage functions?

I want to send these messages to an application:

<00010> 00830BB8 S WM_GETDLGCODE
<00011> 00830BB8 R WM_GETDLGCODE fuDlgCode:DLGC_WANTARROWS
<00012> 00830BB8 P WM_PAINT hdc:00000000
<00013> 00830BB8 S WM_ERASEBKGND hdc:DD012964
<00014> 00830BB8 R WM_ERASEBKGND fErased:True
<00015> 00830BB8 P WM_TIMER wTimerID:1 tmprc:00000000
<00016> 00830BB8 S WM_GETDLGCODE
<00017> 00830BB8 R WM_GETDLGCODE fuDlgCode:DLGC_WANTARROWS
<00018> 00830BB8 S WM_GETDLGCODE
<00019> 00830BB8 R WM_GETDLGCODE fuDlgCode:DLGC_WANTARROWS
<00020> 00830BB8 P WM_PAINT hdc:00000000
<00021> 00830BB8 S WM_ERASEBKGND hdc:7601294E
<00022> 00830BB8 R WM_ERASEBKGND fErased:True

These are from Spy++. How do I send using the SendMessage/PostMessage function, using C#?

Edit.. Thank you guys for your replies! I solved my problem, thanks again!

I tried to send keys to an application, and I used the Spy++ to see the messages goes to this. Specifically I wanted to send arrow keys to the application. From the Spy++, I saw that sent the above messages. After I had tried everything, I sent in the application, the below messages:

PostMessage(handle, WM_KEYDOWN, (int)Keys.Down, 0x00140001);
PostMessage(handle, WM_KEYUP, (int)Keys.Down, 0xC0140001);

Now works properly! Thanks guys!

You cannot send the messages related to painting the window. Only the system can send them. If you need to force a re-paint then you simply call InvalidateRect.

Timer messages you could probably post successfully.

The WM_GETDLGCODE messages you probably don't need to send since they don't have side effects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM