1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
#include <windows.h>
#include <tchar.h>
#include <iostream>
#define FILE_MENU_NEW 1
#define FILE_MENU_OPEN 2
#define FILE_MENU_EXIT 3
#define CHANGE_TITLE 4
LRESULT CALLBACK WinProc(HWND, UINT, WPARAM, LPARAM);
void AddMenus(HWND);
void AddControls(HWND);
void LoadImages();
HMENU hmenu;
HBITMAP hLogoImage;
HWND hedit;
HWND hLogo;
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR args, int ncmdshow) {
WNDCLASSW wc = {0};
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hInstance = hInst;
wc.lpszClassName = L"WinClass";
wc.lpfnWndProc = WinProc;
if(!RegisterClassW(&wc)) {
return -1;
}
CreateWindowW(L"WinClass", L"Iea boi", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 500, 500, NULL, NULL, NULL, NULL);
MSG msg = {0};
while( GetMessage(&msg, NULL, NULL, NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch(msg) {
case WM_COMMAND:
switch(wp){
case FILE_MENU_EXIT:
DestroyWindow(hwnd);
break;
case FILE_MENU_NEW:
MessageBox(hwnd, "HIII", "New", MB_OK);
MessageBeep(MB_ICONQUESTION);
break;
case CHANGE_TITLE:
wchar_t text[100];
GetWindowTextW(hedit, text, 100);
SetWindowTextW(hwnd, text);
break;
}
break;
case WM_CREATE:
LoadImages();
AddMenus(hwnd);
AddControls(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProcW(hwnd, msg, wp, lp);
}
}
void AddMenus(HWND hwnd) {
hmenu = CreateMenu();
HMENU hFileMenu = CreateMenu();
HMENU hSubMenu = CreateMenu();
AppendMenu(hSubMenu, MF_STRING, NULL, "SubMenu Item");
AppendMenu(hFileMenu, MF_STRING, FILE_MENU_NEW, "New");
AppendMenu(hFileMenu, MF_POPUP, (UINT_PTR)hSubMenu, "Open SubMenu");
AppendMenu(hFileMenu, MF_SEPARATOR, NULL, NULL);
AppendMenu(hFileMenu, MF_STRING, FILE_MENU_EXIT, "Exit");
AppendMenu(hmenu, MF_POPUP, (UINT_PTR)hFileMenu, "File");
AppendMenu(hmenu, MF_STRING, NULL, "Help");
SetMenu(hwnd, hmenu);
}
void AddControls(HWND hwnd){
CreateWindowW(L"Static", L"Inserisci testo: ", WS_VISIBLE | WS_CHILD | WS_BORDER | SS_LEFT, 200, 100, 100, 25, hwnd, NULL, NULL, NULL);
hedit = CreateWindowW(L"Edit", L"", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL , 200, 130, 100, 50, hwnd, NULL, NULL, NULL);
//definisce un bottone, nella finestra iniziale, con la funzione CHANGE_TITLE
CreateWindowW(L"Button", L"Change Title", WS_VISIBLE | WS_CHILD, 200, 185, 100, 25, hwnd, (HMENU)CHANGE_TITLE, NULL, NULL);
hLogo = CreateWindowW(L"Static", NULL, WS_VISIBLE | WS_CHILD | SS_BITMAP, 350, 60, 100, 100, hwnd, NULL, NULL, NULL);
SendMessageW(hLogo, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hLogoImage);
}
void LoadImages(){
hLogoImage = (HBITMAP)LoadImageW(NULL, L"C:/Users/Vitiello/Desktop/PEPPE/PROGRAMMAZIONE/C++/WINAPI/logo.bmp", IMAGE_BITMAP, 100, 100, LR_LOADFROMFILE);
if(hLogoImage == NULL){
std::cout << "NULL";
}
}
| |