首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求各位帮忙

2012-02-27 
求各位大虾帮忙!小弟初学win32编程,写了个大体框架:#include windows.hLRESULTCALLBACKWinProc(HWNDhwnd

求各位大虾帮忙!
小弟初学win32编程,写了个大体框架:
#include <windows.h>

LRESULT   CALLBACK   WinProc(HWND   hwnd,             //   handle   to   window
    UINT   uMsg,             //   message   identifier
    WPARAM   wParam,     //   first   message   parameter
    LPARAM   lParam       //   second   message   parameter
);

int   WINAPI   WinMain(HINSTANCE   hInstance,
      HINSTANCE   hPrevInstance,
      LPSTR   lpCmdLine,
      int   cmdShow)
{
WNDCLASS   wndCls;
wndCls.style   =   CS_VREDRAW;
wndCls.cbClsExtra   =   0;
wndCls.cbWndExtra   =   0;
wndCls.hbrBackground   =   (HBRUSH)   GetStockObject(WHITE_BRUSH);
wndCls.hCursor   =   LoadCursor(   NULL,   IDC_CROSS   );
wndCls.hIcon   =   LoadIcon(   NULL,   IDI_APPLICATION   );
wndCls.hInstance   =   hInstance;
wndCls.lpszClassName   =   "ysjh ";
wndCls.lpszMenuName   =   NULL;
wndCls.lpfnWndProc   =   WinProc;

HWND   hWnd;
hWnd   =   CreateWindow(   "ysjh ",   "我的第一个win32程序 ",   WS_OVERLAPPEDWINDOW,0,   0,   600,   400   ,   NULL,   NULL,   hInstance,   NULL   );

RegisterClass(   &wndCls   );

ShowWindow(   hWnd,   SW_SHOWDEFAULT   );

UpdateWindow(   hWnd   );

MSG   msg;

while(   !GetMessage(   &msg,   NULL,   0   ,   0   )   )
{
TranslateMessage(   &msg   );
DispatchMessage(   &msg   );
}
return   msg.wParam;
}编译通过,却运行不起,不知道什么原因,希望大虾们帮帮忙,先谢过了!

[解决办法]
#include <windows.h>

LRESULT CALLBACK WinProc(HWND hWnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{//不上WinProc的定义
PAINTSTRUCT ps;
HDC hdc;

switch (uMsg)
{
case WM_COMMAND:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, "Hello ", strlen( "Hello "), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int cmdShow)
{
WNDCLASS wndCls;
wndCls.style = CS_VREDRAW;
wndCls.cbClsExtra = 0;
wndCls.cbWndExtra = 0;
wndCls.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndCls.hCursor = LoadCursor( NULL, IDC_CROSS );
wndCls.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wndCls.hInstance = hInstance;
wndCls.lpszClassName = "ysjh ";
wndCls.lpszMenuName = NULL;
wndCls.lpfnWndProc = WinProc;
RegisterClass( &wndCls ); //先注册再CreateWindow

HWND hWnd;
hWnd = CreateWindow( "ysjh ", "&Icirc;&Ograve;&micro;&Auml;&micro;&Uacute;&Ograve;&raquo;&cedil;&ouml;win32&sup3;&Igrave;&ETH;ò ", WS_OVERLAPPEDWINDOW,0, 0, 600, 400 , NULL, NULL, hInstance, NULL );


if(!hWnd)
return FALSE;
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );

MSG msg;
while( GetMessage( &msg, NULL, 0 , 0 ) )//你写成了!GetMessage你去查MSDN看看
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
return msg.wParam;
}

热点排行