Option Explicit
Private Const HWND_BROADCAST As Long=& amp; HFFFF&
Private Const WM_SYSCOMMAND As Long=& amp; H112
Private Const SC_MONITORPOWER As Long=& amp; HF170 & amp;
Private Declare Function SendMessage Lib "user32. DLL" Alias "SendMessageA" (_
ByVal HWND As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByRef lParam As Long As Any)
Private Sub Command1_Click ()
SendMessage HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, ByVal 2 & amp;
End Sub
The above code can only be executed once close the screen, then there is no response, why can't we repeat many times GuanBing? To be able to repeat, how to write?
CodePudding user response:
Don't understand what you said "can't repeat many times to execute" is what meaning,If the screen "lit", execution time, system will make the screen "screen out", why the "multiple"!!!
After the "screen out" if you move the mouse, press a key on the keyboard, can make screen resume,
After the screen lights up, you execute the code again, there is no problem...
CodePudding user response:
I use the operating system is Windows 7, I said, I hope that after the code execution is not closed, and then click the button at any time, you can close the screen at any time, in fact, the code after execution, click on the button for the first time, you can turn off the screen, then the code will enter a state of no response, even after the opening screen, under the condition of without shutting down the code, brother second click button, there is no reaction, the code is what I search on the net, listen to people say if you want to learn the API, to C language and the running mechanism of the operating system has a deep understanding, but I won't be any programming language, zero foundation, VB is just see the tutorials, even not a novice, I hope programming a great god can be glad!CodePudding user response:
" I hope that after the code execution is not closed "you that's so strange!If carried out, how could it not shut down!
This is not to say, "have the code will be executed to", just like you posted this paragraph,
After "to run the program", still need to trigger the "button click event", or "take the initiative to call" to other areas in the code will be executed,
If "all the code is" you posted those, of course, there is no "other local calls", there is only one performs conditional "triggering event",
This has nothing to do with "system" (net friend: my android can run? I: roll!!!!!! ),
Win2K system, must have no problem, if you can also find Win98, estimates that can correct operation,
I just tried, also shut down/back to 10 times repeatedly, "ineffective" didn't happen, my system is Windows 7 ultimate, 64/SP1,
You need to be aware that, after the click of a mouse, in its "closing process", don't move the mouse, touch any button...
You can create a new standard EXE engineering, draw a button and paste the code, and run a try,
CodePudding user response:
Fyi:# pragma comment (lib, "user32")
#include
Void main () {
: : SendMessage (HWND_BROADCAST, WM_SYSCOMMAND SC_MONITORPOWER, 2);
Sleep (1000);
: : SendMessage (HWND_BROADCAST, WM_SYSCOMMAND SC_MONITORPOWER, 2);
Sleep (1000);
: : SendMessage (HWND_BROADCAST, WM_SYSCOMMAND SC_MONITORPOWER, 2);
}
CodePudding user response:
VB code, upstairs idea won't work!CodePudding user response: