snarfblam
Leaders-
Posts
2156 -
Joined
-
Last visited
-
Days Won
2
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by snarfblam
-
The first question you should be asking yourself when dealing with a NullReferenceException is which variable (or object refernce) is null (i.e. "Nothing"). Look at the code: If Dir([color="Red"]pfile(j)[/color]) = "" Then There are two references used in the line of code. A reference to the array pfile, and reference to an object within the array, pfile(j). You can use the debugger to examine the array and its contents to see which reference is null. You would discover that pfile is not null, but pfile(j) returns a null reference (i.e. Nothing). To figure out why pfile(j) is null, you need to consider all the places that the value can be assigned. In this case, pfile(j) is only assigned in one place: [color="Red"]pfile(j) =[/color] VSFlexGrid1.Text This must be where pfile(j) is set to null, because this is the only place pfile(j) is ever set. This means that VSFlexGrid1.Text is returning a null reference.
-
Re: C# - Drawing an image (sprite) with Direct3D We can't identify what is wrong with your code based only on knowing that it is running slowly. I recommend you post the code that is run each frame. I wouldn't worry about which file format is faster. The texture should only be loaded once, either when the program starts or when it is first needed. Once a texture is loaded, it is stored as a texture, not a PNG, BMP, or whatever. So unless you are experiencing an extraordinarily long load time when the program starts, I wouldn't worry about which format loads the fastest.
-
I was pretty sure I could see what was wrong with your code off the bat, but I wanted to be sure that it explained the behavior you were seeing, so I changed your code to this: Public Class Form1 Private Delegate Sub SetCloseCallback() Private Sub SetClose() Throw New InvalidOperationException End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Invoke(New SetCloseCallback(AddressOf SetClose), New Object() {}) End Sub End Class [/Code] When run, this code behaves the same way, i.e. nothing happens. I'm obviously throwing an exception, but it's not being caught. I'm not sure exactly why, but the exception is being swallowed somewhere. My guess is that it is related to the Invoke function. This is a problem though, because when you don't get the exception you can't figure out what's going on. If you put a breakpoint at the top of the SetClose function you would see that it's never even being called. The issue is with your use of Invoke; you don't need to specify [font=Courier New][color=Blue]Me[/color][/font] in your argument list. (The target, [font=Courier New][color=Blue]Me[/color][/font], is actually bound when you create the delegate.) An exception is being thrown when the Invoke function tries to call SetClose, because your argument list is wrong, but the exception is being swallowed. The good news is that you can fix the problem with two keystrokes.
-
Reading The Pixels' Color By DirectX
snarfblam replied to Nakedsense's topic in Graphics and Multimedia
You want to examine pixels in a Bitmap? Keep in mind that plenty of software manipulates images without the assistance of the GPU and runs at a more-than-reasonable speed. I'm guessing that your approach involves something along the lines of the GetPixel function, which is terribly slow. A better method is to copy all of the image data into an array of bytes or integers, which is very fast to access. This allows you to quickly scan through the data. Bob Powell posted a good article about this. -
Atma's solution should work, but this might also be the rare case where the appropriate solution is to override the ProcessCmdKey function. If you want escape to close the form any time the user presses escape, even if it overrides another control's behavior for that key, then this would be an acceptable approach. ProcessCmdKey is there to allow controls to implement accelerators or menu short-cuts.
-
There's something I want to draw more attention to here (I'm surprised Atma didn't), and that's that you aren't using option strict. The function supposed to return an integer, but in the first line inside the function, you set the return value to 'Nothing.' Nothing is used with reference types to indicate a variable doesn't hold a reference to anything. It seems VB is "helping" by converting Nothing to zero. Your code should probably read like so, so that what it actually does is clearer: GetStrVal = 0 Even though it sometimes makes things slightly more difficult, option strict should always be used because it forces you to do things the "right way". It might take a little longer to figure some things out when using option strict, but there is a reason that option strict requires you to do things certain ways. Without option strict, VB tries to guess at what you are trying to do. More often it gets it right, and you get an automatic conversion that works. Still, it gets it wrong too often, and you get an automatic conversion that breaks your program. Since you will have typed in the code in a way that seemed to make sense, it will be very hard to figure out what is going wrong with your program when VB is automatically converting data types in a way that causes you issues. I hope that was coherent. I'm a little tired.
-
Re: Remove Duplicate items from a ComboBox How?
snarfblam replied to jisty_guy's topic in Windows Forms
Re: Remove Duplicate items from a ComboBox How? If you are using a data source, you can't modify the Items collection. Try modifying the data source instead? -
I don't think there is much credit due; I didn't come up with the formula. At any rate, if you really feel so compelled I'd say just leave it at snarfblam.
-
Here is a successful implementation of the distance formula: [Color=Blue]using[/Color] System; [Color=Blue]using[/Color] System[Color=Red].[/Color]Drawing; [Color=Blue]using[/Color] System[Color=Red].[/Color]Windows[Color=Red].[/Color]Forms; namespace WindowsFormsApplication1 [b]{[/b] [Color=Blue]public[/Color] [Color=Blue]partial[/Color] [Color=Blue]class[/Color] Form1 [Color=Red]:[/Color] Form [b]{[/b] [Color=Green]// Location and size of bulls-eye[/Color] [Color=Blue]const[/Color] [Color=Blue]int[/Color] originX [Color=Red]=[/Color] 100; [Color=Blue]const[/Color] [Color=Blue]int[/Color] originY [Color=Red]=[/Color] 100; [Color=Blue]const[/Color] [Color=Blue]int[/Color] outerRadius [Color=Red]=[/Color] 10; [Color=Blue]const[/Color] [Color=Blue]int[/Color] innerRadius [Color=Red]=[/Color] 2; [Color=Blue]protected[/Color] [Color=Blue]override[/Color] [Color=Blue]void[/Color] OnPaint[b]([/b]PaintEventArgs e[b])[/b] [b]{[/b] base[Color=Red].[/Color]OnPaint[b]([/b]e[b])[/b]; [Color=Green]// Draw our bulls-eye[/Color] e[Color=Red].[/Color]Graphics[Color=Red].[/Color]DrawEllipse[b]([/b]Pens[Color=Red].[/Color]Black, [Color=Blue]new[/Color] [Color=Blue]Rectangle[/Color][b]([/b]originX [Color=Red]-[/Color] outerRadius, originY [Color=Red]-[/Color] outerRadius, outerRadius [Color=Red]*[/Color] 2, outerRadius [Color=Red]*[/Color] 2[b])[/b][b])[/b]; e[Color=Red].[/Color]Graphics[Color=Red].[/Color]FillEllipse[b]([/b]Brushes[Color=Red].[/Color]Red, [Color=Blue]new[/Color] [Color=Blue]Rectangle[/Color][b]([/b]originX [Color=Red]-[/Color] innerRadius, originY [Color=Red]-[/Color] innerRadius, innerRadius [Color=Red]*[/Color] 2, innerRadius [Color=Red]*[/Color] 2[b])[/b][b])[/b]; [b]}[/b] [Color=Blue]protected[/Color] [Color=Blue]override[/Color] [Color=Blue]void[/Color] OnMouseMove[b]([/b]MouseEventArgs e[b])[/b] [b]{[/b] base[Color=Red].[/Color]OnMouseMove[b]([/b]e[b])[/b]; [Color=Green]// X and Y Distance from bulls-eye[/Color] [Color=Blue]int[/Color] dx [Color=Red]=[/Color] e[Color=Red].[/Color]X [Color=Red]-[/Color] originX; [Color=Blue]int[/Color] dy [Color=Red]=[/Color] e[Color=Red].[/Color]Y [Color=Red]-[/Color] originY; [Color=Green]// Distance formula: Dist = Sqrt(dX ^ 2 + dY ^ 2)[/Color] var dist [Color=Red]=[/Color] Math[Color=Red].[/Color]Sqrt[b]([/b]dx [Color=Red]*[/Color] dx [Color=Red]+[/Color] dy [Color=Red]*[/Color] dy[b])[/b]; [Color=Green]// Show Dist[/Color] [Color=Blue]this[/Color][Color=Red].[/Color]Text [Color=Red]=[/Color] dist[Color=Red].[/Color]ToString[b]([/b][Color=DarkRed]"0.00"[/Color][b])[/b]; [b]}[/b] [b]}[/b] [b]}[/b] Without seeing your code I couldn't even guess where the problem may lie.
-
If you don't post any code or tell us what the program is doing when the error occurs that really doesn't give us much to go on. You need to look at the error details and where the error is thrown to get some idea of why it is being thrown. There may also be DirectX debugging utilities that can give you more info when an error occurs.
-
It's not too complicated. I overlooked your question because it was one among many topics that got spammed in the same day. I think what you are looking for is the distance formula: distance = Sqrt( (x2 - x1) ^ 2 + (y2 - y1) ^ 2 ) You would just want to calculate the distance between the center of the circle and the mouse position.
-
You could periodically enumerate the processes and see if firefox.exe is among them. I think the Process class has a method named GetProcesses.
-
I don't know if this could be related to your issue, but sometimes when I close firefox it keeps running in the background for a while. I see this behavior on multiple machines. I assume it's doing some some house-keeping. Eventually it does close itself.
-
People tend to think of decimal, hex, binary, octal, etc. as different kinds of numbers. They aren't. They are different ways of representing the same exact kind of numbers. (Technically, all of your computer's data is processed in binary to begin with. The decimal values you see are just a different way of displaying the numbers to make it easier on us humans.) Converting numbers to strings to perform mathematical operations just doesn't make sense. Strings are for text. You just need to use the right kind of math on your integers. The purpose of the code I posted is to examine the individual ones and zeros. The fourth code listing in my post can examine any of the binary digits within an integer value. It would be easy to take the code and create a function that can be used the way I did in my last code listing.
-
Have you tried calling DrawToBitmap on the form? I did notice this questionable note in the remarks on MSDN:
-
I get the general idea of what you are trying to do, but it's not clear exactly what you mean. You ask about a text file but give an example with a textbox... It sounds like some basic string/text manipulation is all you need. If you want to deal with lines, maybe consider using String.Split or File.ReadAllLines to get each line of text as a separate string within an array. Then, if you want to remove a line you can create a new string array with only the lines you want, and then replace the original text data with your new text data (likely involving String.Join or File.WriteAllLines).
-
The first thing that jumps out at me is that you are comparing numbers to strings: temp = Microsoft.VisualBasic.Mid(strInputs, count, 1) If temp = 1 And count = 16 Then CheckBox1.Checked = True That kind of brings up the question of why you want to perform mathematical operations with strings anyways. The best way to scan through bits of an integer would be (IMO) to use bit shift and binary operators. To check the least significant bit of an integer, just AND its value with 1. Dim BinValue As Integer = GetValueFromThinAir() Dim lsbValue As Integer = BinValue And 1 If lsbValue = 1 Then ' first bit set Else ' first bit clear End If Now, you can scan through all the bits a couple of ways. One is to keep shifting the bits right. Dim BinValue As Integer = GetValueFromThinAir() ' Show message box with status of each bit For i As Integer = 0 To 15 Dim bitValue As Integer = BinValue And 1 Dim bitIsSet As Boolean = (bitValue = 1) MessageBox.Show("Bit " & i.ToString() & " = " & bitIsSet.ToString()) ' Sample output: "Bit 3 = False" ' Move to next bit BinValue = BinValue >> 1 Next i An alternative, if you want to check the bits in an arbitrary order, would be to create a bit filter for the bit you want to check, and, again, use the AND operator to check that bit. Dim BinValue As Integer = GetValueFromThinAir() Dim bitIndex = 5 ' Let's check bit # 5 Dim bitFilter As Integer = 1 << bitIndex Dim bitIsSet As Boolean = ((BinValue And bitFilter) = bitFilter) MessageBox.Show("Bit " & bitIndex.ToString() & " = " & bitIsSet.ToString()) ' Sample output: Bit 5 = True All the above is assuming you understand the relevant binary math. The other thing that stands out to me is the unrolled-bit-still-in-a-loop for loop. You have a loop, but that loop runs different code on each iteration, so why have a loop. Either make the loop purposeful, or fully unroll the loop. ' Unrolled (with hypothetical CheckBit function) CheckBox1.Checked = CheckBit(intInputs, 0) CheckBox2.Checked = CheckBit(intInputs, 1) CheckBox3.Checked = CheckBit(intInputs, 2) ' so on... ' Better loop (not sure about array syntax) Dim CheckBoxes() As New CheckBox() {CheckBox1, CheckBox2, Checkbox3} '... For i As Integer = 0 to CheckBoxes.Length - 1 CheckBoxes(i).Checked = CheckBit(intInputs, i) Next i
-
It would be more robust if you could ensure that you were always dealing with the same version of the program. Even though the appearance of Calc.exe hasn't changed much over the years, the changes that happen under the hood are significant, and it is updated with each version of Windows. Now, if you try to use predetermined corrdinates of the buttons, what happens if the user has large fonts enabled. Many applications scale themselves with the font size. (Whether or not this actually affects calc, I don't know).
-
First of all, I have a feeling that there may be differences between Calc.exe on different versions of Windows. This might be an issue. This is what I did to get the handle to a particular button. w = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "SciCalc", "Calculator"); w = FindWindowEx(w, IntPtr.Zero, null, "tan"); Looking at Calc.exe on my machine with Spy++, the heirarchy of windows doesn't even resemble what you've posted. The top-level window is "Calculator" whose class is "SciCalc", which directly contains all of the buttons, whose classes are all "Button". I know I've looked at this program with Spy++ a very long time ago (I think when I was running Windows ME) and there were way more windows involved, and everything had "Static" for the class.
-
First, on AutoRedraw: All AutoRedraw really amounts to is double-buffering. The real issue is simply that your control isn't being redrawn when it should. AutoRedraw is a very easy way of making this happen, but the standard painting cycle, if properly implemented, should also correctly paint your form. Now, I ran your code, tinkered with it, and the problem seems a bit unusual. What is actually happening is the invalid region (i.e. the area that needs to be drawn) is not being redrawn with your image, but everything else is. That seems completely backwards, and the result is that every time the control is painted, the area that should have been updated is empty, everything else looks fine. If the entire control should be updated, the entire control will be left blank. If a small area should be updated, you will notice an artifact of blankness there. This is either happening because something is clearing the invalid region after you update it, or because the invalid region is somehow being clipped (the wrong way) when you update. One possibility that occurs to me is that Windows is trying to optimize the painting in a way that is working against you. I don't think this is likely. TL;DR: I'm at a bit of a loss. One solution that worked for me is to render in an idle loop. This is a pretty standard thing when a Windows app that mixes hardware accelerated rendering with an otherwise standard UI. Basically, you run the render code once each time the Applicition.Idle event is raised. It's easy and sidesteps the whole problem. I tried that and it worked very well. Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() frmSelectGraphics.Hide() ' Add any initialization after the InitializeComponent() call. Call OpenGL00() [color="Blue"] AddHandler Application.Idle, AddressOf DoDrawStuff[/color] [color="Green"] 'This handler must be removed when the form is closed! [/color] End Sub [color="Blue"] Private Sub DoDrawStuff(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BttnGraphics.Click DrawStuff() End Sub Sub DrawStuff()[/Color] Gl.glLoadIdentity() Gl.glClearColor(CInt(&HFF And screencolor) / 255, ((&HFF00 And screencolor) \ 256) / 255, ((&HFF0000 And screencolor) \ 65536) / 255, 0) 'Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT) Call CameraPrespective() Glu.gluLookAt(-4, -2, 2.5, 0, 0, 0, 0, 0, 1) Gl.glNewList(1, Gl.GL_COMPILE) Gl.glPushMatrix() Glu.gluDisk(QuadObj, 2, 3, 32, 64) Gl.glPopMatrix() Gl.glEndList() Gl.glPushMatrix() Gl.glCallList(1) Gl.glPopMatrix() Gl.glFlush() Gdi.SwapBuffersFast(hDC) [color="Blue"] End Sub[/color]
-
First, on AutoRedraw: All AutoRedraw really amounts to is double-buffering. The real issue is simply that your control isn't being redrawn when it should. AutoRedraw is a very easy way of making this happen, but the standard painting cycle, if properly implemented, should also correctly paint your form. Now, I ran your code, tinkered with it, and the problem seems a bit unusual. What is actually happening is the invalid region (i.e. the area that needs to be drawn) is not being redrawn with your image, but everything else is. That seems completely backwards, and the result is that every time the control is painted, the area that should have been updated is empty, everything else looks fine. If the entire control should be updated, the entire control will be left blank. If a small area should be updated, you will notice an artifact of blankness there. This is either happening because something is clearing the invalid region after you update it, or because the invalid region is somehow being clipped (the wrong way) when you update. One possibility that occurs to me is that Windows is trying to optimize the painting in a way that is working against you. I don't think this is likely. One solution that worked for me is to render in an idle loop. This is a pretty standard thing when a Windows app that mixes hardware accelerated rendering with an otherwise standard UI. Basically, you run the render code once each time the Applicition.Idle event is raised. It's easy and sidesteps the whole problem. I tried that and it worked very well.
-
How are you opening the web page? Are you using something like the web browser control? Or is your code just connecting to the server and getting the HTML file? And what do you mean, copy the contents of the web page fully? Are you referring to the HTML, or all images, scripts, styles, ect. that the HTML refers to? Because the latter would be pretty difficult, I imagine. Unless such a feature is built into the web browser control, I would think you'd have to examine the HTML or DOM very thoroughly to identify everything it references.