Calling a Function with a Structure Parameter : Native Windows Function « Windows « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / CSharp Tutorial » Windows » Native Windows Function 
25. 10. 2. Calling a Function with a Structure Parameter
// Code from 
// A Programmer's Introduction to C# 2.0, Third Edition
// copyright 2000 Eric Gunnerson

using System;
using System.Runtime.InteropServices;

struct Point
{
    public int x;
    public int y;
    
    public override string ToString()
    {
        return(String.Format("({0}, {1})", x, y));
    }
}

struct Rect
{
    public int left;
    public int top;
    public int right;
    public int bottom;
    
    public override string ToString()
    {
        return(String.Format("({0}, {1})\n    ({2}, {3})", left, top, right, bottom));
    }
}

struct WindowPlacement
{
    public uint length;
    public uint flags;
    public uint showCmd;
    public Point minPosition;
    public Point maxPosition;
    public Rect normalPosition;    
    
    public override string ToString()
    {
        return(String.Format("min, max, normal:\n{0}\n{1}\n{2}",
        minPosition, maxPosition, normalPosition));
    }
}

class MainClass
{
    [DllImport("user32")]
    static extern IntPtr GetForegroundWindow();
    
    [DllImport("user32")]
    static extern bool GetWindowPlacement(IntPtr handle, ref WindowPlacement wp);
    
    public static void Main()
    {
        IntPtr window = GetForegroundWindow();
        
        WindowPlacement wp = new WindowPlacement();
        wp.length = (uintMarshal.SizeOf(wp);
        
        bool result = GetWindowPlacement(window, ref wp);
        
        if (result)
        {
            Console.WriteLine(wp);
        }
    
}
min, max, normal:
(-32000, -32000)
(-60, -8)
(-1, -1)
    (1273, 728)
25. 10. Native Windows Function
25. 10. 1. Calling Native DLL Functions
25. 10. 2. Calling a Function with a Structure Parameter
25. 10. 3. Enumerate Display Monitors
25. 10. 4. Get Workstation information
25. 10. 5. Get Computer name (char * parameter)
25. 10. 6. Get free disk space
25. 10. 7. Use native windows function to read file
25. 10. 8. The windows version information
25. 10. 9. Get current Active Window
25. 10. 10. Writing INI file: Write Private Profile String
25. 10. 11. Reading INI file: Get Private Profile String
25. 10. 12. GetVersionEx by using kernel32.dll
25. 10. 13. Get computer name (StringBuilder parameter)
25. 10. 14. Lock work station
25. 10. 15. Get Monitor Information
w_ww__._j__ava2_s._c___o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.