Page 3 of 3 FirstFirst 123
Results 81 to 85 of 85

Thread: Visual Basic API FAQs

  1. #81
    New Member
    Join Date
    Apr 2023
    Posts
    4

    Re: Visual Basic API FAQs

    Thanks for the info fafalone! Your routine works very nicely.

    However, I still have the problem of how to invoke the routine through code instead of dragging the edges of the form.

    Let's say I have two menu options to set font size: Small font and large font. I have small font selected and calculate a minimum form size based on that. I then drag my form's edges until it reaches the minimum and then I then select large font. I now recalculate the minimum form size and need to increase the form size to this new minimum. I can do it by dragging the edges but I'd rather be able to do it in code the moment that the large font is selected on the menu.

    P.S. I responded earlier but don't see it here, so I hope this doesn't end up being double-posted.

  2. #82
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,994

    Re: Visual Basic API FAQs

    Code:
    Public Enum SWP_Flags
        SWP_NOSIZE = &H1
        SWP_NOMOVE = &H2
        SWP_NOZORDER = &H4
        SWP_NOREDRAW = &H8
        SWP_NOACTIVATE = &H10
        SWP_FRAMECHANGED = &H20
        SWP_DRAWFRAME = SWP_FRAMECHANGED
        SWP_SHOWWINDOW = &H40
        SWP_HIDEWINDOW = &H80
        SWP_NOCOPYBITS = &H100
        SWP_NOOWNERZORDER = &H200
        SWP_NOREPOSITION = SWP_NOOWNERZORDER
        SWP_NOSENDCHANGING = &H400
        
        SWP_DEFERERASE = &H2000
        SWP_ASYNCWINDOWPOS = &H4000
    End Enum
    Public 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 SWP_Flags) As Long
    
    
    SetWindowPos Me.hWnd, 0, 0, 0, DesiredWidthInPixels, DesiredHeightInPixels, SWP_NOMOVE Or SWP_NOZORDER

  3. #83
    New Member
    Join Date
    Apr 2023
    Posts
    4

    Re: Visual Basic API FAQs

    Rock on fafalone!! Works great!! I was thinking that the solution had to involve the NewWndProc function and then on seeing your reply I wondered if I'd have to unHook the window first. But I tried it without unHooking and it works like a champ.

    May I pick your brain with one more api question?

    I have a prog that runs with a vb timer showing a countdown in the background. When certain events take place, I'm displaying a modal form containing some text and a few buttons to gather a response (similar to msgbox). During this time I expect that the timer will stop, and it usually does. However, there are occasions when the timer does NOT stop and the countdown continues. For the life of me I can't figure out why. It's the same modal form that's displayed each time although the amount of text and number of buttons changes. To tell the truth I'd prefer to always keep the timer running. I tried moving it to the main form thinking that might put it in another thread or some such thing, but it didn't change anything. So I was wondering if an api timer would do the trick. What do you think? Is an api timer worth a shot?

    Thanks again for your help!

  4. #84
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,994

    Re: Visual Basic API FAQs

    It's pretty weird that it wouldn't either consistently stop or not... not sure why that would happen.

    An API based timer is pretty easy to use; you've already got a subclass proc set up so you can just use SetTimer to send periodic WM_TIMER messages.

  5. #85

    Re: Visual Basic API FAQs

    Is there a specific reason or scenario where the standard VB Timer control might inconsistently fail to stop during the display of a modal form, and does using an API-based timer, as suggested, seem like a reasonable approach to address this issue?

Page 3 of 3 FirstFirst 123

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