用c语言如何实现弹除对话框

Python011

用c语言如何实现弹除对话框,第1张

#include

#include

char format[]="%s%s\n";

char hello[]="Hello";

char world[]="world";

HWND hwnd;void main(void)

asm

//push NULL

//call dword ptr GetModuleHandle

//mov hwnd,eax push MB_OK mov eax,offset world push eax mov eax,offset hello push eax push 0//说明此处不能将前面注释掉代码处得到的hwnd压栈,否则对话框弹不出来。

call dword ptr MessageBox

}

}

WINDOWS程序MessagBox

WINDOWS或控制台 assert

C/C++ code

// crt_assert.c

// compile with: /c

#include <stdio.h>

#include <assert.h>

#include <string.h>

void analyze_string( char *string )   // Prototype

int main( void )

{

char  test1[] = "abc", *test2 = NULL, test3[] = ""

printf ( "Analyzing string '%s'\n", test1 )fflush( stdout )

analyze_string( test1 )

printf ( "Analyzing string '%s'\n", test2 )fflush( stdout )

analyze_string( test2 )

printf ( "Analyzing string '%s'\n", test3 )fflush( stdout )

analyze_string( test3 )

}

// Tests a string to see if it is NULL,

// empty, or longer than 0 characters.

void analyze_string( char * string )

{

assert( string != NULL )        // Cannot be NULL

assert( *string != '\0' )       // Cannot be empty

assert( strlen( string ) >2 )  // Length must exceed 2

}

扩展资料:

#include <windows.h>

#include <Commdlg.h>

#include <stdio.h>

// 返回值: 成功 1, 失败 0

// 通过 path 返回获取的路径

int FileDialog(char *path)

{

OPENFILENAME ofn

ZeroMemory(&ofn, sizeof(ofn))

ofn.lStructSize = sizeof(ofn)// 结构大小

ofn.lpstrFile = path// 路径

ofn.nMaxFile = MAX_PATH// 路径大小

ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0"// 文件类型

ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST

return GetOpenFileName(&ofn)

}

int main(char argc, char *argv[])

{

char szFile[MAX_PATH] = {0}

if(FileDialog(szFile))

{

puts(szFile)

}

getchar()

return 0

}

while((ch=getche())!='q') 改成

while((ch=getchar())!='\0')

error C2146: syntax error : missing '' before identifier 'WCHAR'

语法错误,在'WCHAR'前丢失''

但我在你的源程序里没发现'WCHAR'

所以还有什么问题,我就不太清楚了

直接调用系统API MessageBox()函数就可以了。

函数原形

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

参数说明

hWnd: 消息框的拥有窗此参数口。如果为NULL,则消息框没有拥有窗口。

lpText:消息框的内容。

lpCaption: 消息框的标题。

uType:

指定一个决定对话框的内容和行为的位标志集。此参数可以为下列标志组中标志的组合。指定下列标志中的一个来显示消息框中的按钮以及图标。

MB_OK 默认值。有一个确认按钮在里面。

MB_YESNO有是和否在里面。

MB_ABORTRETRYIGNORE 有Abort(放弃),Retry(重试)和Ignore(跳过)

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

MB_RETRYCANCEL 有Retry(重试)和Cancel(取消)

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

当然还有其他标志和返回值, 具体内容参考

https://msdn.microsoft.com/en-us/library/ms645505(VS.85).aspx

最后是用系统API时需要包含头文件 windows.h