|
Hi,
I am trying to change the status of checkbox using SendMessage. For some reasons it's not working. Can anyone fix this for me? below is my code:
Imports System.Runtime.InteropServices
Public Class Form1
Private Const BM_GETCHECK As Long = &HF0
Private Const BM_SETCHECK As Long = &HF1
Private Const BS_AUTOCHECKBOX As Long = &H3
Private Const BST_CHECKED As Long = 1
Private Const BST_UNCHECKED As Long = 0
<DllImport("user32.dll")> _
Private Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim CheckBox As Control
CheckBox = CheckBox1
Dim value As IntPtr
value = CheckBox.Handle
SendMessage(value, BM_SETCHECK, BST_CHECKED, 0)
End Sub
End Class
Thanks in advance,
Scot
|
|
|
|
|
Isnt' that a bit extravegant when you could do the exact same thing with:
CheckBox1.Checked = True
Perhaps you've left out some details of what you intend to do with this?
|
|
|
|
|
Yes. Sorry, I didn't explain the purpose. This is just a sample spike application that i am trying to get working. The actual implementation is quite different where using API calls I am trying to check another compiled .NET application's checkbox.
-Thanks
modified on Thursday, December 18, 2008 11:42 PM
|
|
|
|
|
With inspiration from the following web site https://bytes.com/topic/net/answers/637107-how-find-out-if-check-box-checked I solved it like this in C# (it shouldn't be too hard to convert to Visual Basic):
using Accessibility;
[DllImport("oleacc.dll", PreserveSig = false)]
[return: MarshalAs(UnmanagedType.Interface)]
public static extern object AccessibleObjectFromWindow(IntPtr hwnd, uint dwId, ref Guid riid);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, StringBuilder lParam);
public static Nullable<bool> isCheckBoxChecked(IntPtr checkBoxHandle)
{
const UInt32 OBJID_CLIENT = 0xFFFFFFFC;
const int UNCHECKED = 1048576;
const int CHECKED = 1048592;
Guid uid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(checkBoxHandle, OBJID_CLIENT, ref uid);
object o2 = accObj.get_accState(0);
if ((int)o2 == UNCHECKED)
{
return false;
}
else if ((int)o2 == CHECKED)
{
return true;
}
else
{
return null;
}
}
public static void setCheckBoxChecked(IntPtr checkBoxHandle, bool shouldBeChecked)
{
bool isChecked = (bool)isCheckBoxChecked(checkBoxHandle);
if ((!isChecked) && (shouldBeChecked))
{
SendMessage(checkBoxHandle, BM_CLICK, 0, null);
}
else if ((isChecked) && (!shouldBeChecked))
{
const UInt32 OBJID_CLIENT = 0xFFFFFFFC;
Guid uid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(checkBoxHandle, OBJID_CLIENT, ref uid);
accObj.accDoDefaultAction(0);
}
}
|
|
|
|
|
The project I am currently working on involves communication with multiple embedded devices over a network.
I have managed to get to the point where I am getting all of the required information back from the devices, however, until runtime I do not know how many devices there will be.
I have defined a class for the devices which i have called 'unitclass', which has variables for all of the necessary data such as MAC address etc.
What I am wondering, is how can I create new instances of this class at runtime via iteration, ie
for n = 1 to (number of devices)<br />
dim n as new unitclass<br />
next n
Thanks, Chris
|
|
|
|
|
If I am understanding your question correctly, what I would do is add each UnitClass object which is created during your loop to a collection along with a key so that you can access each object when needed.
Please let me know if I have got the wrong end of the stick!
|
|
|
|
|
The problem i have got is that the little code snippet i wrote will not work.
I do not seem able to create an object at run time using the contents of a variable as the object name.
|
|
|
|
|
It won't work for a couple of reasons. First, you reusing your loop variable as an instance of an object. What is n supposed to be?? Is it the loop variable or is it an object? It can't be both.
Second, your creating an instance of a class and then, on the next iteration of the loop, your replacing that instance with a new one. On top of that, since you're not adding these instances to a collection anywhere, the only remaining instance, when the loop terminates, goes out of scope and is destroyed. You have to add these to a collection somewhere to hang onto them.
|
|
|
|
|
The purpose of the for loop was more to help explain what I want to do than anything else.
How would i create n instances of an object, named object 1, 2, 3, ... n. where n is unknown until the app receives n UDP Datagrams at runtime?
I do intend to add them to an arraylist and sort by a particular variable using icomparable.
Regards, Chris
|
|
|
|
|
Why would you want to create named objects anyway?? It's easily done with an array or HashTable. A hashtable example:
Dim myCollection As New Hashtable
For n As Integer = 1 to m
Dim newObject As New SomeClass
myCollection.Add(n, newObject)
Next
|
|
|
|
|
So,ething like this should work:
Dim colObjects as new collection
For n as Integer = 0 to (number of devices)
colObjects.Add(new UnitClass(), n.toString)
Next
You can then access each object of the collection like this (replacing 1 with the number of the object:
Ctype(colObjects.Item("1"), UnitClass).<<property name>> = <<property value>>
Hope this helps
|
|
|
|
|
Thanks to both of you
Until the last couple of weeks, I haven't had to do any serious VB programming for almost 10 years (I mainly code asm for uprocessors), and it's changed a hell of a lot!
Still trying to grasp the system.collections basics...
Regards, Chris
|
|
|
|
|
Hello there,
I have developed an application in VB 2005 backend SQL 2005 Reporting Crystal report 9.0
well now the application is tested everything is done
Now in end simply i want to make a setup for an entire application so that it can be burn into cd's and and be installed on other computers..
Any one can help me with brief.???
Thanks
Kenny.
|
|
|
|
|
You can add a Setup project to your solution and use that. It's not meanth for more complicated installs though. Or, you can use Wise Package Studio, InstallShield, InnoSetup, ... Just Google for "create windows installer" and you'll find other packages that can do this.
|
|
|
|
|
can anybody help me with a vb code that will browse into the folder and then delete/empty all its contents say, to another folder.
phokojoe
|
|
|
|
|
Please, its so easy to do a search here to find the answer to this, there have been similar questions several times in the last few days.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Its really not that hard......
System.IO Perhaps?
And technically you cant delete a file and then move it to another folder.
Lloyd J. Atkinson
|
|
|
|
|
hi every one i want to develop a hotel reservation system. please can someone help, tell me all the requirements i am not very food in programming. i don't know where to start from. thank you. Steven
|
|
|
|
|
sturabumukiza wrote: hi every one i want to develop a hotel reservation system. please can someone help, tell me all the requirements i am not very food in programming. i don't know where to start from
So, why do you want to do this then?
|
|
|
|
|
Well first of all, YOU have to document the requirements, we can't do this as it's your system and you're supposed to know what is required. Once you have the requirements you can then make some decisions on what technologies to use, i.e. what programming language, database system etc. You can then start to design your application with these decisions in mind.
If what I have said makes no sense to you then I suggest reading some books on software design and development first before even contemplating any programming.
|
|
|
|
|
sturabumukiza wrote: i don't know where to start from
Turn off the PC, tell your client you were robbing them, or tell your teacher the subject is beyond you.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
|
Of course, if he onsells this, he is scum, and if he hands it in to class, he deserves to fail.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
I just give sample project instant of requirement. and that is done vb6.0 and done in long back.
He will get some idea. it is wrong Christian
|
|
|
|
|
Plus he will also be nothing but a Fool.
Lloyd J. Atkinson
|
|
|
|