Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- set_time_limit(120);
- $kernel32 = FFI::cdef("
- typedef const char * LPCSTR;
- typedef void * HINSTANCE;
- typedef HINSTANCE HMODULE;
- HMODULE GetModuleHandleA(LPCSTR lpModuleName);
- ", "kernel32.dll");
- $user32 = FFI::cdef("
- typedef int BOOL;
- typedef void VOID;
- typedef VOID *LPVOID;
- typedef void * HANDLE;
- typedef void * HINSTANCE;
- typedef HANDLE HMENU;
- typedef HANDLE HWND;
- typedef const char * LPCSTR;
- typedef unsigned int UINT;
- typedef unsigned char BYTE;
- typedef long LONG;
- typedef unsigned short WORD;
- typedef unsigned long DWORD;
- typedef WORD ATOM;
- typedef unsigned int UINT_PTR, *PUINT_PTR;
- typedef long LONG_PTR, *PLONG_PTR;
- typedef UINT_PTR WPARAM;
- typedef LONG_PTR LPARAM;
- typedef LONG_PTR LRESULT;
- typedef HANDLE HBRUSH;
- typedef HANDLE HICON;
- typedef HICON HCURSOR;
- typedef LONG (__stdcall* WNDPROC)(HWND, UINT, WPARAM, LONG);
- typedef struct tagPOINT {
- LONG x;
- LONG y;
- } POINT, *PPOINT;
- typedef struct tagMSG {
- HWND hwnd;
- UINT message;
- WPARAM wParam;
- LPARAM lParam;
- DWORD time;
- POINT pt;
- DWORD lPrivate;
- } MSG, *PMSG, *NPMSG, *LPMSG;
- typedef struct tagWNDCLASSEXA {
- UINT cbSize;
- UINT style;
- WNDPROC lpfnWndProc;
- int cbClsExtra;
- int cbWndExtra;
- HINSTANCE hInstance;
- HICON hIcon;
- HCURSOR hCursor;
- UINT hbrBackground;
- LPCSTR lpszMenuName;
- HANDLE lpszClassName;
- HICON hIconSm;
- } WNDCLASSEXA, *PWNDCLASSEXA, *NPWNDCLASSEXA, *LPWNDCLASSEXA;
- HWND CreateWindowExA(DWORD,LPCSTR,LPCSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID);
- LRESULT DefWindowProcA(HWND,UINT,WPARAM,LPARAM);
- BOOL DestroyWindow(HWND);
- LRESULT DispatchMessageA(const MSG*);
- BOOL GetMessageA(PMSG,HWND,UINT,UINT);
- HICON LoadIconA(HINSTANCE,long);
- HCURSOR LoadCursorA(HINSTANCE,long);
- int MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);
- BOOL PostMessageA(HWND,UINT,WPARAM,LPARAM);
- void PostQuitMessage(int);
- ATOM RegisterClassExA(const WNDCLASSEXA*);
- BOOL UpdateWindow(HWND);
- BOOL ShowWindow(HWND,int);
- BOOL TranslateMessage(const MSG*);
- ", "user32.dll");
- define('IDI_APPLICATION', 32512);
- define('CS_OWNDC', 0x0020);
- define('IDI_WINLOGO', 32517);
- define('IDC_ARROW', 32512);
- define('MB_OK', 0);
- define('WM_PAINT', 15);
- define('WM_SIZE', 5);
- define('WM_CHAR', 258);
- define('WM_CLOSE', 16);
- define('WM_DESTROY', 2);
- define('WS_OVERLAPPEDWINDOW', 0xcf0000);
- define('WS_CLIPSIBLINGS', 0x4000000);
- define('WS_CLIPCHILDREN', 0x2000000);
- define('MB_ICONEXCLAMATION', 0x30);
- define('WS_EX_CLIENTEDGE', 512);
- define('CW_USEDEFAULT', 0x80000000);
- define('COLOR_WINDOW', 5);
- define('SW_SHOW', 5);
- define('SW_SHOWDEFAULT', 10);
- define('SW_SHOWNORMAL', 1);
- // Step 4: the Window Procedure
- $WndProc = function($hwnd, $msg, $wParam, $lParam){
- global $user32;
- switch($msg){
- case WM_CLOSE:
- $user32->DestroyWindow($hwnd);
- break;
- case WM_DESTROY:
- $user32->PostQuitMessage(0);
- break;
- default:
- return $user32->DefWindowProcA($hwnd, $msg, $wParam, $lParam);
- }
- return 0;
- };
- exit(main());
- function main(){
- global $kernel32, $user32, $WndProc;
- $g_szClassName = "myWindowClass";
- $szClassName = FFI::new(FFI::arrayType(FFI::type("char"), [strlen($g_szClassName)]));
- FFI::memcpy($szClassName, $g_szClassName, strlen($g_szClassName));
- $hInstance = $kernel32->GetModuleHandleA(NULL);
- //$nCmdShow = SW_SHOW;
- //$nCmdShow = SW_SHOWDEFAULT;
- $nCmdShow = SW_SHOWNORMAL;
- $wc = $user32->new("WNDCLASSEXA");
- $msg = $user32->new("MSG");
- //Step 1: Registering the Window Class
- $wc->cbSize = FFI::sizeof($wc);
- $wc->style = 0;
- $wc->lpfnWndProc = $WndProc;
- $wc->cbClsExtra = 0;
- $wc->cbWndExtra = 0;
- $wc->hInstance = $hInstance;
- $wc->hIcon = $user32->LoadIconA(NULL, IDI_APPLICATION);
- $wc->hCursor = $user32->LoadCursorA(NULL, IDC_ARROW);
- $wc->hbrBackground = (COLOR_WINDOW+1);
- $wc->lpszMenuName = NULL;
- $wc->lpszClassName = FFI::addr($szClassName);
- $wc->hIconSm = $user32->LoadIconA(NULL, IDI_APPLICATION);
- if(!$user32->RegisterClassExA(FFI::addr($wc))){
- $user32->MessageBoxA(NULL, "Window Registration Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- // Step 2: Creating the Window
- $hwnd = $user32->CreateWindowExA(
- WS_EX_CLIENTEDGE,
- $g_szClassName,
- "The title of my window",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
- NULL, NULL, $hInstance, NULL);
- if($hwnd == NULL){
- $user32->MessageBoxA(NULL, "Window Creation Failed!", "Error!",
- MB_ICONEXCLAMATION | MB_OK);
- return 0;
- }
- $user32->ShowWindow($hwnd, $nCmdShow);
- $user32->UpdateWindow($hwnd);
- // Step 3: The Message Loop
- while($user32->GetMessageA(FFI::addr($msg), NULL, 0, 0) > 0){
- $user32->TranslateMessage(FFI::addr($msg));
- $user32->DispatchMessageA(FFI::addr($msg));
- }
- return $msg->wParam;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement