永发信息网

谁帮我编个c++ api 窗口小程序 (别用mfc)简单就行

答案:2  悬赏:0  手机版
解决时间 2021-05-24 08:25
  • 提问者网友:谁的错
  • 2021-05-23 17:37

谁给我个程序源代码 最好有调试程序内的所有内容

最佳答案
  • 五星知识达人网友:街头电车
  • 2021-05-23 18:45
// we.cpp : 定义应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include"Windows.h"
#include"Windowsx.h"
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;

#define WIN32_LEANAND_MEAN


LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);


int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;


WNDCLASSEX sampleClass; // declare structure variable
sampleClass.cbSize=sizeof(WNDCLASSEX); // always use this!
sampleClass.style=CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; // standard settings
sampleClass.lpfnWndProc=MsgHandler; // we need to write this!
sampleClass.cbClsExtra = 0; // extra class info, not used
sampleClass.cbWndExtra = 0; // extra window info, not used
sampleClass.hInstance = hinstance; // parameter passed to WinMain()
sampleClass.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Windows logo
sampleClass.hCursor = LoadCursor(NULL, IDC_ARROW); // standard cursor
sampleClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // a simple black brush
sampleClass.lpszMenuName = NULL; // no menu
sampleClass.lpszClassName = L"Sample Class"; // class name
sampleClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // Windows logo again

RegisterClassEx(&sampleClass);

HWND hwnd;
if (!(hwnd = CreateWindowEx(NULL, // extended style, not needed
L"Sample Class", // class identifier
L"Sample Window", // window title
WS_POPUP | WS_VISIBLE,// parameters
0, 0, 320, 240, // initial position, size
NULL, // handle to parent (the desktop)
NULL, // handle to menu (none)
hinstance, // application instance handle
NULL))) // who needs it
return(0);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);


while(1)
{
if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))
{
if(!GetMessage(&msg,NULL,0,0))
return msg.wParam;
TranslateMessage(&msg);
DispatchMessage(&msg);
}

else
WaitMessage();
}
return(0);

}


LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{

if(msg==WM_CREATE);
if(msg==WM_DESTROY) //一定要有这个CASE,不然你结束程序后,进程没有结束
PostQuitMessage(0);
return(DefWindowProc(hwnd,msg,wparam,lparam));
};

全部回答
  • 1楼网友:長槍戰八方
  • 2021-05-23 19:20

#include <windows.h>

LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)

{ HWND hwnd; MSG messages; WNDCLASSEX wincl;

wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof (WNDCLASSEX);

wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

if (!RegisterClassEx (&wincl)) return 0;

hwnd = CreateWindowEx ( 0, szClassName, "Windows App", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 544, 375, HWND_DESKTOP, NULL, hThisInstance, NULL );

ShowWindow (hwnd, nFunsterStil);

while (GetMessage (&messages, NULL, 0, 0)) { TranslateMessage(&messages); DispatchMessage(&messages); }

return messages.wParam; }

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_DESTROY: PostQuitMessage (0); break; default: return DefWindowProc (hwnd, message, wParam, lParam); }

return 0; }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