|
i extented ...
[StructLayout(LayoutKind.Sequential)]
private struct NMHDR
{
public IntPtr hwndFrom;
public int idFrom;
public int code;
}
to ...
[StructLayout(LayoutKind.Sequential)]
private struct NMHDR2
{
public IntPtr hwndFrom;
public int idFrom;
public int code;
public int coder;
}
this new variable 'coder' contains numbers, like: -12, -16, -23 -320, -321, -326 -327, -530
-12 and -530 seam to be mouseover and mouseleave.
-16 and -326 seam to be mouseclick / down and mouse release.
i posted a logoutput.
http://pastebin.com/HuCk5cac[^]
anyone experienced with this?
Bad = knowing 2 much
modified on Tuesday, April 27, 2010 2:47 PM
|
|
|
|
|
this is the entire code to create a listview with a checkbox in the left upper corner of the ListView.
NM_CUSTOMDRAW seams to be the message when the mouse hover over the headers.
but i fail to keep the checkBox visible / ontop @ all time.
if you slightly hoover of the first header, the headers mousehover effect draws over the check.
anyone an idea how to prevent this?
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Listview_Colum_header_checkbox
{
class CCehckBox2 : CheckBox
{
public CCehckBox2()
{
Width = 14;
Height = 14;
}
}
class CustomChechBox2 : Control
{
readonly CCehckBox2 _chb = new CCehckBox2();
public CustomChechBox2()
{
Size = new Size(16, 16);
_chb.Location = new Point(0, 0);
Controls.Add(_chb);
}
}
class CListview2 : ListView
{
public delegate void MessageNeedsSendingCallback(string message, Color color);
public event MessageNeedsSendingCallback OnMessageNeedsSending;
private readonly CustomChechBox2 _cCehckBox = new CustomChechBox2();
private readonly ColumnHeader _header1, _header2, _header3 = new ColumnHeader();
#region PInvoke Declarations
[DllImport("User32", CallingConvention = CallingConvention.Cdecl)]
private static extern uint RealGetWindowClass(IntPtr hwnd, System.Text.StringBuilder pszType, int cchType);
[DllImport("user32")]
private static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
#endregion
public CListview2()
{
View = View.Details;
_header1 = Columns.Add("");
_header1.Width = (Location.X + 5) + 12;
_header1.Name = "CheckBox";
_header1.DisplayIndex = 0;
_header2 = Columns.Add("bah");
_header2.Width = 50;
_header3 = Columns.Add("boh");
_header3.Width = 50;
var wijd = _cCehckBox.Width;
var hoog = _cCehckBox.Height;
_cCehckBox.Location = new Point((Location.X + 5), (Location.Y + 5));
}
protected override void OnHandleCreated(EventArgs e)
{
SetParent(_cCehckBox.Handle, Handle);
base.OnHandleCreated(e);
}
[StructLayout(LayoutKind.Sequential)]
private struct NMHDR
{
public IntPtr hwndFrom;
public int idFrom;
public int code;
public int coder;
}
private const int WM_NOTIFY = 0x4E;
private const int CCM_FIRST = 8192;
private const int CCM_SETBKCOLOR = (CCM_FIRST + 1);
private const int CCM_SETCOLORSCHEME = (CCM_FIRST + 2);
private const int CCM_GETCOLORSCHEME = (CCM_FIRST + 3);
private const int CCM_GETDROPTARGET = (CCM_FIRST + 4);
private const int CCM_SETUNICODEFORMAT = (CCM_FIRST + 5);
private const int CCM_GETUNICODEFORMAT = (CCM_FIRST + 6);
private const int HDN_FIRST = (0 - 300);
private const int HDM_FIRST = 4608;
private const int HDM_HITTEST = (HDM_FIRST + 6);
private const int HDM_GETITEMRECT = (HDM_FIRST + 7);
private const int HDM_SETIMAGELIST = (HDM_FIRST + 8);
private const int HDM_GETIMAGELIST = (HDM_FIRST + 9);
private const int HDM_ORDERTOINDEX = (HDM_FIRST + 15);
private const int HDM_CREATEDRAGIMAGE = (HDM_FIRST + 16);
private const int HDM_GETORDERARRAY = (HDM_FIRST + 17);
private const int HDM_SETORDERARRAY = (HDM_FIRST + 18);
private const int HDM_SETHOTDIVIDER = (HDM_FIRST + 19);
private const int HDM_SETUNICODEFORMAT = CCM_SETUNICODEFORMAT;
private const int HDM_GETUNICODEFORMAT = CCM_GETUNICODEFORMAT;
private const int HDN_ITEMCHANGINGA = (HDN_FIRST - 0);
private const int HDN_ITEMCHANGINGW = (HDN_FIRST - 20);
private const int HDN_ITEMCHANGEDA = (HDN_FIRST - 1);
private const int HDN_ITEMCHANGEDW = (HDN_FIRST - 21);
private const int HDN_ITEMCLICKA = (HDN_FIRST - 2);
private const int HDN_ITEMCLICKW = (HDN_FIRST - 22);
private const int HDN_ITEMDBLCLICKA = (HDN_FIRST - 3);
private const int HDN_ITEMDBLCLICKW = (HDN_FIRST - 23);
private const int HDN_DIVIDERDBLCLICKA = (HDN_FIRST - 5);
private const int HDN_DIVIDERDBLCLICKW = (HDN_FIRST - 25);
private const int HDN_BEGINTRACKA = (HDN_FIRST - 6);
private const int HDN_BEGINTRACKW = (HDN_FIRST - 26);
private const int HDN_ENDTRACKA = (HDN_FIRST - 7);
private const int HDN_ENDTRACKW = (HDN_FIRST - 27);
private const int HDN_TRACKA = (HDN_FIRST - 8);
private const int HDN_TRACKW = (HDN_FIRST - 28);
private const int HDN_GETDISPINFOA = (HDN_FIRST - 9);
private const int HDN_GETDISPINFOW = (HDN_FIRST - 29);
private const int HDN_BEGINDRAG = (HDN_FIRST - 10);
private const int HDN_ENDDRAG = (HDN_FIRST - 11);
private const int HDN_ITEMCHANGING = HDN_ITEMCHANGINGA;
private const int HDN_ITEMCHANGED = HDN_ITEMCHANGEDA;
private const int HDN_ITEMCLICK = HDN_ITEMCLICKA;
private const int HDN_ITEMDBLCLICK = HDN_ITEMDBLCLICKA;
private const int HDN_DIVIDERDBLCLICK = HDN_DIVIDERDBLCLICKA;
private const int HDN_BEGINTRACK = HDN_BEGINTRACKA;
private const int HDN_ENDTRACK = HDN_ENDTRACKA;
private const int HDN_TRACK = HDN_TRACKA;
private const int HDN_GETDISPINFO = HDN_GETDISPINFOA;
private const int NM_FIRST = 0;
private const int NM_OUTOFMEMORY = (NM_FIRST - 1);
private const int NM_CLICK = (NM_FIRST - 2);
private const int NM_DBLCLK = (NM_FIRST - 3);
private const int NM_RETURN = (NM_FIRST - 4);
private const int NM_RCLICK = (NM_FIRST - 5);
private const int NM_RDBLCLK = (NM_FIRST - 6);
private const int NM_SETFOCUS = (NM_FIRST - 7);
private const int NM_KILLFOCUS = (NM_FIRST - 8);
private const int NM_CUSTOMDRAW = (NM_FIRST - 12);
private const int NM_HOVER = (NM_FIRST - 13);
private const int NM_NCHITTEST = (NM_FIRST - 14);
private const int NM_KEYDOWN = (NM_FIRST - 15);
private const int NM_RELEASEDCAPTURE = (NM_FIRST - 16);
private const int NM_SETCURSOR = (NM_FIRST - 17);
private const int NM_CHAR = (NM_FIRST - 18);
protected override void WndProc(ref Message message)
{
bool callBase = true;
switch (message.Msg)
{
case WM_NOTIFY:
NMHDR nmhdr = (NMHDR)message.GetLParam(typeof(NMHDR));
OnMessageNeedsSending("code: " + nmhdr.code + ", hwndFrom: " + nmhdr.hwndFrom + ", idFrom: " + nmhdr.idFrom + ", coder: " + nmhdr.coder, Color.Black);
switch (nmhdr.coder)
{
case HDN_BEGINTRACKA:
OnMessageNeedsSending("HDN_BEGINTRACKA " + message, Color.Black);
break;
case HDN_BEGINTRACKW:
OnMessageNeedsSending("HDN_BEGINTRACKW " + message, Color.Black);
break;
case HDN_ENDTRACKW:
OnMessageNeedsSending("HDN_ENDTRACKW " + message, Color.Black);
break;
case HDN_ITEMCLICKA:
OnMessageNeedsSending("HDN_ITEMCLICKA " + message, Color.Black);
break;
case HDN_ITEMDBLCLICKW:
OnMessageNeedsSending("HDN_ITEMDBLCLICKW " + message, Color.Black);
break;
case HDN_ITEMCLICKW:
OnMessageNeedsSending("HDN_ITEMCLICKW " + message, Color.Black);
break;
case HDN_ITEMCHANGINGW:
OnMessageNeedsSending("HDN_ITEMCHANGINGW " + message, Color.Black);
break;
case HDN_ITEMCHANGEDA:
OnMessageNeedsSending("HDN_ITEMCHANGEDA " + message, Color.Black);
break;
case HDN_ITEMCHANGEDW:
OnMessageNeedsSending("HDN_ITEMCHANGEDW " + message, Color.Black);
break;
case NM_HOVER:
OnMessageNeedsSending("NM_HOVER " + message, Color.Black);
break;
case NM_RELEASEDCAPTURE:
OnMessageNeedsSending("NM_RELEASEDCAPTURE" + message, Color.Black);
break;
case NM_CUSTOMDRAW:
callBase = false;
OnMessageNeedsSending("NM_CUSTOMDRAW" + message, Color.Black);
_cCehckBox.BringToFront();
_cCehckBox.Invalidate();
break;
default:
OnMessageNeedsSending("code: " + nmhdr.code + ", hwndFrom: " + nmhdr.hwndFrom + ", idFrom: " + nmhdr.idFrom + ", coder: " + nmhdr.coder, Color.Black);
break;
}
break;
}
if (callBase)
{
base.WndProc(ref message);
}
}
}
}
Bad = knowing 2 much
|
|
|
|
|
So the deeper I get into my first Windows Forms application the more I'm questioning myself. In the VB6 days I would distribute my apps with a password protected MS Access db (not very secure) and hope nobody hacked into it.
In this app. I created my MDF in MS SQL 2008, copied the mdf and ldf to my VS 2008 application directory and set up a datasource connection to it. When I view the db in VS 2008 I see all of my tables, views and sproc's but I do not see a security node or users. So does my mdf get distributed with no security? Can anyone just attach it to their local MSSQL version and open the db? If it is in fact wide open, can it be locked down or do I need a different solution?
|
|
|
|
|
It's wide open. (SQL Server 2008 R2 has an encryption option, but probably not in the express edition).
The problem is that you cannot encrypt these files, because they will be opened by the SQLServer service, running under Userid that has probably no access to the encryption keys.
If you want to encrypt your database, distribute an SQL Server Compact 3.5 database, and attach a password to it (which of course will be known to your program, and suitably obfuscated in the executable)
|
|
|
|
|
Thank you Michel -
I actually started this project using SqlCe but I was worried it would not be robust enough or become corrupt so I switched.
|
|
|
|
|
|
add the below line at end of your code
label5.Refresh();
Cheers
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
thanks =)
but the solution is to use Convert.toString(anydouble) instead of anydouble.toString()
|
|
|
|
|
Why did you delete your question? Now all we have an answer to an unknown question.
|
|
|
|
|
Kind of like sitting with "42", not knowing what the question is.
Quite frustrating acutally..
|
|
|
|
|
I working in solution vb.net for convert to C#.
my question about this " CopyFile(My.Application.Info.DirectoryPath & "\Ids", "Z:\ID", 1)".
wath the function for this and how do that in C#? .
thnks
|
|
|
|
|
Use System.IO Name Space
System.IO.File.Copy (SourceFilename,TragetFilename);
Cheers
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
|
You could probably just put it in a VB.net/C# converter..
|
|
|
|
|
|
I'm not sure what that means
|
|
|
|
|
Hi,
I have been building a project in OpenGL, and the code to display text I have been using is
Glut.glutBitmapCharacter() which cant be rotated.
There are loads of tutorials out there for C and C++, but not for C#.
Do anyone know how to rotate text in OpenGl, or a good step tutorial.
This is the code class I used to render my text
class String
{
public String()
{
}
public void RenderString(double p_x, double p_y, string str, float rotateAngle)
{
float x = (float)p_x;
float y = (float)p_y;
Gl.glRasterPos2f(x, y);
int len = str.Length;
for (int i = 0; i < len; i++)
{
Gl.glClearColor(0, 0, 0, 0);
Gl.glColor3f(0, 0, 0);
Glut.glutBitmapCharacter(Glut.GLUT_BITMAP_HELVETICA_18, str[i]);
}
}
}
}
|
|
|
|
|
why don't just use c++.
you can included a c++ dll.
but you also could download Nokia Qt C++.
http://qt.nokia.com[^]
download the creator + sdk bundle.
there are many working opengl examples + code included.
very very impressive examples.
c++ is a faster than c# and THE choice for directX and OPENGL.
there is also the TAO dll for c#, but it looks abandoned.
c# is mainly for cheap office develpment, go c++ if you want speed.
Nokia Qt rocks even better for office develpment, every control is opensource, it's easier to hook special needs.
Qt includes a TimeLine class for special effects.
Qt wil rule in the future.
check for Kinetic scrolling tutorial.
google earth is made with Qt and many other, like Adobe use Qt
Bad = knowing 2 much
modified on Tuesday, April 27, 2010 10:36 AM
|
|
|
|
|
I didnt know I could use c++.dll in C#, im writing it in C~ two reason one my C++ isnt good enough, and the program im writing this plug in for is writen in C#.
Thanks very much will have a looked the links.
|
|
|
|
|
there aint much too c++.
the synthax is pretty simular, but you have to take care of cleaning recources used yourself.
in c# you have the garbage handler, in c++ you don't.
in c++ you would have to make a dispose methode pretty much everywhere and it looks very very simular too c#
that's what makes c# the competitor of java.
cheap develpment software.
cheap ... because it needs less time and less acuracy to create something.
you don't have to take care of freeing up recources that aren't used anymore, so you never really know if you software is actually 100%, because you don't need to think about it.
if it wasn't for the 3rd party dll i use to connect to a virtual world.
i wouldn't be using c# at all.
translating this 3rd party dll into c++, would take me a year or so.
but the downfall of DOTNET is ... you can easy reverse engineer your aplication and resell or hack it.
with a simple click in a tool from the internet, you pretty much get the entire code.
if you read about dotnet, you would have read the each executable actually transports the entire source and recompiles on the user machie.
this is done by the JIT compiler.
dotnet wil never be the tool by excellence for software venders.
dotnet is used by people that didn't like the looks or feel of java, but also aren't competent or too lazy for c++.
i don't live from coding, but this is what i learned in the last years.
if my current project is done, i'm going Nokia Qt.
power @ finger tips
Bad = knowing 2 much
|
|
|
|
|
Natural_Demon wrote: dotnet is used by people that didn't like the looks or feel of java, but also aren't competent or too lazy for c++.
I disagree!
I'm not lazy and consider myself to be competent in many languages, but I use C# almost exclusively.
The vast majority of the software I write is for use with bespoke in-house systems where security of source code is simply not an issue. I use C# because it enables me to quickly develop powerful applications and utilities as required in far less time than would be possible using C++.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
bespoke in-house systems = cheap.
'quickly' develop powerful application = cheap.
you boss or what ever pays less, becaue it takes less, right?
so you do agree with me, be it in other words.
regarding 'lazy' didn't count for all readers.
Bad = knowing 2 much
|
|
|
|
|
bespoke in-house systems != cheap; far from it. The cost of having a team of full time staff developing our systems is much greater than buying off the shelf stuff, and greater than having stuff written for us. It's worth while because:
We can change requirements and make alterations when needed.
The costs are constant - even if high.
We have full control over every single line of code.
Natural_Demon wrote: 'quickly' develop powerful application = cheap.
cheap == cost effective. Also, we add/create apps/utilities because we need them - that means we need them ASAP, not after a delay caused by a choice of language.
Don't get me wrong, C/C++ has it's place but so does C#, and it's positives should never be viewed as derogatory to the language or it's users.
If VB or Mickey Mouse for Windows did the job better for us then that's what we'd use. C# strikes the right balance for us in these situations, in others we do use other languages.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Hi,
maybe it's a simple problem for most of you, but I can't find an easy way to quite simple problem, let me describe:
Let's have this code:
<code>public ClassToChange()
{
...
internal List<AnyDataClass> LockAndGetData()
{
Monitor.Enter(cs);
return data;
}
internal Unlock()
{
Monitor.Exit(cs);
}
private object cs = new object();
private List<AnyDataClass> data = new List<AnyDataClass>();
}
public class Editor
{
public Editor(ClassToChange editedObject)
{
this.editedObject = editedObject;
}
public void MyFunctionToChangeData()
{
List<AnyDataClass> data = editedObject.LockAndGetData();
...
editedObject.Unlock();
}
private ClassToChange editedObject;
}
class Program
{
static void Main()
{
Editor ed = new Editor(new ClassToChange());
ed.MyFunctionToChangeData();
}
}</code>
So my aim is to let Editor change the data of ClassToChange in a thread-safe way. But as you can see to call all the List<anydataclass> data = editedObject.LockAndGetData(), then not to forget the editedObject.Unlock() is very boring to write (and not so safe). Do you have any easy solution for this?
Only solution I have, there might be the CS as attribute of ClassToChange and use lock {} in Editor, but I would need an attribute to every data object of ClassToChange, who would check if the cs is locked to make it safe. So that's also not a good way.
Any ideas?
Michal
modified on Tuesday, April 27, 2010 5:16 AM
|
|
|
|
|
You could potentially use Action<T> delegates to do this. Something like this:
public class ClassToChange
{
private object cs = new object();
private List<String> data = new List<String>();
public void LockAndMakeChange(Action<List<String>> changeAction)
{
lock (cs)
{
changeAction(data);
}
}
}
public class Editor
{
private ClassToChange editedObject;
public Editor(ClassToChange editedObject)
{
this.editedObject = editedObject;
}
public void MyFunctionToChangeData()
{
editedObject.LockAndMakeChange((data) =>
{
data.Add("new string");
});
}
}
This would achieve what you are trying to do. It means your editor only has to call LockAndMakeChange and doesn't have to worry about unlocking afterwards because the class handles it after the action has completed, and your lock object remains private (which is good).
However, you need to be careful with this. By allowing external code to run inside an internally private lock you are introducing a great risk of deadlocking. It is having a similar effect to making your locks public (which is bad). If you aren't very careful other code may be able to take advantage of your exposed locking methods to crash or hang your app.
Instead, I would think about having the modification done entirely within the class so no external code runs within the lock. You could have methods like this that just took in the data and did the modification internally:
public void AddNewString(String newString)
{
lock (cs)
{
data.Add(newString);
}
}
public void AddNewString(params String[] newStrings)
{
lock (cs)
{
data.AddRange(newStrings);
}
}
public void AddNewString(IEnumerable<String> newStrings)
{
lock (cs)
{
data.AddRange(newStrings);
}
} Then you would call it like this:
public void MyFunctionToChangeData()
{
editedObject.AddNewString("new");
editedObject.AddNewString("new1", "new2", "new3");
List<String> newStrings = new List<string>();
newStrings.Add("new4");
newStrings.Add("new5");
newStrings.Add("new6");
editedObject.AddNewString(newStrings);
}
This keeps your encapsulation higher and reduces the risk of deadlocking.
Simon
|
|
|
|
|