请教:用Win32 Application创建了一个窗口,想按下button键弹出另一个简单的窗口,麻烦各位帮我补充一下我的代码
我现在的程序中按下button键显示的是一行字,我想改为:按下button键就弹出一个简单的窗口,该如何做呢?#include <afxwin.h>
#include<windows.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
HWND hwnd;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndcls.hIcon = LoadIcon (NULL,IDI_INFORMATION);
wndcls.hCursor = LoadCursor (NULL,IDC_CROSS);
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = "welcome";
wndcls.style = CS_HREDRAW | CS_VREDRAW;
wndcls.lpszMenuName = NULL;
RegisterClass(&wndcls); //注册窗口类
HWND hwnd;
hwnd = CreateWindow ("welcome","My first dialog", WS_OVERLAPPEDWINDOW, 0, 0, 800, 500, NULL, NULL, hInstance, NULL );//创建窗口
/////////
ShowWindow (hwnd, SW_SHOWNORMAL);//显示窗口
UpdateWindow (hwnd);///更新窗口
MSG msg;
while (GetMessage (&msg, NULL, 0, 0 ))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}//endof while
return 0;
} //endof winMain()
LRESULT CALLBACK WinSunProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{ HDC hDC;///handle to DC
HBRUSH hBrush; ///用的是画刷,画出的图里面是有颜色的
HPEN hPen ;///handle to object画笔画出的只是线条
PAINTSTRUCT PtStr;
POINT points [6] = { { 100,212}, {70,227},{70,280},{130,280},{130,227},{100,212} };//用6个点确定一个五边形
switch(uMsg)
{
case WM_CREATE:
CreateWindow("button","关于我们……",WS_CHILD|WS_VISIBLE |BS_PUSHBUTTON,430,300,100,50,hwnd,NULL,NULL,NULL);
break;
case WM_COMMAND:////消息处理函数,单击按钮时会给父窗口发送WM_COMMAND消息
{
switch(wParam)////wParam的高位是BN_CLICKED,低位是button的ID号
{
case BN_CLICKED:
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,150,230,"思源公司成立于2003年……",strlen(("思源达公司成立于2003年……")));
ReleaseDC(hwnd,hdc);
break;
}
}
break;
case WM_LBUTTONDOWN:
MessageBox(NULL,"Left mouse clicked","提示",0);
HDC hdc;
hdc = GetDC(hwnd);
TextOut (hdc,300,80,"思源科技有限公司",strlen("思源科技有限公司"));
ReleaseDC (hwnd,hdc);
break;
case WM_RBUTTONDOWN:
MessageBox(hwnd,"Right mouse clicked","welcome",0);
hdc = GetDC(hwnd);
TextOut (hdc,300,120,"Welcome to our company!",strlen("Welcome to our company!"));
ReleaseDC (hwnd,hdc);
break;
case WM_PAINT://///填充图形
hDC = BeginPaint (hwnd , & PtStr);
hPen = (HPEN) GetStockObject(NULL_PEN);//默认颜色
SelectObject (hDC,hPen);
hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject (hDC,hBrush);
LineTo (hDC, 70, 70);
DeleteObject(hPen);
hPen = CreatePen(PS_SOLID,1,RGB(255,0,0));///pen style,pen width,pen color定义画笔
SelectObject(hDC,hPen);
Polyline(hDC,points,6);//左边最下方显示的图形
Arc(hDC,63,137,138,212,100,137,100,137);
Arc(hDC,83,157,91,165,87,161,87,161);
Arc(hDC,118,157,126,165,122,161,122,161);
RoundRect(hDC,101,185,116,193,15,8);
DeleteObject(hPen);
DeleteObject(hBrush);
EndPaint(hwnd,&PtStr);
return 0;
case WM_KEYUP: // 当收到按ESC键的消息时,(如果当前是全屏模式,必须要加入退出方式)
switch (wParam)
{
case VK_ESCAPE:
MessageBox(hwnd,"您按下了ESC键","消息提示",MB_OK|MB_ICONEXCLAMATION);
return 0;
break;
}
case WM_CLOSE:
if(IDYES == MessageBox(hwnd,"是否真的结束?","要退出程序吗?",MB_YESNO))
{
DestroyWindow(hwnd);
}//ENDOF IF
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg, wParam, lParam);
}//endof swith()
return 0;
}//end of WinSunProc()
[ 本帖最后由 he189 于 2011-8-18 17:54 编辑 ]