004
26.06.2003, 18:08 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, sieht mal wieder nach einem Versuch aus jmd. zu ärgern 1+3 siehe Bsp. 2 ist MFC!
C++: |
// DiesUndDas.cpp : Definiert den Einsprungpunkt für die Anwendung. //
#include "stdafx.h" #include "resource.h" #include <stdio.h> #include <mmsystem.h>
#pragma comment (lib,"winmm.lib")
#define MAX_LOADSTRING 100
HINSTANCE hInst; TCHAR szTitle[MAX_LOADSTRING]; TCHAR szWindowClass[MAX_LOADSTRING];
ATOM MyRegisterClass( HINSTANCE hInstance ); BOOL InitInstance( HINSTANCE, int ); LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); void ShutDown(); void CdDoor_Open(); void CdDoor_Close();
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; HACCEL hAccelTable;
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_DIESUNDDAS, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance);
if( !InitInstance( hInstance, nCmdShow ) ) { return FALSE; }
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DIESUNDDAS);
while( GetMessage(&msg, NULL, 0, 0) ) { if( !TranslateAccelerator (msg.hwnd, hAccelTable, &msg) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } }
return msg.wParam; }
ATOM MyRegisterClass( HINSTANCE hInstance ) { WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DIESUNDDAS); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_DIESUNDDAS; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex); }
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow ) { HWND hWnd;
hInst = hInstance; hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if( !hWnd ) { return FALSE; }
ShowWindow( hWnd, nCmdShow ); UpdateWindow( hWnd );
return TRUE; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch( message ) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Menüauswahlen analysieren: switch( wmId ) { case ID_ACTION_SHUTDOWN: ShutDown(); break;
case ID_ACTION_CDDOOROPEN: CdDoor_Open(); break; case ID_ACTION_CDDOORCLOSE: CdDoor_Close(); break; case IDM_EXIT: DestroyWindow( hWnd ); break; default: return DefWindowProc( hWnd, message, wParam, lParam ); } break; case WM_PAINT: hdc = BeginPaint (hWnd, &ps); // ZU ERLEDIGEN: Hier beliebigen Code zum Zeichnen hinzufügen... RECT rt; GetClientRect( hWnd, &rt ); EndPaint( hWnd, &ps ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; default: return DefWindowProc( hWnd, message, wParam, lParam ); } return 0; }
void ShutDown() { HANDLE hToken_SHUTDOWN; TOKEN_PRIVILEGES tkp_SHUTDOWN;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken_SHUTDOWN)) printf("fehler"); LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp_SHUTDOWN.Privileges[0].Luid);
tkp_SHUTDOWN.PrivilegeCount = 1; tkp_SHUTDOWN.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken_SHUTDOWN, FALSE, &tkp_SHUTDOWN, 0, (PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS) printf("fehler");
if (!ExitWindowsEx(EWX_SHUTDOWN|EWX_POWEROFF, NULL)) printf("fehler"); }
void CdDoor_Open() { MCIERROR err; err = mciSendString("Set cdaudio door open wait",NULL,0,NULL); }
void CdDoor_Close() { MCIERROR err; err = mciSendString("Set cdaudio door closed wait",NULL,0,NULL); }
|
-- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe |