Results 1 to 10 of 10

Thread: [UNRESOLVED]can't swtich from window onbottom to normal or ontop

  1. #1

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172

    [UNRESOLVED]can't swtich from window onbottom to normal or ontop

    I'm trying to get switching from window on bottom to window on top and normal window behaviour to work, but I can't find any solution. Here's my code:
    Code:
    Public Const SWP_NOSIZE = &H1
    Public Const HWND_TOPMOST = -1
    Public Const HWND_NOTOPMOST = -2
    Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE
    
    Public FormPosition As String
    
    Sub FormOnBottom(Frm As Form)
    Dim DeskH As Long
    
    Call SetWindowPos(Frm.hWnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, Flags)
    
    DeskH = GethWndByWinTitle("Program Manager")
    Call SetParent(Frm.hWnd, DeskH)
    
    FormPosition = "onbtm"
    
    End Sub
    
    Sub FormNormal(Frm As Form)
    Dim DeskH As Long
    
    DeskH = GethWndByWinTitle(frmMain.Caption)
    Call SetParent(Frm.hWnd, DeskH)
    
    Call SetWindowPos(Frm.hWnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, Flags)
    
    FormPosition = "normal"
    
    End Sub
    
    Sub FormOnTop(Frm As Form)
    Dim DeskH As Long
    
    DeskH = GethWndByWinTitle(frmMain.Caption)
    Call SetParent(Frm.hWnd, DeskH)
    
    Call SetWindowPos(Frm.hWnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, Flags)
    
    FormPosition = "ontop"
    
    End Sub
    
    Public Function GethWndByWinTitle(winTitle As String) As Long
    
        Dim RetVal As Long
        GethWndByWinTitle = FindWindow(vbNullString, winTitle)
        
    End Function
    FormOnBottom gets called first, which results in form going to the bottom. But when I execute FormOnTop/FormNormal after FormOnBottom, the form disappears.

    Does anyone have any idea why this happens, or have any solution/code for a proper function?

    Thanks in advance
    Last edited by vigge89; Sep 5th, 2004 at 01:52 AM.


  2. #2
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711

    Re: can't swtich from window onbottom to normal or ontop

    Originally posted by vigge89
    Code:
    DeskH = GethWndByWinTitle(frmMain.Caption)
    Call SetParent(Frm.hWnd, DeskH)
    
    Call SetWindowPos(Frm.hWnd, HWND_NOTOPMOST, 0&, 0&, 0&, 0&, Flags)
    I am not sure but I think you need to put a Refresh in the middle of that because i think the hWnd changes when you use SetParent.

    PS: I didn't try running the code
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  3. #3

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    nope, still doesn't work


  4. #4
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711
    try running through the code one line at a time, and moniter everything that is happining within your program.

    if you are still stuck then delete stuff that is not an absolute nessesaty, and maby even some that you do need. like the setparent statment

    see if you can just get it down to the least amount of lines as possable
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  5. #5

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    The problem seems to be the
    VB Code:
    1. DeskH = GethWndByWinTitle(frmMain.Caption)
    2. Call SetParent(Frm.hWnd, DeskH)
    code.
    Maybe there's something wrong with the DeskH, should the frmMains hWnd parent be frmMain?

    Also, when I change the windowstate from onbottom to ontop or normal, the windows position (x,y) is changed to high numbers (everything from 500,500 to 1400,1200 - outside the desktop), i'm not sure if this has got to do about the setparent part, but i think so, because if i change it back to onbottom from normal or ontop when the window have disappeared, it becomes visible again, and the xy-positions reset themself to the value before switching to normal/ontop.


  6. #6
    Fanatic Member ALL's Avatar
    Join Date
    Jul 2004
    Location
    192.168.1.1
    Posts
    711
    I am not sure, I would be of more help if i tried this code my self, but my laptop with VB6 on it is in many pieces, so I would recomend that you get help form a nother user.

    I am so sorry that i am not of more help.
    -ALL

    PS: put "UNRESOLVED" in the title of this thred by editing the origional post, that will give you help faster
    sorry again
    Please support one of my projects?
    TKForums.com

    Web Forum
    JavaScript Wiki
    ________________________
    If somone helps you, please rate their post, by clicking the to rate their post

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    My guess is you should probably use GetWindowPos first, then edit the settings to your liking and then call SetWindowPos. I think you aren't taking care too well of the other properties, ie. you are trying to brute force to have only some settings when there should be some other settings too.

    I'm not too familiar with these APIs, so it is a wild guess. Have you tried finding a working solution?

  8. #8

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    Originally posted by Merri
    My guess is you should probably use GetWindowPos first, then edit the settings to your liking and then call SetWindowPos. I think you aren't taking care too well of the other properties, ie. you are trying to brute force to have only some settings when there should be some other settings too.

    I'm not too familiar with these APIs, so it is a wild guess. Have you tried finding a working solution?
    how do you mean? and, yes i've tried different things, eg. taking away setwindowpos/setparent but I still can't get it to work


  9. #9
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246
    Try changing this:
    VB Code:
    1. Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE
    To this:
    VB Code:
    1. Public Const SWP_SHOWWINDOW = &H40
    2. Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW
    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  10. #10

    Thread Starter
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    tried your code phreak

    now it flicker when i change it to onbottom, and the x,y positions change to something strange, but the window disappears right after the flicker.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width