|
发表于 2013-5-22 14:53:14
|
显示全部楼层
我把你的代码稍微改了一点点 就两个地方加了强制装换就可以跑了。我的环境是vs 2005- #include "stdafx.h"
- #pragma once
- #include "resource.h"
- #include <Windows.h>
- HINSTANCE g_hInst=NULL;
- LRESULT CALLBACK WndProc(HWND hWnd,
- UINT nMsg,
- WPARAM wParam,
- LPARAM lParam)
- {
- switch( nMsg )
- {
- case WM_DESTROY:
- {
- PostQuitMessage( 0 );
- return 0;
- }
- }
- return DefWindowProc(hWnd,nMsg,wParam,lParam);
- }
- BOOL MyRegister( LPSTR pszClassName)
- {
- WNDCLASS wc = {0};
- wc.style = CS_VREDRAW|CS_HREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = g_hInst;
- wc.hIcon = NULL;
- wc.hCursor = NULL;
- wc.hbrBackground =(HBRUSH)(COLOR_BTNFACE);
- wc.lpszClassName = NULL;
- wc.lpszClassName = (LPCWSTR)pszClassName;
- ATOM nAtom = RegisterClass( &wc );
- if( nAtom == 0)
- {
- MessageBox(NULL,TEXT("注册窗口失败"),TEXT("提示"),MB_OK|32);
- return FALSE;
- }
- else
- {
- MessageBox(NULL,TEXT("注册窗口成功"),TEXT("提示"),MB_OK);
- return TRUE;
- }
- }
- HWND MyCreate( LPSTR pszClassName)
- {
- HWND hWnd = CreateWindow( (LPCWSTR)pszClassName,_T("HelloWnd"),WS_OVERLAPPEDWINDOW,100,
- 100,300,500,NULL,NULL,g_hInst,NULL);
- if( NULL == hWnd )
- {
- MessageBox(NULL,TEXT("创建窗口失败"),TEXT("提示"),MB_OK);
- return NULL;
- }
- else
- {
- MessageBox(NULL,TEXT("创建窗口成功"),TEXT("提示"),MB_OK);
- return hWnd;
- }
- }
- void DisplayWnd( HWND hWnd)
- {
- ShowWindow( hWnd,SW_SHOW);
- UpdateWindow( hWnd );
- }
- void Message()
- {
- MSG msg ={0};
- while( GetMessage( &msg,NULL,0,0))
- {
- DispatchMessage( &msg);
- }
- }
- int WINAPI WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR IpCmdLine,
- int nCmdShow)
- {
- g_hInst = hInstance;
- MyRegister("MyWnd");
- HWND hWnd =MyCreate("MyWnd");
- DisplayWnd( hWnd);
- Message();
- return 0;
- }
复制代码 windows 的程序要记得包含stdafx.h |
|