| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3184 人关注过本帖
标题:请教:用Win32 Application创建了一个窗口,想按下button键弹出另一个简单的 ...
只看楼主 加入收藏
he189
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-8-17
结帖率:75%
收藏
已结贴  问题点数:10 回复次数:3 
请教:用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 编辑 ]
搜索更多相关主题的帖子: 如何 include button 
2011-08-18 17:20
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:0 
INT_PTR DialogBox(
  HINSTANCE hInstance,  // handle to module
  LPCTSTR lpTemplate,   // dialog box template
  HWND hWndParent,      // handle to owner window
  DLGPROC lpDialogFunc  // dialog box procedure
);

BOOL EndDialog(
  HWND hDlg,        // handle to dialog box
  INT_PTR nResult   // value to return
);
用这两个函数。
2011-08-18 18:47
he189
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-8-17
收藏
得分:0 
回复 2楼 zhoufeng1988
版主,不太懂用这两个函数呢,能不能给个例子我学习学习啊,谢谢啦
2011-08-18 19:00
zhoufeng1988
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:北京
等 级:贵宾
威 望:27
帖 子:1432
专家分:6329
注 册:2009-5-31
收藏
得分:10 
WinAPI_Dialog.zip (4.76 KB)

你能写上面的程序,这个自然不是问题啦。
用资源文件。
2011-08-18 21:37
快速回复:请教:用Win32 Application创建了一个窗口,想按下button键弹出另一个 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032590 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved