반응형

* VBNET API를 이용한 NetworkNetwork MacAddress (네트워크 맥 주소 구하기) 예제...

 

 

전체 소스 코드

Form1.vb

 

Public Class Form1


    Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As UInt32, ByVal SrcIP As UInt32, _
      ByVal pMacAddr As Byte(), ByRef PhyAddrLen As Integer) As Integer

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        MessageBox.Show(Get_MACAddress("192.168.0.6"))

    End Sub


    Private Function Get_MACAddress(ByVal strIPAddress As String) As String
        Dim ip As Net.IPAddress = Net.IPAddress.Parse(strIPAddress)

        Dim btIPArray() As Byte = New Byte(6) {}

        Dim uiIP As System.UInt32 = CType(btIPArray.Length, System.UInt32)

        Dim iIPValue As Integer = BitConverter.ToInt32(ip.GetAddressBytes(), 0)

        Dim iReturnCode As Integer = SendARP(iIPValue, 0, btIPArray, uiIP)

        If iReturnCode <> 0 Then
            Return ""
        End If

        Dim strIP(Convert.ToInt32(uiIP)) As String

        Dim i As Integer
        For i = 0 To uiIP - 1 Step i + 1
            strIP(i) = btIPArray(i).ToString("X2")
        Next
        Dim strMacAddress As String = String.Join(":", strIP)
        Return strMacAddress
    End Function

End Class

*예제 결과 확인

 

 

어댑터 설정 변경 - > 해당 어댑터 더블 클릭 - > 자세히 버튼을 클릭 하여 맥주소를 확인 



https://kdsoft-zeros.tistory.com/143

 

[C#] IP MacAddress (IP 맥 주소 구하기)

* C# IP MacAddress 구하기 예제... 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; us..

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# Network MacAddress 구하기 예제...

 

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Net;
using System.Runtime.InteropServices;

namespace CSharp_MacAddress
{
    public partial class Form1 : Form
    {
        [DllImport("iphlpapi.dll", ExactSpelling = true)]
        private static extern int SendARP(int destinationIPValue, int sourceIPValue, byte[] physicalAddressArray, ref uint physicalAddresArrayLength);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strMacAddress = Get_MACAddress("192.168.0.6");

            MessageBox.Show(strMacAddress);

        }

        public string Get_MACAddress(string strIPAddress)
        {
            IPAddress ip = IPAddress.Parse(strIPAddress);
            
            byte[] btIPArray       = new byte[6];
            
            uint uiIP = (uint)btIPArray.Length;
            
            int iIPValue = BitConverter.ToInt32(ip.GetAddressBytes(), 0);
            
            int iReturnCode = SendARP(iIPValue, 0, btIPArray, ref uiIP);

            if (iReturnCode != 0)
            {
                return null;
            }

            string[] strIP = new string[(int)uiIP];

            for (int i = 0; i < uiIP; i++)
            {
                strIP[i] = btIPArray[i].ToString("X2");
            }
            string strMacAddress = string.Join(":", strIP);
            return strMacAddress;

        }

    }
}

*예제 결과 확인 

 

 

어댑터 설정 변경 - > 해당 어댑터 더블 클릭 - > 자세히 버튼을 클릭 하여 맥주소를 확인 

 

https://kdsoft-zeros.tistory.com/144

 

[VBNET] IP MacAddress (IP 맥 주소 구하기)

