win32 怎么实现弹出几个窗口!
愚人节想和同学开个玩笑。怎么写一个简单的Main函数,实现弹出好几个HelloWorld窗口呢?我尝试用MessageBox但是,只是出现一个,点击确定才又出现一个。小弟...
愚人节想和同学开个玩笑。怎么写一个简单的Main函数,实现弹出好几个Hello World窗口呢?
我尝试用MessageBox但是,只是出现一个,点击确定才又出现一个。小弟C++不是太懂,请大侠别拿MFC特别复杂的例子教我。
谢谢啦。 展开
我尝试用MessageBox但是,只是出现一个,点击确定才又出现一个。小弟C++不是太懂,请大侠别拿MFC特别复杂的例子教我。
谢谢啦。 展开
3个回答
展开全部
//给你个例子,你可以自己修改一下更适合你的
#include <windows.h>#include <stdio.h>
#define NUM 10
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("AltWind") ;
HWND hwnd[NUM] ;
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 ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
for(int i = 0; i < NUM; i += 1)
{
hwnd[i] = CreateWindow (szAppName,
TEXT ("Alternate and Winding Fill Modes"),
WS_OVERLAPPEDWINDOW,
160 * i,
90 * i,
250,
200,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow (hwnd[i], iCmdShow) ;
UpdateWindow (hwnd[i]) ;
}
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOutA(hdc, 0, 80, "愚人节快乐!", 12);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
#include <windows.h>#include <stdio.h>
#define NUM 10
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("AltWind") ;
HWND hwnd[NUM] ;
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 ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
for(int i = 0; i < NUM; i += 1)
{
hwnd[i] = CreateWindow (szAppName,
TEXT ("Alternate and Winding Fill Modes"),
WS_OVERLAPPEDWINDOW,
160 * i,
90 * i,
250,
200,
NULL,
NULL,
hInstance,
NULL) ;
ShowWindow (hwnd[i], iCmdShow) ;
UpdateWindow (hwnd[i]) ;
}
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
TextOutA(hdc, 0, 80, "愚人节快乐!", 12);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
更多追问追答
追问
你真是厉害,如果我想改成让人一个个窗口关闭。应该修改哪个代码呢?我肯定给你加分的。
追答
额,代码有点长,写不下了,给个邮箱,我传给你吧
展开全部
CString str;
for(int i=0;i<100;i++)
{
str.Format("%d",i);
::MessageBox(NULL,str,"愚人节快乐",MB_OK);
}
这样100个是同时弹出的。
for(int i=0;i<100;i++)
{
str.Format("%d",i);
::MessageBox(NULL,str,"愚人节快乐",MB_OK);
}
这样100个是同时弹出的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你可以在让你同学点击的时候触发onclick()事件,然后调用javascript函数,不断弹出窗口
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询