Hiding/showing a form (vb.net) - Windows Mobile Development and Hacking General

I am trying to replace my contacts program with one I wrote myself but I'm having a little problem getting the form to hide and then show again?
I would like to start my app from a button, easy enough but I'm a little confused with hiding it again. I can hide the form but if I press the button again nothing happens but I'd like my app to show itself again?
Could someone please help the village idiot and point me in the right direction please?

Ok solved my problem. I used another exe to boot the program and if it was already booted then show the program via the API.
Imports System.Runtime.InteropServices
Imports System.Diagnostics
Module ModMain
<DllImport("coredll")> _
Public Function FindWindow(ByVal lpClass As String, ByVal lpTitle As String) As IntPtr
End Function
<DllImport("CoreDll")> _
Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
End Function
<DllImport("CoreDll")> _
Public Function SetForegroundWindow(ByVal hWnd As IntPtr) As Boolean
End Function
Const SW_HIDE As Integer = 0
Const SW_SHOW As Integer = 5
Public Sub Main()
Dim hWnd As Long = FindWindow("#NETCF_AGL_BASE_", "Contacts")
If hWnd = IntPtr.Zero Then
Dim AP As New Process
AP.StartInfo.FileName = "Program Files\ContactsList2\ContactsList2.exe"
AP.Start()
Else
ShowWindow(hWnd, SW_SHOW)
SetForegroundWindow(hWnd)
End If
End Sub
End Module

Related

Trapping Hardware buttons

