سوال در مورد توابع api

amirxbest

Member
سلام خدمت تمام دوستان.:rose:

با کدوم تابع api میتونم سایز screen resolution رو بگیرم؟؟؟اگه میشه با نمومه.
 

the_king

مدیرکل انجمن
سلام خدمت تمام دوستان.:rose:

با کدوم تابع api میتونم سایز screen resolution رو بگیرم؟؟؟اگه میشه با نمومه.
لطفا همیشه زبان برنامه نویسی رو در عنوان سوال مشخص کنید.

روش های مختلفی داره، ساده ترینش استفاده از تابع GetSystemMetrics است.

در ویژوال بیسیک کلاسیک :
کد:
Private Const SM_CXSCREEN As Long = 0
Private Const SM_CYSCREEN As Long = 1

Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long

Private Sub Form_Load()
    Dim screenWidth As Long, screenHeight As Long
    screenWidth = GetSystemMetrics(SM_CXSCREEN)
    screenHeight = GetSystemMetrics(SM_CYSCREEN)
    MsgBox CStr(screenWidth) & " x " & CStr(screenHeight)
End Sub

در ویژوال سی :
کد:
#include <stdio.h>

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	int screenWidth = GetSystemMetrics(SM_CXSCREEN);
	int screenHeight = GetSystemMetrics(SM_CYSCREEN);
	char text[12];
	sprintf(text, "%d x %d", screenWidth, screenHeight);
	MessageBox(0, text, "", 0);
	return 0;
}

البته در اغلب زبان های برنامه نویسی نیازی به تابع API نیست.
در ویژوال بیسیک کلاسیک :
کد:
Private Sub Form_Load()
    Dim screenWidth As Long, screenHeight As Long
    screenWidth = Screen.Width / Screen.TwipsPerPixelX
    screenHeight = Screen.Height / Screen.TwipsPerPixelY
    MsgBox CStr(screenWidth) & " x " & CStr(screenHeight)
End Sub

در ویژوال بیسیک دات نت :
کد:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim screenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim screenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
        MessageBox.Show(CStr(screenWidth) & " x " & CStr(screenHeight))
    End Sub

در سی شارپ :
کد:
        private void Form1_Load(object sender, EventArgs e)
        {
            int screenWidth = Screen.PrimaryScreen.Bounds.Width;
            int screenHeight = Screen.PrimaryScreen.Bounds.Height;
            MessageBox.Show(screenWidth.ToString() + " x " + screenHeight.ToString());
        }
 

جدیدترین ارسال ها

بالا