c语言编程非控制台 - 爱问答

(爱问答)

c语言编程非控制台

我学c语言编出来的只有控制台程序,怎样编出非控制台(即windows窗口图形程序)?大神求解!

代码如下:

/*  * This is a simple windows program, it does nothing but draw an ellipse.  * Windows SDK, Win32 API ,Pure C, (Not C++ or mfc !!)  * Suxpert at gmail dot com, 2008/8/24  * */  #include <windows.h>  LONG WINAPI WndProc( HWND, UINT, WPARAM, LPARAM );  int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,  LPSTR lpszCmdLine, int nCmdShow ){  /* The Entry for windows program, just like main() in dos */  WNDCLASS wc;  HWND hwnd;  MSG msg;  wc.style = 0; // Class style  wc.lpfnWndProc = (WNDPROC)WndProc; // Window procedure address  wc.cbClsExtra = 0; // Class extra bytes  wc.cbWndExtra = 0; // Window extra bytes  wc.hInstance = hInstance; // Instance handle  wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Icon handle  wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Cursor handle  wc.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 ); // Background color  wc.lpszMenuName = NULL; // Menu name  wc.lpszClassName = "WinSDKtest"; // WNDCLASS name  RegisterClass( &wc );  hwnd = CreateWindow (  "WinSDKtest", // WNDCLASS name  "SDK Application", // Window title  WS_OVERLAPPEDWINDOW, // Window style  CW_USEDEFAULT, // Horizontal position  CW_USEDEFAULT, // Vertical position  CW_USEDEFAULT, // Initial width  CW_USEDEFAULT, // Initial height  HWND_DESKTOP, // Handle of parent window  NULL, // Menu handle  hInstance, // Application's instance handle  NULL // Window-creation data  );  ShowWindow( hwnd, nCmdShow );  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 )  {  /* Windows will call this function anytime... */  PAINTSTRUCT ps;  HDC hdc;  switch(message){  case WM_PAINT:  hdc = BeginPaint( hwnd, &ps );  Ellipse( hdc, 0, 0, 800, 600 );  // Here we Draw an ellipse in the window of our program  EndPaint( hwnd, &ps );  break; // Someone like to write return here.  case WM_DESTROY:  PostQuitMessage(0);  break;  default:  return DefWindowProc( hwnd, message, wParam, lParam );  }  return 0;  }


mfc框架,不过那得用C++写,而且比较复杂


用单纯的C很难写出窗口程序的(初学者基本不可能做到)

相关标签:控制c语言

下一篇:编程问题:16进制出错在哪?只要出错处

上一篇:虚拟机玩不了荒野行动

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?