2013年4月6日16:31:56
大家好今天是清明节放假的最后一天明天我就要去学校了所以这几天不会更新日志了,不过星期天回家我就更新
好,我们开始
一个窗口的创建有一些几个步骤
注册窗口
创建窗口
HWND hwin=CreateWindow(TEXT("第一个窗口"),TEXT("jh第一个窗口"), WS_OVERLAPPEDWINDOW,100,110,45,205,NULL,NULL,hInstance,NULL);
这就是一个窗口的创建过程我给大家看下完整的代码吧
:看我们只要100行代码就创建除了一个可以拖动,可以缩放的可以在窗口中点来点去的窗口了
=========华丽分割线=================================汇编的创建过程,比较长====================
大家好今天是清明节放假的最后一天明天我就要去学校了所以这几天不会更新日志了,不过星期天回家我就更新
好,我们开始
一个窗口的创建有一些几个步骤
注册窗口
WNDCLASS wnd;//定义窗口类
wnd.style=CS_HREDRAW | CS_VREDRAW;
//窗口类型
wnd.lpfnWndProc=CallProc;//消息处理函数
wnd.cbClsExtra=0;//预留的
wnd.cbWndExtra=0;//预留的
wnd.hCursor=LoadCursor(NULL,IDC_ARROW);
//鼠标的形态
wnd.hbrBackground=/*(HBRUSH)*/GetStockObject(WHITE_BRUSH);//设置背景 HBRUSH:转换为画刷的句柄
wnd.lpszMenuName=NULL;
wnd.lpszClassName=TEXT("第一个窗口");
if (!RegisterClass(&wnd))
{
MessageBox(NULL,TEXT("注册失败"),TEXT("WO NO !"),MB_OK|MB_ICONHAND);
return 0;
}
创建窗口
HWND hwin=CreateWindow(TEXT("第一个窗口"),TEXT("jh第一个窗口"), WS_OVERLAPPEDWINDOW,100,110,45,205,NULL,NULL,hInstance,NULL);
消息循环
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
}
return msg.lParam;
/*------------------------------------------------------------
HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
(c) Charles Petzold, 1998
------------------------------------------------------------*/
#include <windows.h>
#pragma comment(lib, "Winmm.lib")
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)
{
aaa: case WM_PAINT:
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rect);
DrawText (hdc, TEXT("hool"), -1, &rect,
DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
//MessageBox(NULL,TEXT("自绘中"),TEXT("OK"),0);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY:
if(MessageBox(NULL,TEXT("确定关闭?"),TEXT("OK"),MB_YESNO)==IDYES)
{
PostQuitMessage(0);
break;
}else
{
goto aaa;
}
case WM_QUIT:
if(MessageBox(NULL,TEXT("确定关闭?"),TEXT("OK"),MB_YESNO)==IDYES)
{
PostQuitMessage(0);
break;
}else
{
goto aaa;
}
case WM_CLOSE:
if(MessageBox(NULL,TEXT("确定关闭?"),TEXT("OK"),MB_YESNO)==IDYES)
{
PostQuitMessage(0);
break;
}else
{
goto aaa;
}
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
借鉴一些windows程序设计的一句话
:看我们只要100行代码就创建除了一个可以拖动,可以缩放的可以在窗口中点来点去的窗口了
=========华丽分割线=================================汇编的创建过程,比较长====================
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include
windows.inc
include
gdi32.inc
includelib
gdi32.lib
include
user32.inc
includelib
user32.lib
include
kernel32.inc
includelib
kernel32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data?
hInstance
dd
?
hWinMain
dd
?
.const
szClassName
db
'MyClass',0
szCaptionMain
db
'My first Window !',0
szText
db
'Win32 Assembly, Simple and powerful !',0
szButton
db
'button',0
szButtonText
db
'&OK',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_ProcWinMain
proc
uses ebx edi esi,hWnd,uMsg,wParam,lParam
local
@stPs:PAINTSTRUCT
local
@stRect:RECT
local
@hDc
mov
eax,uMsg
;********************************************************************
.if
eax ==
WM_PAINT
invoke
BeginPaint,hWnd,addr @stPs
mov
@hDc,eax
invoke
GetClientRect,hWnd,addr @stRect
invoke
DrawText,@hDc,addr szText,-1,\
addr @stRect,\
DT_SINGLELINE or DT_CENTER or DT_VCENTER
invoke
EndPaint,hWnd,addr @stPs
;********************************************************************
; 建立一个按钮
;********************************************************************
.elseif
eax ==
WM_CREATE
invoke
CreateWindowEx,NULL,\
offset szButton,offset szButtonText,\
WS_CHILD or WS_VISIBLE,\
10,10,65,22,\
hWnd,1,hInstance,NULL
;********************************************************************
.elseif
eax ==
WM_CLOSE
invoke
DestroyWindow,hWinMain
invoke
PostQuitMessage,NULL
;********************************************************************
.else
invoke
DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
;********************************************************************
xor
eax,eax
ret
_ProcWinMain
endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain
proc
local
@stWndClass:WNDCLASSEX
local
@stMsg:MSG
invoke
GetModuleHandle,NULL
mov
hInstance,eax
invoke
RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
;********************************************************************
; 注册窗口类
;********************************************************************
invoke
LoadCursor,0,IDC_ARROW
mov
@stWndClass.hCursor,eax
push
hInstance
pop
@stWndClass.hInstance
mov
@stWndClass.cbSize,sizeof WNDCLASSEX
mov
@stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov
@stWndClass.lpfnWndProc,offset _ProcWinMain
mov
@stWndClass.hbrBackground,COLOR_WINDOW + 1
mov
@stWndClass.lpszClassName,offset szClassName
invoke
RegisterClassEx,addr @stWndClass
;********************************************************************
; 建立并显示窗口
;********************************************************************
invoke
CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,\
WS_OVERLAPPEDWINDOW,\
100,100,600,400,\
NULL,NULL,hInstance,NULL
mov
hWinMain,eax
invoke
ShowWindow,hWinMain,SW_SHOWNORMAL
invoke
UpdateWindow,hWinMain
;********************************************************************
; 消息循环
;********************************************************************
.while
TRUE
invoke
GetMessage,addr @stMsg,NULL,0,0
.break
.if eax
== 0
invoke
TranslateMessage,addr @stMsg
invoke
DispatchMessage,addr @stMsg
.endw
ret
_WinMain
endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call
_WinMain
invoke
ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end
start