Mega Code Archive

 
Categories / Delphi / Forms
 

Creating an alone window with API

Title: Creating an alone window with API Question: How to build a form without just using calls API. Answer: Creating an alone window with API //Turn off every project that this inside of the (*.DRP) and copy the code that this below ! program Project1; uses windows, messages; procedure MainPaint(hWindow:HWND; pt:TPaintStruct); begin SetBkMode(pt.hdc,TRANSPARENT); TextOut(pt.hdc,1,1,'Janela feita s com EIPIAI do Windows!',38 ); end; procedure MainDestroy(hWindow: HWND); begin PostQuitMessage(0); end; // Main Window Procedure function MainWndProc(hWindow: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall; export; var ps: TPaintStruct; begin Result := 0; case Msg of WM_PAINT: begin BeginPaint(hWindow, ps); MainPaint(hWindow,ps); EndPaint( hWindow, ps ); end; WM_DESTROY: MainDestroy(hWindow); else begin result := DefWindowProc( hWindow, Msg, wParam, lParam ); exit; end; end; // case end; // Main Procedure var wc: TWndClass; hWindow: HWND; Msg: TMsg; begin wc.lpszClassName := 'GenericAppClass'; wc.lpfnWndProc := @MainWndProc; wc.style := CS_VREDRAW or CS_HREDRAW; wc.hInstance := hInstance; wc.hIcon := LoadIcon(0,IDI_APPLICATION); wc.hCursor := LoadCursor(0,IDC_ARROW); wc.hbrBackground := (COLOR_WINDOW+1); wc.lpszMenuName := nil; wc.cbClsExtra := 0; wc.cbWndExtra := 0; RegisterClass(wc); hWindow := CreateWindowEx(WS_EX_CONTROLPARENT or WS_EX_WINDOWEDGE, 'GenericAppClass', 'API', WS_VISIBLE or WS_CLIPSIBLINGS or WS_CLIPCHILDREN or WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,0, 400,300, 0, 0, hInstance, nil); ShowWindow(hWindow,CmdShow); UpDateWindow(hWindow); // Message Loop while GetMessage(Msg, 0, 0, 0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end; Halt(Msg.wParam); end. //after having compiled that project it should create an executable of 17KB approximately