Читаем Программирование КПК и смартфонов на .NET Compact Framework полностью

   MessageBox.Show("Поворот экрана поддерживается");

  }

 } else {

  MessageBox.Show("Поворот экрана не поддерживается");

 }

}


private void butRot90_Click(object sender, EventArgs e) {

 SystemSettings.ScreenOrientation = ScreenOrientation.Angle90;

}


private void butRestore_Click(object sender, EventArgs e) {

 if (SystemSettings.ScreenOrientation != initialOrientation) {

  try {

   SystemSettings.ScreenOrientation = initialOrientation;

  } catch (Exception) {

   // Unable to change the orientation back

   // to the original configuration.

   MessageBox.Show("This sample was unable to set the " +

    "orientation back to the original state.");

  }

 }

}

Прячем кнопку Start

Функция SHFullScreen позволяет прятать и показывать кнопку Start и пиктограмму виртуальной клавиатуры SIP. Соответствующий код приведен в листинге 13.6.

Листинг 13.6

///

/// Функция используется для изменения вида экрана.

/// Вы можете модифицировать панель задач, панель ввода, значок

/// Пуск

///

/// Дескриптор окна

/// Определяет состояние окна

/// B успешном случае возвращается True, иначе -

/// False

[DllImport("aygshell.dll")]

static extern uint SHFullScreen(IntPtr hwndRequester, uint dwState);


const uint SHFS_SHOWTASKBAR = 0x0001;

const uint SHFS_HIDETASKBAR = 0x0002;

const uint SHFS_SHOWSIPBUTTON = 0x0004;

const uint SHFS_HIDESIPBUTTON = 0x0008;

const uint SHFS_SHOWSTARTICON = 0x0010;

const uint SHFS_HIDESTARTICON = 0x0020;


private void butHideStart_Click(object sender, EventArgs e) {

 IntPtr hwnd = this.Handle;

 //прячем кнопку Start

 SHFullScreen(hwnd, SHFS_HIDESTARTICON);

 //прячем SIP

 //SHFullScreen(hwnd, SHFS_HIDESIPBUTTON);

}


private void butShowStart_Click(object sender, EventArgs e) {

 //показываем кнопку Start

 IntPtr hwnd = this.Handle;

 SHFullScreen(hwnd, SHFS_SHOWSTARTICON);

 //показываем SIP

 //SHFullScreen(hwnd, SHFS_SHOWSIPBUTTON);

}

В примере показано, как прятать кнопку Start. Если нужно спрятать пиктограмму SIP, то надо убрать комментарии при втором вызове функции. На рис. 13.1 показан внешний вид экрана со спрятанной кнопкой Start.

Рис. 13.1. Скрытие кнопки Start

Панель задач

Очень часто программисты в качестве шутки создают программы, которые прячут привычные для пользователя элементы интерфейса. В предыдущем примере было показано, как можно скрыть кнопку Start. Теперь нужно рассмотреть пример работы с панелью задач.

Для создания тестового приложения на форме надо разместить две кнопки. Одна из них будет скрывать панель задач, а вторая — показывать ее. Соответствующий код приведен в листинге 13.7.

Листинг 13.7

///

/// Скрывает одно окно и активирует другое

///

private const int SW_HIDE = 0;


///

/// Активирует окно

///

private const int SW_SHOW = 5;


[DllImport("coredll.dll")]

private static extern IntPtr FindWindow(string ClassName, string WindowName);


[DllImport("coredll.dll")]

private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);


///

/// Прячем панель задач, чтобы пользователь не мог

/// нажать кнопку Start

///

public static void HideTaskbar() {

Перейти на страницу:

Похожие книги

C++ Primer Plus
C++ Primer Plus

C++ Primer Plus is a carefully crafted, complete tutorial on one of the most significant and widely used programming languages today. An accessible and easy-to-use self-study guide, this book is appropriate for both serious students of programming as well as developers already proficient in other languages.The sixth edition of C++ Primer Plus has been updated and expanded to cover the latest developments in C++, including a detailed look at the new C++11 standard.Author and educator Stephen Prata has created an introduction to C++ that is instructive, clear, and insightful. Fundamental programming concepts are explained along with details of the C++ language. Many short, practical examples illustrate just one or two concepts at a time, encouraging readers to master new topics by immediately putting them to use.Review questions and programming exercises at the end of each chapter help readers zero in on the most critical information and digest the most difficult concepts.In C++ Primer Plus, you'll find depth, breadth, and a variety of teaching techniques and tools to enhance your learning:• A new detailed chapter on the changes and additional capabilities introduced in the C++11 standard• Complete, integrated discussion of both basic C language and additional C++ features• Clear guidance about when and why to use a feature• Hands-on learning with concise and simple examples that develop your understanding a concept or two at a time• Hundreds of practical sample programs• Review questions and programming exercises at the end of each chapter to test your understanding• Coverage of generic C++ gives you the greatest possible flexibility• Teaches the ISO standard, including discussions of templates, the Standard Template Library, the string class, exceptions, RTTI, and namespaces

Стивен Прата

Программирование, программы, базы данных