|
Can I use bit shifting operators in VB. According to MSDN I can. But...my msdn library is 2003 and my VB is 2002! Do I have to import something because I see erros when I try a = B >> 2. I am using VB 2002.
Thanks you lot!
Nursey
|
|
|
|
|
The bit shift operators are new to 2003. They don't exist in 2002...
Sorry!
RageInTheMachine9532
|
|
|
|
|
Hey Rage,
I thought as much, presumably they are in C# so really I could just knock up a quick C# object which offers bit shifting and byte extraction from 32-bit ints, the stuff we take for granted in C++.
As a feeler, how long has it taken people to get to grips with C# if you know C++, or VB for example?
Just another language is what I say, and they should all be learned if possible, it helps you to think outside the box.
Chris.
Nursey
|
|
|
|
|
And your right my friend! This is what learning all those different languages is all about! I prefer VB for the bulk of my code just because it's fast to write up. But I also write components in C# and C++, and for the real down and dirty with API's, NetWare, and libraries, in use C++.
It didn't take very long at all to get used to C#, having a background in both VB and C++, it was a snap to learn. It just took a couple weeks to get used to the hybrid syntax! In all, I think I have my hands in something like 14 different languages. I'm by no means a master of all of them, but the concepts are the same amongst them all. But you're right! The more you know, the better off you are!
RageInTheMachine9532
|
|
|
|
|
Well, as soon as I have put some polish on this current control library I'll dive into C#. I have a feeling the hybrid syntax will be pretty intuitive. I just have to remember to keep putting the ";" in the right places again!
Have you used any free tracing tools that help you to dig out strange bugs which are hard to track down at design time? I was getting "Null reference exception..." and I couldn't pinpoint the line which it was at until I put some message boxes in. It seems at design time code gets run which you can't step through. I remember running two copies of VB6 to debug controls at design time. Presumably that's still an option?
Ta.
Nursey
|
|
|
|
|
Yep, you can debug design-time code just about the same way you could under VB6. Microsoft was kind enough to supply a sample of it here[^].
RageInTheMachine9532
|
|
|
|
|
The previous poster is correct - the shifting operators are 2003 only.
However, if you have an integer value you can mimic some of the shifting by dividing or multiplying by two, although this is far from perfect and may cause overflow errors and suchlike. You might also find that you can bit mask, and created the shifted up or down value by adding or subtracting the relevant powers of 2 to an initial zero value.
You could also create a lookup table of shifts if you don't mind the memory overhead, but this would be fast and simple (note this is only really practical for small bitfields, of size 8 bits or there abouts (an array 256 Bytes each way) - 32 bits woud be right out due to needing 4 gig of memory for each )
Or upgrade your project to 2003
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
Having put your 4 Gig of memory method to the test I seem to have scratched the area of my hard disk, right around the place where the swap file seems to go
I am gonna go the C# route just to have a little utility function until my 2003 hits the front door carpet. I was using the div mul method of shifting up until now though and who cares if its 4 nano seconds slower than the C++ like bit shifts!
Ah well, all I have to do now is wait for the garbage collector to give me my 4 gig back hahaha 8-)
See Yah!
Nursey
|
|
|
|
|
Hello! Im new to these forums so please forgive me if I have posted in the wrong section for this.
Using winforms under vb.net, how does one set the GWL_EXSTYLE to include WS_EX_LAYERED? I need to set this
flag so that I may use UpdateLayeredWindow on the form. This is what I am using :
Dim lStyle As Long = GetWindowLong(Me.Handle.ToInt32, GWL_EXSTYLE)
lStyle = lStyle And WS_EX_LAYERED
Dim retval As Long = SetWindowLong(Me.Handle.ToInt32, GWL_EXSTYLE, lStyle)
I tried it after a .Show() call and in the _Load event as well.
Someone, please enlighten me! This is holding up my project atm. Thanks!
Edited by - andrew_ on 12/4/2003 8:09:57 PM
|
|
|
|
|
Andrew,
I sincerely hope this example, which I found for you, helps out...
Using Layered Windows
To have a dialog box come up as a translucent window, first create the dialog as usual. Then, on WM_INITDIALOG, set the layered bit of the window's extended style and call SetLayeredWindowAttributes with the desired alpha value. The code might look like this:
// Set WS_EX_LAYERED on this window
SetWindowLong(hwnd,
GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
// Make this window 70% alpha
SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
Note that the third parameter of SetLayeredWindowAttributes is a value that ranges from 0 to 255, with 0 making the window completely transparent and 255 making it completely opaque. This parameter mimics the more versatile BLENDFUNCTION of the AlphaBlend function.
To make this window completely opaque again, remove the WS_EX_LAYERED bit by calling SetWindowLong and then ask the window to repaint. Removing the bit is desired to let the system know that it can free up some memory associated with layering and redirection. The code might look like this:
// Remove WS_EX_LAYERED from this window styles
SetWindowLong(hwnd,
GWL_EXSTYLE,
GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED);
// Ask the window and its children to repaint
RedrawWindow(hwnd,
NULL,
NULL,
RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
Nursey
|
|
|
|
|
Nursey, thanks for trying address the issue at hand here.
My main objective is to draw to an offscreen DC and use UpdateLayeredWindow to render the form. Being VB.NET Winforms, I am not quite sure how one goes about handling the WM_CREATE, or WM_INITDIALOG messages. If this were VB6 or below I would have no problem with this.
The reason why I thought it would be worthwhile to pose the question is because I had checked the winform with spy++ and the WS_EX_LAYERED exstyle was not listed for the window.
If there is a setting or a way to assert the WX_EX_LAYERED exstyle to a winform without calling SetWindowLong (Which has no effect on the winform at all) please do let me know!
Thanks!
|
|
|
|
|
Just for learning purposes ... What are you trying to do with the layered window? What is the goal of rendering the window offscreen?
SetWindowLong is the only way your going to set WS_EX_LAYERED, BUT what I noticed in your code is that your ANDing the value in. You must OR the value in to get it to work, at least in the examples I've found (see here[^])
RageInTheMachine9532
|
|
|
|
|
*headsmack* Youre absolutely right.
As for your question of why... If you draw to an offscreen DC, maintain a background color (which in this case is argb(0,0,0,0)) of the DC, pass it to UpdateLayeredWindow with the right params, it will render the window for you and continue to handle the wm_paint messages that come in, until you remove the ws_ex_layered style and re-add it (in which case you need to call your fuction which draws offscreen again...). Its a great lil bit o' magic, and it allows you to have a window, for example, based on a PNG with alpha channel support.
Thanks for bringing that ANDing to my attention though!
UPDATE:
I stumbled upon an article which stated that Integers in vb.net are Longs in vb6. I had to modify the declares for SetWindowLong and GetWindowLong so that the params used Integers and returned Integers instead of Longs. Once I changed this, and used the ORing instead of the ANDing, everything worked as it should have.
Thanks again for the help guys!
|
|
|
|
|
Andrew...this is a comment to you, because we all get code blindness, but the rest of us have learned a very valuable lesson from Rage, read the code brothers, be the code. I just had the urge to assume I could grab you a quick example and let you go from there. If I had read the code properly then I too would have learned somthing 8-)
say la vee as people who talk foreign languages phonetically would say.
Chris.
Nursey
|
|
|
|
|
I am attempting to add a form or control as an object to my instance of the MSScriptControl, where the control or form will extend its events to the loaded script...
oScripting.AddObject("Window", Me, True)
oScripting.State = MSScriptControl.ScriptControlStates.Connected
That is supposed to add the object and attach its members and events... but it doesnt fire the event within the script..
Sub Window_Click()
Msgbox "clicked"
End Sub
I have also tried;
Sub Window_Click(sender, e)
Msgbox "clicked"
End Sub
Please advise! I would very much like to know what I am doing wrong!
|
|
|
|
|
Hi everyone;
I have a problem about what can I integrate a Combo box who's list is link with a table (called department) but the text of the combo is link with other table (called user).
Table 1 = user
Field 1 = User
Field 2 = DeptCode
Table 2 = Department
Field = DeptCode
Field = DeptDescription
I other words, I have a form presenting the user informtion (this information is from the table user), but the field called deptCode in user table. I want present every time the records is changed the dept description from table department.
(I think all of that is without Coding)
Please me on that...
Johnny
Johnny Lizardo
|
|
|
|
|
Hi everyone ...
When i am inside a big loop in VB6 (for .. to; if .. then; while .. wend) the form stops responding.
How can I make a stop button in the form ??
Thank you ,
Rodrigo
|
|
|
|
|
You need to provide a means to break the loop. This is an example (untested), but you should get the idea:
dim StopButtonPressed as Boolean
sub MyLongLoopSubroutine()
StopButtonPressed = false
while (MyCondition = true ) and (StopButtonPressed = false)
' do loop stuff here
' DoEvents allows the UI and other windows messages to get through
DoEvents
wend
end sub
sub StopButton_Click()
StopButtonPressed = true
end sub
Bear in mind you need to be careful when using DoEvents to keep a user interface responsive, as any actions the user has may interfere with the loop you're running.
--
Ian Darling
"The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
|
|
|
|
|
If anyone can give me clues on how to add an icon to the WinXP My Computer that directly access a program.
Eg... Accessing a custom FTP program like a disk drive under My Computer.
|
|
|
|
|
I have VS.NET 2002. I have developed several user controls and have a solution which contains these and a test form. When I load the solution and go to the form on which I place my controls for testing, I often get a freeze, or VS freeks out, like showing a toolbox with no controls on it, until you move the mouse all over it and get it to redraw them all, but even then it doesn't show tooltips.
I'm perfectly willing to accept that some of my code is runing in design mode and that may be freezing VS. But how do you trace code in your controls in design time? Do you have to use the old method of having two copies of VB running? One for the control and one for the form? It would make sense but I dont want to start sticking loads of trace code and making changes until I consult you guys, coz you be good!
Thanks!
Chris.
Nursey
|
|
|
|
|
I want to draw icon in CheckedListbox. May you help me.
VitaminY
|
|
|
|
|
What is the difference between Directcast and CType?
Also is it better to use CType(MyObect, Integer) than CInt(MyObject) - does it get compiled to the same MSIL or is a helper function called in the Microsoft.VisualBasic.dll?
Jim
|
|
|
|
|
While DirectCast and CType are both used for casting, DirecCast can only case object to object they have a direct relationship (ie. inheritance ) with. For example, if B inherits A, and C inherits A, you can use DirectCast to cast a C object to A.
OTOH, CType can be used to cast from any object to any object. The advantage of DirectCast is that it's much faster than CType , so use it whenever appropriate.
Looking through the IL for CType and CInt , they're actually doing the same thing, so I assume there's no difference in using either.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
Support Bone
|
|
|
|
|
CType is more flexible because it's not limited to converting between standard types. It can be used to convert between composite types as well as converting an object to any one of its interfaces.
CType is also compiled in-line with the expression whereas the CInt is not. CInt calls a library function to convert an already evaluated expression result whereas CType code is actually compiled as part of the expression.
Now, DirectCast... The difference between the two is that CType succeeds as long as there is a valid conversion defined between the expression and the type, whereas DirectCast requires the run-time type of an object variable to be the same as the specified type. If the specified type and the run-time type of the expression are the same, however, the run-time performance of DirectCast is better than that of CType
Consider the following code:
Dim Q As Object = 2.37 ' Requires Option Strict to be Off.
Dim I As Integer = CType(Q, Integer) ' Succeeds.
Dim J As Integer = DirectCast(Q, Integer) ' Fails.
The run-time type of Q is Double. CType succeeds because Double can be converted to Integer, but DirectCast fails because the run-time type of Q is not already Integer.
Clear as mud?
RageInTheMachine9532
|
|
|
|
|
Thanks, that is a lot clearer.
Jim
|
|
|
|
|