首页
社区
课程
招聘
[求助]C语言如何调用API...
发表于: 2007-5-25 11:25 9326

[求助]C语言如何调用API...

2007-5-25 11:25
9326
想学习API的使用(想写个内存修改程序来玩玩)

在网上找到了一个例子

MessageBox(NULL,"Hello   World.","hi",MB_OK);

请问那里有API函数的语法说明之类的资料,

=================

    函数功能:该函数创建、显示、和操作一个消息框。消息框含有应用程序定义的消息和标题,加上预定义图标与Push(下按)按钮的任何组合。

    函数原型:int MessageBox(HWND hWnd,LPCTSTR IpCaption,UINT UType);

    参数:

    hWnd:标识将被创建的消息框的拥有窗口。如果此参数为NULL,则消息框没有拥有窗口。

    IpText:指向一个以NULL结尾的、含有将被显示的消息的字符串的指针。

    IpCaption:指向一个以NULL结尾的、用于对话框标题的字符串的指针。

    uType:指定一个决定对话框的内容和行为的位标志集。此参数可以为下列标志组中标志的组合。

    指定下列标志中的一个来显示消息框中的按钮,标志的含义如下。

    MB_ABORTRETRYIGNORE:消息框含有三个按钮:Abort,Retry和Ignore。

    MB_OK:消息框含有一个按钮:OK。这是缺省值。

    MB_OKCANCEL:消息框含有两个按钮:OK和Cancel。

    MB_RETRYCANCEL:消息框含有两个按钮:Retry和Cancel。

    MB_YESNO:消息框含有两个按钮:Yes和No。

    MB_YESNOCANCEL:消息框含有三个按钮:Yes,No和Cancel。

    指定下列标志中的一个来显示消息框中的图标:标志的含义如下。

    MB_ICONEXCLAMATION:

    MB_ICONWARNING:一个惊叹号出现在消息框。

    MB_ICONINFORMATION:

    MB_ICONASTERISK:一个圆圈中小写字母i组成的图标出现在消息框。

    MB_ICONOUESTION:一个问题标记图标出现在消息框。

    MB_ICONSTOP:

    MB_ICONERROR:

    MM_ICONHAND:一个停止消息图标出现在消息框。

    指定下列标志中的一个来显不缺省的按钮:标志的含义如下。

    MB_DEFBUTTON1:第一个按钮为缺省按钮。如果MB_DEFBUTTON2,MB_DEFBUTTON3,MB_DEFBUTTON4没有被指定,则MB_DEFBUTTON1为缺省值。

    MB_DEFSUTTON2;第二个按钮为缺省按钮。

    MB_DEFBUTTON3:第三个按钮为缺省按钮。

    MB_DEFBUTTON4:第四个按钮为缺省按钮。

    指定下列标志中的一个来显示对话框的形态:标志的含义如卜。

    MB_APPLMODAL:在hwnd参数标识的窗口中继续工作以前,用户一定响应消息框。但是,用户可以移动到其他线程的窗口且在这些窗口中工作。根据应用程序中窗口的层次机构,用户则以移动到线程内的其他窗口。所有母消息框的子窗口自动地失效,但是弹出窗口不是这样。如果既没有指定MB_SYSTEMMODAL也没有指定MB_TASKMOOAL,则MB_APPLMODAL为缺省的。

    MB_SYSTEMMODAL:除了消息框有WB_EX_TOPMOST类型,MB_APPLMODAL和WS_EX_TOPMOST一样。用系统模态消息框来改变各种各样的用户,主要的损坏错误需要立即注意(例如,内存溢出)。如果不是那些与hwnd联系的窗口,此标志对用户对窗口的相互联系没有影响。

    MB_TASKMODAL:如果参数hwnd为NULL,除了所有属于当前线程高层次的窗口足失效的,MB_TASKMODALL和MB_ApPLMODAL一样。当调用应用程序或库没有一个可以得到的窗口句柄时,使用此标志。但仍需要阻止到调用应用程序甲其他窗口的输入而不是搁置其他线程。

    另外,可以指定下列标志。

    MB_DEFAULT_DESKTOP_ONLy:接收输入的当前桌面一定是一个缺省桌面。否则,函数调用失败。缺省桌面是一个在用户已经纪录且以后应用程序在此上面运行的桌面。

    MB_HELP:把一个Help按钮增加到消息框。选择Help按钮或按F1产生一个Help事件。

    MB_RIGHT:文本为右调整。

    MB_RTLREADING:用在Hebrew和Arabic系统中从右到左的顺序显示消息和大写文本。

    MB_SETFOREGROUND:消息框变为前景窗口。在内部系统为消息个调用SetForegrundWindow函数。

    MB_TOPMOSI:消息框用WS_EX_TOPMOST窗口类型来创建MB_SERVICE_NOTIFICATION。

    Windows NT:调用程序是一个通知事件的用户的服务程序。函数在当前活动桌面上显示一个消息框,即使没有用户登记到计算机。

    如果设置了此参数,则hwnd参数一定为NULL。所以消息框可以出现在一个桌面上而不是桌面响应参数hwnd。

    对于Windows NT 4.0,MB_SERVICE_NOTIFICATION的值己经改变。对于旧的和新的值,请参见WINUSER。

    Windows NT 4.O通过把旧值映射到MessageBox和MessageBoxEx执行中的新值,为先存在的服务程序提供逆兼容。此映射只为有了版本数目的可执行程序而做。

    为了建立一个用MB_SERVICE_NOTIFICATION的服务器,且可以在Windows NT 3.X和Window NT 4.0上执行,可有两种选择。在连接时间,指定一个版本数目小于4.0的版本,或在连接时间,指定一个4.0版本。在运行时间,用函数GetVersionEx来检测系统版本,然后在Windows NT 3.X上用MB_SERVICE_NOTIFICATION_NT 3.x来运行和在Windows NT 4.0上用MB_SERVICE_NOTIFICAION来运行。MB_SERVCE_NOTIFICATION_NT3.x(WindowNT)此值响应于为WindowNT3.51的MB_SERVICE_NOTIFICAION

    定义的值。

    返回值:如果没有足够的内存来创建消息框,则返回值为零。如果函数调用成功,则返回值为下列对话框返回的菜单项目值中的一个:

    IDABORT:Abort 按钮被选中。IDCANCEL:Cancel按钮被选中。IDIGNORE:Ignore按钮被选中。

    IDNO:NO按钮被选中。IDOK:OK按钮被选中。IDRETRY:RETRY按钮被选中。

    IDYES:YES按钮被选中。

    如果一个消息框有一个Cancel按钮,且如果Esc键被按下或Cancel键被选择,则函数返回IDCANCEL值。如果消息框没有Cancel按钮,则按Esc键没有作用。

    备注:当创建一个系统模态消息框来表示系统在内存的低端中时,由lpTeXt和lpCaption参数指向的字符串不应该从一个资源文件中取出,因为试图装载此资源可能导致失败。

    当一个应用程序调用MessageBox,且为uType参数指定MB_ICONHAND和MB_SYSTEMMODAL标志时,系统不管可用内存为多少,直接显示结果消息框。当这些标志被指定,系统把消息框文本的长度局限于三行。系统不能自动截断要填到消息框的行,但是消息字符串一定含有回车换行,以在合适的位置换行。

    如果在对话框出现的的同时创建了消息框,则可使用对话框的句柄作为hwnd参数,hwnd参数不应该标识一个子窗口,例如对话框中的一个控制。

    Windows 95:系统可以支持最大达16364个窗口句柄。

    Windows CE:Windows CE 不支持uType参数的下列值:

    MB_STSTEMMODAL;MB_TASKMODAL;MB_HELP;MB_RTLREADING;MB_DEFAULT_DESKTOP_ONLY;

    MB_SERVICE_NOTIFICATION;MB_USERICON。

    不支持下列返回值:IDCLOSE;IDHELP。

    速查:Windows:3.1及以上版本:Windows:95及以上版本;Windows:1.0及以上版本;头文件:Winuser.h;库文件:USer32.lib;URicode:在Windows NT上实现为Unicode和ANSI两种版本。

