- 浏览: 30446 次
- 性别:
- 来自: 北京
最新评论
被Delphi惯坏了,发现写一个原生的Form这么麻烦
vc版本
Delphi版本
vc版本
<!---->#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows 98! By ZhangSK"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HelloWin") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox (NULL, TEXT ("This program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow (szAppName, // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
switch (message)
{
case WM_CREATE:
PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
return 0 ;
case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rect) ;
DrawText (hdc, TEXT ("Hello, Windows 98! By ZhangSK"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Delphi版本
<!---->program HelloWin;
uses
Windows,
Messages,
MMSystem,
SysUtils;
Const
AppName:String = 'HelloWin';
Null:Integer = 0;
function WndProc(WindowHwnd:HWND;TheMessage:UINT;WPARAMS:wParam;LPARAMS:lParam):Integer;stdcall;
var
ClientDC:HDC;
ps:TPaintStruct;
ClientRect:TRect;
sUser, sPower: string;
begin
case TheMessage of
WM_CREATE: begin
PlaySound('hellowin.wav',null,SND_FILENAME or SND_ASYNC);
Result:=0;
end;
WM_PAINT: begin
ClientDc:=BeginPaint(WindowHwnd,ps);
GetClientRect(WindowHwnd,ClientRect);
DrawText(ClientDc,PChar('Hello,Window98!'),-1,ClientRect,DT_SINGLELINE or
DT_CENTER OR DT_VCENTER);
sUser := 'ZhangSK''Testing';
sPower := 'POWERD BY DELPHI';
TextOut(ClientDC, 5, 5, PChar(sUser), Length(sUser));
TextOut(ClientDC, ClientRect.Right-200, ClientRect.Bottom-30, PChar(sPower), Length(sPower));
Endpaint(Windowhwnd,ps);
Result:=0;
end;
WM_DESTROY: begin
PostQuitMessage(0);
Result:=0;
end;
else
Result:=DefWindowProc(WindowHwnd,TheMessage,WPARAMS,LPARAMS);
end;
end;
var
WinHwnd:HWND;
WinMsg:MSG;
WinClass:WNDCLASS;
ECode:DWORD;
EString:PChar;
begin
WinClass.style:=CS_HREDRAW OR CS_VREDRAW;
WinClass.lpfnWndProc:=@WndProc;
WinClass.cbClsExtra:=0;
WinClass.cbWndExtra:=0;
WinClass.hInstance:=hInstance;
WinClass.hIcon:=LoadIcon(NULL,IDI_APPLICATION);
WinClass.hCursor:=LoadCursor(Null,IDC_ARROW);
WinClass.hbrBackground:=HBRUSH(GetStockObject(WHITE_BRUSH));
WinClass.lpszMenuName:=nil;
WinClass.lpszClassName:=PChar(AppName);
if (RegisterClass(WinClass)=0) then
begin
MessageBox(null,'This application need WINDOWS platform','message',MB_ICONERROR);
exit;
end;
WinHwnd:=CreateWindow(PChar(AppName),'First SDK Application',WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
0,0,hInstance,nil);
if Iswindow(WinHwnd)then
begin
ShowWindow(WinHwnd,SW_SHOWNORMAL);
updateWindow(WinHwnd);
end
else begin
ECode:=GetLastError;
EString:=PChar(Inttostr(LoWord(ECode)));
Messagebox(null,EString,'Error',MB_ICONERROR);
exit;
end;
while(Getmessage(WinMsg,null,0,0))do
begin
TranslateMessage(WinMsg);
DispatchMessage(WinMsg);
end;
UnregisterClass(PChar(AppName),hInstance);
end.
uses
Windows,
Messages,
MMSystem,
SysUtils;
Const
AppName:String = 'HelloWin';
Null:Integer = 0;
function WndProc(WindowHwnd:HWND;TheMessage:UINT;WPARAMS:wParam;LPARAMS:lParam):Integer;stdcall;
var
ClientDC:HDC;
ps:TPaintStruct;
ClientRect:TRect;
sUser, sPower: string;
begin
case TheMessage of
WM_CREATE: begin
PlaySound('hellowin.wav',null,SND_FILENAME or SND_ASYNC);
Result:=0;
end;
WM_PAINT: begin
ClientDc:=BeginPaint(WindowHwnd,ps);
GetClientRect(WindowHwnd,ClientRect);
DrawText(ClientDc,PChar('Hello,Window98!'),-1,ClientRect,DT_SINGLELINE or
DT_CENTER OR DT_VCENTER);
sUser := 'ZhangSK''Testing';
sPower := 'POWERD BY DELPHI';
TextOut(ClientDC, 5, 5, PChar(sUser), Length(sUser));
TextOut(ClientDC, ClientRect.Right-200, ClientRect.Bottom-30, PChar(sPower), Length(sPower));
Endpaint(Windowhwnd,ps);
Result:=0;
end;
WM_DESTROY: begin
PostQuitMessage(0);
Result:=0;
end;
else
Result:=DefWindowProc(WindowHwnd,TheMessage,WPARAMS,LPARAMS);
end;
end;
var
WinHwnd:HWND;
WinMsg:MSG;
WinClass:WNDCLASS;
ECode:DWORD;
EString:PChar;
begin
WinClass.style:=CS_HREDRAW OR CS_VREDRAW;
WinClass.lpfnWndProc:=@WndProc;
WinClass.cbClsExtra:=0;
WinClass.cbWndExtra:=0;
WinClass.hInstance:=hInstance;
WinClass.hIcon:=LoadIcon(NULL,IDI_APPLICATION);
WinClass.hCursor:=LoadCursor(Null,IDC_ARROW);
WinClass.hbrBackground:=HBRUSH(GetStockObject(WHITE_BRUSH));
WinClass.lpszMenuName:=nil;
WinClass.lpszClassName:=PChar(AppName);
if (RegisterClass(WinClass)=0) then
begin
MessageBox(null,'This application need WINDOWS platform','message',MB_ICONERROR);
exit;
end;
WinHwnd:=CreateWindow(PChar(AppName),'First SDK Application',WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
0,0,hInstance,nil);
if Iswindow(WinHwnd)then
begin
ShowWindow(WinHwnd,SW_SHOWNORMAL);
updateWindow(WinHwnd);
end
else begin
ECode:=GetLastError;
EString:=PChar(Inttostr(LoWord(ECode)));
Messagebox(null,EString,'Error',MB_ICONERROR);
exit;
end;
while(Getmessage(WinMsg,null,0,0))do
begin
TranslateMessage(WinMsg);
DispatchMessage(WinMsg);
end;
UnregisterClass(PChar(AppName),hInstance);
end.
发表评论
-
java反射机制2 -- 通过名称创建类,并通过该类创建实例
2007-12-05 12:43 2667这几天一直在找java中是如何实现delphi中使用元类统一管 ... -
转 从DELPHI到JAVA
2007-12-05 12:20 2820转 http://blog.csdn.net/windin ... -
How does Java compiler resolve the ambiguity to decide which
2007-12-03 17:01 1130转http://bobcat.webappcabaret.ne ... -
java中的类之类 java.lang.reflect
2007-12-02 14:41 984不知道java.lang.reflect实现的功能算 ... -
转载,浅谈Object Pascal的指针
2007-11-30 16:15 1385转载,浅谈Object Pascal ... -
Delphi7远程调试
2007-11-30 16:12 2250Delphi7远程调试 请保留完整信息 Delphi7远程调 ... -
python thread lock
2007-11-30 16:11 29981 #coding=utf-8 2 ... -
delphi 函数指针 方法指针
2007-11-30 16:08 5095unit Unit1; interface ... -
Java线程
2007-11-30 16:07 7611 package org.zsk.error; 2 ... -
PostMessage和SendMessage区别
2007-11-30 16:06 1575PostMessage 只是把消息放入队列,不管其他程序是否处 ... -
模拟键盘输入
2007-11-30 16:04 1230SetForegroundWindow(HApp); ... -
控制另一个程序
2007-11-30 16:03 961实现思路分析: 1、找到目标程序的句柄,可以通过窗口的capt ... -
Eclipse 常用设置 快捷键
2007-11-30 15:50 1771常用设置 1、显示行号 Window->Prefe ... -
重构-保护
2007-11-30 15:46 817重构前的代码,使用字符串处理状态 package org.zs ...
相关推荐
windows 程序设计 HellWin.c 注释 。比较早一点的东西,对学习windows程序入门还是可以看看的。
HelloWin_v1; --WinAPI模板;标准窗口示例程序; [博文]WinAPI入门: 第一个标准Win32窗口程序 [改进&详细注释版;] 本示例可作为WinAPI编程入门教程;也可作为Win32编程的框架和模板; 查看教程及背景说明,请看同名博文;
最简单的VC开发程序
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
[博文]WinAPI入门: 第一个标准Win32窗口程序: 1.本程序演示最简单的标准Win32应用程序的结构框架; 2.WinAPI编程作为一切Windows应用程序的基础,本程序的大部分语句都会出现在任何Windows程序中;...
或许你已经看了programming Windows的前三章,但是对于那个hellowin程序甚为迷惘。希望hfire的这篇文章能帮你填补这个gap,并提供一些学习的经验。为什么是浅谈,因为hfire知道的也不够深,肯定会有错误,请批评指正...
您这样做是因为HELLOWIN将使用多媒体功能呼叫,而内定的项目中又不包括多媒体链接库文件。不然连结程序报告了错误信息,表明PlaySound函数不可用。(或者在函数预编译命令时加上:#pragma comment(lib,"Winmm.lib"),...
实验1 Windows编程基础实验报告 一、实验目的和要求 (1)创建一...", "HelloWin", 0) ; return 0 ; } // 创建窗口 hwnd = CreateWindow ("SDKWin", // 窗口类名 "实验1——Windows编程基础", // 窗口标题 WS_OVERLAPP
2.3.4 在Windows中使用printf 2.3.5 格式化的消息框 2.3.6 国际化之于本书 第3章 窗口与消息 3.1 窗口的创建 3.1.1 系统结构概述 3.1.2 HELLOWIN程序 3.1.3 通盘考虑 3.1.4 窗口类的注册 3.1.5 窗口的创建 3.1.6 ...
3.1.2 hellowin程序 3. 1.3 总体考虑 3.1.4 注册商口类 3.1.5 创建窗口 3.1.6 显示窗口 3.1.7 消息循环 3.1.8 窗口过程 3.1.9 处理消息 3.1.10 播放声音文件 3.1.11 wm_paint消息 ...
HELLOWIN windows API编程
c语言程序设计/第二个程序hellowin
hellowin.wav 博文链接:https://godspeedhu.iteye.com/blog/1135048
HELLOWIN.C应用程序的分析,主要是在显示区中央显示"hello,windows98!
win32 api上写的第一个程序,HELLOWIN.C -- Displays "Hello, Windows 98!" in client area (c) Charles Petzold, 1998
Haskell-OpenGL-教程 尝试创建具有基本IO的简洁现代Haskell OpenGL样板... 一个简单的应用程序,可以使用处理动画和用户事件,使用SDL2管理窗口和输入,并作为构建系统进行。 windows and input: SDL2 ... HelloWin
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow){static TCHAR szAppName[]=TEXT(“HelloWin”);HWND hwnd;MSG msg;WNDCLASS wndclass; wndclass.style =CS_HREDRAW...