谁有代码贴出来让我学习学习吧
这是我的代码,不知错在哪里!uses
Windows,Messages;
var hinstance:Dword;
CommandLine:Pchar;
ClassName,AppName:Pchar;
hWnd:Dword;
procedure WndProc(hwnd:DWord;uMsg:Word;wParam:word;lParam:word);
begin
IF uMsg=WM_DESTROY then
PostQuitMessage(0)
else
DefWindowProc(hWnd,uMsg,wParam,lParam);
end;
function winMain(hInst,hPrevInstance:LongWord;
lpCmdLine:LPSTR;nCmdShow:integer):DWord;
var wc:WNDCLASSEX;
msg:TMsg;
begin
ClassName := 'test';
AppName :='hehe';
wc.cbSize := SIZEOF(WNDCLASSEX);
wc.style := CS_HREDRAW or CS_VREDRAW;
wc.lpfnWndProc := @wndproc;
wc.cbClsExtra :=0;
wc.cbWndExtra :=0;
wc.hInstance := Hinstance;
wc.hbrBackground :=COLOR_WINDOW+1;
wc.lpszMenuName:=nil;
wc.lpszClassName:= ClassName;
wc.hIcon := LoadIcon(0,IDI_APPLICATION);
wc.hIconSm:= LoadIcon(0,IDI_APPLICATION);
wc.hCursor := LoadCursor(0,IDC_ARROW);
RegisterClassEx(wc); hWnd := CreateWindowEx(0,ClassName,AppName,
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,
hInst,nil);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while TRUE do
IF not GetMessage(msg,0,0,0) then
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
Result:=0;
end;begin
hInstance:=GetModuleHandle(Nil);
CommandLine := GetCommandLine;
WinMain(hInstance,0,CommandLine, SW_SHOWDEFAULT);
end.
这是我的代码,不知错在哪里!uses
Windows,Messages;
var hinstance:Dword;
CommandLine:Pchar;
ClassName,AppName:Pchar;
hWnd:Dword;
procedure WndProc(hwnd:DWord;uMsg:Word;wParam:word;lParam:word);
begin
IF uMsg=WM_DESTROY then
PostQuitMessage(0)
else
DefWindowProc(hWnd,uMsg,wParam,lParam);
end;
function winMain(hInst,hPrevInstance:LongWord;
lpCmdLine:LPSTR;nCmdShow:integer):DWord;
var wc:WNDCLASSEX;
msg:TMsg;
begin
ClassName := 'test';
AppName :='hehe';
wc.cbSize := SIZEOF(WNDCLASSEX);
wc.style := CS_HREDRAW or CS_VREDRAW;
wc.lpfnWndProc := @wndproc;
wc.cbClsExtra :=0;
wc.cbWndExtra :=0;
wc.hInstance := Hinstance;
wc.hbrBackground :=COLOR_WINDOW+1;
wc.lpszMenuName:=nil;
wc.lpszClassName:= ClassName;
wc.hIcon := LoadIcon(0,IDI_APPLICATION);
wc.hIconSm:= LoadIcon(0,IDI_APPLICATION);
wc.hCursor := LoadCursor(0,IDC_ARROW);
RegisterClassEx(wc); hWnd := CreateWindowEx(0,ClassName,AppName,
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,
hInst,nil);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
while TRUE do
IF not GetMessage(msg,0,0,0) then
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
Result:=0;
end;begin
hInstance:=GetModuleHandle(Nil);
CommandLine := GetCommandLine;
WinMain(hInstance,0,CommandLine, SW_SHOWDEFAULT);
end.
var
wc: WNDCLASS;
begin
Result := False;
// Set up and register window class
wc.style := CS_HREDRAW or CS_VREDRAW;
wc.lpfnWndProc := @WindowProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := hInst;
wc.hIcon := LoadIcon(hInst, 'MAINICON');
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.hbrBackground := GetStockObject(BLACK_BRUSH);
wc.lpszMenuName := NAME;
wc.lpszClassName := NAME;
RegisterClass(wc); // Create a window
h_Wnd := CreateWindowEx(WS_EX_TOPMOST,
NAME,
TITLE,
WS_POPUP,
0,
0,
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
0,
0,
hInst,
nil); if h_Wnd = 0 then
begin
Result := False;
Exit;
end; ShowWindow(h_Wnd, nCmdShow);
UpdateWindow(h_Wnd);
SetFocus(h_Wnd); Result := True;
end;
Windows,
Messages,
ShellAPI,
sysutils;
const
AppName = 'DeskTop Hide';
function DummyWindowProc (Wnd: hWnd; Msg, wParam: Word; lParam: LongInt) : LongInt; stdcall; {注意这里有一个 stdcall;定义了回调函数}
var
dc: hDC;
ps: PaintStruct;
begin
DummyWindowProc := 0;
if Msg=wm_Destroy then {收到关闭窗口消息时的处理}
PostQuitMessage (0)
else if (Msg=WM_Paint) then
begin
dc:=BeginPaint(wnd,ps);
FillPath(dc);
LineTo(dc, 100, 100);
EndPaint(wnd,ps);
end;
DummyWindowProc := DefWindowProc (Wnd, Msg, wParam, lParam);
end;procedure WinMain;
var
Wnd: hWnd;
Msg: TMsg;
cls: TWndClass;
begin
FillChar (cls, sizeof (cls), 0);
cls.lpfnWndProc := @DummyWindowProc;
cls.hInstance := hInstance;
cls.lpszClassName := AppName;
cls.hbrBackground := COLOR_WINDOW+2;
cls.style := CS_HREDRAW or CS_VREDRAW;
RegisterClass (cls);
Wnd := CreateWindow(AppName, AppName, ws_OverlappedWindow,
cw_UseDefault, cw_UseDefault, cw_UseDefault,
cw_UseDefault, 0, 0, hInstance, Nil);
ShowWindow (Wnd,sw_Show);
UpdateWindow(Wnd);
while GetMessage (Msg, 0, 0, 0) do
begin
TranslateMessage (Msg);
DispatchMessage (Msg);
end;
end;
begin
WinMain;
end.
为什么以上的代码不重绘呢?