Illusion Posted March 19, 2007 Posted March 19, 2007 Hi, I was looking for a way to make my form fullscreen. I have tried a few things and looked on the interweb :) but nothing seems to work, but it looks like it should. for example: Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const SWP_NOSIZE = &H1 Const SWP_NOMOVE = &H2 Const SWP_NOACTIVATE = &H10 Const SWP_SHOWWINDOW = &H40 Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetWindowPos(Me.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE) End Sub would work if form returned a hWnd and not a handle like it is doing now.. The fullscreen needs to cover the windows start bar and also stay on topmost too. Any ideas? Thanks Illusion Quote
Administrators PlausiblyDamp Posted March 21, 2007 Administrators Posted March 21, 2007 Try changing the Longs to Integers and seeing if that makes a difference. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Illusion Posted March 22, 2007 Author Posted March 22, 2007 Hey, I tried that one before posting, (sorry I should have said). I got this message.. A call to PInvoke function 'fullscreen!fullscreen.Form1::SetWindowPos' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. Thanks Quote
Administrators PlausiblyDamp Posted March 22, 2007 Administrators Posted March 22, 2007 Try Declare Auto Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, _ ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, _ ByVal uFlags As UInteger) As Boolean as your declaration. Depending on exactly what you are trying to do via this call you might be able to do without the API anyway. Try the following and see if it suits your needs. Me.TopMost = True Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None Me.Location = New Point(0, 0) Me.Size = Screen.PrimaryScreen.Bounds.Size Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Nerseus Posted March 22, 2007 *Experts* Posted March 22, 2007 If you just want fullscreen, I do it with setting the border style to none and window state to maximized - you can also set TopMost to true. Those three properties should make the form go fullscreen, covering even the taskbar and system tray. If you want "true" full screen, with mouse capture and all including preventing Alt-Tab from switching, you're likely thinking of DirectX or similar libraries that allow more "total control." That's a lot more work. If you want the API to work, just change the call to accept an IntPtr and make sure the other params are all "Integer" instead of "Long" - assuming you're using a 32 bit version of Windows. If you've got WinXp for 64 bit then you're on your own :) For example: Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As IntPtr, ... -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Illusion Posted March 22, 2007 Author Posted March 22, 2007 Hi, I tried the API thing, but it gave the same problem. Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load SetWindowPos(Me.Handle, IntPtr.Zero, 0, 0, 1024, 768, 64) End Sub I will try the other stuff.. I did really want to use full screen and be able to control the key presses. Other than directx, what way could I do it? Thanks Quote
*Experts* Nerseus Posted March 23, 2007 *Experts* Posted March 23, 2007 Illusion, I'm not being rude, but have you read all the replies that are provided in this thread? It's not clear to me that you have. For example, I said you'd likely have to replace all "Long" with "Integer" yet your sample shows you're still trying "Long." Also, have you tried PD's example or mine, where you just change the border style and other properties of a form (no API call needed)? Did that work or not work? If it didn't, what was wrong about it or what behavior did you see that didn't work the way you expected? -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
MrPaul Posted March 23, 2007 Posted March 23, 2007 Function vs Sub I tried that one before posting, (sorry I should have said). The SetWindowPos function returns a value - in VB terms this means it is a Function, not a Sub. The declaration that PlausiblyDamp posted should work fine. Good luck :) Quote Never trouble another for what you can do for yourself.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.