关于VC6.0自动关闭MessageBox的方法整理。

找到一个方法,并在自己的MFC的基于对话框的工程里试验了下,基本代码如下:

SetTimer( 150, 1000, NULL );
MessageBox( Msg, title, MB_OK );

//在OnTimer中:

//这里传递的参数顺序和网上查到的有点区别!
HWND hwnd = ::FindWindow( NULL, title);


if ( hwnd )
::PostMessage( hwnd, WM_CLOSE, 0, 0 );


大家可以试验下哈:)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
使用VC6.0创建Windows窗口的步骤如下: 1. 创建一个新的Win32应用程序工程。 2. 在工程中添加一个新的源文件,用于存放窗口过程。 3. 在窗口过程中处理窗口消息。 4. 在WinMain函数中注册窗口类并创建窗口。 5. 在窗口过程中处理窗口消息。 下面是一个简单的示例代码: 1. 在VC6.0中创建一个新的Win32应用程序工程,命名为"WinApp"。 2. 添加一个新的源文件"WinApp.cpp"。 3. 在"WinApp.cpp"中编写窗口过程: ``` LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, uMsg, wParam, lParam); } return 0; } ``` 4. 在WinMain函数中注册窗口类并创建窗口: ``` int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASS wc = { 0 }; wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszClassName = "WinAppClass"; if (!RegisterClass(&wc)) { MessageBox(NULL, "RegisterClass failed!", "Error", MB_OK); return 0; } HWND hWnd = CreateWindow("WinAppClass", "WinApp", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL); if (!hWnd) { MessageBox(NULL, "CreateWindow failed!", "Error", MB_OK); return 0; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); MSG msg = { 0 }; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int)msg.wParam; } ``` 5. 编译并运行程序,即可看到一个简单的窗口。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值