Heath Thanks again. Your comments are sufficient for me to sort this out now. benny
bennyrascal
Posts
-
Capturing mouse movement while transparent -
Capturing mouse movement while transparentG'day Have a little program that captures mouse movements and displays the form and relative mouse location on labels on the form in real time. It also allows the form to be dragged while the mouse button is pressed. There is also a rich text box which has text in it. The form's transparency key and the rich text box colour are the same so that the rich text box is transparent. There are buttons which set the rich text box's enable property to either true or false. When the disable button is pressed, the enable property is set to false. This has the effect of allowing the mouse movement to be captured over the rich text box area. When the enable button is pressed, the enable property is set to true. Now, mouse movement is not captured in the rich text box area. Basically, things are working as I expect them to. Want I would like to do is to be able to drag the form while the rich text box is enabled or transparent. I know this can be done as there is a program called "DSCLOCK" which does it. It might be using a normal text box or a label. It doesn't matter to me. Just want a way to allow the area to be moved and still be transparent. Thought about trying to capture the mouse movements at a parent level (Windows). Thought that would let me see all mouse movement and then I could sort out which bits I wanted. Does anyone know how this can be done? Sorry about the size of this but it will be easier to see what i'm doing if you cut and paste this into a new C# project. benny ************************************************************ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace RichTextBox { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private int mousePressedX, mousePressedY; private System.Windows.Forms.RichTextBox rTxt1; private System.Windows.Forms.Label lblMouseStatus; private System.Windows.Forms.Label lblMouseLocation; private System.Windows.Forms.Button btnEnable; private System.Windows.Forms.Button btnDisable; private System.Windows.Forms.Button btnExit; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label lblFormLocation; private System.Windows.Forms.GroupBox groupBox2; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() {
-
updating system time in c#Thanks Heath, Had totally missed the ref bit. Changed the declaration to what you suggested and then there were compile errors on the SetSystemTime call. Changed it to ” result = SetSystemTime(ref timeStru);” and also changed the result from int to bool. It works now. The reason for P/Invoke being public was that I cut and pasted it from a forum. My technique in building applications is to write and test little functions separately before moulding them into the final source. So these little stubs are often a bit sloppy. Thanks again benny
-
updating system time in c#Pulled this description of CType from a .NET forum: Q: What are the differences between Ctype and (cint,cstr,cool,etc...) S: VB.NET A: The Ctype keyword is used to perform an explicit conversion also known as casting, the Ctype keyword when used will also check for a valid destination data type or an error will occur, such as converting a long to integer. The other keywords Cint, Cbool,etc do not check for valid data types and they are about 3 times faster than Ctype because the code is included in the MSIL. i think it is not relevant to the problem. SetSystemTime has one parameter sent to it and it is a datatype which is the structure which the program defined as SYSTEMTIME. When i trace the code stopping at the "result = SetSystemTime(timeStru);" statement in both VB and C#, i can see the data that is parsed to it. The actual time and date fields are the same. The top level of the structures are a little different though. it is easy to test my code as i pasted most of it. Only needs a few using statements and a small wrapper to get it going. i'll supply the whole lot if asked for. benny
-
updating system time in c#Am trying to update the system time using c#. Have a bit of code written in VB.NET that I’ve plundered ( from Alastair Dallas) , which works. The VB code is: _ Public Structure SYSTEMTIME Public wYear As Int16 Public wMonth As Int16 Public wDayOfWeek As Int16 Public wDay As Int16 Public wHour As Int16 Public wMinute As Int16 Public wSecond As Int16 Public wMilliseconds As Int16 End Structure Private Declare Function GetSystemTime Lib "kernel32.dll" (ByRef stru As SYSTEMTIME) As Int32 Private Declare Function SetSystemTime Lib "kernel32.dll" (ByRef stru As SYSTEMTIME) As Int32 Public Shared Sub SetWindowsClock(ByVal dt As DateTime) 'Sets system time. Note: Use UTC time; Windows will apply time zone Dim timeStru As SYSTEMTIME Dim result As Int32 timeStru.wYear = CType(dt.Year, Int16) timeStru.wMonth = CType(dt.Month, Int16) timeStru.wDay = CType(dt.Day, Int16) timeStru.wDayOfWeek = CType(dt.DayOfWeek, Int16) timeStru.wHour = CType(dt.Hour + 2, Int16) ' used to verify system time is actually changed timeStru.wMinute = CType(dt.Minute, Int16) timeStru.wSecond = CType(dt.Second, Int16) timeStru.wMilliseconds = CType(dt.Millisecond, Int16) result = SetSystemTime(timeStru) End Sub ************************************************** Have converted this to C# as follows: [StructLayout(LayoutKind.Sequential)] public struct SYSTEMTIME { public Int16 wYear; public Int16 wMonth; public Int16 wDayOfWeek; public Int16 wDay; public Int16 wHour; public Int16 wMinute; public Int16 wSecond; public Int16 wMilliseconds; } [DllImport("kernel32.dll")] public static extern int SetSystemTime(SYSTEMTIME lpSystemTime); public static void SetWindowsClock(DateTime dt) { SYSTEMTIME timeStru; int result; timeStru.wYear = ((Int16)dt.Year); timeStru.wMonth = ((Int16)dt.Month); timeStru.wDay = ((Int16)dt.Day); timeStru.wDayOfWeek = ((Int16)dt.DayOfWeek); timeStru.wHour = ((Int16)dt.Hour); timeStru.wMinute = ((Int16)dt.Minute); timeStru.wSecond = ((Int16)dt.Second); timeStru.wMilliseconds = ((Int16)dt.Millisecond); result = SetSystemTime(timeStru); } The C# code crashes on the SetSystemTime(timeStru). While tracing, the only thing I noticed which
-
List 2.0 checkbox and togglebuttonThanks Can't use true as i get a compiler error: D:\Development\C++\Source\CheckBoxes\CheckBoxesDlg.cpp(195) : warning C4805: '==' : unsafe mix of type 'struct tagVARIANT (__thiscall CMdcToggleButton::*)(void)' and type 'const bool' in operation When using the class wizard to add a member variable the only choice i have is a category of control and a variable type of CMdcToggleButton. There are no other choices. If i use the standard checkBox then i get the categories of control and of value and the value bit works. As far as the updatedata, Here is the actual code: void CCheckBoxesDlg::OnClickToggleButton1() { UpdateData(TRUE); m_ToggleButton1Control.UpdateData(TRUE); m_ToggleButton1Control.GetValue(); if (m_ToggleButton1Control.GetValue == false) {m_ToggleButton1Control.SetForeColor(olive_note);} else {m_ToggleButton1Control.SetForeColor(red_note);} } As you can see i even did the update two different ways as an experiment. A similar function for a simple checkbox works perfectly: void CCheckBoxesDlg::OnClickFormsCheckBox1() { UpdateData(TRUE); if (m_FormsCheckBox1Control.GetValue == 0) { m_CommandButtonControl.SetForeColor(blue_note); m_CommandButtonControl.SetCaption("FormsCheckBox set on"); m_FormsCheckBox1Control.SetBackColor(blue_note); } else { m_CommandButtonControl.SetForeColor(yellow_note); m_CommandButtonControl.SetCaption("FormsCheckBox set off"); m_FormsCheckBox1Control.SetBackColor(yellow_note); } } Again thanks for any help as i'm baffled. benny
-
List 2.0 checkbox and togglebuttonHave revisited a C++ program i wrote about 6 years ago. It used the THREED vbx controls. Am now using Visual C++ 6.0 and i can not develop with them as they need a licence. Originally got them from buying the SAMS Visual C++ 1.5 book and CD. Anyway, i decided to replace them with an ocx that is more available. When i did an 'insert activex control', the Microsoft Forms 2.0 controls were available. Had no probs replacing my command buttons and frames but the check boxes have been a nightmare. Then i thought the toggle button might look better and tried it. Still a nightmare. Where my problem lies is in seeing the state of the checkbox and/or toggle button. Thought the following line would differentiate between depressed and not depressed: if (m_ToggleButton1Control.GetValue == false) However, it always returns true. i use other properties that work: {m_ToggleButton1Control.SetForeColor(olive_note);} The 'value' is defined as a VARIANT of which i can not find any documentation. Can anyone help??? benny