Create a form with subtitle Windows API under Delphi: Author: Anonymous Source: Monopoly Hits: 119 Update Time: 2005-2-25 Delphi created under the Windows API with Forms // Create a form called Windows API under Delphi /. /// Template ------- By Hottey 2004-4-13-0: 18 ///////ww.ttp://asp.itdrp.com/hottey // Program Delphi
Uses Windows, Messages;
Const hellostr = 'Hello World!';
{$ R Delphi.res}
// Window message processing function .function mywinproc (hwnd: thandle; umsg: uint; wparam, lparam: cardinal): cardinal;
VAR HDCA, HDCB: THANDLE; / / Device Description Table Handle. RECT: TRECT; // Rectangular Structure. Font: HFont; PS: TPAINTSTRUCT; // Drawing Structure. Begin Result: = 0; Case Umsg of WM_Paint: Begin HDCA: = BeginPaint (HWND, PS); SetBKMode (HDCA, Transparent); SetBkColor (HDCA, GetBkcolor (HDCA)); getClientRect (hwnd, rect); // Get the size of the window customer area. DrawText (HDCA, PCHAR (Hellostr), -1, Rect, DT_SINGLINE OR DT_CENTER OR DT_VCENTER; // Textout (HDC, 100, 40, Hellostr, Length (Hellostr)); EndPaint (HWND, PS); END; WM_CREATE: Begin HDCB: = Getdc (hwnd); font: = CreateFont (45, 0, 0, 0, FW_normal, 0, 0, 0, ansi_charset, out_default_precis, clip_default_precis, default_quality, 34, PChar ( 'Arial')); SelectObject (hdcb, font); ReleaseDC (hWnd, HDCB); END; WM_DESTROY: PostquitMessage (0) Else // uses the default window message processing function. Result: = DefWindowProc (HWND, UMSG, WPARAM, LPARAM); end; end;
// The main program begins.
VAR MSG: TMSG; // Message structure. HWND, Hinst: thandle; // windows window handle. WinClass: TwndClassex; // windows window class structure. Segin Hinst: = getModuleHandle (nil); // Get the Application Instance WinClass. CBSIZE: = SIZEOF (TWNDCLASSEX); Winclass.lpszclassName: = 'myWindow'; // class name. WinClass.Style:=cs_hredraw or cs_vredraw or cs_owndc; WinClass.hinstance: = HINST; / / Program instance handle. // Setting Window message processing function. WinClass.lpfnWndproc: = @ mywinproc; // window process. Winclass.cbclsextra: = 0; // The following two domains are used to save the window structure in the class structure and Windows WinClass.cbWndextra: = 0; // Reserve some extra space. Winclass.hicon: = Loadicon (Hinstance, MakeintResource ('mainicon')); WinClass.hiconsm: = Loadicon (Hinstance, MakeintResource ('mainicon')); WinClass.hcursor: = loadingcursor 0, IDC_ARROW); // getStockObject Get a graphic object, here is a brush to draw the background of the window, return a handle of a white brush. Winclass.hbrbackground: = Hbrush (GetStockObject (white_brush); winClass.lpsz Gene: = nil; // Specify the window class menu. // Register the window class to the Windows. If registerclassex (winclass) = 0 THEN BE GIN Messagebox (0, 'Registeration Error!', 'SDK / API', MB_OK; EXIT; END;
// Create the window object hWnd:... = CreateWindowEx (WS_EX_OVERLAPPEDWINDOW, // extended window style WinClass.lpszClassName, // class name 'Hello Window', // window title WS_OVERLAPPEDWINDOW, // window style CW_USEDEFAULT, //.. The top left corner of the window relative to the initial position x. 0, // .... right y. CW_USEDEFAULT, // window width x. 0, // window height y. 0, // parent window handle. 0, // Window menu handle. Hinst, // program instant sequence. NIL); // Create a parameter pointer. If hwnd <> 0 Then Begin showWindow (hwnd, sw_shownormal); // Display window. UpdateWindow (hwnd); // Indication Window refreshes yourself. SetwindowPos (hwnd, hwnd_topmo ST, 0, 0, 0, 0, SWP_NOMOVE SWP_NOSize; ELSE MessageBox (0, 'Window Not Created!', 'SDK / API', MB_OK);
// Main message loop program. While getMessage (MSG, 0, 0, 0) DO Begin TranslateMessage (MSG); // Convert some keyboard messages. DispatchMessage (MSG); // Send the message to the window process. End; end; .