Announcement

Collapse
No announcement yet.

How can I get the 'hwnd' for using 'sendmessage'

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I get the 'hwnd' for using 'sendmessage'

    Hello to all,

    I'll create a simple program using the function 'sendmessage' for putting on/off the Monitor. Later I'll use this as a function.
    Here is my code:


    '#####################################
    #COMPILE EXE
    #DIM ALL
    #INCLUDE ONCE "WIN32API.INC"


    'monitor.exe on -> Monitor = on
    'monitor.exe off -> Monitor = off


    FUNCTION PBMAIN() AS LONG

    LOCAL hwnd AS DWORD

    LOCAL WM_SYSCOMMAND AS LONG : WM_SYSCOMMAND = &H112&
    LOCAL SC_MONITORPOWER AS LONG : SC_MONITORPOWER = &HF170&

    hwnd = ?? 'This is my problem

    DIM a AS STRING
    a = COMMAND$

    IF a = "on" THEN
    SendMessage hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, BYVAL -1&
    ELSE
    SendMessage hwnd, WM_SYSCOMMAND, SC_MONITORPOWER, BYVAL 2&
    END IF

    END
    END FUNCTION
    '#####################################

    I'm new in PB.

    Thank you in advance
    Frank



  • #2
    Hi Frank, not sure I understand, but try using %HWND_BROADCAST instead of hWnd.

    Comment


    • #3
      Usually the first parameter of the SendMessage call is the handle of the dialog box that owns control that you are trying to send a message to. This is usually saved when you do a DIALOG NEW command to create your dialog. Since you are not creating a Dialog box I would guess you should use %HWND_DESKTOP which equates to 0.

      Comment


      • #4
        related to what your are trying to do.
        https://forum.powerbasic.com/forum/u...-monitor-sleep

        Comment


        • #5
          Also found this old one from Lance. The second post works
          link

          Comment


          • #6
            Thanks to all. I havend found "monito sleep", becouse I was looking for "Monitor off/on" .....
            I'm new in PB. Now i know, that the answer is: %hWnd_Broadcast.

            Thanks again to everyone.
            Frank

            Comment

            Working...
            X