I have tried to write an initialization subroutine for my ddt dialogs
but I do not seem to be using the Pixel/Unit conversion functions
correctly. What I would like to have happen is for the user to place the
dialog where he wants and then when he restarts the app the program remembers
where it was and the dialog appears where he left it.
This is more of a concern with Win98 and now Win2000 multiple monitor
PC's
I want to store the user selected location with these statements:
Dialog Get Client hDlg To rcDlgIni.nWidth, rcDlgIni.nHeight
Dialog Get Loc hDlg To nPixLeft, nPixTop
Dialog Pixels hDlg, nPixLeft, nPixTop To Units rcDlgIni.nLeft, rcDlgIni.nTop
and store those values in an INI file
and then use to re-create the Dialog
Dialog New hParent, sAppTitle, _
rcDlgIni.nLeft, rcDlgIni.nTop, rcDlgIni.nWidth, rcDlgIni.nHeight _ etc
But each time the program is stopped and then restarted the Dialog creeps toward
the Top Left corner. I have found through trial and error that the following
statement mostly stop the dialog movement.
rcDlgIni.nTop = (rcDlgIni.nTop * 8&) \ 5&
rcDlgIni.nLeft = (rcDlgIni.nLeft * 3&) \ 2&
An example source code is shown below
Does anyone know what I am doing wrong -or- have a better way of
saving the Dialog Position from the previous run.
Thanks Joe Murphy
but I do not seem to be using the Pixel/Unit conversion functions
correctly. What I would like to have happen is for the user to place the
dialog where he wants and then when he restarts the app the program remembers
where it was and the dialog appears where he left it.
This is more of a concern with Win98 and now Win2000 multiple monitor
PC's
I want to store the user selected location with these statements:
Dialog Get Client hDlg To rcDlgIni.nWidth, rcDlgIni.nHeight
Dialog Get Loc hDlg To nPixLeft, nPixTop
Dialog Pixels hDlg, nPixLeft, nPixTop To Units rcDlgIni.nLeft, rcDlgIni.nTop
and store those values in an INI file
and then use to re-create the Dialog
Dialog New hParent, sAppTitle, _
rcDlgIni.nLeft, rcDlgIni.nTop, rcDlgIni.nWidth, rcDlgIni.nHeight _ etc
But each time the program is stopped and then restarted the Dialog creeps toward
the Top Left corner. I have found through trial and error that the following
statement mostly stop the dialog movement.
rcDlgIni.nTop = (rcDlgIni.nTop * 8&) \ 5&
rcDlgIni.nLeft = (rcDlgIni.nLeft * 3&) \ 2&
An example source code is shown below
Does anyone know what I am doing wrong -or- have a better way of
saving the Dialog Position from the previous run.
Code:
============================================================= Main Program ============================================================= #COMPILE EXE "c:\murphy\status\xstatus.exe" #DIM ALL #REGISTER NONE #INCLUDE "c:\pbdll60\winapi\win32api.inc" #INCLUDE "c:\murphy\status\appinfo.inc" #INCLUDE "c:\murphy\status\dlgini.bas" #INCLUDE "c:\murphy\status\globequ.bas" #INCLUDE "c:\murphy\status\status.ddt" Function PbMain () As Long Dim hParent As Long Dim nRetC As Long Call GetAppInfo ("Trade Completion Status Program") hParent = 0 nRetC = Create_StatusDialog(hParent) End Function ============================================================= Included Sources Code: GLOBEQU.BAS ============================================================= Global hStatusDialog As Long %DLG_1_Timer = 101 %DLG_1_Pause = 102 %DLG_1_Continue = 103 %DLG_1_Exit = 104 %DLG_1_LastUser = 105 %DLG_1_Status = 106 %DLG_1_Number = 107 ============================================================= APPINFO.INC ============================================================= Type tyApp Path as String * 128 EXEName as String * 8 Title as String * 128 End Type Global App0 as tyApp Sub GetAppInfo (Byval sBuffer As String) Local nLen As Long Local nRet As Long Local sTxt As String Local nDot As Long Local nSlash As Long App0.Title = Trim$(sBuffer) App0.Path = "Not Available" App0.EXEName = "NONE" nLen = 127 sTxt = Space$(nLen) nRet = GetModuleFileName (0, BYVAL STRPTR(sTxt), nLen) sBuffer = Trim$(sTxt) App0.Path = sBuffer ' Remember that pesky Hex(00) at the end of the String sTxt = Left$(UCase$(Right$(sBuffer, 5)), 4) If sTxt < > ".EXE" Then Exit Sub nDot = Len(sBuffer) - 4 nSlash = nDot - 1 Do While nSlash > 0 If Mid$(sBuffer, nSlash, 1) = "\" Then Exit Do If Mid$(sBuffer, nSlash, 1) = ":" Then Exit Do nSlash = nSlash - 1 Loop If (nDot - nSlash) < 2 Then Exit Sub If nSlash > 1 Then App0.Path = LEFT$(sBuffer, nSlash) nSlash = nSlash + 1 nDot = nDot - nSlash App0.EXEName = Mid$(sBuffer, nSlash, nDot) End If End Sub ============================================================= DLGINI.BAS ============================================================= Declare Function MakeSureDir Lib "Imagehlp" Alias _ "MakeSureDirectoryPathExists" (lpPath As Asciiz) As Long ' Example of MakeSureDir Win32API function call ' Dim RetC As Long ' RetC = MakeSureDir("s:\archive\trading\ccyymmdd\") Type tyDlgIni nTop As Long nLeft As Long nHeight As Long nWidth As Long End Type Global rcDlgIni As tyDlgIni Global FileIni As String Sub ReadDlgIni() Dim xSection As Asciiz * 128 Dim xKey As Asciiz * 128 Dim xVar As Asciiz * 128 Dim xDefault As Asciiz * 128 Dim xFileName As Asciiz * 128 Dim xLen As Long Dim xRet As Long xFileName = FileIni xSection = "Setup" xKey = "Top" xDefault = "5" xLen = 128 xVar = Space$(127) xRet = GetPrivateProfileString(xSection, xKey, xDefault, xVar, xLen, xFileName) rcDlgIni.nTop = Val(Trim$(Left$(xVar, xRet))) xKey = "Left" xDefault = "5" xLen = 128 xVar = Space$(127) xRet = GetPrivateProfileString(xSection, xKey, xDefault, xVar, xLen, xFileName) rcDlgIni.nLeft = Val(Trim$(Left$(xVar, xRet))) xKey = "Height" xDefault = "280" xLen = 128 xVar = Space$(127) xRet = GetPrivateProfileString(xSection, xKey, xDefault, xVar, xLen, xFileName) rcDlgIni.nHeight = Val(Trim$(Left$(xVar, xRet))) xKey = "Width" xDefault = "420" xLen = 128 xVar = Space$(127) xRet = GetPrivateProfileString(xSection, xKey, xDefault, xVar, xLen, xFileName) rcDlgIni.nWidth = Val(Trim$(Left$(xVar, xRet))) End Sub Sub WriteDlgIni(hDlg As Long) Dim xSection As Asciiz * 128 Dim xKey As Asciiz * 128 Dim xVar As Asciiz * 128 Dim xFileName As Asciiz * 128 Dim xRet As Long Dim nPixTop As Long Dim nPixLeft As Long Dialog Get Client hDlg To rcDlgIni.nWidth, rcDlgIni.nHeight Dialog Get Loc hDlg To nPixLeft, nPixTop Dialog Pixels hDlg, nPixLeft, nPixTop To Units rcDlgIni.nLeft, rcDlgIni.nTop ' rcDlgIni.nTop = (rcDlgIni.nTop * 8&) \ 5& ' rcDlgIni.nLeft = (rcDlgIni.nLeft * 3&) \ 2& xFileName = FileIni xSection = "Setup" xKey = "Top" xVar = Str$(rcDlgIni.nTop) xRet = WritePrivateProfileString(xSection, xKey, xVar, xFileName) xKey = "Left" xVar = Str$(rcDlgIni.nLeft) xRet = WritePrivateProfileString(xSection, xKey, xVar, xFileName) xKey = "Height" xVar = Str$(rcDlgIni.nHeight) xRet = WritePrivateProfileString(xSection, xKey, xVar, xFileName) xKey = "Width" xVar = Str$(rcDlgIni.nWidth) xRet = WritePrivateProfileString(xSection, xKey, xVar, xFileName) End Sub ============================================================= STATUS.DDT ============================================================= CallBack Function StatusDialog_CB As Long Dim hJunk As Long Dim hMenu As Long Dim szText As Asciiz * 100 Dim sTxtStart As String Select Case CbMsg Case %WM_INITDIALOG Control Disable hStatusDialog, %DLG_1_Continue sTxtStart = "Request #0" Control Set Text hStatusDialog, %DLG_1_Number , sTxtStart hMenu = 500 ' 0.5 Seconds hJunk = SetTimer (hStatusDialog, %DLG_1_Timer , hMenu , %NULL) Case %WM_TIMER ' Call the timer subroutine UpdateWindow hStatusDialog Dialog DoEvents Case %WM_COMMAND If CbCtlMsg = %BN_CLICKED Then Select Case CbCtl Case %DLG_1_Pause ' MAKDWD(%DLG_1_Pause, %BN_CLICKED) Control Enable hStatusDialog, %DLG_1_Continue Control Disable hStatusDialog, %DLG_1_Pause Control Set Text hStatusDialog, %DLG_1_Status , "Press Continue to restart" Case %DLG_1_Continue ' MAKDWD(%DLG_1_Continue, %BN_CLICKED) Control Disable hStatusDialog, %DLG_1_Continue Control Enable hStatusDialog, %DLG_1_Pause Control Set Text hStatusDialog, %DLG_1_Status , "Continuing ..." Case %DLG_1_Exit ' MAKDWD(%DLG_1_Exit, %BN_CLICKED) hJunk = KillTimer (hStatusDialog, %DLG_1_Timer) UpdateWindow hStatusDialog Dialog DoEvents Call WriteDlgIni(hStatusDialog) Dialog End CbHndl, - 1 End Select End If End Select End Function '=========================================================================== Function Create_StatusDialog (ByVal hParent As Long ) As Long Dim lRetVal As Long Dim sAppTitle As String FileIni = "c:\windows\xstatus.ini" Call ReadDlgIni ' Dialog will not be resizable, only moveable so I will force my width and height rcDlgIni.nWidth = 220 rcDlgIni.nHeight = 65 sAppTitle = Trim$(App0.Title) Dialog New hParent, sAppTitle, _ rcDlgIni.nLeft, rcDlgIni.nTop, rcDlgIni.nWidth, rcDlgIni.nHeight _ , %WS_POPUP Or %WS_CAPTION Or %WS_SYSMENU Or %DS_MODALFRAME Or %WS_MINIMIZEBOX _ To hStatusDialog Control Add Button, hStatusDialog, %DLG_1_Pause , "&Pause" , 5, 5, 50, 14 Control Add Button, hStatusDialog, %DLG_1_Continue, "&Continue", 5, 25, 50, 14 Control Add Button, hStatusDialog, %DLG_1_Exit , "E&xit" , 5, 45, 50, 14 Control Add Label, hStatusDialog, %DLG_1_LastUser, "Last User Serviced", _ 60, 5, 155, 25, %SS_LEFT Or %SS_SUNKEN Control Add Label, hStatusDialog, %DLG_1_Status , "Program Status" , _ 60, 35, 155, 11, %SS_LEFT Or %SS_SUNKEN Control Add Label, hStatusDialog, %DLG_1_Number , "Number of Requests", _ 60, 48, 155, 11, %SS_LEFT Or %SS_SUNKEN Dialog Show Modal hStatusDialog, Call StatusDialog_CB To lRetVal End Function ============================================================= End of Listing =============================================================
Comment