unit UtilFunc; interface uses windows, messages; // //--------------- window support functions ------------------------ // function GetExeName: string; function MakeMainWindow(WndProc:TFNWndProc): HWND; function MessageLoopNormal: integer; implementation // //--------------- window support functions ------------------------ // function GetLowDir(var Path: string): Boolean; var p,Len: integer; begin result := false; p := Pos('\',Path); if p <> 0 then begin result := true; Len := Length(Path)-p; Path := Copy(Path,p+1,Len); SetLength(Path,Len); end; end; function GetExeName: string; var s,t: string; buf: array[0..MAX_PATH] of Char; Len: integer; begin Len := GetModuleFileName(0,buf,SizeOf(buf)); SetString(s,buf,Len); t := s; while GetLowDir(t) do s := t; Len := Pos('.',s); result := Copy(s,0,Len-1); end; function MakeMainWindow(WndProc:TFNWndProc): HWND; var wc: TWndClass; hWindow: HWND; s: string; begin s := GetExeName; wc.lpszClassName := PChar(s); wc.lpfnWndProc := WndProc; 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, PChar(s), PChar(s), WS_VISIBLE or WS_OVERLAPPEDWINDOW, 200,100, 300,200, 0, 0, hInstance, nil); ShowWindow(hWindow,CmdShow); UpDateWindow(hWindow); result := hWindow; end; function MessageLoopNormal: integer; var Msg: TMsg; begin while GetMessage(Msg, 0, 0, 0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end; result := Msg.wParam; end; end.