プロが教える店舗&オフィスのセキュリティ対策術

INIファイルからPCのモニターとフォームサイズデータの比率を読み込み、そのデータを元にフォームを画面を呼び出したいのですが、どの様にしてよいかがわかりません。申し訳ありませんが教えていただけないでしょうか??
ちなみにINIファイルのデータを読み込み、ボタンに名前を表示するといったことはできました。

A 回答 (3件)

フォームサイズは、そのフォームのScaleWidthやScaleHeightプロパティで取得することができますよね。


ディスプレイサイズ(解像度)は、以下のようなAPI関数を使って取得できますので(X=1280, Y=800等のピクセル値)、両者の値から行いたい値を算出して、フォームの前述のプロパティを変更すれば良いのではないでしょうか。

Option Explicit
Private Declare Function GetSystemMetrics Lib "user32" _
      (ByVal nIndex As Long) As Long
Private Const SM_CXSCREEN As Long = 0
Private Const SM_CYSCREEN As Long = 1
Private Sub Form_Load()
  Dim X As Long, Y As Long
  X = GetSystemMetrics(SM_CXSCREEN) '画面の幅を取得します。
  Y = GetSystemMetrics(SM_CYSCREEN) '画面の高さを取得します。
  Debug.Print X, Y
End Sub
注)ステートメントを見易くするため先頭に全角スペースを入れてます。
 
    • good
    • 0

INIファイルのデータの読み方と、更新を説明します。



'ini情報取得
Declare Function GetPrivateProfileString Lib "KERNEL32.DLL" _
Alias "GetPrivateProfileStringA" _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
'ini情報更新
Declare Function WritePrivateProfileString Lib "KERNEL32.DLL" _
Alias "WritePrivateProfileStringA" _
(ByVal lpAppName As String, ByVal lpKeyName As String, _
ByVal lpString As String, ByVal lpFileName As String) As Long
' 機能 :設定ファイルの読み込み
'
' 返値 :設定文字数
'
' 引数 :StrSection - 設定ファイルのセクション名
' StrEntry - 設定ファイルのエントリー名
' StrDefault - 設定デフォルト値
'
' 機能説明 :設定ファイル(*.INI)から値(設定文字列)を取得する
'
' 備考 :
'
Public Function GetProfile(StrSection As String, StrEntry As String, StrDefault As String, StrIniFileName As String) As String


Dim LInt_Length As Integer '' 対象文字数
Dim LStr_ProFile As String * 256 '' 取得文字列
Dim LInt_RetBufSize As Integer

LInt_RetBufSize = 256
LStr_ProFile = String$(256, " ")
'' 読み込み実行
LInt_Length = GetPrivateProfileString$(StrSection, StrEntry, StrDefault, LStr_ProFile, _
LInt_RetBufSize, StrIniFileName)
If LInt_Length <> 0 Then
GetProfile = Trim$(StrConv(LeftB$(StrConv(LStr_ProFile, vbFromUnicode), LInt_Length), vbUnicode))
Else
GetProfile = ""
End If

End Function

' 機能 :設定ファイルの書き込み
'
' 返値 :設定文字数
'
' 引数 :StrSection - 設定ファイルのセクション名
' StrEntry - 設定ファイルのエントリー名
' StrDefault - 設定デフォルト値
'
' 機能説明 :設定ファイル(*.INI)に値(設定文字列)を設定する
'
' 備考 :
'
Public Function PutProfile(StrSection As String, StrEntry As String, StrWrite As String, StrIniFileName As String) As Boolean


Dim LInt_Length As Integer '' 対象文字数

'' 読み込み実行
LInt_Length = WritePrivateProfileString$(StrSection, StrEntry, StrWrite, StrIniFileName)
If LInt_Length <> 0 Then
PutProfile = True
Else
PutProfile = False
End If

End Function

参考URL:http://www.red.oit-net.jp/tatsuya/vb/INI.htm
    • good
    • 0

デスクトップの大きさは Screenオブジェクトから算出できます



幅:Screen.Width、高さScreen.Height
単位はTWIPSですのでPixel(ドット)で欲しいなら ScreenオブジェクトのTwipsPerPixelX/TwipsPerPixelYプロパティによって除算しましょう

dx = Screen.Width / TwipsPerPixelX
dy = Screen.Height / TwipsPerPixelY
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!