|
Hi Dave, first of all thaks for your help!!
My code is in Vb.NET, and to get an idea of the functionality, it is an app that runs in the sysTray and has some global hotkeys defined(allready). So an exactly example would be that if I have the notepad open with some text selected, I can press this hotkey to copy the text. The hotkey capture is done and filtered by a case, so from here I call the sendMessage(). The code is something like this:
Public Const WM_COPY = &H301
Private Declare Function GetForegroundWindow Lib "user32" () As intPtr
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hWnd As intPtr, ByVal uMsg As Long, _
ByVal wParam As integer, ByVal lParam As integer) As Long
'Now I call the sendMessage function from the case
case...
SendMessage(GetForegroundWindow(), WM_COPY, 0, &0)
One important thing is that if I pass the handle of one textbox of my app, it runs! like this: SendMessage(Me.TextBox.Handle, WM_COPY, 0, &0)
And the way that I know (or think) that getForegroundWindow is working is because if I try with different active windows, the handle that returns this function, change.
The point I think where could be the problem is that I don't know if the handle of the active window is sufficient to let the WM_COPY knows where is the selected text to copy. Would be necesary to specify the edit control in the active window that has the selected text, as I did with "Me.TextBox.Handle" ?? If so, I don't know how to find the edit control that has the selected text in the active window.
Well Dave, thank you in advance for your help.
Bye
Damian
|
|
|
|
|
dcastroviejo wrote:
Would [it] be necesary to specify the edit control in the active window that has the selected text, as I did with "Me.TextBox.Handle" ?? If so, I don't know how to find the edit control that has the selected text in the active window.
Yes, WM_COPY must be sent to the edit control handle, not the parent window. There is really no way of determining which edit control has the focus.
Applications that let you drap a cross hair around the screen and see each and every window, including edit controls, use the function ChildWindowFromPoint to get the window handle. This won't work in your case because you really cant get a reliable point to pass to this function.
Also, you can't enumerate the child windows of a window to find the edit control because there are so many different window classes that can process this message, you can't just send the message to all the child windows. Each window will overwrite the previous windows data on the clipboard.
An alternative, since you have the parent windows handle, is to send the Ctrl-C keyboard sequence. It's pretty much universal that Ctrl-C means "Copy" in any application. Check into the WM_KEYDOWN and WM_KEYUP messages.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
OK, I'll investigate on this WM_KEYDOWN and WM_KEYUP messages.
I'll let you know when this run!
Thanks about the info !
|
|
|
|
|
I have a MS Access 2003 report that simply displays data from columns in one Access table. One of the columns is called Amount. The Report Footer displays the Total on a text box calculated as Sum(Amount) and works fine.
I want to display the Amount subtotal for each page but when I assign
Sum(Amount) to a textbox in the Page Footer I get an error at runtime.
How can I display the subtotal of Amount column on each page??
(I cannot group as the records have nothing in common)
1fm1fu
|
|
|
|
|
And this has what to do with VB/VB.Net? So far, you haven't mentioned any code problems you might be having. Just something with the Report Designer in Access. You might want to try finding an Access Forum for this question.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi everybody... I got a short question about one nasty little API function which I am in most dire need of. I need to somehow update the translucency / transparency setting of a normal window. Say I got two buttons and a Scrollbar. I need to somehow call the UpdateLayeredWindow function each time the scrollbar is modified so I can modify the translucency (opacity) level of my window. So far, I need to DESTROY and create the window AGAIN and use "SetLayeredWindowAttributes" to achieve this. But it's not a solution, this is a workaround and it's not nice at all : ), I think you agree : ).
Here's what I got so far... (this is VB6 code, but any language will do, I can adapt to anything, the only thing that I need is to actually make this WORK : ) ).
<br />
UpdateLayeredWindow Me.hwnd, Me.hdc, ByVal 0, m_windowSize, m_mainSurfaceDC, <br />
m_srcPoint, 0, m_blendFunc, ULW_ALPHA
You don't have to care about the parameters. My question is not related to those. My question is... can this nasty function be used to set a NORMAL WINDOW? I mean not a bitmap! A window... with some buttons and stuff on it. I am sure it must be possible, but I just don't know how. It's one nasty little function and I can't find anywhere some good documentation about it, only examples that are not working properly or do more than I need this function to do. I Googled for it and 60% of the results were declaring it, but not using it ! HA! Imagine that! : (. The other 40% were either using bitmaps, either not working.
I got one example that uses bitmaps, but that's too complicated and it's not what I need. I tried to put a scrollbar on that window and it wouldn't even appear, of course, since the guy who did this is using some bunch of functions to work with the bitmaps : (.
Thank you a LOT for reading this and I would really appreciate any help, it's for a good cause : ) (freeware application). I sure hope there are some people on the Code Project who ran into this function before.
Just before you ask... no, I can't use .Net to do this, but some .Net ideas WOULD be usefull since I could at least port it to my VB 6.
Have a nice day everybody : )
The Greater Mind Balance
|
|
|
|
|
1) Cross posting in multiple forums on the same site is considered very rude!
2) Posting VB code and asking VB questions in a C# or C++ Forum could get you strung up by your nads! Be prepared to receive much abuse.
3) You can't use the UpdateLayeredWindow function on a VB6 created window because the WS_EX_LAYERED attribute is not set when VB6 creates its windows. You'll have to modify the window after it's created in order to use this function. See this[^] article on BuilderAU.com for an example of how to do this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm sorry for posting in both groups, but as my question was a general one, I wanted more programmers to see it. Not all C# programmers look in the Visual Basic.Net area and not Visual Basic.Net programmers look in the C# area. I just wanted to cover both groups : ). I don't find this very rude, but I do apologize and I will not do this again.
Thank you for your answer, but you didn't read my message carefully I think. I already achieved all that. SetWindowLong, SetLayeredWindowAttributes are working. I already have my LayeredWindow, but the problem is that I don't know how to use that tricky UpdateLayeredWindow function. I ran through the whole MSDN documentation about that function and lots of examples from the internet but as I said, they are using bitmaps and stuff, and I only want to use that function on the HDC of my window but without bitmaps and things like that. I just want to use it to dinamically change translucency without having to destroy and re-create the window.
Thank you : )
The Greater Mind Balance
|
|
|
|
|
Actually, I did read your message and the question was this:
My question is... can this nasty function be used to set a NORMAL WINDOW?
The answer to that question is No. But, like you said, the window must be modified before you can call this function.
Also, you said:
You don't have to care about the parameters.
Actually, when people start posting questions about why API calls don't work, it's because the parameters are screwed up. We'd need to see you declaration for UpdateLayeredWindow , your structure definitions that are used by it, the code the fills in these structures, and the code that sets up the call to UpdateLayeredWindow. Without that, you're hiding the small details that can make all the difference in the world.
From what I've seen in other source code, this isn't very complex.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Haha. You're ok : ). You are kind of right. Let me just ask this question: do I need to use a bitmap to use that function (I guess no... but I'm asking just to be sure). And another question: did you come across that function and used it until now?
Hey, for all the trouble I gave you, I'll make it up by making an article about using this function (when and if I'm gonna make it work) in both C# and VB.Net, so I can wash my cardinal sin of cross posting : D, haha. Happy ? : ). Have a nice day mate! : ).
The Greater Mind Balance
|
|
|
|
|
In a form i have a button(btnCaption) and a panel(pnlTemplate).Button's Location can be changed with mouse and ctrl key.If i press at button's left top corner then change its location, there is no problem, but When i press any other side of button; while i drop button, mouse pointer(X,Y)location is set to button left top corner. Probably i have to change pnlTemplate_DragDrop sub, but i couldnt yet. please help me.
-CODE-----------------------------------------------------------
Dim m_MouseIsDown As Boolean = False
Dim LastClickedButton As String
Private Sub btnCaption_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnCaption.MouseDown
If e.Button = MouseButtons.Left And m_ControlKeyPressed Then
m_MouseIsDown = True
End If
End Sub
Private Sub btnCaption_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles btnCaption.MouseMove
If m_MouseIsDown Then
btnCaption.DoDragDrop(btnCaption, DragDropEffects.Move)
End If
End Sub
Dim m_ControlKeyPressed As Boolean = False
Private Sub btnCaption_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnCaption.KeyUp
Select Case e.KeyCode
Case Keys.Escape : m_MouseIsDown = False : m_ControlKeyPressed = False
Case Keys.ControlKey : m_ControlKeyPressed = False
End Select
End Sub
Private Sub btnCaption_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles btnCaption.KeyDown
Select Case e.KeyCode
Case Keys.ControlKey : m_ControlKeyPressed = True
End Select
End Sub
Private Sub pnlTemplate_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pnlTemplate.DragEnter
If m_MouseIsDown Then
If e.Data.GetDataPresent(GetType(Button)) Then
e.Effect = DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
m_MouseIsDown = False
m_ControlKeyPressed = False
End If
End If
End Sub
Private Sub pnlTemplate_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles pnlTemplate.DragDrop
If m_MouseIsDown Then
If e.Effect = DragDropEffects.Move Then
Dim btn As Button = DirectCast(e.Data.GetData(GetType(Button)), Button)
Dim clientpoint As Point
clientpoint = PointToClient(New Point(e.X, e.Y))
If Not (clientpoint.X < 0 Or clientpoint.Y < 0) Then
btn.Left = clientpoint.X - pnlTemplate.Left
btn.Top = clientpoint.Y - pnlTemplate.Top
End If
m_MouseIsDown = False
m_ControlKeyPressed = False
End If
End If
End Sub
|
|
|
|
|
Hi
I created very simple dll (vc++) which has three functions (start, stop and
initialization). it starts capturing sound from soundblaster and when the
buffer is filled with the data, dll calls VB calback function (passed with
initialization) and passes the buffer size (integer type). First I have
some problems with __stdcall declaration in VC dll, but I think I solved that
problem. Callback function runs in separated thread under main dll thread.
Declaration of initialization of callback function looks like this:
__declspec(dllexport) int __stdcall RecToR_Init_Cap(void (__stdcall *tmp)(int_4 size));
IN VB:
Public Delegate Sub Callback(ByVal size As Int32)
Public Declare Function RecToR_Init_Cap Lib "RecToR_Cap_TR.dll" (ByVal CalBckFunc As Callback) As Int32
"Private Sub Button1_Click" event in VB:
Dim cb As Callback
cb = AddressOf CallBackFunc
Success = RecToR_Init_Cap(cb)
Public Sub CallBackFunc(ByVal size As Int32)
TextBox1.Text = size & vbCrLf
End Sub
When I run the application, the callback function is called 50 times and
then the application crashes:
"An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Unknown Module. Additional information: External component has thrown an exception.
An exception 'System.NullReferenceException' has occured in..."
I think I override stack pointer. How can I trace down the problem?
From Microsoft articles I get information that I cannot call callbacks from
spawned threads within my DLL.
Is it possible to overcome this problem?
Thanks for any idea
Tomaz Rotovnik
|
|
|
|
|
Could be the garbage collector.
Try to put this code when you want to stop recording.
<br />
GC.KeepAlive(cb)<br />
I had the same problem with callback function when capturing video.
|
|
|
|
|
Hi
When the callback function is trigered 50 times I still capturing the sound.
I didn't stop sound capturing.
Do I need to call GC.KeepAlive(cb) inside the callback function?
Tomaz Rotovnik
|
|
|
|
|
The statement GC.KeepAlive is a way to keep a reference to an object.
When the garbage collector "scans" your code, and there isn’t a further reference to an object, it removes it.
E.g. the reference to your callback function is lost.
In your code….
When the recording is finished, you should call GC.KeepAlive(cb)
That way you will not loose your reference.
|
|
|
|
|
OK
Now I understand.
Unfortunately dll is still capturing when the error arrise (I didn't call stop function at all)
Tomaz Rotovnik
|
|
|
|
|
Can anyone guide me on how to make a phone answering application in vb.net. I have to start from 0.
|
|
|
|
|
How can I convert the float value to hexadecimal value using visual basic 6 ?
For example
let a = 45.36
after the conversion of 45.36, the hexadecimal value is :: 2D
can anyone please tell how to code the the coversion from float to hexadecimal value in visual basic?
Hoping for a early reply
philip
|
|
|
|
|
This question carries the stench of homework.
2D is the hexadecimal value for 45, not 45.36. Getting the hex value of any number is easy, just use the Hex() function. Note: You'll get the Hexadecimal value of the integer version of the number, not the whole floating point value.
Dim hexString As String
hexString = Hex(45.36)
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi yall
i am a student and am finding it difficult to connect to ms excel. pls assist
|
|
|
|
|
Hi ,
Dim DS As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\myData.XLS; " & _
"Extended Properties=Excel 8.0;")
' Select the data from Sheet1 of the workbook.
MyCommand = New System.Data.OleDb.OleDbDataAdapter( _
"select * from [Sheet1Name]", MyConnection)
DS = New System.Data.DataSet()
MyCommand.Fill(DS)
MyConnection.Close()
Hope This code will help u............:->
Reagrds,
Ritesh
|
|
|
|
|
Is this possible?
copy coversheet1 from test.xls in c:\test directory
paste or create coversheet1 to test2.xls in c:\test2 directory
both excel documents exist but I need to transfer a sheet from one document to the other.
I am using visual basic 6.
Any help would be greatly appreciated.
Thanks
Beginner in VB.Net
|
|
|
|
|
Roman Nurik wrote:
I am befuddled as to why API functions (I had similar problems calling ZLib DLL functions from VB.NET) don't work properly in VB.NET.
They work perfectly in VB.NET when done properly.
Without seeing more of your code, we really can't determine what's wrong. I've used the API functions myself about a year ago and never had a problem like what your having.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hey, i got it to work.. the problem was with my api declaration... the last parameter, i was declaring ByRef lpOverlapped As Overlapped... apparently that isnt right (i dont really know why) and all i did was i changed it to ByVal lpOverlapped as IntPtr and set it to zero (since i dont use overlapped)
not sure why it works, but it works
thanks for the replies
r -€
|
|
|
|
|
Glad you got it to work!
ByVal will work so long as you never pass in an OVERLAPPED structure and always pass in a 0 for this parameter. If you ever do pass in an OVERLAPPED structure, then you have to change the declaration back to ByRef lpOverlapped As OVERLAPPED and properly declare the OVERLAPPED structure in your code.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|