调用函数有关问题? 懂API的前辈进来看看吧
调用函数问题?? 懂API的前辈进来看看吧!
我在CALLBACK 函数中想调用WinCreate这个函数来创建一个新的窗体,但是编译有错 不知道怎么去改 望指点一二
还有一个问题就是 我可不可不调用WinCreate这个函数 而直接调用WinMain主函数来创建窗口可以的吗 ??
想法:单击进入这个按钮 进入另外一个窗体 当前窗体消失
#include<windows.h>
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowClass(HINSTANCE hInstance);
BOOL InitWinsow(HINSTANCE hInstance,int nCmdShow);
int WinCreate(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hwnd;
hwnd=CreateWindow(
"实验",
"实验",
WS_OVERLAPPED|WS_MINIMIZE|WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
BOOL InitWindowClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinProc;
wndclass.lpszClassName="实验";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&wndclass);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int WinCreate(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
int nCtrlId = LOWORD(wparam);
static HWND hStatic;
switch(message)
{
case WM_CREATE:
CreateWindow(
"button",
"进入",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
400,
200,
70,
24,
hwnd,
(HMENU)1050,
((LPCREATESTRUCT)lparam)->hInstance,
NULL
);
CreateWindow(
"button",
"退出",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
500,
200,
70,
24,
hwnd,
(HMENU)1060,
((LPCREATESTRUCT)lparam)->hInstance,
NULL
);
break;
case WM_COMMAND:
switch (nCtrlId)
{
case 1050:
//MessageBox(hwnd, "clicked me", "note", MB_OK);
我在CALLBACK 函数中想调用WinCreate这个函数来创建一个新的窗体,但是编译有错 不知道怎么去改 望指点一二
还有一个问题就是 我可不可不调用WinCreate这个函数 而直接调用WinMain主函数来创建窗口可以的吗 ??
想法:单击进入这个按钮 进入另外一个窗体 当前窗体消失
#include<windows.h>
#pragma comment(lib,"kernel32.lib")
#pragma comment(lib,"user32.lib")
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowClass(HINSTANCE hInstance);
BOOL InitWinsow(HINSTANCE hInstance,int nCmdShow);
int WinCreate(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hwnd;
hwnd=CreateWindow(
"实验",
"实验",
WS_OVERLAPPED|WS_MINIMIZE|WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
BOOL InitWindowClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WinProc;
wndclass.lpszClassName="实验";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&wndclass);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int WinCreate(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
int nCtrlId = LOWORD(wparam);
static HWND hStatic;
switch(message)
{
case WM_CREATE:
CreateWindow(
"button",
"进入",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
400,
200,
70,
24,
hwnd,
(HMENU)1050,
((LPCREATESTRUCT)lparam)->hInstance,
NULL
);
CreateWindow(
"button",
"退出",
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON,
500,
200,
70,
24,
hwnd,
(HMENU)1060,
((LPCREATESTRUCT)lparam)->hInstance,
NULL
);
break;
case WM_COMMAND:
switch (nCtrlId)
{
case 1050:
//MessageBox(hwnd, "clicked me", "note", MB_OK);