Announcement

Collapse
No announcement yet.

A stupid question

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

  • A stupid question

    Is it possible for an application to process %WM_ messages
    from within the WINMAIN function? If so, what must be done before
    that function can actually receive the messages?

    Thanks in advance!


    ------------------
    Clay C. Clear

    http://www.v3space.com/a/a39/202/

    [email protected]
    [email protected]

  • #2
    I am not sure if it is possible, never tried. You might
    want to take a look at SetWindowLong, maybe something if you
    subclass. I don't know why you would want to do this though.

    ------------------
    -Greg
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

    Comment


    • #3
      Gregery,

      I want to be able to do it because some of my programs go in the
      system tray at Windows bootup, and run in the background
      continuously until/unless manually closed.

      Semen told me that it is possible to put an icon in the tray
      without a dialog, and have it respond to mouse clicks by
      using popup menus. But, how could I receive/process the
      %WM_LBUTTONDOWN, %WM_RBUTTONDOWN, and %WM_COMMAND messages
      without a Callback function? And, to have a callback function,
      aren't I required to have a parent dialog?

      That is why I posted the original message, because I want to
      be able to code those programs so they don't require Dialog's or
      Callback Functions.

      Any ideas?


      ------------------
      Clay C. Clear

      http://www.v3space.com/a/a39/202/

      [email protected]
      [email protected]

      Comment


      • #4

        Clay,

        All *proper* Windows apps need a callback function to operate, it is how Windows works.

        Maybe a hidden Window might be what you're after?!?

        (Sorry for short reply, ima bit 'bizzy')

        ------------------
        Kev G Peel
        KGP Software, Bridgwater, UK.
        mailto:[email protected][email protected]</A> http://www.kgpsoftware.com
        kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

        Comment


        • #5
          Kev,

          Thanks for your reply! That's all the info I needed, as I now
          know not to pursue that avenue.

          My system tray apps already use "hidden" windows - figured that
          out with some help from source code posted in the Forums, and
          some help from Lance.

          Regards,


          ------------------
          Clay C. Clear

          http://www.v3space.com/a/a39/202/

          [email protected]

          Comment


          • #6
            I thought I posted this already....

            This uses a dialog box, but this window is invisible...
            And can be put in the system tray....

            Code:
            wndclass.cbSize = SizeOf(WndClass)
            wndclass.style = %CS_HREDRAW Or %CS_VREDRAW
            wndclass.lpfnWndProc = CodePtr( WndProc )
            wndclass.cbClsExtra = 0
            wndclass.cbWndExtra = 0
            wndclass.hInstance = hInstance
            wndclass.hIcon = LoadIcon (hInstance, "WINICO")
            wndclass.hCursor = LoadCursor( %NULL, ByVal %IDC_ARROW)
            wndclass.hbrBackground = GetStockObject(%LTGRAY_BRUSH)
            wndclass.lpszMenuName = %NULL
            wndclass.lpszClassName = VarPtr( szClassName )
            wndclass.hIconSm = LoadIcon( hInstance,"WINICO")
            RegisterClassEx wndclass
            
            '--------------------------------------------------------------
            '*Get the handle of an existing window and pass this on as the
            ' parent to this window so we can hide our process from showing
            ' up on the task bar
            '--------------------------------------------------------------
            'hdTopWnd& = GetDeskTopWindow()
             hNextWnd = GetTopWindow(0)
             hParent  = GetParent(hNextWnd)
            '--------------------------------------------------------------
            
            hWnd = CreateWindowEx(0,szClassName, _
                                  "", _
                                  %WS_POPUP Or %WS_DLGFRAME,_
                                  %CW_USEDEFAULT, _
                                  %CW_USEDEFAULT, _
                                  %CW_USEDEFAULT, _
                                  %CW_USEDEFAULT, _
                                  hParent, _ '<-- assign to a parent window
                                  %NULL, _
                                  hInstance, _
                                  ByVal %NULL)
            UpdateWindow hWnd
            
            'Remove from Task list
            pid = GetCurrentProcessId()
            RegisterServiceProcess pid, 1
            
            While GetMessage(Msg, %NULL, 0, 0)
             TranslateMessage Msg
             DispatchMessage Msg
            Wend
            Function WndProc (ByVal hWnd As Long, _
                              ByVal wMsg As Long, _
                              ByVal wParam As Long, _
                              ByVal lParam As Long) Export As Long
            
            
            Do your system tray stuff here as in the example given in samples\tray
            
            
            End Function

            ------------------
            Scott
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              Thanks, Scott! I just printed out your source code.

              Regards,


              ------------------
              Clay C. Clear

              http://www.v3space.com/a/a39/202/

              [email protected]

              Comment


              • #8
                Well, now you have two ways to create a hidden window/dialog...

                Kev has the right answer here - you are supposed to have a separate callback function to handle messages from Windows.

                One idea here could be to just process the messages in your message pump, but do not dispatch the messages... I've never tried it, and it looks like a lot of work considering that a callback is incredibly easy to implement... I don't see what you stand to gain by trying to eliminate the callback.

                ------------------
                Lance
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Lance
                mailto:[email protected]

                Comment


                • #9
                  Lance,

                  You raise a good point. However, it were actually the dialog's
                  that I was trying to eliminate, as my approach to it was pretty
                  kludgey (as you know ). Now, though, I can start implementing
                  Scott's approach.

                  Thanks again, Scott!


                  ------------------
                  Clay C. Clear

                  http://www.v3space.com/a/a39/202/

                  [email protected]

                  Comment


                  • #10
                    Clay --
                    As I remember, you wanted to hide initial appearence of dialog.
                    And I told you that you don't need to use dialog (because you can use classic SDK window).
                    In "tray" directory I found a sample, which is a part of PB tray.bas.
                    I beleive that I already posted it.

                    Code:
                    #Compile Exe
                    #Dim All
                    #Register None
                    #Resource "TRAY.PBR"
                    #Include "WIN32API.INC"
                    
                    %WM_TRAYICON = %WM_USER + 400
                    
                    CallBack Function DlgProc
                      Static ti    As NOTIFYICONDATA
                      Select Case CbMsg
                    
                        Case %WM_CREATE
                          ti.cbSize           = SizeOf(ti)
                          ti.hWnd             = CbHndl
                          ti.uID              = GetModuleHandle(ByVal 0&)
                          ti.uFlags           = %NIF_ICON Or %NIF_MESSAGE Or %NIF_TIP
                          ti.uCallbackMessage = %WM_TRAYICON
                          ti.hIcon            = LoadIcon(GetModuleHandle(ByVal 0&), "FACE1")
                          ti.szTip            = "Task Tray Example"
                          Shell_NotifyIcon %NIM_ADD, ti
                          DestroyIcon ti.hIcon
                    
                        Case %WM_TRAYICON
                          Select Case LoWrd(CbLparam)
                            Case %WM_LBUTTONDOWN, %WM_RBUTTONDOWN
                              MsgBox "Qu-qu. Finished.", %MB_TASKMODAL
                              PostMessage CbHndl, %WM_SYSCOMMAND, %SC_CLOSE, 0
                          End Select
                    
                        Case %WM_DESTROY
                          Shell_NotifyIcon %NIM_DELETE, ti
                          PostQuitMessage 0
                      End Select
                    
                      Function = DefWindowProc(CbHndl, CbMsg, CbWparam, CbLparam)
                    
                    End Function
                    
                    Function PbMain
                      Local Msg         As tagMsg
                      Local wndclass    As WndClassEx
                      Local szAppName   As Asciiz * 80
                      Local hWnd        As Long
                    
                      szAppName              = "HelloWin"
                    
                      wndclass.cbSize        = SizeOf(WndClass)
                      wndclass.lpfnWndProc   = CodePtr(DlgProc)
                      wndclass.hInstance     = GetModuleHandle(ByVal 0&)
                      wndclass.lpszClassName = VarPtr(szAppName)
                      RegisterClassEx wndclass
                    
                      hWnd = CreateWindow(szAppName, "", 0, 0, 0, 0, 0, 0, 0, wndClass.hInstance, ByVal 0&)
                      MsgBox "Look system tray and click an icon"
                    
                      While GetMessage(Msg, %NULL, 0, 0)
                        TranslateMessage Msg
                        DispatchMessage Msg
                      Wend
                    
                    End Function
                    ------------------
                    E-MAIL: [email protected]

                    Comment


                    • #11
                      Strangely enough, that code still creates a window...

                      ------------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment


                      • #12
                        Haven't tried it out yet in PB, but in MASM I've written a little Prog, wich uses "GetMessage" in an endless loop to receive the "WM_TIMER" message.

                        Code:
                        again:
                        
                              invoke GetMessage,ADDR msg,NULL,0,0
                              cmp eax, 0
                              je stop
                              mov eax,msg.message
                              cmp eax,WM_TIMER
                              jne again
                        
                        stop:
                        Would be in PB:

                        Code:
                        again:
                             call GetMessage(msg, 0, 0, 0)
                             if msg.message = 0 then
                             goto stop
                             elseif msg.message <> WM_TIMER then goto again
                             ...
                        
                        stop:
                             'end of prog, because if the programm does not receive any      messages, it should be terminated.
                             ...
                        ------------------
                        E-Mail (home): mailto:[email protected]webm[email protected]</A>
                        E-Mail (work): mailto:[email protected][email protected]</A>

                        [This message has been edited by Sven Blumenstein (edited July 09, 2001).]

                        Comment


                        • #13
                          Scott,

                          Can you post the DECLARE statement for RegisterServiceProcess()?

                          I couldn't find any reference to it in the PB/DLL INC's, nor is it
                          referenced in the Win32.hlp file.

                          Thanks!


                          ------------------
                          Clay C. Clear

                          http://www.v3space.com/a/a39/202/

                          [email protected]

                          Comment


                          • #14
                            When all else fails, try a BBS search...
                            Code:
                            Declare Function RegisterServiceProcess Lib "kernel32" Alias "RegisterServiceProcess" ( ByVal dwProcessID As Long, ByVal dwType As Long ) As Long
                            Note: RegisterServiceProcess does not "hide" applications under Windows NT/2000.


                            ------------------
                            Lance
                            PowerBASIC Support
                            mailto:[email protected][email protected]</A>
                            Lance
                            mailto:[email protected]

                            Comment


                            • #15
                              RegisterServiceProcess is not listed in the Windows SDKs. According to
                              the latest MSDN:

                              To call RegisterServiceProcess, retrieve a function pointer using GetProcAddress
                              on KERNEL32.DLL. Use the function pointer to call RegisterServiceProcess.

                              Why? Dunno, but it would seem prudent to follow this advice rather than using
                              that DECLARE.


                              ------------------
                              Tom Hanlin
                              PowerBASIC Staff

                              Comment


                              • #16
                                Doesn't hide under NT/Win2k at all, as lance mentioned...since that's not an issue here it will still function and not show the window...

                                Under NT/Win2k I just rename the exe to something like MSCBSS.EXE or something not uncommon... (From SPYDER application)..

                                Scott

                                ------------------
                                Scott
                                Scott Turchin
                                MCSE, MCP+I
                                http://www.tngbbs.com
                                ----------------------
                                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                Comment


                                • #17
                                  Lance, Scott,

                                  Which code were you trying? Semen's or the other one? I couldn't get it to work
                                  at all, though I think I figured it out. Before I tried it, I created
                                  a custom resource DLL with icons that will be common to my Public
                                  programs. It also has a default right-click menu in it. Well, I was
                                  using LoadIcon to TRY to load the system tray's (ti.hIcon) icon.
                                  When I couldn't get their code to work, I tried the custom DLL with
                                  MY technique. That didn't work, either. Finally, I read the
                                  Win32.hlp on LoadIcon, and that's when I found out that it ONLY works
                                  on EXE's. So, I recoded the test program that was using my techniques
                                  to use use LoadImage, and voila, it worked! So, I might try the code
                                  posted in this topic, again. But, first, I'd like to know which
                                  version(s) of the code didn't work (i.e., showed the window when it
                                  shouldn't've).

                                  Thanks!


                                  ------------------
                                  Clay C. Clear

                                  http://www.v3space.com/a/a39/202/

                                  [email protected]

                                  Comment

                                  Working...
                                  X