Announcement

Collapse
No announcement yet.

Main to callback PostMessage()

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

  • Main to callback PostMessage()

    Code:
    #COMPILE EXE '#Win 9.07#
    #DIM ALL
    #REGISTER NONE
    #INCLUDE "Win32Api.inc"
    
    GLOBAL hDlg AS DWORD
    
    $AppName  = "Main to callback"
    %Static   = 101
    %Edit     = 201
    '______________________________________________________________________________
    
    CALLBACK FUNCTION DlgProc
    
     SELECT CASE CBMSG
    
       CASE %WM_INITDIALOG
         'PostMessage(hDlg, %WM_APP, 0, 0) 'For when dialog initialization is done
    
       '********************************************************************************
       '* To know when dialog initialization is done,                                  *
       '* you can also put a PostMessage() just before the "DIALOG SHOW" line,         *
       '* and use it to send some info that may save you the use of global variable.   *
       '********************************************************************************
    
       CASE %WM_APP
         LOCAL pz AS ASCIIZ POINTER
         pz = CBWPARAM
         SetDlgItemText(hDlg, %Edit, @pz)
    
      END SELECT
    
    END FUNCTION
    '______________________________________________________________________________
    
    FUNCTION PBMAIN()
     LOCAL hIcon AS DWORD
    
     DIALOG FONT "Segoe UI", 9
     DIALOG NEW %HWND_DESKTOP, $AppName, , , 200, 80, _
     %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
    
     hIcon = ExtractIcon(GetModuleHandle(""), "%SystemRoot%\system32\powrprof.dll", 1)
     SetClassLong(hDlg, %GCL_HICON, hIcon)
    
     CONTROL ADD LABEL, hDlg, %Static, $AppName & " message via PostMessage", 5, 15, 190, 10, %SS_CENTER
     CONTROL ADD TEXTBOX, hDlg, %Edit, "Edit", 5, 40, 190, 10
    
     LOCAL sMessage AS STRING
     sMessage = "Hello from the main function!"
     PostMessage(hDlg, %WM_APP, STRPTR(sMessage), 0)
    
     DIALOG SHOW MODAL hDlg CALL DlgProc
    
     DestroyIcon(hIcon)
    
    END FUNCTION
    '______________________________________________________________________________
    '
Working...
X