C win32 应用程序可以编译 link 但除了 process.why 什么也没有显示给我?
C win32 app there can be compile and link but show nothing to me but process.why?
可以编译,link但是除了process.why什么都没有给我看?
我已经下载了另一个类似的我的,但这显示了 window。我很困惑。
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(//可以通过MSDN查看回调函数的声明方式
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
){
WNDCLASS wndcls;//设计一个窗口类
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//黑色的刷子
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);//窗口上面是应用程序的图标
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;/窗口过程函数。回调函数
wndcls.lpszClassName = "First MFC";//类名
wndcls.lpszMenuName = NULL; //没有菜单
wndcls.style = CS_HREDRAW | CS_VREDRAW;//CS:类的样式---水平重绘、垂直重绘
RegisterClass(&wndcls);//注册窗口
HWND hwnd;//创建窗口
hwnd = CreateWindow("MFC", "JLU", WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);//显示窗口
UpdateWindow(hwnd);
MSG msg;//消息循环机制
while (GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hDC; //Device Context的句柄
switch (uMsg) //针对不同消息处理过程
{
case WM_PAINT: //窗口重绘时,触发的消息
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps); //BeginPaint/EndPaint只能用在WM_PAINT消息中
TextOut(hDC, 50, 50, "This is first MFC Program!", strlen("This is first MFC Program!"));
EndPaint(hwnd, &ps);
break;
case WM_CHAR: //按下键盘字母键响应消息
char cArry[20];
memset(cArry, 0, 20);
sprintf(cArry, "char is %d", wParam);
MessageBox(hwnd, cArry, "WM_CHAR", MB_OKCANCEL);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "LeftMouse Click", "WM_LBUTTONDOWN", MB_OKCANCEL);
hDC = GetDC(hwnd);
TextOut(hDC, 50, 100, "MFC Program!", strlen("MFC Program!"));
ReleaseDC(hwnd, hDC);
break;
case WM_CLOSE:
if (IDOK == MessageBox(hwnd, "是否真的要退出?", "提示", MB_OKCANCEL))
{
DestroyWindow(hwnd); //销毁窗口,同时发送WM_DESTROY消息
}
break;
case WM_DESTROY:
PostQuitMessage(0); //发送WM_QUIT消息
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam); //对待不关心的消息,采用默认方式处理
}
return 0;
}
i post WINMAIN 和 CALLBACK 函数我找不到任何错误。请帮我解决这个问题。
首先它不是MFC应用程序。它只是一个用 C 编写的非常简单的 Win32 应用程序。
据我所知,您的 WindowProc
函数是 WinQinProc()
,但出于某种原因,您确实使用 WinSunProc
注册了 window class。那是你的第一个问题。另一个问题是您的 Window class (WNDCLASS) 的名称。请注意,您还应该 使用在 CreateWindow()
调用中注册的相同 Window Class 名称。
这是您的应用程序的固定版本(包括 "tchar.h"
以使应用程序 UNICODE 识别):
LRESULT CALLBACK WinSunProc(//可以通过MSDN查看回调函数的声明方式
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;//设计一个窗口类
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//黑色的刷子
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);//窗口上面是应用程序的图标
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = _T("MyClassName");//类名
wndcls.lpszMenuName = NULL; //没有菜单
wndcls.style = CS_HREDRAW | CS_VREDRAW;//CS:类的样式---水平重绘、垂直重绘
RegisterClass(&wndcls);//注册窗口
HWND hwnd;//创建窗口
hwnd = CreateWindow(_T("MyClassName"), _T("JLU"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);//显示窗口
UpdateWindow(hwnd);
MSG msg;//消息循环机制
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hDC; //Device Context的句柄
switch (uMsg) //针对不同消息处理过程
{
case WM_PAINT: //窗口重绘时,触发的消息
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps); //BeginPaint/EndPaint只能用在WM_PAINT消息中
TextOut(hDC, 50, 50, _T("This is first Win32 Program!"), _tcslen(_T("This is first Win32 Program!")));
EndPaint(hwnd, &ps);
break;
case WM_CHAR: //按下键盘字母键响应消息
char cArry[20];
memset(cArry, 0, 20);
// sprintf(cArry, "char is %d", wParam);
// MessageBox(hwnd, cArry, "WM_CHAR", MB_OKCANCEL);
break;
case WM_LBUTTONDOWN:
// MessageBox(hwnd, "LeftMouse Click", "WM_LBUTTONDOWN", MB_OKCANCEL);
hDC = GetDC(hwnd);
TextOut(hDC, 50, 100, _T("Win32 Program!"), _tcslen(_T("Win32 Program!")));
ReleaseDC(hwnd, hDC);
break;
case WM_CLOSE:
if (IDOK == MessageBox(hwnd, _T("是否真的要退出?"), _T("提示"), MB_OKCANCEL))
{
DestroyWindow(hwnd); //销毁窗口,同时发送WM_DESTROY消息
}
break;
case WM_DESTROY:
PostQuitMessage(0); //发送WM_QUIT消息
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam); //对待不关心的消息,采用默认方式处理
}
return 0;
}
可以编译,link但是除了process.why什么都没有给我看? 我已经下载了另一个类似的我的,但这显示了 window。我很困惑。
#include<windows.h>
#include<stdio.h>
LRESULT CALLBACK WinSunProc(//可以通过MSDN查看回调函数的声明方式
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
){
WNDCLASS wndcls;//设计一个窗口类
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//黑色的刷子
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);//窗口上面是应用程序的图标
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;/窗口过程函数。回调函数
wndcls.lpszClassName = "First MFC";//类名
wndcls.lpszMenuName = NULL; //没有菜单
wndcls.style = CS_HREDRAW | CS_VREDRAW;//CS:类的样式---水平重绘、垂直重绘
RegisterClass(&wndcls);//注册窗口
HWND hwnd;//创建窗口
hwnd = CreateWindow("MFC", "JLU", WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);//显示窗口
UpdateWindow(hwnd);
MSG msg;//消息循环机制
while (GetMessage(&msg, NULL, 0, 0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hDC; //Device Context的句柄
switch (uMsg) //针对不同消息处理过程
{
case WM_PAINT: //窗口重绘时,触发的消息
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps); //BeginPaint/EndPaint只能用在WM_PAINT消息中
TextOut(hDC, 50, 50, "This is first MFC Program!", strlen("This is first MFC Program!"));
EndPaint(hwnd, &ps);
break;
case WM_CHAR: //按下键盘字母键响应消息
char cArry[20];
memset(cArry, 0, 20);
sprintf(cArry, "char is %d", wParam);
MessageBox(hwnd, cArry, "WM_CHAR", MB_OKCANCEL);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "LeftMouse Click", "WM_LBUTTONDOWN", MB_OKCANCEL);
hDC = GetDC(hwnd);
TextOut(hDC, 50, 100, "MFC Program!", strlen("MFC Program!"));
ReleaseDC(hwnd, hDC);
break;
case WM_CLOSE:
if (IDOK == MessageBox(hwnd, "是否真的要退出?", "提示", MB_OKCANCEL))
{
DestroyWindow(hwnd); //销毁窗口,同时发送WM_DESTROY消息
}
break;
case WM_DESTROY:
PostQuitMessage(0); //发送WM_QUIT消息
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam); //对待不关心的消息,采用默认方式处理
}
return 0;
}
i post WINMAIN 和 CALLBACK 函数我找不到任何错误。请帮我解决这个问题。
首先它不是MFC应用程序。它只是一个用 C 编写的非常简单的 Win32 应用程序。
据我所知,您的 WindowProc
函数是 WinQinProc()
,但出于某种原因,您确实使用 WinSunProc
注册了 window class。那是你的第一个问题。另一个问题是您的 Window class (WNDCLASS) 的名称。请注意,您还应该 使用在 CreateWindow()
调用中注册的相同 Window Class 名称。
这是您的应用程序的固定版本(包括 "tchar.h"
以使应用程序 UNICODE 识别):
LRESULT CALLBACK WinSunProc(//可以通过MSDN查看回调函数的声明方式
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
WNDCLASS wndcls;//设计一个窗口类
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);//黑色的刷子
wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);//窗口上面是应用程序的图标
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WinSunProc;
wndcls.lpszClassName = _T("MyClassName");//类名
wndcls.lpszMenuName = NULL; //没有菜单
wndcls.style = CS_HREDRAW | CS_VREDRAW;//CS:类的样式---水平重绘、垂直重绘
RegisterClass(&wndcls);//注册窗口
HWND hwnd;//创建窗口
hwnd = CreateWindow(_T("MyClassName"), _T("JLU"), WS_OVERLAPPEDWINDOW, 0, 0, 600, 400, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, SW_SHOWNORMAL);//显示窗口
UpdateWindow(hwnd);
MSG msg;//消息循环机制
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
HDC hDC; //Device Context的句柄
switch (uMsg) //针对不同消息处理过程
{
case WM_PAINT: //窗口重绘时,触发的消息
PAINTSTRUCT ps;
hDC = BeginPaint(hwnd, &ps); //BeginPaint/EndPaint只能用在WM_PAINT消息中
TextOut(hDC, 50, 50, _T("This is first Win32 Program!"), _tcslen(_T("This is first Win32 Program!")));
EndPaint(hwnd, &ps);
break;
case WM_CHAR: //按下键盘字母键响应消息
char cArry[20];
memset(cArry, 0, 20);
// sprintf(cArry, "char is %d", wParam);
// MessageBox(hwnd, cArry, "WM_CHAR", MB_OKCANCEL);
break;
case WM_LBUTTONDOWN:
// MessageBox(hwnd, "LeftMouse Click", "WM_LBUTTONDOWN", MB_OKCANCEL);
hDC = GetDC(hwnd);
TextOut(hDC, 50, 100, _T("Win32 Program!"), _tcslen(_T("Win32 Program!")));
ReleaseDC(hwnd, hDC);
break;
case WM_CLOSE:
if (IDOK == MessageBox(hwnd, _T("是否真的要退出?"), _T("提示"), MB_OKCANCEL))
{
DestroyWindow(hwnd); //销毁窗口,同时发送WM_DESTROY消息
}
break;
case WM_DESTROY:
PostQuitMessage(0); //发送WM_QUIT消息
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam); //对待不关心的消息,采用默认方式处理
}
return 0;
}