鱼C论坛

 找回密码
 立即注册
查看: 2798|回复: 2

windows程序设计的HelloWin程序编译后打不开!什么原因??

[复制链接]
发表于 2011-12-24 15:26:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
windows程序设计的HelloWin程序编译后打不开!什么原因??

#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCowShow)
{
static TCHAR szAppName[]=TEXT("Hellow Windows");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style   = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra  = 0;
wndclass.cbWndExtra  = 0;
wndclass.hIcon   = LoadIcon( NULL, IDI_APPLICATION );
wndclass.hCursor  = LoadCursor( NULL, IDC_ARROW );
wndclass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if ( !RegisterClass( &wndclass ) )
{
  MessageBox( NULL, TEXT("111111"), szAppName, MB_ICONERROR );
  return 0;
}
hwnd = CreateWindow(szAppName, TEXT("1111111"), WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
      NULL, NULL, hinstance, NULL);
ShowWindow( hwnd, iCowShow );
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 )
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch( message )
{
  case WM_CREATE:
   //PlaySound( TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC );
   return 0;
   break;
  case WM_PAINT:
   hdc = BeginPaint( hwnd, &ps);
   GetClientRect( hwnd, &rect);
   DrawText( hdc, TEXT("11111111"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
   EndPaint( hwnd, &ps);
   return 0;
   break;
   
  case WM_DESTROY:
   PostQuitMessage(0);
   return 0;  
   
}
return DefWindowProc( hwnd, message, wParam, lParam );
}




编译没有问题,程序也能运行,就是不显示界面,哪里出现的问题呢??

还是VC6的设置和我系统的问题啊!!!

系统环境XP,求设置啊@!
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-12-24 17:10:41 | 显示全部楼层
  1. #include <windows.h>
  2. LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
  3. int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCowShow)
  4. {
  5.         static TCHAR szAppName[]=TEXT("Hellow Windows");
  6.         HWND hwnd;
  7.         MSG msg;
  8.         WNDCLASS wndclass;
  9.         wndclass.style   = CS_HREDRAW | CS_VREDRAW;
  10.         wndclass.lpfnWndProc = WndProc;
  11.         wndclass.cbClsExtra  = 0;
  12.         wndclass.cbWndExtra  = 0;
  13.         //加上下面这一行
  14.         wndclass.hInstance        =        hinstance;
  15.         wndclass.hIcon   = LoadIcon( NULL, IDI_APPLICATION );
  16.         wndclass.hCursor  = LoadCursor( NULL, IDC_ARROW );
  17.         wndclass.hbrBackground = ( HBRUSH )GetStockObject( WHITE_BRUSH );
  18.         wndclass.lpszMenuName = NULL;
  19.         wndclass.lpszClassName = szAppName;
  20.         if ( !RegisterClass( &wndclass ) )
  21.         {
  22.                 MessageBox( NULL, TEXT("111111"), szAppName, MB_ICONERROR );
  23.                 return 0;
  24.         }
  25.         hwnd = CreateWindow(szAppName, TEXT("1111111"), WS_OVERLAPPEDWINDOW,
  26.                 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  27.                 NULL, NULL, hinstance, NULL);
  28.         ShowWindow( hwnd, iCowShow );
  29.         UpdateWindow( hwnd );
  30.         while ( GetMessage( &msg, NULL, 0, 0))
  31.         {
  32.                 TranslateMessage( &msg );
  33.                 DispatchMessage( &msg );
  34.         }
  35.         return msg.wParam;
  36. }
  37. LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  38. {
  39.         HDC hdc;
  40.         PAINTSTRUCT ps;
  41.         RECT rect;
  42.         switch( message )
  43.         {
  44.         case WM_CREATE:
  45.                 //PlaySound( TEXT("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC );
  46.                 return 0;
  47.                 break;
  48.         case WM_PAINT:
  49.                 hdc = BeginPaint( hwnd, &ps);
  50.                 GetClientRect( hwnd, &rect);
  51.                 DrawText( hdc, TEXT("11111111"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER );
  52.                 EndPaint( hwnd, &ps);
  53.                 return 0;
  54.                 break;
  55.                
  56.         case WM_DESTROY:
  57.                 PostQuitMessage(0);
  58.                 return 0;  
  59.                
  60.         }
  61.         return DefWindowProc( hwnd, message, wParam, lParam );
  62. }

复制代码
小甲鱼最新课程 -> https://ilovefishc.com
发表于 2011-12-24 17:10:58 | 显示全部楼层
//加上下面这一行

14.        wndclass.hInstance        =        hinstance;
小甲鱼最新课程 -> https://ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-10 10:20

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表