Device Optimized Functions not working

Discussion in 'Questions (Windows Mobile)' started by eww245, Jan 23, 2009.

  1. eww245

    eww245 Member Licensed User

    I have not been able to find anything specfic to my problem in the forum. I see some people lost some functions when using optimized compile for the device.

    I'm using Door library with Keydown and KeyUp events. It works fine on the IDE while running, and it works when standard complie.

    What it is doing is moving a sprite with right keypress. Using if KeyCode = right. This will not work while optimized.

    The other problem I have is a timer that will display a msgbox under certain conditions. Again, this works on the IDE and standard compile. But I dont get a message box when optimized.

    Part of what I am doing is setting the the Visible property to false when a Sprite hits a point, and true after the msgbox. It just wont give me the messagebox so It wont show my form.

    Does anyone know why this would happen while optimized? I have no problems compiling, and other programs will optimize and work properly.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you post some code that demonstrates these differences?
     
  3. eww245

    eww245 Member Licensed User

    Thanks for willing to help.

    After showing the form I have a panel using MouseMove to move a sprite.
    Then the Door library sets Visible false when the Sprite reaches an X location.

    It then disables all active timers, and enables Timer4.
    It also runs hook.unhook. Hook is a library i wrote to use SetWindowsHookEx and some other functions,
    hook.unhook naturally unhooks the keys while the form is hidden. And Hook.New2 starts the hook.

    To this point all works. The problem is that Timer4 doesn't appear to be active to set Visible to true,
    and KeyDown_NewEvent won't work either.


    All of this works with legacy device compile.
    Some of this code is not need, as I am still debugging.
    I've included my Library if you want to test.

    Thanks again.

    Code:
    Sub Panel1_MouseMove (x,y)
    Sprite.X = x - Sprite.Width + 
    10
       
    If Sprite.X < 0 Then 
    Sprite.X = 
    0
       
    Else If Sprite.X >155 Then
    Sprite.X = 
    155
    obj.New1(
    False)
    obj.FromControl (
    "Form1")
    obj.SetProperty (
    "Visible",False)
    Sprite.X = 
    0
    hook.UnHook
    Timer5.Enabled = 
    False
    Timer1.Enabled = 
    False
    Timer2.Enabled = 
    False
    Timer3.Enabled = 
    False
    Timer4.Interval = 
    15000
    Timer4.Enabled = 
    True
        
    led.ActivateLed(5)
         Sleep(
    120)
        
    led.DeActivateLed(5)
       
    End If
    Timer4 gets the idle time, sleeps for 15sec, then gets the idle time again.
    To prevent Timer4 from running while in sleep state, I set it's interval high enough before sleeping so it won't run twice.

    It then sets Visible to true, enables the Timers, disables Timer4, and creates a new Hook to Hook the keys.

    Code:
    Sub Timer4_Tick
    obj.New1(
    False)
    obj.FromControl(
    "Form1")
    obj.Value = obj.GetProperty(
    "Visible")

       
    If obj.Value = False Then
         idletime = hook.GetIdleTime
    Timer4.Interval = 
    150000
    Sleep (
    15000)
         idletime2 = hook.GetIdleTime
    idle = (idletime2 - idletime) /  
    1000

    Msgbox(idle)
    Timer4.Interval = 
    15000
         
    If idle > 10 Then
       obj.New1(
    False)
       obj.FromControl (
    "Form1")
       obj.SetProperty (
    "Visible",True)

    hook.New2(
    "Form1")
    Timer1.Enabled = 
    True
    Timer2.Enabled = 
    True
    Timer3.Enabled = 
    True
    Timer5.Enabled = 
    True
    Timer5.Interval = 
    25000
         
    End If
       
    End If
    End Sub
    Here I have a door object to GetProperty Keycode Right, to also move the Sprite. which won't when Optimized.
    Hook.New2 allows KeyRight within the library.
    Hook.FullOnState is setting the backlight on, after Timer5 has already set the backlight off.

    Code:
    From AppStart
    obj.New1 (
    False)
       obj.FromControl (
    "Form1")
       KeyUp.New1 (obj.Value,
    "KeyUp")
       KeyDown.New1 (obj.Value,
    "KeyDown")
    End AppStart

    Sub KeyDown_NewEvent
    obj.Value = KeyDown.Data
       
    If (obj.GetProperty("KeyCode") = "Right"Then
    hook.FullOnState
       Timer5.Interval = 
    25000
    Sprite.X = Sprite.X + 
    15
       
    End If

       
    If Sprite.X >160 Then
    Sprite.X = 
    155
    Form1.Close
       
    End If
    End Sub
     
    Last edited: Jan 26, 2009
  4. Erel

    Erel Administrator Staff Member Licensed User

    I haven't tested your code. It is much easier if you upload a working source code so we won't need to add all controls and objects.
    Why don't you use a HardKey (from Hardware) library to catch the required keys: Hardware

    Instead of changing the Visible property with the Door library you should use Form.Close.
     
  5. eww245

    eww245 Member Licensed User

    Hardware doesn't hook all keys, I added Volume up and down to it and still didn't work. and sometimes it doesn't work at all for me. So I wrote the library with SetHookEx which hooks everything.

    If I use Form.Close then the program will not run in the background. With setting Visible false it will start the program faster after being hidden.

    Since I was using Door I figured KeyCode Property should work fine.
    I'll try hardware for moving the Sprite right.

    I just don't understand why some of this doesn't work when optimized.

    I'll upload the source when I'm at my PC
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You can use Hardware.ShowTodayScreen to move your program to the background.
     
  7. eww245

    eww245 Member Licensed User

    Yes, It will, I have tried all of your sugesstions already on my own before I created the dll. The drawback to ShowTodayScreen, is exactly that, it shows the today screenand not the last active application. This is possible through DzHw library, but then I have more libraries to include with the exe and more code.

    My last option was to try and created the dll, which somehow I did. I am not a programmer, or at least not for more that a few months, and for C# only for about 1 week.

    I've been having internet connection issues, and my laptop radio died on me at the same time. Guess I should have gotten that extra warranty with HP.......

    Anyway, I would still like to post my source code but might take me a bit of time. I have also removed the Library, I don't want anyone to have it at this point, until I have it finallized and into the Additional Library Sub.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice