locked
want to modify a registry value RRS feed

  • Question

  • want to modify registry values to hide the keboard slide event from the phone. Please help... :(
    Saturday, January 16, 2010 9:40 AM

Answers

  • I just made some tests about the SystemSettings.ScreenOrientation. I found that if I try to change the screen orientation again while the orientation is being changed, then an exception occurs. To overcome this I started a new thread and made some delay before setting the screen orientation, as shown below:

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (SystemSettings.ScreenOrientation != ScreenOrientation.Angle270)
            {
                new Thread(new ThreadStart(new Action(delegate()     //Start a new thread to change the orientation and let the Resize event return.
               {
                   Thread.Sleep(500);                                                //add a delay.
                   if (this.InvokeRequired)
                   {
                       this.Invoke(new Action(delegate()
                       {
                           SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
                       }));
                   }
               }))).Start();
            }
        }

    This however introduces a small flash when the QWERTY keyboard is slided in/out. If you think the registry values can work better, don't forget to answer the second question I asked in my previous post.

    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by warrentang Friday, May 14, 2010 4:31 AM
    Wednesday, January 20, 2010 7:03 AM

All replies

  • Hi,

    You can use the Registry class to modify registry values :-

    http://msdn.microsoft.com/en-us/library/microsoft.win32.registry.aspx

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Sunday, January 17, 2010 9:16 AM
  • Paul thanks for your reply, but i tried using that class for my htc tp2 phone, but it wont change the registry values for the same.

    Can you also suggest me which registry values do i have to change if i want to modify screen orientation cos i tried modifying the settings in this registry keys...

    state = new RegistryState("HKEY_LOCAL_MACHINE\\System\\GDI\\Rotation", "Angle");

     

    state = new RegistryState("HKEY_LOCAL_MACHINE\\System\\GDI\\Rotation", "SlideKey");

    state =

    new RegistryState("HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Keypad", "IsSlideOut");


    but they wont work. changing those values didnt change the orientation, i was able to read those values, but changing them did not change the device behaviour...

    Pls help...as landscape mode is necessary for my app, and sliding the keypad back in automatically changes back the orientation to potrait and my application throws exception....

    Monday, January 18, 2010 6:14 AM
  •     HKEY hKey = NULL;
        LONG lRet;
        wchar_t* szWallpaperPath = L"TEST";
    
        // OPEN
        lRet = RegOpenKeyEx(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Today"), 0, 0, &hKey);
    
        if (ERROR_SUCCESS == lRet)
        {
            wchar_t szPath[512] = {0};
            DWORD dwType = REG_SZ, dwBytes = 512;
    
            // READ
            lRet = RegQueryValueEx(hKey, L"Wall", NULL, &dwType, (LPBYTE)szPath, &dwBytes);
     
    
            if (wcscmp(szPath, szWallpaperPath) == 0)
            {
                LOGALWAYS("SAME WALLPAPER, NO CHANGE\n");
    
                return ;
            }
    
    
            // WRITE
            RegSetValueEx(hKey, L"Wall", 0, REG_SZ,(const BYTE*)szWallpaperPath, (wcslen(szWallpaperPath) * 2) + 1);
           RegCloseKey(hKey);
        }
    
    Monday, January 18, 2010 6:31 AM
  • Kurome, i guess the code u have posted is in cpp.

    can u give me a C# equivalent of that??

    Monday, January 18, 2010 8:49 AM
  • >>Can you also suggest me which registry values do i have to change if i want to modify screen orientation cos i tried modifying the settings in this registry keys...

    So your purpose is to change the the screen orientation of a Windows Mobile device programmatically, isn't it? There is API SystemSettings.ScreenOrientation to do that so you don't need to change the registry at all.

    The following video will show you how to use it:
    How Do I: Monitor and Manage Display Orientation Changes? 
      
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Tuesday, January 19, 2010 7:18 AM
  • thanks for your reply Tang, but the Api itself is causing me problems...!!

    let me elaborate my handler to u... its as follows...

    First up i'll show you my Form load event, which rotates the screen to 270(i'm using the HTCpro2 thats why....)

    private void Form1_Load(object sender, EventArgs e)
            {
                SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
            }
    ok...works fine...orientation changes to 270.

    Next up System state declared at class level and initialized in the constructor.

    SystemState S;
    
    public Form1()
    {
      InitializeComponent();
      S = new SystemState(SystemProperty.DisplayRotation);
      S.Changed += new ChangeEventHandler(S_Changed);
    }
    

    and now its handler implementation


    private void S_Changed(object Sender, ChangeEventArgs args)
    {
        try
           {
             if (args.NewValue.ToString() !="270")
               {
                 Thread.Sleep(1000);
                  SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;->this causes problems!!
                }
    
           }
        catch (Exception ex)
          {
              MessageBox.Show(ex.ToString());
          }
    }
    So the statement to change orientation works fine if i rotate screen through code, like as follows..

    private void btn0_Click(object sender, EventArgs e)
            {
                SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
            }
    
            private void btn90_Click(object sender, EventArgs e)
            {
                SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;
            }
    
            private void btn180_Click(object sender, EventArgs e)
            {
                SystemSettings.ScreenOrientation = ScreenOrientation.Angle180;
            }
    
            private void btn270_Click(object sender, EventArgs e)
            {
                SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
            }
    it works perfectly fine, even if i put in a conditon to to override the rotation and bring back to angle 0.

    My problem comes when the keypad SLIDES...

    I start the app in landscape mode. then i slid out the Touch Pro's 2 keypad. As the screen is already in landscape mode, nothing happens. But as soon as i slide the keypad back in, something triggers the screen orientation, and even the "SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;" line which is what i desire, the screen should rotate to 270 irrespective of the phones settings, doesnt seem to work. And this line throws me an exception which i mentioned above in the post. Hope u got my problem!

    If its feasible to you, you can give me your email id, i'll zip my code to you, and then you can check that on any device having a keypad. Note, changing registry values make the code works on the HTC tynTII

    Hope to hear from you soon.
    Tuesday, January 19, 2010 12:17 PM
  • >> the screen should rotate to 270 irrespective of the phones settings, doesnt seem to work. And this line throws me an exception which i mentioned above in the post. Hope u got my problem!

    Could you be more specific about the exception (exception type, error message, stack trace etc.)?

    >>Note, changing registry values make the code works on the HTC tynTII

    I don't follow. Which registry values do you change? Which code works? In your previous posts you said changing the registry values didn't work. 


    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Wednesday, January 20, 2010 6:28 AM
  • I just made some tests about the SystemSettings.ScreenOrientation. I found that if I try to change the screen orientation again while the orientation is being changed, then an exception occurs. To overcome this I started a new thread and made some delay before setting the screen orientation, as shown below:

        private void Form1_Resize(object sender, EventArgs e)
        {
            if (SystemSettings.ScreenOrientation != ScreenOrientation.Angle270)
            {
                new Thread(new ThreadStart(new Action(delegate()     //Start a new thread to change the orientation and let the Resize event return.
               {
                   Thread.Sleep(500);                                                //add a delay.
                   if (this.InvokeRequired)
                   {
                       this.Invoke(new Action(delegate()
                       {
                           SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
                       }));
                   }
               }))).Start();
            }
        }

    This however introduces a small flash when the QWERTY keyboard is slided in/out. If you think the registry values can work better, don't forget to answer the second question I asked in my previous post.

    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by warrentang Friday, May 14, 2010 4:31 AM
    Wednesday, January 20, 2010 7:03 AM
  • Tang...  Please could you explain your code.
    Dont mind, i'm a newbie, and cannot get proper guidance for coding. So i have to do everything by trial and error.

    My question is, why have you wrote this specific code in form resize? I mean, wat does this event handler exactly do? Does it change the orientation at startup? Cos i noticed that bye using a new project and implementing your code in that.

    What i did was, first i ran the project by commenting the whole 
     
       private void Form1_Resize(object sender, EventArgs e)

    routing, and next by commenting only your logic...

    I found out that, when i commented the whole handler, my form started in potratit mode. But when i commented just your logic, that is an empty handler, the form started rotating 270 degree..

    Can u please elaborate, exactly what is going on in here. Pardon my knowledge, but i am very very less experienced than you...

    Hope to hear form you soon.
    Thursday, January 21, 2010 9:09 AM
  • >>My question is, why have you wrote this specific code in form resize? I mean, wat does this event handler exactly do? Does it change the orientation at startup? Cos i noticed that bye using a new project and implementing your code in that.

    When the screen orientation is changed, your form will be rotated and *resized*, thus a Form.Resize event is trigered. In general the Resize event is similiar to the S_Changed event in your code, except that the Resize event is also fired at application startup.

    >>What i did was, first i ran the project by .. ...

    Sorry I don't understand your description. As a test you can create a new project, and then add a Resize event to Form1 and paste my code there. The code keeps the screen orientation to be Angle270.
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Friday, January 22, 2010 6:59 AM
  • Exactly that is wat i was asking.. At what precise time does the RESIZE event get fired? Is it when the constructor of the form is called? or is it when the form loads?
    .
    .
    .
    .
    I am asking you all these questions, because i am quite new to system programming. I've done business apps before for the mobile. But this is the first time i am attempting system programming. So i just wanted a review of the flow of system programming, that is, which event gets called when, or, for a particular system scenario which all events we can handle and so forth. Can u explain it to me or point to some resource where i can get all these answers???

    Waiting for a reply..

    Friday, January 22, 2010 8:55 AM
  • >>At what precise time does the RESIZE event get fired? Is it when the constructor of the form is called? or is it when the form loads?
     
    The resize event is fired every time the size of the Form is changed. To find it out exactly you can set some breakpoints and see it in Visual Studio.


    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Friday, January 22, 2010 10:00 AM
  • so wat you mean is tht, when the keypad is slid out, the Resize event will fire??? Always?. So if i cant trap that, i can prevent the form from changing orientation?
    Friday, January 22, 2010 5:32 PM
  • Yes, that's what I mean.
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    • Marked as answer by swaps_2k1 Monday, January 25, 2010 5:42 AM
    • Unmarked as answer by swaps_2k1 Tuesday, January 26, 2010 5:37 PM
    Monday, January 25, 2010 5:34 AM
  • ok...
    Tang...can u direct me to some good resource where i can understand all these events and their working properly...?
    cos i tried using putting break points and noticed tht the resize event is fired, more than 2 or 3 times, even when a form is just loaded...

    Btw...Thanks 4 ur help....Seems i need to do a lot of work on it...
    • Marked as answer by swaps_2k1 Monday, January 25, 2010 5:42 AM
    • Unmarked as answer by swaps_2k1 Monday, January 25, 2010 5:42 AM
    Monday, January 25, 2010 5:42 AM

  • I don't think you need to worry about that. Have you noticed that there is an if statement in my code?

      if (SystemSettings.ScreenOrientation != ScreenOrientation.Angle270)

    So the code to change screen orientation is executed only once when the form is loaded, no matter how many times the Resize event is triggered. Please do try the code I've posted so we can be on the same page. 
     


    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Monday, January 25, 2010 7:35 AM
  • so tell me tang..
    if i simply write the above if statement in the resize event, will it not throw any exception? i mean the code kept throwing exception every time i tried to use it with the keyboard slide....

    Will check and let u know....
    Monday, January 25, 2010 8:00 AM
  • Have you tried my code? (This is actually the third time I asked you to do it.)

    >> i mean the code kept throwing 

    By "the code" did you mean your code or my code?
    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Monday, January 25, 2010 8:19 AM
  • i mean...your code...tried to mod it according to my requirement, and it kept throwing exceptions...
    so i will try to work out something...nd if i fail, i'll consult u again....sorry to bother u so much! :(
    Monday, January 25, 2010 8:35 AM
  •  this.Invoke(new Action(delegate()
                       {
                           SystemSettings.ScreenOrientation = ScreenOrientation.Angle270;
                       }));
                   }
               }))).Start();



    Tang i'm facing a problem with ur above code brother... works fine when the application is working.. 
    but when i try to close the application, the application closes, but throws an error on the above code..
    i cant seem to understand its root cause.

    I am setting the orientation back to Angle 0 while quitting the application...
    i write this in form_closing event.

    if (SystemSettings.ScreenOrientation != ScreenOrientation.Angle0)
                {
                    SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
                }
    Please help.... 
    Monday, January 25, 2010 12:17 PM

  • Before you call the code to change the orientation to Angle0, unsubscribe the Resize event first like this:

    this.Resize -= this.Form1_Resize;

    if (SystemSettings.ScreenOrientation != ScreenOrientation.Angle0)
                {
                    SystemSettings.ScreenOrientation = ScreenOrientation.Angle0;
                }


    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Wednesday, January 27, 2010 2:21 AM
  • Sorry Tang...Still the same problem...I'm using your code as a part of a media playing app i am developing. I thought that maybe because there are too many components on the form so, the resize was taking too much of a time to execute and hence problems in orientation changes. So i tried changing the delay to 1000 ms. Worked fine for sometime, but after i did a stress test, by sliding the keypad in and out for mulitple times, the same error cropped up again.
    Can you shed some light on what is happening here? Cos the user may slid the keypad in and out many times just for fun, but the app should be able to handle that na...

    Btw thanks for all the help you are giving me...Really appreciate ur time... :)

    Wednesday, January 27, 2010 7:03 AM
  • Seems like someone else got to the same situation and found a solution:
    http://www.blondmobile.com/2008/02/windows-mobile-ui-how-to-change-device_3078.html 


    Please mark the post that helps you, and unmark that does not. This benefits our community.
    Thursday, January 28, 2010 3:12 AM
  • Nice post Tang... I'll try it today...
    In the mean while....talking about your code, can you tell me one thing please.

    See, everything works fine except the one i stated in the above post.. But one of my college unearthed another small bit of a problem.

    Something funny happens if we minimize our program. Ideally, a phone being in a potrait mode, if we minimize our app the phone should go back to potrait mode right? The phone does go back to potrait mode, but after some time goes back in landscape mode even if the application is kept minimized!....

    Solutions Mr Tang???
    Thursday, January 28, 2010 7:21 AM
  • Sorry to disappoint u tang...your last post did not work very well for the htc touch pro 2.... your solution was atleast working, but that lady's solution doesnot seem to be working at all for me....i guess she tried the solution for motionsensor hand sets...and not for the slider ones...Please see if you can give me a better solution....

    As i said in my last post...if we slid in and out frequently at high speed your solution fails....other wise it works as a charm... :) execpt for the problem in my previous post....

    Friday, January 29, 2010 9:46 AM