*   >> Leitura Educação Artigos >> science >> programação

Iniciantes guia para c ++

Bem-vindo ao meu guia para a criação de uma pequena c ++ aplicativo, que consiste em nenhum código adicional. Isto foi feito para iniciantes para entender.

Vou colocar todo o código aqui, porque eu sei que a maioria de vocês só quero que isso :) doente explicar abaixo.

ps.

im usando Visual C ++ 2005, livre de microsft

#include

//Declare WndProcedureLRESULT CALLBACK WndProcedure (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {MSG Msg; HWND hWnd; HRESULT hRet; WNDCLASSEX MyClass;

MyClass.cbSize = sizeof (WNDCLASSEX); MyClass.style = CS_HREDRAW | CS_VREDRAW; MyClass.lpfnWndProc = WndProcedure; MyClass.cbClsExtra = 0; MyClass.cbWndExtra = 0; MyClass.hIcon = LoadIcon (NULL, IDI_APPLICATION); MyClass.

hCursor = LoadCursor (NULL, IDC_ARROW); MyClass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); MyClass.lpszMenuName = NULL; MyClass.lpszClassName = "CHWND"; MyClass.hInstance = hInstance; MyClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);

RegisterClassEx (& MyClass);

< p> hWnd = CreateWindow ("CHWND", "Dannys janela em branco :D",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);

if(!hWnd){return 0; //Se HWND retorna false, a janela foi criada unsucessfully} //Mostra a windowShowWindow (hWnd, SW_SHOWNORMAL); UpdateWindow (hWnd);

while ((hRet = GetMessage (& Msg, NULL, 0, 0)) = 0) {

TranslateMessage (& Msg); //Translate, e Dispach a mensagem procedure.

DispatchMessage (& Msg);

}!

}

//Mensagem Procedimento

LRESULT CALLBACK WndProcedure (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) {switch (Msg) {case WM_DESTROY: PostQuitMessage (WM_QUIT); //quitbreak usuário; default: voltar DefWindowProc (hWnd, Msg, wParam, lParam); //Se você não usar o MSG, dá-lo como padrão para lidar com

}

return 0;}

Agora eu vou passar pelo código, explicando que, em seções importantes.


Em primeiro lugar, você precisa incluir o arquivo de cabeçalho do Windows, que é feito por

#include

Depois disso, você precisa declarar o procedimento Windows, isso irá processar todas as informações que o usuário interage com a janela

LRESULT CALLBACK WndProcedure (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);


Depois vem a função WinMain, esta

Page   <<       [1] [2] [3] >>
Copyright © 2008 - 2016 Leitura Educação Artigos,https://artigos.nmjjxx.com All rights reserved.