Hi,
anyone know how, or if it is possible to trap the green 'call' button on the xda ii. I can trap the camera, voice recorder and top 2 buttons, but i need to trap the call button
Thanks
Pete
use GetAsyncKeyState
Hi,
tried trapping it in a timer with getasynckeystate , but only seem to pick up the 'd' pad, not any of the other keys.
Using registerhotkey for the other 4 which works fine, just not for the call button
Thanks
Pete
Could you please let me know how you could trap the camera and the two top buttons.
Could you also trap the Red button ?
Many Thanks
Hi,
Paste the following code into a module, and call in in the form_load as follows:-
Dim messageWindow As Hwbuttons.hwMessageWindow
Me.messageWindow = New Hwbuttons.hwMessageWindow(Me)
RegisterHKeys.RegisterRecordKey(Me.messageWindow.Hwnd)
The original code for this comes from www.opennetcf.org - I modified it for my needs, so kudos to the original poster(s).
I have still not found a way to trap the 'green and red' keys
Pete
Imports Microsoft.WindowsCE.Forms
Imports System.Runtime.InteropServices
Public Enum KeyModifiers As Integer
None = 0
Alt = 1
Control = 2
Shift = 4
Windows = 8
Modkeyup = &H1000
End Enum
Public Enum KeysHardware As Integer
Hardware1 = 193
Hardware2 = 194
Hardware3 = 195
Hardware4 = 196
Hardware5 = 202
End Enum
Public Module RegisterHKeys
<DllImport("coredll.dll", Entrypoint:="RegisterHotKey", setLastError:=True)> _
Public Function RegisterHotKey( _
ByVal hWnd As IntPtr, _
ByVal id As Integer, _
ByVal Modifiers As KeyModifiers, _
ByVal key As Integer) As Boolean
End Function
<DllImport("coredll.dll")> _
Private Function UnregisterFunc1( _
ByVal modifiers As KeyModifiers, _
ByVal keyID As Integer) As Boolean
End Function
Public Sub RegisterRecordKey(ByVal hWnd As IntPtr)
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware1, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware1, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware1, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware2, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware2, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware2, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware3, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware3, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware3, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware4, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware4, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware4, Integer))
UnregisterFunc1(KeyModifiers.Windows, CType(KeysHardware.Hardware5, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hardware5, Integer), KeyModifiers.Windows, CType(KeysHardware.Hardware5, Integer))
End Sub
Public Class Hwbuttons
Inherits System.Windows.Forms.Form
Public Shared messageWindow As hwMessageWindow
Public Class hwMessageWindow
Inherits messageWindow
Public Const WM_HOTKEY = &H312
Dim example As frmComms
Public Sub New(ByVal example As frmComms)
Me.example = example
End Sub
Protected Overrides Sub WndProc(ByRef msg As Message)
Select Case msg.Msg
Case WM_HOTKEY
'ButtonPressed(msg.WParam.ToInt32())
Return
End Select
MyBase.WndProc(msg)
End Sub
Public Sub ButtonPressed(ByVal button As Integer)
Select Case button
Case KeysHardware.Hardware1
MessageBox.Show("Button 1 pressed!")
Exit Sub
Case KeysHardware.Hardware2
MessageBox.Show("Button 2 pressed!")
Exit Sub
Case KeysHardware.Hardware3
MessageBox.Show("Button 3 pressed!")
Exit Sub
Case KeysHardware.Hardware4
MessageBox.Show("Button 4 pressed!")
Exit Sub
Case KeysHardware.Hardware5
MessageBox.Show("Button 5 pressed!")
Exit Sub
End Select
End Sub
End Class
End Class
End Module
Many Thanks.
I will give it a go.
Please let me know if you could find a way to control the Green and Red Buttons.
Thanks Again
:lol:
the green+red keys are already registered to the cprog.exe phone app.
you can grab them, by killing cprog.exe and then registering them.
this will prevent the original phone app from starting up.
( it is automatically restarted every minute orso, by shell32.exe )
Hi,
thanks for that - but using PHM task manager I am unable to stop the process from running.
I will take the 'o2active' from the startup and generally poke around to see if i can get it to stop
Thanks
Pete
I mean you should stop it from your own program, using 'TerminateProcess'
see http://www.xs4all.nl/~itsme/projects/xda/tools.html itsutils.cpp
for how to use TerminateProcess
Hi,
thanks - pkill does terminate the process - I thought PHM task manager would work using 'end process' but it does not.
Right - when I kill it, I then start 'button finder' to trap the hardware buttons, but as soon as I hit the green button, cprog relaunches
Thanks for your help
Pete
you should program it your self:
Code:
#define VK_ANSWER 0x72
#define VK_HANGUP 0x73
TerminateProcess(...); // kill cprog.exe
RegisterHotKey(..., 1, 0, VK_ANSWER); // steal hotkey
RegisterHotKey(..., 1, 0, VK_HANGUP); // steal hotkey
Isn't there some win32 way to "steal" messages from another application? If you can do that, you could steal the WM_HOTKEY message from the phone app, that way, you wouldn't have to kill it. I am not sure if killing it would cause you to miss calls or not.
Has anyone posted a clear solution
I have been searching all over the net for a clear solution on hhow to trap these hardware keys and I just can't find anything. Does anyone have a nice clear solution yet?
I have to get the green call key and the red hang up key.
thanks,
Dan
Re: Has anyone posted a clear solution
I've seen several games that intercept "call" and "hang" buttons using GAPI. I have not tested this myself, but you can try.
You can unregister and register the buttons to your own app without killing the phone process, using the same functions as the code pete posted:-
UnregisterFunc1(KeyModifiers.None, CType(KeysHardware.Answer, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Answer, Integer), KeyModifiers.None, CType(KeysHardware.Answer, Integer))
UnregisterFunc1(KeyModifiers.None, CType(KeysHardware.Hangup, Integer))
RegisterHotKey(hWnd, CType(KeysHardware.Hangup, Integer), KeyModifiers.None, CType(KeysHardware.Hangup, Integer))
Where KeysHardware.Answer = &H72 and KeysHardware.Hangup = &h73
The difference between these two keys and the other hardware keys is they are not sent with the Windows key modifier.
Peter
sorry to bring back this old post, i have tried the code in this thread and successfully capture the green button, but after my application quit how can i restore back the button original function? anyone can help?

little coding help needed

hey folks,
here's what I wanna do:
I need a program that runs in the background and checks if my mda2 is in the cradle or not. if it's plugged in the cradle I want it to change in my connection settings from work to internet. I need this for the following reason: my cellphone provider only offers grps over a proxy and that proxy wount work in the cralde when I share my PC connection via active sync. so right now I always need to switch between work and internet connection by myself.
I only know visual basic so I guess I need to take a look at eVB.
Is such a tool even possible in eVB? if so, where would I start? can someone point me in the right direction? maybe give me some links for research.
thanks for your help in advance
cyas
ait, did some research.
looks like just turning the proxy off should do the trick.
I tried doing this via the registry.
for now I just wanted to read out a key. this is what I got so far:
Code:
Option Explicit
Public Declare Function RegOpenKeyEx Lib "Coredll" Alias "RegOpenKeyExW" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegQueryValueEx Lib "Coredll" Alias "RegQueryValueExW" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long
Public Declare Function RegCloseKey Lib "Coredll" (ByVal hKey As Long) As Long
Const ERROR_SUCCESS = &O0
Const HKEY_LOCAL_MACHINE = &H80000001
Private Sub Command1_Click()
Dim lngSize As Long, hlngSubKey As Long
Dim lngType As Long, lngResult As Long
Dim RegData As Integer
lngSize = 256
RegData = String(lngSize, 0)
lngResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "\SOFTWARE\Microsoft\ConnMgr\Providers\{EF097F4C-DC4B-4c98-8FF6-AEF805DC0E8E}\HTTP-{18AD9FBD-F716-ACB6-FD8A-1965DB95B814}", 0, 0, hlngSubKey)
lngResult = RegQueryValueEx(hlngSubKey, "Proxy", 0, lngType, RegData, lngSize)
MsgBox RegData, vbOKOnly, "o2 proxy"
lngResult = RegCloseKey(hlngSubKey)
End Sub
Private Sub Form_OKClick()
App.End
End Sub
unfortunately when I press the button I only get a blank window. it wount show the proxy.
can someone tell me what I'm doing wrong?
oh and I still dont know how I could detect wether there is an active sync connection open or not. any ideas on that?
uhm, no one here who knows some eVB?
_4saken_ said:
Dim RegData As Integer
Click to expand...
Click to collapse
RegData should be declared as
Code:
Dim RegData As String
thanks for the answer but changing it to string didnt help. I still get an empty msg box.
any other ideas what I'm doing wrong?

