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


annoying behaviours


annoying behaviours

Author
Message
TrickyRic
TrickyRic
Forum God
Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)

Group: Forum Members
Posts: 711, Visits: 6
ah cheers. seems the ambient.usermode check was whats needed, have to admit i'm still puzzled by it but it works now .

also used a little more of your code to edit mine. i'll credit you fo that, but just to check i've got it right (sorry i'm not much good with names hehe), is it "mark thesing"?

ty.




API Guide - VB/MySQL - W3Schools - WinsockVB

Mark
Mark
Forum God
Forum God (144K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

Ok Ric, I have rewritten what you had posted and I think it is doing what you are after so far. I also removed the settings module that you had in the project since everything you had there should be placed in the usercontrol. I also change the transparency porperty to take a value between 0 and 100 to represent the percent of transparency you are looking for. I added a second project making a group so the control could be tested in design time.

Load Group1.vbg and run things and see if this is close.


TrickyRic
TrickyRic
Forum God
Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)

Group: Forum Members
Posts: 711, Visits: 6
to be honest i'm too tired to test lol, i'll have a look tomorrow though, and until then heres the code. at the mo it handles both the windows topmost position, and its transparency, but when i get to adding the rest it will also handle draggability (using the whole form as a caption bar basically), shape, size, and image. basically i'm wanting this control to replace all the messy coding behind nk4/5 but at the same time keep it generic so i can reuse .

everythings working fine except for this problem of changing the properties at design time. odd...

anyway i'm off to bed, thanks.

[EDIT]
hmm "to be honest" seems to be my phrase of the week i think...




API Guide - VB/MySQL - W3Schools - WinsockVB

Mark
Mark
Forum God
Forum God (144K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

Looking at what your code, I'm guessing that you are trying to make a control that when you place it on a form you can set the form to be the topmost window or not. If that is what you are after then I think this does it. I reset your some of your variable names to fit the way I usally code properties.

 

Option Explicit
Private Declare Function 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) As Long
Dim m_TopMostWindow As Boolean

Public Property Get TopMostWindow() As Boolean
    TopMostWindow = m_TopMostWindow
End Property

Public Property Let TopMostWindow(ByVal New_TopMostWindow As Boolean)
    m_TopMostWindow = New_TopMostWindow
    SetWinPos
    PropertyChanged "TopMostWindow"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    m_TopMostWindow = PropBag.ReadProperty("TopMostWindow", False)
    SetWinPos
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "TopMostWindow", m_TopMostWindow, False
End Sub

Private Sub UserControl_Resize()
    UserControl.Width = 495
    UserControl.Height = 495
End Sub

Private Sub SetWinPos()
Dim frm As Form
Dim lngPos As Long

    'If the form is running then set its position
    If Ambient.UserMode Then
        Set frm = UserControl.Parent
        If m_TopMostWindow Then
            lngPos = -1
        Else
            lngPos = -2
        End If
        SetWindowPos frm.hwnd, lngPos, 0, 0, 0, 0, &H10 Or &H40 Or &H2 Or &H1
    End If
End Sub


TrickyRic
TrickyRic
Forum God
Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)

Group: Forum Members
Posts: 711, Visits: 6
to be honest i don't have a clue if i'm using propbag or not lol. tried your code though and its having no effect no errors are shown, but the properties still reset.

and yes, i did just say properties. i did a lil more and now have 2 properties, the second handles the forms transparency, so both use api, both need a handle to the form, and both reset if i try to change them in design time .




API Guide - VB/MySQL - W3Schools - WinsockVB

Mark
Mark
Forum God
Forum God (144K reputation)

Group: Moderators
Posts: 1.1K, Visits: 11K

Are you using the PropBag to presist you variables? With what you are showing here, This is how I would write it. I have not tested it to see if it work.

Option Explicit
Private Declare Function 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) As Long
Dim is_top As Boolean

Public Property Get TopMostWindow() As Boolean
    TopMostWindow = is_top
End Property

Public Property Let TopMostWindow(ByVal TopMost As Boolean)
    is_top = TopMost
    If is_top = True Then
        SetWindowPos UserControl.ContainerHwnd, -1, 0, 0, 0, 0, &H10 Or &H40 Or &H2 Or &H1
    Else
        SetWindowPos UserControl.ContainerHwnd, -2, 0, 0, 0, 0, &H10 Or &H40 Or &H2 Or &H1
    End If

    PropertyChanged "TopMostWindow"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    is_top = PropBag.ReadProperty("TopMostWindow", False)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "TopMostWindow", is_top, False
End Sub


TrickyRic
TrickyRic
Forum God
Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)Forum God (92K reputation)

Group: Forum Members
Posts: 711, Visits: 6
only me .

i've written a few controls, but i've never had to write one that just provides functionality (invisible at runtime, like the timer or winsock are...). anyway, i'm already having probs .

first of all i don't want the control to be resized at design time, but i can't find how to remove the width and height properties. obviously i could just stick some code into the resize event to reset the values but thats messy! try resizing a timer control and you'll see what i'm after .

and secondly i'm having a little trouble with a property, it works fine, but when i change it at design time, then run the form its sat on, its automatically reset! this is a boolean property, but it handles the forms windowpos through api, which i thinks where the problem is as at design time its not really a form that can recieve api events (i wouldn't have thought). heres the events for this property...

Public Property Get TopMostWindow() As Boolean
TopMostWindow = is_top
End Property

Public Property Let TopMostWindow(ByVal TopMost As Boolean)
is_top = TopMost
If is_top = True Then
SetWindowPos UserControl.ContainerHwnd, -1, 0, 0, 0, 0, &H10 Or &H40 Or &H2 Or &H1
Else
SetWindowPos UserControl.ContainerHwnd, -2, 0, 0, 0, 0, &H10 Or &H40 Or &H2 Or &H1
End If
UserControl.PropertyChanged "TopMostWindow"
End Property

...works fine at runtime, but just resets to false if i change it at design time and try running.

ty.

[EDIT]
ok ignore the resize problem, setting it to windowless removes the width/height properties and the resize event does the rest .

still baffled by the resetting variable though ...




API Guide - VB/MySQL - W3Schools - WinsockVB

GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search