=================

上面这个,好像跟例子的语法有些不一样

[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 268
活跃值: (40)
能力值: ( LV10,RANK:170 )
在线值:
发帖
回帖
粉丝
2
最好,最全的资料就是MSDN了!

MessageBox Function

--------------------------------------------------------------------------------

The MessageBox function creates, displays, and operates a message box. The message box contains an application-defined message and title, plus any combination of predefined icons and push buttons.

Syntax

int MessageBox(          HWND hWnd,
    LPCTSTR lpText,
    LPCTSTR lpCaption,
    UINT uType
);
Parameters

hWnd
[in] Handle to the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window.
lpText
[in] Pointer to a null-terminated string that contains the message to be displayed.
lpCaption
[in] Pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title Error is used.
uType
[in] Specifies the contents and behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.
To indicate the buttons displayed in the message box, specify one of the following values.
MB_ABORTRETRYIGNORE
The message box contains three push buttons: Abort, Retry, and Ignore.
MB_CANCELTRYCONTINUE
Microsoft® Windows® 2000/XP: The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.
MB_HELP
Windows 95/98/Me, Windows NT® 4.0 and later: Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner.
MB_OK
The message box contains one push button: OK. This is the default.
MB_OKCANCEL
The message box contains two push buttons: OK and Cancel.
MB_RETRYCANCEL
The message box contains two push buttons: Retry and Cancel.
MB_YESNO
The message box contains two push buttons: Yes and No.
MB_YESNOCANCEL
The message box contains three push buttons: Yes, No, and Cancel.
To display an icon in the message box, specify one of the following values.
MB_ICONEXCLAMATION
An exclamation-point icon appears in the message box.
MB_ICONWARNING
An exclamation-point icon appears in the message box.
MB_ICONINFORMATION
An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONASTERISK
An icon consisting of a lowercase letter i in a circle appears in the message box.
MB_ICONQUESTION
A question-mark icon appears in the message box.
MB_ICONSTOP
A stop-sign icon appears in the message box.
MB_ICONERROR
A stop-sign icon appears in the message box.
MB_ICONHAND
A stop-sign icon appears in the message box.
To indicate the default button, specify one of the following values.
MB_DEFBUTTON1
The first button is the default button.
MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.

MB_DEFBUTTON2
The second button is the default button.
MB_DEFBUTTON3
The third button is the default button.
MB_DEFBUTTON4
The fourth button is the default button.
To indicate the modality of the dialog box, specify one of the following values.
MB_APPLMODAL
The user must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the user can move to the windows of other threads and work in those windows.
Depending on the hierarchy of windows in the application, the user may be able to move to other windows within the thread. All child windows of the parent of the message box are automatically disabled, but popup windows are not.

MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.

MB_SYSTEMMODAL
Same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.
MB_TASKMODAL
Same as MB_APPLMODAL except that all the top-level windows belonging to the current thread are disabled if the hWnd parameter is NULL. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the calling thread without suspending other threads.
To specify other options, use one or more of the following values.
MB_DEFAULT_DESKTOP_ONLY
Windows NT/2000/XP: Same as MB_SERVICE_NOTIFICATION except that the system will display the message box only on the default desktop of the interactive window station. For more information, see Window Stations.
Windows NT 4.0 and earlier: If the current input desktop is not the default desktop, MessageBox fails.

Windows 2000/XP: If the current input desktop is not the default desktop, MessageBox does not return until the user switches to the default desktop.

Windows 95/98/Me: This flag has no effect.

MB_RIGHT
The text is right-justified.
MB_RTLREADING
Displays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
MB_SETFOREGROUND
The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
MB_TOPMOST
The message box is created with the WS_EX_TOPMOST window style.
MB_SERVICE_NOTIFICATION
Windows NT/2000/XP: The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.
Terminal Services: If the calling thread has an impersonation token, the function directs the message box to the session specified in the impersonation token.

If this flag is set, the hWnd parameter must be NULL. This is so the message box can appear on a desktop other than the desktop corresponding to the hWnd.

For more information on the changes between Microsoft® Windows NT® 3.51 and Windows NT 4.0, see Remarks.

MB_SERVICE_NOTIFICATION_NT3X
Windows NT/2000/XP: This value corresponds to the value defined for MB_SERVICE_NOTIFICATION for Windows NT version 3.51.
For more information on the changes between Windows NT 3.51 and Windows NT 4.0, see Remarks.

Return Value

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

If the function succeeds, the return value is one of the following menu-item values.

IDABORT Abort button was selected.
IDCANCEL Cancel button was selected.
IDCONTINUE Continue button was selected.
IDIGNORE Ignore button was selected.
IDNO No button was selected.
IDOK OK button was selected.
IDRETRY Retry button was selected.
IDTRYAGAIN Try Again button was selected.
IDYES Yes button was selected.

Remarks

When you use a system-modal message box to indicate that the system is low on memory, the strings pointed to by the lpText and lpCaption parameters should not be taken from a resource file, because an attempt to load the resource may fail.

If you create a message box while a dialog box is present, use a handle to the dialog box as the hWnd parameter. The hWnd parameter should not identify a child window, such as a control in a dialog box.

Windows 95/98/Me: The system can support a maximum of 16,364 window handles.

Windows NT/2000/XP: The value of MB_SERVICE_NOTIFICATION changed starting with Windows NT 4.0. Windows NT 4.0 provides backward compatibility for pre-existing services by mapping the old value to the new value in the implementation of MessageBox. This mapping is only done for executables that have a version number less than 4.0, as set by the linker.

To build a service that uses MB_SERVICE_NOTIFICATION, and can run on both Microsoft Windows® NT 3.x and Windows NT 4.0, you can do one of the following.

At link-time, specify a version number less than 4.0
At link-time, specify version 4.0. At run-time, use the GetVersionEx function to check the system version. Then when running on Windows NT 3.x, use MB_SERVICE_NOTIFICATION_NT3X; and on Windows NT 4.0, use MB_SERVICE_NOTIFICATION.

Windows 95/98/Me: Even though MessageBoxW exists, it is supported by the Microsoft Layer for Unicode to give more consistent behavior across all Windows operating systems. To use this, you must add certain files to your application, as outlined in .

Example

For an example, see Displaying a Message Box.

Function Information

Header Declared in Winuser.h, include Windows.h
Import library User32.lib
Minimum operating systems Windows 95, Windows NT 3.1
Unicode Implemented as Unicode and ANSI versions on Windows NT, Windows 2000, Windows XP

See Also

Dialog Boxes Overview, FlashWindow, MessageBeep, MessageBoxEx, MessageBoxIndirect, SetForegroundWindow

--------------------------------------------------------------------------------

© 2003 Microsoft Corporation. All rights reserved.
2007-5-25 13:29
0
游客
登录 | 注册 方可回帖
返回
//