//#include"windows.h"
#include<windows.h>
LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow )
{
WNDCLASS wc;//wndcladd是一个结构体
HWND hwnd;
MSG msg; wc.style=CS_VREDRAW;//可以改变成别的样式,中间用或隔开;
wc.lpfnWndProc=(WNDPROC)WndProc;//不懂为什么是这么个值;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO); //引用了一个新函数loadicon,即光标样式
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName=NULL;
wc.lpszClassName="我爱老婆";
RegisterClass(&wc);
hwnd=CreateWindow(
"我爱我家",
"SDK Application",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hInstance,
NULL
); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg); }
return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Ellipse(hdc,0,0,200,100);
EndPaint(hwnd,&ps);
return 0; case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message, wParam, lParam);
}
各位大侠们请问我的这个程序怎么就是不能显示出来呢????
我通过任务管理器看到程序已经运行了呀,我也有showwindow呀。怎么就是不能显示呢?
快疯了。麻烦各位大侠帮忙看看。
谢谢……
#include<windows.h>
LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow )
{
WNDCLASS wc;//wndcladd是一个结构体
HWND hwnd;
MSG msg; wc.style=CS_VREDRAW;//可以改变成别的样式,中间用或隔开;
wc.lpfnWndProc=(WNDPROC)WndProc;//不懂为什么是这么个值;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hInstance;
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO); //引用了一个新函数loadicon,即光标样式
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName=NULL;
wc.lpszClassName="我爱老婆";
RegisterClass(&wc);
hwnd=CreateWindow(
"我爱我家",
"SDK Application",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
HWND_DESKTOP,
NULL,
hInstance,
NULL
); ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg); }
return msg.wParam;}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Ellipse(hdc,0,0,200,100);
EndPaint(hwnd,&ps);
return 0; case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message, wParam, lParam);
}
各位大侠们请问我的这个程序怎么就是不能显示出来呢????
我通过任务管理器看到程序已经运行了呀,我也有showwindow呀。怎么就是不能显示呢?
快疯了。麻烦各位大侠帮忙看看。
谢谢……
等待………………
返回的值有效么?#include <windows.h>
// Global variable
HINSTANCE hinst;
// Function prototypes.
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
InitApplication(HINSTANCE);
InitInstance(HINSTANCE, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
// Application entry point.
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if (!InitApplication(hinstance))
return FALSE;
if (!InitInstance(hinstance, nCmdShow))
return FALSE;
BOOL fGotMessage;
while ((fGotMessage = GetMessage(&msg, (HWND) NULL, 0, 0)) != 0 && fGotMessage != -1)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
UNREFERENCED_PARAMETER(lpCmdLine);
}
BOOL InitApplication(HINSTANCE hinstance)
{
WNDCLASSEX wcx;
// Fill in the window class structure with parameters
// that describe the main window.
wcx.cbSize = sizeof(wcx); // size of structure
wcx.style = CS_HREDRAW |
CS_VREDRAW; // redraw if size changes
wcx.lpfnWndProc = MainWndProc; // points to window procedure
wcx.cbClsExtra = 0; // no extra class memory
wcx.cbWndExtra = 0; // no extra window memory
wcx.hInstance = hinstance; // handle to instance
wcx.hIcon = LoadIcon(NULL,
IDI_APPLICATION); // predefined app. icon
wcx.hCursor = LoadCursor(NULL,
IDC_ARROW); // predefined arrow
wcx.hbrBackground = GetStockObject(
WHITE_BRUSH); // white background brush
wcx.lpszMenuName = "MainMenu"; // name of menu resource
wcx.lpszClassName = "MainWClass"; // name of window class
wcx.hIconSm = LoadImage(hinstance, // small class icon
MAKEINTRESOURCE(5),
IMAGE_ICON,
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
LR_DEFAULTCOLOR);
// Register the window class.
return RegisterClassEx(&wcx);
}
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
HWND hwnd;
// Save the application-instance handle.
hinst = hinstance;
// Create the main window.
hwnd = CreateWindow(
"MainWClass", // name of window class
"Sample", // title-bar string
WS_OVERLAPPEDWINDOW, // top-level window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
CW_USEDEFAULT, // default width
CW_USEDEFAULT, // default height
(HWND) NULL, // no owner window
(HMENU) NULL, // use class menu
hinstance, // handle to application instance
(LPVOID) NULL); // no window-creation data
if (!hwnd)
return FALSE;
// Show the window and send a WM_PAINT message to the window
// procedure.
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
return TRUE;
}
我的程序应该没什么问题,编译,连接都通过了。运行也行,只是没有显示。通过任务管理器可以看到运行的程序进程。我想在不对我原代码的情况下,稍微修改,显示运行结果。我在网上查询的结果是WS_VISIBLE应该在Creatwindow函数的调用中与WS_OVERLAPPED-window结合使用。
希望得到您的具体指点。我也有参考孙鑫老师的vc++课件,但是也没发现他有使用WS_VISIBLE。