c语言怎么实现按扭
c语言里有没有接受鼠标点击的函数.?我想做一个window下的窗口,很简单的那种.几个按扭就行,每一个按扭可以打开一个网站...
程序代码:#include <windows.h>
#define IDE_WEB 101
#define IDB_END 117
#define IDB_OPENWEB 118
#define WIN_START_X 100
#define WIN_START_Y 100
#define WIN_WIDTH 320
#define WIN_HEIGHT 80
HWND hwnd ;
HWND hEdit_Web ;
HWND hButton_OpenWeb, hButton_End ;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; //消息处理过程函数
int winLayout(HINSTANCE hInstance) ; //窗口布局函数
int CheckString(char *strA, char *strB) ; //字符串匹配判断函数
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("SineWave") ;
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 (LTGRAY_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
if (!RegisterClass (&wndclass))
{
MessageBox ( NULL, TEXT ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return 0 ;
}
hwnd = CreateWindow ( szAppName, TEXT ("打开指定网页程序"),
WS_POPUP,
WIN_START_X, WIN_START_Y ,
WIN_WIDTH, WIN_HEIGHT ,
NULL, NULL, hInstance, NULL) ;
winLayout(hInstance);
SetWindowPos(hwnd
, HWND_TOPMOST
, WIN_START_X, WIN_START_Y
, WIN_WIDTH, WIN_HEIGHT
,SWP_SHOWWINDOW) ; //最顶端显示
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
HBRUSH hBrush ;
switch (message)
{
case WM_CREATE:
return 0 ;
case WM_PAINT: //背景绘制与重画
hdc = BeginPaint (hwnd, &ps) ;
hBrush = CreateSolidBrush (RGB(201, 207, 202)) ;
SelectObject (hdc, hBrush) ;
Rectangle(hdc , 0, 0, WIN_WIDTH, WIN_HEIGHT);
DeleteObject (hBrush) ;
for(int i = 5; i < WIN_HEIGHT-5; i++)
for(int j = 5; j < WIN_WIDTH-5; j++)
{
SetPixel(hdc, j, i, RGB (18, 445-i, j/2)) ;
}
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_COMMAND: //点击按钮控件事件
switch(LOWORD(wParam))
{
case IDB_END:
exit(0) ;
break ;
case IDB_OPENWEB: //连接网站按钮
char lastChar[100] = "", webChar[100] = "http:\\\\", *linkChar ;
GetWindowText(hEdit_Web, lastChar, 99) ;
//对不浏览器不能识别的网址进行处理
if(CheckString(lastChar, "http:\\\\"))
{
strcat(webChar, lastChar) ;
linkChar = webChar ;
SetWindowText(hEdit_Web, webChar) ;
}
else
{
linkChar = lastChar ;
}
//连接网站
ShellExecute(hwnd, "open", linkChar, "", "", SW_SHOW);
break ;
}
return 0;
case WM_DESTROY: //销毁窗口
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
int winLayout(HINSTANCE hInstance)
{
hEdit_Web = CreateWindow("EDIT", //建立网址输入文本框
NULL,
WS_CHILD | WS_VISIBLE | ES_RIGHT | WS_BORDER,
10, 10 ,
260, 20 ,
hwnd,
(HMENU)IDE_WEB,
hInstance,
NULL);
hButton_End = CreateWindow("BUTTON", //建立退出按钮
"退出",
WS_CHILD | WS_VISIBLE,
110, 40 ,
50, 20 ,
hwnd,
(HMENU)IDB_END,
hInstance,
NULL);
hButton_OpenWeb = CreateWindow("BUTTON", //建立连接网页按钮
"连接网站",
WS_CHILD | WS_VISIBLE,
10, 40 ,
80, 20 ,
hwnd,
(HMENU)IDB_OPENWEB,
hInstance,
NULL);
}
int CheckString(char *strA, char *strB)
{
do
{
if(*strA != *strB)
return 1 ;
}while(*(strA++) && *(strB++)) ;
return 0 ;
}C-FREE编译运行通过
[/url]