* VBNET API를 이용한 IP MacAddress (IP 맥 주소 구하기) 예제... 전체 소스 코드 Form1.vb Public Class Form1 Declare Function SendARP Lib "iphlpapi.dll" (ByVal DestIP As UInt32, ByVal SrcIP As UInt32,..

kdsoft-zeros.tistory.com

 

반응형
반응형

* out 키워드 : 인수를 참조로 전달하는 데 사용.

                   다만 전달 인수가 초기화가 되지 않아도 참조 전달이 됨.

   ref 키워드 : 인수를 참조로 전달하는 데 사용.

                   다만 전달 인수가 반드시 초기화가 되어서 전달 되어야 됨.

 

 

위 그림에서 보듯이 ref 참조는 밑줄로 오류가 되어 있습니다. 초기화가 되지 않은 변수가 참조 전달 인수로 되었기 때문입니다. out 참조는 함수 안에서 변수를 초기화 하여 다시 리턴 하는 방식으로 되어 있습니다.

 

 

* ref 참조는 반드시 변수가 초기화 되어서 전달 되어야 되지만 out 참조는 변수 초기화 하고 안하고 둘다 참조 전달이 되는 부분이 가장 큰 차이겠습니다. 

반응형
반응형

* C# API 를 이용해 해당 윈도우 폼(Window Form) 을 찾아서 최상위 윈도우로 포커스(Focus) 맞추기 예제...

 

메인 화면

 

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

Public Class Form1

    'API 선언...
    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    Private Shared Function FindWindow( _
     ByVal lpClassName As String, _
     ByVal lpWindowName As String) As IntPtr
    End Function

    <DllImport("user32.dll")> _
    Private Shared Function SetForegroundWindow(ByVal hWnd As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
     Private Shared Function ShowWindowAsync(ByVal hwnd As IntPtr, ByVal nCmdShow As Integer) As Boolean
    End Function

    '윈도우 상태...
    Const SHOWHIDE As Integer = 0
    Const SHOWNORMAL As Integer = 1
    Const SHOWMINIMIZED As Integer = 2
    Const SHOWMAXIMIZED As Integer = 3

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        Dim ipHandle As IntPtr = FindWindow(Nothing, textBox1.Text)

        '해당 윈도우를 찾았으면...
        If Not ipHandle.Equals(IntPtr.Zero) Then

            '해당 윈도우가 최소화 되어 있으면 노멀로 변경...
            ShowWindowAsync(ipHandle, SHOWNORMAL)

            '해당 윈도우에 포커스를 줘서 최상위로 올리기...
            SetForegroundWindow(ipHandle)

        End If

    End Sub

End Class

*예제 결과

 

결과 화면

 

https://kdsoft-zeros.tistory.com/108

 

[VBNET] [API] 윈도우 창 찾기 (Window Form Search)

* VBNET API 윈도우 (Window) 창 찾기 예제... 전체 소스 코드 Form1.vb Imports System.Runtime.InteropServices Public Class Form1 <dllimport("user32.dll", setlasterror:="True," charset:="CharSet.Auto)"> _..</dllimport("user32.dll",>

kdsoft-zeros.tistory.com

 

반응형
반응형

* C# API 를 이용해 해당 윈도우 폼(Window Form) 을 찾아서 최상위 윈도우로 포커스(Focus) 맞추기 예제...

 

메인 화면

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;

namespace CSharp_FirstFocus
{
    public partial class Form1 : Form
    {
        //API 선언...
        [DllImport("user32.dll")]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);

        //윈도우 상태...
        private const int SHOWNORMAL = 1;
        private const int SHOWMINIMIZED = 2;
        private const int SHOWMAXIMIZED = 3;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            IntPtr ipHandle = FindWindow(null, textBox1.Text);

            if (!ipHandle.Equals(IntPtr.Zero))
            {
                // 윈도우가 최소화 되어 있다면 활성화... 
                ShowWindowAsync(ipHandle, SHOWNORMAL);

                // 윈도우에 포커스를 줘서 최상위로...
                SetForegroundWindow(ipHandle);
            }
        }
    }
}

 

*예제 결과

 

결과 화면

 

 

https://kdsoft-zeros.tistory.com/107

 

[C#] [API] 윈도우 창 찾기 (Window Form Search)

* C# API 윈도우 창 이름으로 윈도우 창 찾기 예제... (Window Form Search) 전체 소스 코드 Form1.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using..

kdsoft-zeros.tistory.com

 

반응형
반응형

* VBNET 윈도우 폼(Window Form) 포커스(Focus) 가 가지 않게 하기 예제...

 

메인화면

 

전체 소스 코드

Form1.vb

 

Imports System.Runtime.InteropServices

Public Class Form1

    <DllImport("user32.dll")> _
Private Shared Sub keybd_event(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As UInteger, ByVal dwExtraInfo As Integer)
    End Sub

    Dim WS_NOACTIVE As Long = 134217728

    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or WS_NOACTIVE
            Return cp
        End Get
    End Property

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        keybd_event(Convert.ToByte(Keys.W), 0, 0, 0)        'KeyDown 
        keybd_event(Convert.ToByte(Keys.W), 0, &H2, 0)      'KeyUp

    End Sub
End Class

 

위 소스와 같이 keybd_event API 함수를 이용해 키보드를 입력한 효과를 나타 낼 수 있습니다.

 

3번째 전달인자     0 : 키를 눌렀을 때 효과

                    &H2 : 키가 올라왔을 때 효과

 

이므로 두개를 합치면 키를 눌렀다 땠다 하는 효과를 볼 수 있습니다.

 

 

*예제 결과

 

보통 윈도우 폼에서 버튼을 클릭을 하게 되면 마우스 커서 즉 포커스가 윈도우 폼으로 이동 하게 되는데 아래의 그림과 같이 버튼을 클릭 하여도 마우스 커서 즉 포커스가 윈도우 폼으로 이동 되지 않는 다는 것을 볼 수 있습니다. 

 

 

 

반응형
반응형

* C# 윈도우 폼 (Window Form) 이 포커스(Focus) 를 가지지 않게 하기 예제...

 

메인화면

전체 소스 코드

Form1.cs

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


using System.Runtime.InteropServices;

namespace CSharp_FormNoActive
{
    public partial class Form1 : Form
    {
        [DllImport("user32.dll")]
        static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, int dwExtraInfo);

        private const long WM_NOACTIVATE = 0x8000000L;

        public Form1()
        {
            InitializeComponent();
        }

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle = cp.ExStyle | (int)WM_NOACTIVATE;
                return cp;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            keybd_event((byte)Keys.W, 0, 0, 0);     //KeyDown   이벤트
            keybd_event((byte)Keys.W, 0, 0x02, 0);  //KeyUp     이벤트
        }
    }
}

위 소스와 같이 keybd_event API 함수를 이용해 키보드를 입력한 효과를 나타 낼 수 있습니다.

 

3번째 전달인자 0 : 키를 눌렀을 때 효과

                0x02 : 키가 올라왔을 때 효과

 

이므로 두개를 합치면 키를 눌렀다 땠다 하는 효과를 볼 수 있습니다.

 

 

*예제 결과

 

보통 윈도우 폼에서 버튼을 클릭을 하게 되면 마우스 커서 즉 포커스가 윈도우 폼으로 이동 하게 되는데 아래의 그림과 같이 버튼을 클릭 하여도 마우스 커서 즉 포커스가 윈도우 폼으로 이동 되지 않는 다는 것을 볼 수 있습니다. 

 

 

 

 

 

반응형
반응형

* Android 오버라이드 함수 찾기 (Override)

 

1. MainActivity 클래스에서 Ctrl + O 를 키 입력

2. 아래의 그림과 같이 원하는 오버라이드 함수를 찾아서 클릭 해 줍니다.

 

3. 아래의 그림처럼 오버라이드 함수가 추가된 모습을 보실 수 있습니다.

 

반응형

+ Recent posts