Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Common Dialog didn't work??

6 views
Skip to first unread message

Nelson Lopes

unread,
Jan 29, 2000, 3:00:00 AM1/29/00
to
Thank you to those who responded to my last question on positioning the
Common Dialog box from within VB. I have tried your example code, but it
does not position my dialog box. It appears that windows is remembering
where it's last position was and opens it in that same place each time. I
traced through the subclassing code and found that it was detecting the
WM_INITDIALOG message and setting the window position for it, but....??
What is causing Windows 98 (Second Edition) to place the dialog box in the
last position where it was opened and not where the code tells it?.

In my program, when the user clicks on the open button, I am using the
Common Dialog control to show the "open" dialog box. I would like to
position this in the center of my applications form. Any help resolving
this would be greatly appreciated.

Thank you,

Nelson


Nelson Lopes

unread,
Jan 29, 2000, 3:00:00 AM1/29/00
to
Thank you for the code. However, again it does not place the common dialog
box in the center of the screen each time it is opened. If I run the code
and open the common dialog box, it is centered. If I move the dialog box to
another position, hit the cancel button, and then open the common dialog
again. It opens at the position where I moved it too...not the center of
the screen! Hmmmm?

Thanks,

Nelson

Nelson Lopes <nlo...@tampabay.rr.com> wrote in message
news:#7pua7ra$GA.279@cppssbbsa05...

Juergen Thuemmler

unread,
Jan 30, 2000, 3:00:00 AM1/30/00
to
> Thank you for the code. However, again it does not place the common dialog
> box in the center of the screen each time it is opened. If I run the code
> and open the common dialog box, it is centered. If I move the dialog box to
> another position, hit the cancel button, and then open the common dialog
> again. It opens at the position where I moved it too...not the center of
> the screen! Hmmmm?
>
Yes, you're right ... I've seen it also...
No idea at the moment - sorry.

Juergen.

Paul Gooch

unread,
Jan 30, 2000, 3:00:00 AM1/30/00
to
IMO that's how you should leave it. Forcing your users to continually
re-position the dialogue isn't good.

--


Regards, Paul.

pa...@gooch.co.uk
www.gooch.co.uk


"Nelson Lopes" <nlo...@tampabay.rr.com> wrote in message

news:eiFO3msa$GA.256@cppssbbsa05...


> Thank you for the code. However, again it does not place the common
dialog
> box in the center of the screen each time it is opened. If I run the code
> and open the common dialog box, it is centered. If I move the dialog box
to
> another position, hit the cancel button, and then open the common dialog
> again. It opens at the position where I moved it too...not the center of
> the screen! Hmmmm?
>

Schmidt

unread,
Jan 30, 2000, 3:00:00 AM1/30/00
to
Here's another example with no positioning-problems:
(Extends the File-Open-Dlg with a simple Picture-Preview)

VB6

*******Into a Form (Form1)
'ComDlg-Pos. and Resize Copyright Olaf Schmidt 1999
'Picture-Preview
Option Explicit

Public WithEvents T1 As TextBox, WithEvents P1 As PictureBox

Private Sub Form_Click()
Dim OF As OPENFILENAME
'generate Controls
ScaleMode = 3
Set T1 = Controls.Add("VB.Textbox", "T1")
T1.Left = 425: T1.Top = 32: T1.Width = 113: T1.Height = 22
Set P1 = Controls.Add("VB.Picturebox", "P1")
P1.Left = 425: P1.Top = 57: P1.Width = 113: P1.Height = 114
'prepare and show Dialog
OF.lStructSize = Len(OF)
OF.hwndOwner = hwnd: OF.lpstrTitle = "My Dialog"
OF.nMaxFile = 255: OF.lpstrFile = String(OF.nMaxFile, Chr(0))
PosX = 22: PosY = 222: PosDX = 555: PosDY = 300
PosHook = SetWindowsHookEx(4, AddressOf PosProc, 0, App.ThreadID)
GetOpenFileName OF
UnhookWindowsHookEx PosHook

Controls.Remove "T1": Set T1 = Nothing
Controls.Remove "P1": Set P1 = Nothing

Print Left$(OF.lpstrFile, InStr(OF.lpstrFile, Chr$(0)) - 1)
End Sub

Private Sub T1_Change()
Beep
End Sub

*******Into a Module
'ComDlg-Pos. and Resize Copyright Olaf Schmidt 1999
Option Explicit

Public Type WINDOWPOS
hwnd As Long
hWndInsertAfter As Long
x As Long
y As Long
cx As Long
cy As Long
flags As Long
End Type

Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Type CWPSTRUCT
lParam As Long
wParam As Long
Message As Long
hwnd As Long
End Type

Type OFHdr
hwnd As Long
id As Long
code As Long
pOF As Long
pSF As Long
End Type

Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA"
(ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook&) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd
As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
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
Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA"
(pOpenfilename As OPENFILENAME) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal
hWndNewParent As Long) As Long
Declare Sub RtlMoveMemory Lib "kernel32" (Dst As Any, Src As Any, ByVal
Bytes As Long)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public PosHook&, PosX&, PosY&, PosDX&, PosDY&

Function PosProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
Dim S As String, NM As OFHdr, WP As WINDOWPOS
Static hw&, CC&, SizehWnd&
On Error Resume Next
Select Case Inf.Message
Case 1 'WM_CREATE
S = Space(7): GetClassName Inf.hwnd, S, 7
If Left(S, 6) = "#32770" Then
hw = Inf.hwnd: SizehWnd = Inf.hwnd
SetParent Form1.T1.hwnd, hw: SetParent Form1.P1.hwnd, hw
Form1.T1.Visible = True: Form1.P1.Visible = True
End If
Case &H4E 'WM_NOTIFY
RtlMoveMemory NM, ByVal Inf.lParam, Len(NM)
If NM.code = -12 Then
S = String(255, Chr(0)): DoEvents
SendMessage hw, 1125, 255, ByVal S
S = Left(S, InStr(S, Chr(0)) - 1)
Form1.T1 = Mid(S, InStrRev(S, "\") + 1)
Select Case LCase(Right(S, 3))
Case "bmp", "jpg", "gif": Form1.P1.Picture = LoadPicture(S)
End Select
End If
Case &H46 'WM_WindowPosChanging
If Inf.hwnd = SizehWnd Then
RtlMoveMemory WP, ByVal Inf.lParam, Len(WP)
CC = CC + 1: WP.flags = 0
WP.x = PosX: WP.y = PosY
WP.cx = PosDX: WP.cy = PosDY
If CC = 3 Then CC = 0: SizehWnd = 0
RtlMoveMemory ByVal Inf.lParam, WP, Len(WP)
End If
End Select
End Function

Olaf

Edward Rothwell

unread,
Jan 30, 2000, 3:00:00 AM1/30/00
to
Woooooaahhhhh! Seriously cool Schmidt.

I've not seen it done this way before. Very interesting and useful.

Ed.

0 new messages