Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- using namespace std;
- void TellError(const char* error){
- cout << error << endl;
- }
- int AppRunning = 1;
- LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam) {
- switch(msg){
- case WM_KEYDOWN:
- AppRunning=0;
- break;
- case WM_CLOSE:
- DestroyWindow(hWnd);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- }
- return DefWindowProc(hWnd,msg,wparam,lparam);
- }
- HWND createWindow(WNDPROC wndProc, int nCmdShow) {
- HINSTANCE hInstance = GetModuleHandle(0);
- WNDCLASS WindowClass;
- WindowClass.style = 0;
- WindowClass.lpfnWndProc = wndProc;
- WindowClass.cbClsExtra = 0;
- WindowClass.cbWndExtra = 0;
- WindowClass.hInstance = hInstance;
- WindowClass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
- WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- WindowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- WindowClass.lpszMenuName = 0;
- WindowClass.lpszClassName = TEXT("Class");
- RegisterClass(&WindowClass);
- HWND hWnd = CreateWindow(
- "Class",
- NULL,
- WS_BORDER|WS_VISIBLE,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- 0,0,
- hInstance,
- NULL
- );
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- return hWnd;
- }
- int main() {
- cout << "Start" << endl;
- MSG msg;
- HWND hWnd = createWindow(WindowProcedure, 0);//NewWindow("Hello window", 0, 0, 100, 100);
- if(!hWnd){
- TellError("Cannot create window!");
- return 0;
- }
- while(AppRunning){
- if(PeekMessage(&msg,hWnd,0,0,PM_REMOVE)){
- //if(!IsDialogMessage(hWnd,&msg)){
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- //}
- }
- }
- DestroyWindow(hWnd);
- cout << "End" << endl;
- return 0;
- }
Advertisement