菜鸟看到论坛上有人不用加载form就可以做程序,就是直接在程序.dpr里写程序,我想实现显示一张图片,怎么实现啊?(50分)

  • 主题发起人 主题发起人 wanglongb
  • 开始时间 开始时间
W

wanglongb

Unregistered / Unconfirmed
GUEST, unregistred user!
菜鸟看到论坛上有人不用加载form就可以做程序,就是直接在程序.dpr里写程序,我想实现显示一张图片,怎么实现啊?
 
给你一段程序吧
Application.Initialize;
if not untInit.Login then//登录窗体
Application.Terminate
else
begin
frmFlash := TfrmFlash.Create(Application);
frmFlash.show;
frmFlash.update; //====启动闪现窗体
Application.CreateForm(TfrmAppMain, frmAppMain);
。。。。。
frmFlash.hide;
frmFlash.free;
end;
Application.Run;
 
以上代码就是在dpr里写的
 
不用想了
用delphi不能实现
 
怎么不能实现,我从http://kuga.51.net/download/index.htm上下载的淡入淡出的例子就
是直接在*.dpr里直接写的!!!
 
自己用API写代码,注册窗口类,填充,然后在窗口的DC上画图就可以了,还要用到
HBITMAP之类的结构,建议看看查理的《Programming Windows》
 
可以的,以前有一个不用TForm类,就可以实现Form的例子
 
WinMain
{
HBITMAP bitmap=CreateBitmap(...);
HDC screen=GetDC(NULL);
StretchDIBits(...screen...bitmap... );
}
 
你可以看一下KOL,
http://xcl.cjb.net
 
program Project1;

uses
Windows,Messages;

{$R *.RES}
var
hWnd : HWND; //窗口句柄
Active : Bool; //窗口激活标志

function WndProc(hWnd : HWND;
Message :UINT;
wParam : WPARAM;
lParam : LPARAM):LRESULT;stdcall;
begin
case Message of
WM_ACTIVATE:
begin
if(HIWORD(wParam)=0) then
Active :=true
else
Active :=false;
Result :=0;
end;
WM_CLOSE:
begin
PostQuitMessage(0);
Result :=0;
end;
else
begin
Result :=DefWindowProc(hWnd,Message,wParam,lParam);
end;
end;
end;

procedure KillWindow;
begin
if hWnd<>0 then
hWnd :=0;
end;

function CreateWindow(Title:PChar;Width,Height:Integer):boolean stdcall;
var
WndClass : TWndClass;
dwExStyle : DWORD;
dwStyle : DWORD;
hInstance : HINST;
begin
hInstance :=getModuleHandle(nil);

with WndClass do
begin
style :=CS_HREDRAW or CS_VREDRAW or CS_OWNDC;
lpfnWndProc :=@WndProc;
cbClsExtra :=0;
cbWndExtra :=0;
hInstance :=hInstance;
hIcon :=LoadIcon(0,IDI_WINLOGO);
hCursor :=LoadCursor(0,IDC_ARROW);
hbrBackground :=0;
lpszMenuName :=nil;
lpszClassName :='MyWin';
end;
if RegisterClass(WndClass)=0 then
begin
MessageBox(0,'注册窗口失败','错误提示',MB_OK or MB_ICONERROR);
CreateWindow :=false;
exit;
end;

hWnd :=CreateWindowEx(dwExStyle,
'MyWin',
Title,
dwStyle,
0,0,
Width,Height,
0,0,
hInstance,
nil);
if hWnd=0 then
begin
KillWindow;
MessageBox(0,'创建窗口失败','错误提示',MB_OK or MB_ICONEXCLAMATION);
CreateWindow :=false;
exit;
end;
CreateWindow :=true;
end;

function WinMain(hInstance :HINST;
hPrevInst : HINST;
lpszCmdLine : PChar;
nCmdShow : Integer):Integer;stdcall;
var
Msg : TMSG;
Done : Bool;
begin
Done :=false;
if not CreateWindow('My Window',200,100) then
begin
Result :=0;
exit;
end;

while not Done do
begin
if(PeekMessage(Msg,0,0,0,PM_REMOVE)) then
begin
if Msg.message = WM_QUIT then
Done :=true
else
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
KillWindow;
Result :=Msg.message;
end;
end;

begin
Active :=true;
WinMain(hInstance,hPrevInst,CmdLine,CmdShow);
end.
 
这是一个创建窗体 + label + Edit + 按钮的例子
program testwindow;

uses
Windows,
Messages;

var
WinClass: TWndClassA;
Inst, Handle, Button1, Label1, Edit1: Integer;
Msg: TMsg;
hFont: Integer;

{ Checks if typed password is 'Amigreen' and shows Message }
procedure CheckPassword;
var
Textlength: Integer;
Text: PChar;
begin
TextLength := GetWindowTextLength(Edit1);
if TextLength = 8 then
begin
GetMem(Text, TextLength + 1);
GetWindowText(Edit1, Text, TextLength + 1);
if Text = 'Amigreen' then
begin
MessageBoxA(Handle, 'Password is correct.', 'Password check', MB_OK);
FreeMem(Text, TextLength + 1);
Exit;
end;
end;
MessageBoxA(Handle, 'Password is incorrect.', 'Password check', MB_OK);
end;

{ Custom WindowProc function }
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;
begin
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
{ Checks for messages }
if (lParam = Button1) and (uMsg = WM_COMMAND) then
CheckPassword;
if uMsg = WM_DESTROY then
Halt;
end;

begin
{ ** Register Custom WndClass ** }
Inst := hInstance;
with WinClass do
begin
style := CS_CLASSDC or CS_PARENTDC;
lpfnWndProc := @WindowProc;
hInstance := Inst;
hbrBackground := color_btnface + 1;
lpszClassname := 'AG_TESTWINDOW';
hCursor := LoadCursor(0, IDC_ARROW);
end; { with }
RegisterClass(WinClass);

{ ** Create Main Window ** }
Handle := CreateWindowEx(WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'Amigreen TestWindow 1.00',
WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
363, 168, 305, 85, 0, 0, Inst, nil);
// 363, 278, 305, 65, 0, 0, Inst, nil);
{ ** Create a button ** }
Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
216, 8, 75, 25, handle, 0, Inst, nil);
{ ** Create a label (static) ** }
Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,
8, 12, 76, 13, Handle, 0, Inst, nil);

{ ** Create an edit field ** }
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
WS_BORDER or ES_PASSWORD, 88, 8, 121, 21, Handle, 0, Inst, nil);

//=============== { ** Create an edit field ** }
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
WS_BORDER or ES_PASSWORD, 88, 31, 121, 21, Handle, 0, Inst, nil);

{ ** Create Font Handle ** }
hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');

{ Change fonts }
if hFont <> 0 then
begin
SendMessage(Button1, WM_SETFONT, hFont, 0);
SendMessage(Label1, WM_SETFONT, hFont, 0);
SendMessage(Edit1, WM_SETFONT, hFont, 0);
end;
{ Change label (static) text }
SetWindowText(Label1, 'Enter password:');
{ Set the focus to the edit control }
SetFocus(Edit1);

UpdateWindow(Handle);

{ ** Message Loop ** }
while(GetMessage(Msg,Handle, 0, 0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end; { with }
end.
 
他不要窗体阿,大家不要再CreateWindows了
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
851
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部