
vc6.0 C++ 创建窗口编译无错误,但运行后不显示窗口,进程里能看到程序,求帮忙!!
//WinMdi.cpp:Definestheentrypointfortheapplication.//#include"stdafx.h"HWNDg_hMDIClie...
// WinMdi.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
HWND g_hMDIClient = NULL;
HINSTANCE g_hInstance = 0;
//主窗口的处理含住
LRESULT CALLBACK MainProc(HWND hWnd, UINT nMsg,WPARAM wParam, LPARAM lParam)
{
switch (nMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefFrameProc(hWnd, g_hMDIClient,nMsg, wParam, lParam);
}
//子窗口处理函数
LRESULT CALLBACK ChildProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
return DefMDIChildProc(hWnd, nMsg, wParam,lParam);
}
//窗口注册函数
BOOL RegisterWnd(LPSTR pszClassName, WNDPROC Proc,int nBrush)
{
WNDCLASSEX wce = {0};
wce.cbSize = sizeof(wce);
wce.style = CS_HREDRAW|CS_VREDRAW;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.lpfnWndProc = Proc;
wce.hInstance = g_hInstance;
wce.hIcon = NULL;
wce.hCursor = NULL;
wce.hbrBackground = HBRUSH(nBrush);
wce.lpszClassName = pszClassName;
wce.lpszMenuName = NULL;
wce.hIconSm = NULL;
ATOM nAtom = RegisterClassEx(&wce);
if (nAtom == 0)
{
return FALSE;
}
return TRUE;
}
//创建主窗口
HWND CreateMain(LPSTR pszClassName)
{
HWND hWnd = CreateWindowEx(0,pszClassName,"MainWindow", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,g_hInstance,NULL);
return hWnd;
}
//显示窗口
void Display(HWND hWnd)
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
//消息循环
void Message()
{
MSG msg = { 0 };
while(GetMessage(&msg, NULL,0,0))
{
DispatchMessage(&msg);
}
}
//主函数
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here
g_hInstance = hInstance;
RegisterWnd("MainWnd", MainProc,COLOR_BTNFACE+1);
RegisterWnd("ChildWnd",ChildProc,COLOR_WINDOW);
HWND hMain = CreateMain("Main");
g_hMDIClient = hMain;
Display(hMain);
Message();
return 0;
} 展开
//
#include "stdafx.h"
HWND g_hMDIClient = NULL;
HINSTANCE g_hInstance = 0;
//主窗口的处理含住
LRESULT CALLBACK MainProc(HWND hWnd, UINT nMsg,WPARAM wParam, LPARAM lParam)
{
switch (nMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefFrameProc(hWnd, g_hMDIClient,nMsg, wParam, lParam);
}
//子窗口处理函数
LRESULT CALLBACK ChildProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
return DefMDIChildProc(hWnd, nMsg, wParam,lParam);
}
//窗口注册函数
BOOL RegisterWnd(LPSTR pszClassName, WNDPROC Proc,int nBrush)
{
WNDCLASSEX wce = {0};
wce.cbSize = sizeof(wce);
wce.style = CS_HREDRAW|CS_VREDRAW;
wce.cbClsExtra = 0;
wce.cbWndExtra = 0;
wce.lpfnWndProc = Proc;
wce.hInstance = g_hInstance;
wce.hIcon = NULL;
wce.hCursor = NULL;
wce.hbrBackground = HBRUSH(nBrush);
wce.lpszClassName = pszClassName;
wce.lpszMenuName = NULL;
wce.hIconSm = NULL;
ATOM nAtom = RegisterClassEx(&wce);
if (nAtom == 0)
{
return FALSE;
}
return TRUE;
}
//创建主窗口
HWND CreateMain(LPSTR pszClassName)
{
HWND hWnd = CreateWindowEx(0,pszClassName,"MainWindow", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,g_hInstance,NULL);
return hWnd;
}
//显示窗口
void Display(HWND hWnd)
{
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
}
//消息循环
void Message()
{
MSG msg = { 0 };
while(GetMessage(&msg, NULL,0,0))
{
DispatchMessage(&msg);
}
}
//主函数
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here
g_hInstance = hInstance;
RegisterWnd("MainWnd", MainProc,COLOR_BTNFACE+1);
RegisterWnd("ChildWnd",ChildProc,COLOR_WINDOW);
HWND hMain = CreateMain("Main");
g_hMDIClient = hMain;
Display(hMain);
Message();
return 0;
} 展开
1个回答
展开全部
注册的时候用MainWnd创建的时候用Main所以失败了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询