API for Window creation

Can anyone tell me the correct way to display a MODAL window using the API SetWindowPos, or possibly another API call?
Who is Participating?
stewfidgeonConnect With a Mentor Commented:
If you are using a 32 bit version of VB, you cant. It doesnt allow for system modal windows. If you are using VB4 16bit version then it is done like this:

private declare function setsysmodalwindow lib "user" (ByVal hwnd as Integer) as integer

private sub form1_load()
result = Setsysmodalwindow (form1.hwnd)
end sub

It sets form1 to the topmost window, and keeps it there until you close the form. No other applications or forms can be used until you close the modal form.

If you need to display a form to simulate a system modal window, you can work on the lostfocus event, and use that to set focus back to your form.

If you need code examples, just add a comment saying so, and I'll write some for you.

Hope this answers your question.


doesn't NickHeitz3 want to fiaplay a modal form similar to what in WIN32 API called "Modal Dialog Box"? I think he does. And wouldn't it be simplier to do something like this:

Dim frmMyForm As New Form2

frmMyForm.Show 1

Hmm, it is enterily possible that I have got the wrong end of a whole bunch of sticks. Oooops.....

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


The only reason you should be using the Windows API to do this is if you want to manipulate external windows/programs.  Otherwise, use the code given above to do it :

Form1.Show vbModal

I believe that stewfidgeon was right when he said that you can NOT display a form SystemModally.  Though you CAN display a dialog box SystemModally.

If you're more specific on what you want, maybe we could help more.

NickHeitz3Author Commented:
Sorry guys, I was actually trying to mimic the vbmodal aspect of vb windows using api calls.  I will be within a vb environment, but I want ot have more control ovr how the window behaves, namely, how the background is refreshed, and wanted to see if there was a way to display a form modally.  
If there still isn't a way, then I will givethe points to stewfidgeon.

To refresh the form, or any object on it, simply use the REFRESH property :


To bring up a form modally, simply Show it using "vbModal"  :

Form2.Show vbModal

NickHeitz3Author Commented:
Please, would somebody just tell me how to bring up a show a form modally using API calls.  I a man experienced programmer, I know how to refresh a form and how to use vb for modality, but my situation os more complex than that.  I am working inside an environment whose environment I only have bits of control over, nad I am looking for other option in terms of showing a form.  I acknowledge that what I want may not be possible.
NickHeitz3Author Commented:
Actually, it looks like your answer may be the one I want...sorry it took so long.  If you could post me some examples, I would appreciate it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.