Simulate Button Click

Hi,
I am trying to simulate a PictureBox.Click event. I have searched these forums and the ones on MSDN with many different combinations of search terms.
However I cannot find anything!
Basically what I am trying to achieve is to fire the picturebox's click event from within my code. What I have read so far seems to indicate that I need to make a call to SendMessage (COM interop?) to actually make windows perform the click.
This is for the compact framework version 1.0.
Any help you can give would be great because this is all very new to me, I'm a web application developer by trade so i'm a fish out of water on this one!
OK, the other method that I am investigating is the use of the mouse_event as demonstrated in this article by Daniel Moth.
However I am struggling to find the namespace Win32Api anywhere in the framework so I'm struggling with that also.
*Update*
I have been able to simulate a click using mouse_event in a call to the coredll using the following code:
Code:
[DllImport("coredll")]
static extern bool SetCursorPos(int X, int Y);
[DllImport("coredll")]
static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData, int dwExtraInfo);
[Flags]
public enum MouseEventFlags
{
LEFTDOWN = 0x00000002,
LEFTUP = 0x00000004,
MIDDLEDOWN = 0x00000020,
MIDDLEUP = 0x00000040,
MOVE = 0x00000001,
ABSOLUTE = 0x00008000,
RIGHTDOWN = 0x00000008,
RIGHTUP = 0x00000010
}
bool tempVal = SetCursorPos(x, y);
mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
however I have one outstanding problem (that I know of!).
I am struggling to capture the corrext X and Y co-ordinates of the control. I have tried many different methods and they all return values of 0 for both axis.
How do you guys do it?
Many Thanks
I haven't answered till now since I don't know .NET
But since you found your way to using native APIs I think I can help you.
This is how I would do it in C/C++:
Code:
RECT wndRect; //this is a structure that contains window top, left, bottom and right coordinates.
GetWindowRect(FindWind(L"[I]window class[/I]", L"[I]window name[/I]"), &wndRect);
x = wndRect.left + 1; //add 1 to window position to make sure the click is inside
y = wndRect.top + 1;
GetWindowRect returns the window position in screen coordinates for top left and bottom right corners.
For FindWindow to work you need to know the class and name of the window you want to find. You can find them using a utility called SPY++ which comes with any Microsoft C++ compiler.
The class is window type (so it will probably be something like 'PictureBox' or 'Image') and window name is most likely blank.
Hope this helps.
Thanks fo your help
I don't know if your code would have done the trick or not but I managed to work my way through the different class definitions to find what i needed.
Code:
int x = selectedButton.PointToScreen(selectedButton.Bounds.Location).X + 2;
int y = selectedButton.PointToScreen(selectedButton.Bounds.Location).Y + 2;
This still doesn't work but I really don't have time to work out why, all I know is that the call to SetCursorPos() returns false. I know the mouse_event code works because if I position the cursor over the Start button it opens the menu.
Time is of an essence so for now I'm just going to have to drop this and pray that I have time to finish this when towards the end of my project.
/me thinks writing my first Mobile 5.0 application in 4 days (I'm a web application developer by trade) was bad planning on the management's fault anyway
Thanks for your input though
use this method signature:
[DllImport("coredll")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
int instead of uint or long.
For me it worked.

Problem creating Registry Keys - VB.NET CF 1.x

Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?
Here the important part of my code:
Code:
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long
Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long
Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)
CreateNewKey = hNewKey
RegCloseKey(hNewKey)
End Function
...
i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.
BongoUser said:
Hi, if i create a registry key i get an NonSupportet Exception.
Can someone Help?
Here the important part of my code:
Code:
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_ALL_ACCESS = &H3F
Public Const REG_OPTION_NON_VOLATILE = 0
Private Declare Function RegCreateKeyEx Lib "coredll.dll" Alias "RegCreateKeyExW" ( _
ByVal hkey As Long, _
ByVal lpSubKey As String, _
ByVal Reserved As Long, _
ByVal lpClass As String, _
ByVal dwOptions As Long, _
ByVal samDesired As Long, _
ByVal lpSecurityAttributes As Long, _
ByRef phkResult As Long, _
ByRef lpdwDisposition As Long) As Long
Public Shared Function CreateNewKey(ByVal lSection As Long, _
ByVal sNewKeyName As String) As Long
Dim hNewKey As Long
Dim lRetVal As Long
RegCloseKey(lSection)
--HERE--> lRetVal = RegCreateKeyEx(lSection, sNewKeyName, 0, _
vbNullString, REG_OPTION_NON_VOLATILE, _
KEY_ALL_ACCESS, _
0, hNewKey, lRetVal)
CreateNewKey = hNewKey
RegCloseKey(hNewKey)
End Function
...
i call for example:
CreateNewKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Today\Items\""Wireless""" )
Please help.
Thanks.
Click to expand...
Click to collapse
Hi,
1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.
If it is not the problem then:
2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.
Hope it helps,
Cheers,
.Fred
ps.: use a real program language like C/C++. VB is crap!!!
dotfred said:
Hi,
1) I wouldn't use lRetVal for the last parameter and the return function value. The last parameter returns the disposition value and the function return value returns 0 for success or an error that you can find in WINERROR.H and so in MSDN documentation.
If it is not the problem then:
2) In place of trying to create a key in HKLM, try first in HKCU, maybe the problem doesn't reside in the code but in the fact that you are trying to create a key in HKLM where you need "authorization" to do it. Your application needs to have privileges like being signed.
Hope it helps,
Cheers,
.Fred
ps.: use a real program language like C/C++. VB is crap!!!
Click to expand...
Click to collapse
Hi,
it works nowm thanks.
I have found a working sample in www.

Capturing the Talk Key?

I am pasting this from my post on the MS .NETCF Dev Forums:
========================8< snip ======================
Hello.
I cannot seem to find a complete example for this, and as I am new to using unmanaged code, I need a COMPLETE one. If there is a MANAGED way to do this - great, but I certainly can't find one. Even the SHCMBM_OVERRIDEKEY constant was buried so far into the docs I needed spelunking equipment to find it.
I am writing a Dialer App, mostly as proof of concept. I cannot figure out how to capture the Talk key in order to actually place the call.
I pulled some constants from winuser.h and aygshell.h:
Code:
public const int WM_USER = 0x0400;
public const int SHCMBM_OVERRIDEKEY = (WM_USER + 403);
public const int VK_F3 = 0x72;
public const int VK_TTALK = VK_F3;
public const int SHMBOF_NODEFAULT = 0x00000001; // do not do default handling of this key
public const int SHMBOF_NOTIFY = 0x00000002; // send us the WM_* messages for this key
and imported some funcs from coredll and aygshell:
Code:
[DllImport("coredll.dll", SetLastError=true)]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport("aygshell", SetLastError=true)]
public static extern IntPtr SHFindMenuBar(IntPtr hwnd);
And then I have this call in InitializeComponent():
Code:
SendMessage((IntPtr)SHFindMenuBar(this.Handle), SHCMBM_OVERRIDEKEY, VK_TTALK, SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
Now I have a couple of questions.
A - is there anything wrong with all of that?
and B - in other examples, I see people somehow getting ahold of a .Message property of the Form, but I don't seem to have System.Windows.Forms.Message anywhere... Not in the namespace or off the window object itself. I assume it's being passed back in some sort of event related to the form, but what?
I hope these aren't total n00b questions, but as I asid I am really unfamiliar with how unmanaged code really works, and have never done any Win32 C++ only vanilla C++ under unix.
Thanks in advance.
====================>8 unsnip =================
In case that's not clear: I want to make the green talk button NOT launch the phone's default dialer, but instead initiate the call from within MY dialer. The actual hardware button, not a softkey and not an on-screen button.
I am using an HTC Mogul.
.NETCF 2.0
VS2005
C#
and a partridge in a pear tree!
Any help would be MUCH appreciated. I am a little surprised that there doesn't seem to be an obvious way of doing it. Seems like a rather glaring omission to the managed SDK. Perhaps there is a way and I have just missed it.
Thanks!
Bump for the daytime crew.

Categories

Resources