VC6.0 用api新建一个窗口却显示不出来
按照书上讲的编了一个Windos窗口,编译后显示没有错误却无法显示出窗口代码如下:#include"windows.h"#include"resource.h"LRESU...
按照书上讲的编了一个Windos窗口,编译后显示没有错误却无法显示出窗口
代码如下:
#include"windows.h"
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdline,
int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd=NULL;
char*szAppName="Windows API Application";
char*szAppTitle="Windows API 窗口程序";
wcApp.style=CS_HREDRAW;
wcApp.lpfnWndProc=WndProc;
wcApp.cbWndExtra=0;
wcApp.cbClsExtra=0;
wcApp.hInstance=hInstance;
wcApp.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcApp.hbrBackground=(HBRUSH)COLOR_WINDOW;
wcApp.lpszMenuName=NULL;
wcApp.lpszClassName=szAppName;
RegisterClass(&wcApp);
ghWnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);
if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,SW_SHOWNORMAL);
UpdateWindow(ghWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
LPCSTR lpszCreate="收到WM_CREATE消息,建立窗口";
LPCSTR lpszDestroy="收到WM_DESTROY消息,窗口关闭";
LPCSTR lpszCaption="收到消息";
LPCSTR lpszLBTN="鼠标左键按下,收到WM_LBUTIONDOWN消息";
LPCSTR lpszExit="你确定要退出么?";
switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(),lpszCreate,lpszCaption,MB_OK|MB_ICONEXCLAMATION);
break;
case WM_LBUTTONDOWN:
MessageBox(GetFocus(),lpszLBTN,lpszCaption,MB_OK|MB_ICONINFORMATION);
break;
case WM_KEYDOWN:
if(wParam==VK_ESCAPE)
SendMessage(hwnd,WM_CLOSE,NULL,NULL);
break;
case WM_CLOSE:
if(MessageBox(NULL,lpszExit,lpszCaption,MB_YESNO|MB_DEFBUTTON2|MB_ICONASTERISK)==IDYES)
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return FALSE;
}
望大神给予帮助 展开
代码如下:
#include"windows.h"
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdline,
int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd=NULL;
char*szAppName="Windows API Application";
char*szAppTitle="Windows API 窗口程序";
wcApp.style=CS_HREDRAW;
wcApp.lpfnWndProc=WndProc;
wcApp.cbWndExtra=0;
wcApp.cbClsExtra=0;
wcApp.hInstance=hInstance;
wcApp.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcApp.hbrBackground=(HBRUSH)COLOR_WINDOW;
wcApp.lpszMenuName=NULL;
wcApp.lpszClassName=szAppName;
RegisterClass(&wcApp);
ghWnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);
if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,SW_SHOWNORMAL);
UpdateWindow(ghWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
LPCSTR lpszCreate="收到WM_CREATE消息,建立窗口";
LPCSTR lpszDestroy="收到WM_DESTROY消息,窗口关闭";
LPCSTR lpszCaption="收到消息";
LPCSTR lpszLBTN="鼠标左键按下,收到WM_LBUTIONDOWN消息";
LPCSTR lpszExit="你确定要退出么?";
switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(),lpszCreate,lpszCaption,MB_OK|MB_ICONEXCLAMATION);
break;
case WM_LBUTTONDOWN:
MessageBox(GetFocus(),lpszLBTN,lpszCaption,MB_OK|MB_ICONINFORMATION);
break;
case WM_KEYDOWN:
if(wParam==VK_ESCAPE)
SendMessage(hwnd,WM_CLOSE,NULL,NULL);
break;
case WM_CLOSE:
if(MessageBox(NULL,lpszExit,lpszCaption,MB_YESNO|MB_DEFBUTTON2|MB_ICONASTERISK)==IDYES)
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return FALSE;
}
望大神给予帮助 展开
1个回答
展开全部
#include"windows.h"
#include"resource.h"
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdline,
int nCmdShow)
{
WNDCLASS wcApp;
MSG msg;
HWND ghWnd=NULL;
char*szAppName="Windows API Application";
char*szAppTitle="Windows API 窗口程序";
wcApp.style=CS_HREDRAW|CS_VREDRAW; // 此处修改
wcApp.lpfnWndProc=WndProc;
wcApp.cbWndExtra=0;
wcApp.cbClsExtra=0;
wcApp.hInstance=hInstance;
wcApp.hCursor = LoadCursor (NULL, IDC_ARROW); // 此处修改
wcApp.hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wcApp.hbrBackground=(HBRUSH)COLOR_WINDOW;
wcApp.lpszMenuName=NULL;
wcApp.lpszClassName=szAppName;
RegisterClass(&wcApp);
ghWnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
100,
100,
350,
300,
NULL,
NULL,
hInstance,
NULL);
if(NULL==ghWnd)
return 0;
ShowWindow(ghWnd,SW_SHOWNORMAL);
UpdateWindow(ghWnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
//////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
LPCSTR lpszCreate="收到WM_CREATE消息,建立窗口";
LPCSTR lpszDestroy="收到WM_DESTROY消息,窗口关闭";
LPCSTR lpszCaption="收到消息";
LPCSTR lpszLBTN="鼠标左键按下,收到WM_LBUTIONDOWN消息";
LPCSTR lpszExit="你确定要退出么?";
switch(message)
{
case WM_CREATE:
MessageBox(GetFocus(),lpszCreate,lpszCaption,MB_OK|MB_ICONEXCLAMATION);
break;
case WM_LBUTTONDOWN:
MessageBox(GetFocus(),lpszLBTN,lpszCaption,MB_OK|MB_ICONINFORMATION);
break;
case WM_KEYDOWN:
if(wParam==VK_ESCAPE)
SendMessage(hwnd,WM_CLOSE,NULL,NULL);
break;
case WM_CLOSE:
if(MessageBox(NULL,lpszExit,lpszCaption,MB_YESNO|MB_DEFBUTTON2|MB_ICONASTERISK)==IDYES)
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
break; // 此处修改
}
return DefWindowProc(hwnd,message,wParam,lParam); // 此处修改
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询