本例子举例说明了在LabWindows/CVI中调用SDK函数过程中使用两种方式获得调用句柄。在LabWindows/CVI句柄的数据类型为整型,而在Windows中,句柄的类型通常为HWND类型,这就需要在使用过程中进行强制转换。 如果想在电脑运行时关闭显示器节电,那么可以用如下程序。 程序界面: 程序代码: #include "windows.h" #include #include #include "显示器操作.h" static int panelHandle; int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { if (InitCVIRTE (hInstance, 0, 0) == 0) return -1; /* out of memory */ if ((panelHandle = LoadPanel (0, "显示器操作.uir", PANEL)) < 0) return -1; DisplayPanel (panelHandle); RunUserInterface (); DiscardPanel (panelHandle); return 0; } int CVICALLBACK QuitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { switch (event) { case EVENT_COMMIT: QuitUserInterface (0); break; } return 0; } //关闭按钮 int CVICALLBACK off (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int handle; switch (event) { case EVENT_COMMIT: //获得面板句柄 GetPanelAttribute (panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, &handle); //关闭显示器 SendMessage((HWND)handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2); break; } return 0; } //开启按钮 int CVICALLBACK on (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { int handle; switch (event) { case EVENT_COMMIT: //获得CVI窗口句柄 handle = GetCVIWindowHandle(); //打开显示器 SendMessage((HWND)handle, WM_SYSCOMMAND, SC_MONITORPOWER, -1); break; } return 0; }
转自:小信的博客
guQ1JWmz.rar (383.34 KB)
|