Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm updating an old ScreenSaver that I wrote in VB6 to VB.net 2010 I initially used a windows forms application that worked fine until the preview screen. Loading the application into the preview screen (or other application like notepad) using the code:


VB
Public Sub SetForm(ByRef frm As Form, ByRef arg As String)
     Dim style As Integer
     Dim preview_hwnd As Integer = Integer.Parse(CType(arg, _
         String))
     Dim r As New RECT

     'Get the preview window's size.
     GetClientRect(preview_hwnd, r)

     With frm
         .WindowState = FormWindowState.Normal
         .FormBorderStyle = FormBorderStyle.None
         .Width = r.right
         .Height = r.bottom
     End With

     ' Add the WS_CHILD style to the form.
     style = GetWindowLong(frm.Handle.ToInt32, GWL_STYLE)
     style = style Or WS_CHILD
     SetWindowLong(frm.Handle.ToInt32, GWL_STYLE, style)

     ' Reparent the form into the preview window.
     SetParent(frm.Handle.ToInt32, preview_hwnd)

     'Set the form's GWL_PARENT value to the preview window.
     SetWindowLong(frm.Handle.ToInt32, GWL_HWNDPARENT, _
         preview_hwnd)

     ' Position the form in the preview window.
     SetWindowPos(frm.Handle.ToInt32, 0, r.left, 0, r.right, _
         r.bottom, SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_SHOWWINDOW)
 End Sub


freezes the parent window and there is no input to the launched form.

Switching to a console app and using

VB
Dim scrsvr As New frmScr
 scrsvr.Preview = True
 SetForm(scrsvr, args(1))
 Application.Run(scrsvr)


fixed most of the problem, but the form/screensaver still doesn't accept keyboard input, either when in the preview screen or running as a full screen screensaver without running "setform". Interestingly, the configuration screen runs fine when launched from the console app.

In VB.net 2010, the only options seem to be running an app either from a form (forms application) or from the console(Console app). In VB6 we could run a forms app yet start from a Sub Main.

Any help is appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 16-Nov-15 16:11pm    
I see no problem at all. First of all, a screensaver written through the use of System.Windows.Form should be a regular form application. A console has no merit here. But it you want to start application from a console, in the same project, you can always do it. The applications actually starts with Application.Run call.

The problem is: you are complaining about some problem most showing any piece of code relevant to the problem. What, not keyboard event handling? But you did not show a single line of code where you attempt to handle them. Instead, you show some P/Invoked code, not only irrelevant, but probably totally redundant: a screen saver can be written using pure .NET FCL.

—SA
fREBie 16-Nov-15 17:18pm    
Thanks for the quick reply.

>But you did not show a single line of code where you attempt to handle them

I am using the screensaver form event handlers which do not trigger when a key is pressed IF I launch the form from the console, ie

Private Sub frmScr_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = 83 Or e.KeyCode = 123 Then '"S" or F12 to Save image
SaveImage()

>a screensaver written through the use of System.Windows.Form should be a regular form application

That's where I started, with a forms application. Everything was fine until the preview. The preview showed up in the preview screen, but completely froze the host screen- it could not be moved, closed, etc.

>a screen saver can be written using pure .NET FCL.

I looked for managed code to move my app/form into another window, but couldn't find it. I'd used the API calls in VB6 and tried them here. Do you have any reference where I can find how to move my app into another window using managed code?

Again, thanks for your interest.
fREBie 16-Nov-15 17:22pm    
Just saw your second comment/email. I'm looking at the link now. The MS links I found did not include /p preview.

1 solution

Please see my comment to the question. The problem looks artificial to me, but of course you could screw up the keyboard event handling in one of many different ways; the problem is that you did not show us relevant piece of code.

Generally, there is no a problem specific to the screen savers and related to keyboard event handling. This is all that matters.
For example, you can look at this project:
https://msdn.microsoft.com/en-us/library/ms686421%28v=vs.85%29.aspx[^].

You can find a lot more.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900