在windows API做的窗口程序中怎样获取一个按钮被点击的次数
展开全部
比如在这个程序中要怎么改?
// Button.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
//
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp);
//
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HWND hwnd;
char WindowName[]={"This Window\0"};
WNDCLASS wobj;
wobj.style=0;
wobj.lpfnWndProc=WndProc;
wobj.lpszClassName=WindowName;
wobj.lpszMenuName=NULL;
wobj.hIcon=NULL;
wobj.hCursor=LoadCursor(NULL,IDC_ARROW);
wobj.hInstance=hInstance;
wobj.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wobj.cbClsExtra=0;
wobj.cbWndExtra=0;
RegisterClass(&wobj);
hwnd=CreateWindow(WindowName,WindowName,WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL|WS_SIZEBOX,150,50,200,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DeleteObject(hwnd);
return 0;
}
#include"stdafx.h"
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp)
{
HDC hdc;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:CreateWindow("Button","按钮",WS_VISIBLE|WS_CHILD,10,10,100,120,hwnd,0,0,0);break;
case WM_PAINT:break;
case WM_DESTROY:PostQuitMessage(0);return 0;
default:break;
}
return DefWindowProc(hwnd,message,wp,lp);
}
我想在按钮被点击后输出信息
如何用API编写这样一个程序??最好能有示例代码。
程序打开后显示窗口一,点击窗口一的按钮,显示窗口二,且窗口一不可用。关闭窗口二后,窗口一重新变为可用,且按钮获得焦点。
我曾试着编写了个程序,但执行起来总是有问题,关闭窗口二后,窗口自动不见了,找到窗口一并激活后,按钮不能显示出来。请各位高手解惑。
// Button.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
//
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp);
//
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HWND hwnd;
char WindowName[]={"This Window\0"};
WNDCLASS wobj;
wobj.style=0;
wobj.lpfnWndProc=WndProc;
wobj.lpszClassName=WindowName;
wobj.lpszMenuName=NULL;
wobj.hIcon=NULL;
wobj.hCursor=LoadCursor(NULL,IDC_ARROW);
wobj.hInstance=hInstance;
wobj.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
wobj.cbClsExtra=0;
wobj.cbWndExtra=0;
RegisterClass(&wobj);
hwnd=CreateWindow(WindowName,WindowName,WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL|WS_SIZEBOX,150,50,200,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,hwnd,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DeleteObject(hwnd);
return 0;
}
#include"stdafx.h"
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wp,LPARAM lp)
{
HDC hdc;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:CreateWindow("Button","按钮",WS_VISIBLE|WS_CHILD,10,10,100,120,hwnd,0,0,0);break;
case WM_PAINT:break;
case WM_DESTROY:PostQuitMessage(0);return 0;
default:break;
}
return DefWindowProc(hwnd,message,wp,lp);
}
我想在按钮被点击后输出信息
如何用API编写这样一个程序??最好能有示例代码。
程序打开后显示窗口一,点击窗口一的按钮,显示窗口二,且窗口一不可用。关闭窗口二后,窗口一重新变为可用,且按钮获得焦点。
我曾试着编写了个程序,但执行起来总是有问题,关闭窗口二后,窗口自动不见了,找到窗口一并激活后,按钮不能显示出来。请各位高手解惑。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询