Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Problem with the API call: SetWindowRgn


Problem with the API call: SetWindowRgn

Author
Message
jviper
jviper
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 10, Visits: 28
I used the API call SetWindowRgn to cut holes in a form. But when I use this call, I lose the skins and visual styles on the windows. Heres some screenshots showing what's happening:

You will notice in the background, there is that nice Panther looking skin on the windows. But if you look at the FigureEditor window, the windows looks like it came from windows 95. Does anyone know how to fix this?


Jabstract: Don't just imagine, make it happen!

Destroyer
Destroyer
Forum God
Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)Forum God (42K reputation)

Group: Forum Members
Posts: 244, Visits: 188
You're not giving us much to go on here.  Maybe if you posted the
relevant code that you are using someone will be able to make sense of
what you are asking.


Destroyer Smooooth
jviper
jviper
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 10, Visits: 28
Ok. The following code came from http://www.vb-helper.com/HowTo/recthole.zip. Sorry if the link is dead. The purpose of the program is to cut a rectangular hole in the middle of a form. You will notice that if you have the Windows and Buttons style set to "Windows Xp Styles", the window will look plain, as if you set the Windos and Buttons style to "Windows Classic Style". You can tell the differnce becuase the "Windows Xp Style" has a bouble-like apperance, and the "Windows Classic Style" has the flat-Windows 98 appearence. Here is the code:

Option Explicit

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Sub Form_Load()
    'OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
    Form1.Left = (Screen.Width - Form1.Width) / 2
    Form1.Top = (Screen.Height - Form1.Height) / 2
    'SetScreenRegion
End Sub
Public Sub Moving()
    SetScreenRegion
End Sub
' The form has finished moving.
Public Sub Moved()
    SetScreenRegion
End Sub
Private Sub Form_Resize()
    SetScreenRegion
End Sub
Private Sub SetScreenRegion()
    Const RGN_DIFF = 4

Dim outer_rgn As Long
Dim inner_rgn As Long
Dim combined_rgn As Long
Dim wid As Single
Dim hgt As Single
Dim border_width As Single
Dim title_height As Single

    If WindowState = vbMinimized Then Exit Sub
   
    ' Create the regions.
    wid = ScaleX(Width, vbTwips, vbPixels)
    hgt = ScaleY(Height, vbTwips, vbPixels)
    outer_rgn = CreateRectRgn(0, 0, wid, hgt)
   
    border_width = (wid - ScaleWidth) / 2
    title_height = hgt - border_width - ScaleHeight
    inner_rgn = CreateRectRgn( _
        wid * 0.25, hgt * 0.25, _
        wid * 0.75, hgt * 0.75)

    ' Subtract the inner region from the outer.
    combined_rgn = CreateRectRgn(0, 0, 0, 0)
    CombineRgn combined_rgn, outer_rgn, _
        inner_rgn, RGN_DIFF
   
    ' Restrict the window to the region.
    SetWindowRgn hwnd, combined_rgn, True

    DeleteObject combined_rgn
    DeleteObject inner_rgn
    DeleteObject outer_rgn
End Sub

Hope this is enough info.

Jabstract: Don't just imagine, make it happen!

Edited
8/23/2005 by jviper
kwandobe
kwandobe
Forum God
Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)

Group: Forum Members
Posts: 22, Visits: 4
It is because you are using a StyleXP skin. The entire time you use a stylexp skin, stylexp is running and adjusting the windows. Unfortunately when you use an API call, stylexp doesn't realize that the window was resized and therefore doesn't draw it, instead you get the windowsxp classic skin.

-kwandobe


jviper
jviper
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 10, Visits: 28
Is there some API call that I could use to refresh the skins on thw windows, or Am I stuck, and cannot use this call?

Note that this happens no matter which theme I use. Even when I use the new win-xp themes that came with windows xp. That kind of stucks, as it makes the program look like it's from windows 95

Jabstract: Don't just imagine, make it happen!

Edited
9/1/2005 by jviper
kwandobe
kwandobe
Forum God
Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)Forum God (5.8K reputation)

Group: Forum Members
Posts: 22, Visits: 4
The only way you can get past it is by using VB.NET. :\

-kwandobe


jviper
jviper
Forum God
Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)Forum God (3.3K reputation)

Group: Forum Members
Posts: 10, Visits: 28
Ok. Well I have another idea: Is there a way I could draw the controls and contents of a form onto another?

Jabstract: Don't just imagine, make it happen!
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search