| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 442 人关注过本帖
标题:一个简单的按扭
只看楼主 加入收藏
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
结帖率:83.33%
收藏
 问题点数:0 回复次数:1 
一个简单的按扭

先说明,我不是做MFC的。我想定义多个按扭可总是不成功,这是单独一个的:

#include <windows.h>
static HWND hwndButton = 0;//声明
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)

{
HWND hwnd;
MSG messages;
WNDCLASSEX wincl;


wincl.hInstance = hThisInstance;
wincl.lpszClassName = "win player";
wincl.lpfnWndProc = WindowProcedure;
wincl.style = CS_DBLCLKS;
wincl.cbSize = sizeof (WNDCLASSEX);


wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL;
wincl.cbClsExtra = 0;
wincl.cbWndExtra = 0;
wincl.hbrBackground = (HBRUSH) COLOR_WINDOWFRAME;//程序底色,设置为白色


if (!RegisterClassEx (&wincl))
return 0;

hwnd = CreateWindowEx (
0,
"win player",
"天使梦魔",
WS_CAPTION,//显示方式,这是一个单独的,应该用组合.因为不用任何效果所以可以为0
300,
300,
400,
250,
HWND_DESKTOP,
NULL,
hThisInstance,
NULL
);


ShowWindow (hwnd, nFunsterStil);


while (GetMessage (&messages, NULL, 0, 0))
{

TranslateMessage(&messages);

DispatchMessage(&messages);
}

return messages.wParam;
}

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;

switch (message)
{
case WM_PAINT://当窗口被重画时
hdc = BeginPaint (hwnd, &ps);//使绘图区域有效
TextOut(hdc,165,10,"天使梦魔",8);//参数为:窗口句柄.X,Y坐标.内容.数量(文字占2)
TextOut(hdc,10,30,"当您看到时给我邮件,可以一起讨论C++,系统,网络等问题.",51);
TextOut(hdc,10,50,"E-mail:shakugan.shana@163.com",29);
TextOut(hdc,10,70,"QQ:297397170【397841047】",25);
TextOut(hdc,10,90,"Blog:shakugan.shana.blog.163.com",32);
TextOut(hdc,10,110,"------------------------------------------------",48);
TextOut(hdc,10,125,"梦醒的时候,就全部结束了.我在寻找什么,那是心中的永恒.",52);
EndPaint (hwnd, &ps);//结束绘图区域
return 0;
break;

case WM_CREATE://当一个窗口创建
{
hwndButton = CreateWindow (//创建一个区域,还不确定为何控件
"button",//类型为一个按钮
"退出",//按钮文本
WS_CHILD | WS_VISIBLE,//显示方式
165 , 185,//在程序上显示的X,Y坐标
60, 30,//按钮大小
hwnd,//所在窗口句柄
(HMENU) 1,//按钮ID=1
((LPCREATESTRUCT) lParam)->hInstance,
NULL
);
return 0;
break;
}

case WM_COMMAND://点击按钮
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndButton)
{
DestroyWindow (hwnd);
}
return 0;
break;

case WM_DESTROY:
MessageBox (NULL, "程序已卸出内存.", "^_^", MB_OK);
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}

return 0;
}

搜索更多相关主题的帖子: 成功 include 
2007-08-30 08:57
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
回复:(天使梦魔)一个简单的按扭

My SDK template (written in 1999).

I did not read your program throughly.

======================================================================

#include <windows.h>


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
PSTR szCmdLine, // command line
int iCmdShow) // show state
{
static TCHAR szAppName[] = "MainWindow";
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

// wndclass has 10 data memembers
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)) // register windowclass
return 0;

// create window
hwnd = CreateWindow(
szAppName, // window class name
"Main Window", // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL); // creation parameters

ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return msg.wParam;
}


// WndProc function
LRESULT CALLBACK WndProc(
HWND hwnd, // handle to window
UINT message, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam) // second message parameter
{
HDC hdc;
PAINTSTRUCT ps;

switch(message)
{
case WM_CREATE:
// Initialize the window


return 0;

case WM_PAINT:
// Paint the window's client area
hdc = BeginPaint(hwnd, &ps);


EndPaint(hwnd, &ps);

return 0;

case WM_SIZE:
// Set the size and position of the window


return 0;

case WM_DESTROY:
// Destroy the window
PostQuitMessage(0);
return 0;


default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-08-30 09:32
快速回复:一个简单的按扭
数据加载中...
 
   



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

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