Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;GUI按钮粘在底部 我在Windows .h中为我的妈妈制作了一个C++ GUI窗体,我不知道如何让“AdgAube”、“iSeRear”、“刷新”等按钮贴在Windows窗体的底部。我想让它们在调整窗体大小时自动移动,这样它们就可以始终位于右下角。 请大家帮帮我,因为我是C++的初学者!p> #if defined(UNICODE) && !defined(_UNICODE) #define _UNICODE #elif defined(_UNICODE) && !defined(UNICODE) #define UNICODE #endif #include <tchar.h> #include <windows.h> #include <iostream> #include <string> #include <cstring> #include <fstream> using namespace std; ofstream fout; ifstream fin; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); HWND hwnd; /* This is the handle for our window */ HWND button[5]; HWND banda[100]; HWND tip[100]; HWND lungime[100]; HWND latime[100]; HWND data1[100]; HWND button_valideaza[100]; int button_index[100]; int i = 0, counter = 1; char buffer[10]; char textEP[20]; char textTip[20]; char textLungime[20]; char textLatime[20]; char textData[20]; char textAll[101]; /* Make the class name into a global variable */ TCHAR szClassName[] = _T("CodeBlocksWindowsApp"); int getIndex(){ fin.open("record.txt", std::ios_base::in); string line1; string line; while(getline(fin, line1)) { line = line1; } char save[line.size()]; strcpy(save, line.c_str()); char *p = strtok(save, " "); fin.close(); return atoi(p); } void refresh() { } int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx(&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ _T("Flux Artego"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 700, /* The programs width */ 300, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow(hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage(&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ void scrie() { } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WORD cmd = LOWORD(wParam); switch (message) /* handle the messages */ { case WM_CREATE: // fac butoane, label etc counter = getIndex(); counter++; fout.open("record.txt", std::ios_base::app); std::fill_n(button_index, 100, -1); button[0] = CreateWindow("BUTTON", "Iesire", WS_VISIBLE | WS_CHILD | WS_BORDER, 560, 220, 100, 20, hwnd, (HMENU)1, NULL, NULL); // (HMENU) 1 reprezinta care case din switch se executa button[1] = CreateWindow("BUTTON", "Adauga", WS_VISIBLE | WS_CHILD | WS_BORDER, 450, 220, 100, 20, hwnd, (HMENU)2, NULL, NULL); button[2] = CreateWindow("BUTTON", "Refresh", WS_VISIBLE | WS_CHILD | WS_BORDER, 340, 220, 100, 20, hwnd, (HMENU)3, NULL, NULL); break; case WM_COMMAND: // fac instructiuni butoane switch (cmd) { case 1: //::MessageBeep(MB_ICONERROR); //::MessageBox(hwnd, "Ai salvat ?", "atentie", MB_OKCANCEL); cout << "GoodBye!"; PostQuitMessage(0); break; case 2: // Adaug nou record banda[i] = CreateWindow("EDIT", "EP", WS_BORDER | WS_CHILD | WS_VISIBLE, 20, 30 * i, 30, 25, hwnd, NULL, NULL, NULL); tip[i] = CreateWindow("EDIT", "100", WS_BORDER | WS_CHILD | WS_VISIBLE, 55, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); lungime[i] = CreateWindow("EDIT", "Lungime", WS_BORDER | WS_CHILD | WS_VISIBLE, 160, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); latime[i] = CreateWindow("EDIT", "Latime", WS_BORDER | WS_CHILD | WS_VISIBLE, 265, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); data1[i] = CreateWindow("EDIT", "Data", WS_BORDER | WS_CHILD | WS_VISIBLE, 370, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); button_valideaza[i] = CreateWindow("BUTTON", "Scrie", WS_VISIBLE | WS_CHILD | WS_BORDER, 475, 30 * i, 80, 20, hwnd, (HMENU)(i+5), NULL, NULL); i++; break; case 3: // Refresh refresh(); break; case 4: // Compute break; default: if (cmd > 4 && cmd < 103) { int index; if (button_index[cmd-3] == -1){ // daca buton index nu a fost setata button_index[cmd-3] = counter; index = counter; //cout << "Prima apasare a butinului " << cmd-3 << " si primeste index "<<counter<<endl; counter++; } else { // a fost setat index = button_index[cmd-3]; //cout << "Deja apasat butonul "<< cmd-3 << " si are vechiul index " << button_index[cmd-3] << endl; ::MessageBox(hwnd, "Pentru a rescrie apasa pe REFRESH","Suprascriere", MB_OK); } int gwtstat = 0; gwtstat = GetWindowText(banda[cmd-5], &textEP[0], 20); gwtstat = 0; gwtstat = GetWindowText(tip[cmd-5], &textTip[0], 20); gwtstat = 0; gwtstat = GetWindowText(lungime[cmd-5], &textLungime[0], 20); gwtstat = 0; gwtstat = GetWindowText(latime[cmd-5], &textLatime[0], 20); gwtstat = 0; gwtstat = GetWindowText(data1[cmd-5], &textData[0], 20); itoa(index, buffer, 10); strcpy(textAll, buffer); strcat(textAll," "); strcat(textAll,textEP); strcat(textAll, " "); strcat(textAll,textTip); strcat(textAll, " "); strcat(textAll, textLungime); strcat(textAll, " "); strcat(textAll, textLatime); strcat(textAll, " "); strcat(textAll, textData); fout << textAll << "\n"; ::MessageBox(hwnd, textAll,"text", MB_OKCANCEL); } break; } break; case WM_DESTROY: fout.close(); PostQuitMessage(0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } #如果已定义(UNICODE)&&!已定义(_UNICODE) #定义UNICODE #elif定义(_UNICODE)&&!已定义(UNICODE) #定义UNICODE #恩迪夫 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; 流式流量计; 流鳍; /*声明Windows过程*/ LRESULT回调窗口过程(HWND、UINT、WPARAM、LPARAM); HWND HWND;/*这是我们窗户的把手*/ HWND按钮[5]; HWND banda[100]; HWND尖端[100]; HWND lungime[100]; HWND纬度[100]; HWND数据1[100]; HWND按钮_valideaza[100]; int按钮索引[100]; int i=0,计数器=1; 字符缓冲区[10]; char-textEP[20]; 字符文本提示[20]; char textLungime[20]; 字符文本时间[20]; 字符文本数据[20]; chartextall[101]; /*将类名设置为全局变量*/ TCHAR szClassName[]=“代码块swindowsapp”); int getIndex(){ 打开(“record.txt”,std::ios\u base::in); 字符串行1; 弦线; while(getline(fin,line1)){ line=line1; } 字符保存[line.size()]; strcpy(save,line.c_str()); char*p=strtok(保存“”); fin.close(); 返回atoi(p); } 无效刷新(){ } int WINAPI WinMain(HINSTANCE Hthis实例, HINSTANCE HPPrevenstance, LPSTR LPSZ参数, 国际展览(nCmdShow) { MSG messages;/*此处保存应用程序的消息*/ windowclass的WNDCLASSEX wincl;/*数据结构*/ /*窗口结构*/ wincl.hInstance=hthis实例; wincl.lpszClassName=szClassName; wincl.lpfnWndProc=WindowProcedure;/*此函数由windows调用*/ wincl.style=CS_DBLCLKS;/*捕捉双击*/ wincl.cbSize=sizeof(WNDCLASSEX); /*使用默认图标和鼠标指针*/ wincl.hIcon=加载图标(空,IDI_应用程序); wincl.hIconSm=加载图标(空,IDI_应用程序); wincl.hCursor=LoadCursor(空,IDC_箭头); wincl.lpszMenuName=NULL;/*无菜单*/ wincl.cbClsExtra=0;/*窗口类后没有额外字节*/ wincl.cbWndExtra=0;/*结构或窗口实例*/ /*使用Windows的默认颜色作为窗口的背景*/ wincl.hbrBackground=(HBRUSH)颜色背景; /*注册窗口类,如果失败,退出程序*/ if(!RegisterClass(&wincl)) 返回0; /*类已注册,让我们创建程序*/ hwnd=CreateWindowEx( 0,/*变化的扩展可能性*/ szClassName,/*Classname*/ _T(“通量Artego”),/*标题文本*/ WS_OVERLAPPEDWINDOW,/*默认窗口*/ CW_USEDEFAULT,/*Windows决定位置*/ CW_USEDEFAULT,/*窗口在屏幕上结束*/ 700,/*程序宽度*/ 300、/*和高度(以像素为单位)*/ HWND_DESKTOP,/*该窗口是桌面的子窗口*/ 空,/*无菜单*/ hThisInstance,/*程序实例处理程序*/ NULL/*无窗口创建数据*/ ); /*使窗口在屏幕上可见*/ 显示窗口(hwnd、nCmdShow); /*运行消息循环。它将一直运行,直到GetMessage()返回0*/ while(GetMessage(&messages,NULL,0,0)) { /*将虚拟密钥消息转换为字符消息*/ 翻译消息(和消息); /*向WindowProcedure发送消息*/ DispatchMessage(&messages); } /*程序返回值为0—PostQuitMessage()给出的值*/ 返回messages.wParam; } /*此函数由Windows函数DispatchMessage()调用*/ 无效代币(){ } LRESULT回调窗口过程(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM) { 单词cmd=LOWORD(wParam); 开关(消息)/*处理消息*/ { 案例WM_创建://fac butoane、标签等 计数器=getIndex(); 计数器++; fout.open(“record.txt”,std::ios\u base::app); 标准:填充(按钮索引,100,-1); 按钮[0]=创建窗口(“按钮”, “Iesire”, WS|U可见| WS|U儿童| WS|U边界, 560, 220, 100, 20, hwnd,(HMENU)1,空,空);/(HMENU)1个reprezinta护理箱din开关se executa 按钮[1]=创建窗口(“按钮”, “阿杜加”, WS|U可见| WS|U儿童| WS|U边界, 450, 220, 100, 20, hwnd,(HMENU)2,空,空); 按钮[2]=创建窗口(“按钮”, “刷新”, WS|U可见| WS|U儿童| WS|U边界, 340, 220, 100, 20, hwnd,(HMENU)3,空,空); 打破 案例WM_命令://fac指令UNI butoane 开关(cmd) { 案例1: //::MessageBeep(MB_icon错误); //::MessageBox(hwnd,“Ai salvat?”,“atentie”,MB_OKCANCEL); cout 4&&cmd_C++_User Interface_Winapi_Button - Fatal编程技术网

C++;GUI按钮粘在底部 我在Windows .h中为我的妈妈制作了一个C++ GUI窗体,我不知道如何让“AdgAube”、“iSeRear”、“刷新”等按钮贴在Windows窗体的底部。我想让它们在调整窗体大小时自动移动,这样它们就可以始终位于右下角。 请大家帮帮我,因为我是C++的初学者!p> #if defined(UNICODE) && !defined(_UNICODE) #define _UNICODE #elif defined(_UNICODE) && !defined(UNICODE) #define UNICODE #endif #include <tchar.h> #include <windows.h> #include <iostream> #include <string> #include <cstring> #include <fstream> using namespace std; ofstream fout; ifstream fin; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); HWND hwnd; /* This is the handle for our window */ HWND button[5]; HWND banda[100]; HWND tip[100]; HWND lungime[100]; HWND latime[100]; HWND data1[100]; HWND button_valideaza[100]; int button_index[100]; int i = 0, counter = 1; char buffer[10]; char textEP[20]; char textTip[20]; char textLungime[20]; char textLatime[20]; char textData[20]; char textAll[101]; /* Make the class name into a global variable */ TCHAR szClassName[] = _T("CodeBlocksWindowsApp"); int getIndex(){ fin.open("record.txt", std::ios_base::in); string line1; string line; while(getline(fin, line1)) { line = line1; } char save[line.size()]; strcpy(save, line.c_str()); char *p = strtok(save, " "); fin.close(); return atoi(p); } void refresh() { } int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx(&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ _T("Flux Artego"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 700, /* The programs width */ 300, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow(hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage(&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ void scrie() { } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WORD cmd = LOWORD(wParam); switch (message) /* handle the messages */ { case WM_CREATE: // fac butoane, label etc counter = getIndex(); counter++; fout.open("record.txt", std::ios_base::app); std::fill_n(button_index, 100, -1); button[0] = CreateWindow("BUTTON", "Iesire", WS_VISIBLE | WS_CHILD | WS_BORDER, 560, 220, 100, 20, hwnd, (HMENU)1, NULL, NULL); // (HMENU) 1 reprezinta care case din switch se executa button[1] = CreateWindow("BUTTON", "Adauga", WS_VISIBLE | WS_CHILD | WS_BORDER, 450, 220, 100, 20, hwnd, (HMENU)2, NULL, NULL); button[2] = CreateWindow("BUTTON", "Refresh", WS_VISIBLE | WS_CHILD | WS_BORDER, 340, 220, 100, 20, hwnd, (HMENU)3, NULL, NULL); break; case WM_COMMAND: // fac instructiuni butoane switch (cmd) { case 1: //::MessageBeep(MB_ICONERROR); //::MessageBox(hwnd, "Ai salvat ?", "atentie", MB_OKCANCEL); cout << "GoodBye!"; PostQuitMessage(0); break; case 2: // Adaug nou record banda[i] = CreateWindow("EDIT", "EP", WS_BORDER | WS_CHILD | WS_VISIBLE, 20, 30 * i, 30, 25, hwnd, NULL, NULL, NULL); tip[i] = CreateWindow("EDIT", "100", WS_BORDER | WS_CHILD | WS_VISIBLE, 55, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); lungime[i] = CreateWindow("EDIT", "Lungime", WS_BORDER | WS_CHILD | WS_VISIBLE, 160, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); latime[i] = CreateWindow("EDIT", "Latime", WS_BORDER | WS_CHILD | WS_VISIBLE, 265, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); data1[i] = CreateWindow("EDIT", "Data", WS_BORDER | WS_CHILD | WS_VISIBLE, 370, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); button_valideaza[i] = CreateWindow("BUTTON", "Scrie", WS_VISIBLE | WS_CHILD | WS_BORDER, 475, 30 * i, 80, 20, hwnd, (HMENU)(i+5), NULL, NULL); i++; break; case 3: // Refresh refresh(); break; case 4: // Compute break; default: if (cmd > 4 && cmd < 103) { int index; if (button_index[cmd-3] == -1){ // daca buton index nu a fost setata button_index[cmd-3] = counter; index = counter; //cout << "Prima apasare a butinului " << cmd-3 << " si primeste index "<<counter<<endl; counter++; } else { // a fost setat index = button_index[cmd-3]; //cout << "Deja apasat butonul "<< cmd-3 << " si are vechiul index " << button_index[cmd-3] << endl; ::MessageBox(hwnd, "Pentru a rescrie apasa pe REFRESH","Suprascriere", MB_OK); } int gwtstat = 0; gwtstat = GetWindowText(banda[cmd-5], &textEP[0], 20); gwtstat = 0; gwtstat = GetWindowText(tip[cmd-5], &textTip[0], 20); gwtstat = 0; gwtstat = GetWindowText(lungime[cmd-5], &textLungime[0], 20); gwtstat = 0; gwtstat = GetWindowText(latime[cmd-5], &textLatime[0], 20); gwtstat = 0; gwtstat = GetWindowText(data1[cmd-5], &textData[0], 20); itoa(index, buffer, 10); strcpy(textAll, buffer); strcat(textAll," "); strcat(textAll,textEP); strcat(textAll, " "); strcat(textAll,textTip); strcat(textAll, " "); strcat(textAll, textLungime); strcat(textAll, " "); strcat(textAll, textLatime); strcat(textAll, " "); strcat(textAll, textData); fout << textAll << "\n"; ::MessageBox(hwnd, textAll,"text", MB_OKCANCEL); } break; } break; case WM_DESTROY: fout.close(); PostQuitMessage(0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } #如果已定义(UNICODE)&&!已定义(_UNICODE) #定义UNICODE #elif定义(_UNICODE)&&!已定义(UNICODE) #定义UNICODE #恩迪夫 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; 流式流量计; 流鳍; /*声明Windows过程*/ LRESULT回调窗口过程(HWND、UINT、WPARAM、LPARAM); HWND HWND;/*这是我们窗户的把手*/ HWND按钮[5]; HWND banda[100]; HWND尖端[100]; HWND lungime[100]; HWND纬度[100]; HWND数据1[100]; HWND按钮_valideaza[100]; int按钮索引[100]; int i=0,计数器=1; 字符缓冲区[10]; char-textEP[20]; 字符文本提示[20]; char textLungime[20]; 字符文本时间[20]; 字符文本数据[20]; chartextall[101]; /*将类名设置为全局变量*/ TCHAR szClassName[]=“代码块swindowsapp”); int getIndex(){ 打开(“record.txt”,std::ios\u base::in); 字符串行1; 弦线; while(getline(fin,line1)){ line=line1; } 字符保存[line.size()]; strcpy(save,line.c_str()); char*p=strtok(保存“”); fin.close(); 返回atoi(p); } 无效刷新(){ } int WINAPI WinMain(HINSTANCE Hthis实例, HINSTANCE HPPrevenstance, LPSTR LPSZ参数, 国际展览(nCmdShow) { MSG messages;/*此处保存应用程序的消息*/ windowclass的WNDCLASSEX wincl;/*数据结构*/ /*窗口结构*/ wincl.hInstance=hthis实例; wincl.lpszClassName=szClassName; wincl.lpfnWndProc=WindowProcedure;/*此函数由windows调用*/ wincl.style=CS_DBLCLKS;/*捕捉双击*/ wincl.cbSize=sizeof(WNDCLASSEX); /*使用默认图标和鼠标指针*/ wincl.hIcon=加载图标(空,IDI_应用程序); wincl.hIconSm=加载图标(空,IDI_应用程序); wincl.hCursor=LoadCursor(空,IDC_箭头); wincl.lpszMenuName=NULL;/*无菜单*/ wincl.cbClsExtra=0;/*窗口类后没有额外字节*/ wincl.cbWndExtra=0;/*结构或窗口实例*/ /*使用Windows的默认颜色作为窗口的背景*/ wincl.hbrBackground=(HBRUSH)颜色背景; /*注册窗口类,如果失败,退出程序*/ if(!RegisterClass(&wincl)) 返回0; /*类已注册,让我们创建程序*/ hwnd=CreateWindowEx( 0,/*变化的扩展可能性*/ szClassName,/*Classname*/ _T(“通量Artego”),/*标题文本*/ WS_OVERLAPPEDWINDOW,/*默认窗口*/ CW_USEDEFAULT,/*Windows决定位置*/ CW_USEDEFAULT,/*窗口在屏幕上结束*/ 700,/*程序宽度*/ 300、/*和高度(以像素为单位)*/ HWND_DESKTOP,/*该窗口是桌面的子窗口*/ 空,/*无菜单*/ hThisInstance,/*程序实例处理程序*/ NULL/*无窗口创建数据*/ ); /*使窗口在屏幕上可见*/ 显示窗口(hwnd、nCmdShow); /*运行消息循环。它将一直运行,直到GetMessage()返回0*/ while(GetMessage(&messages,NULL,0,0)) { /*将虚拟密钥消息转换为字符消息*/ 翻译消息(和消息); /*向WindowProcedure发送消息*/ DispatchMessage(&messages); } /*程序返回值为0—PostQuitMessage()给出的值*/ 返回messages.wParam; } /*此函数由Windows函数DispatchMessage()调用*/ 无效代币(){ } LRESULT回调窗口过程(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM) { 单词cmd=LOWORD(wParam); 开关(消息)/*处理消息*/ { 案例WM_创建://fac butoane、标签等 计数器=getIndex(); 计数器++; fout.open(“record.txt”,std::ios\u base::app); 标准:填充(按钮索引,100,-1); 按钮[0]=创建窗口(“按钮”, “Iesire”, WS|U可见| WS|U儿童| WS|U边界, 560, 220, 100, 20, hwnd,(HMENU)1,空,空);/(HMENU)1个reprezinta护理箱din开关se executa 按钮[1]=创建窗口(“按钮”, “阿杜加”, WS|U可见| WS|U儿童| WS|U边界, 450, 220, 100, 20, hwnd,(HMENU)2,空,空); 按钮[2]=创建窗口(“按钮”, “刷新”, WS|U可见| WS|U儿童| WS|U边界, 340, 220, 100, 20, hwnd,(HMENU)3,空,空); 打破 案例WM_命令://fac指令UNI butoane 开关(cmd) { 案例1: //::MessageBeep(MB_icon错误); //::MessageBox(hwnd,“Ai salvat?”,“atentie”,MB_OKCANCEL); cout 4&&cmd

C++;GUI按钮粘在底部 我在Windows .h中为我的妈妈制作了一个C++ GUI窗体,我不知道如何让“AdgAube”、“iSeRear”、“刷新”等按钮贴在Windows窗体的底部。我想让它们在调整窗体大小时自动移动,这样它们就可以始终位于右下角。 请大家帮帮我,因为我是C++的初学者!p> #if defined(UNICODE) && !defined(_UNICODE) #define _UNICODE #elif defined(_UNICODE) && !defined(UNICODE) #define UNICODE #endif #include <tchar.h> #include <windows.h> #include <iostream> #include <string> #include <cstring> #include <fstream> using namespace std; ofstream fout; ifstream fin; /* Declare Windows procedure */ LRESULT CALLBACK WindowProcedure(HWND, UINT, WPARAM, LPARAM); HWND hwnd; /* This is the handle for our window */ HWND button[5]; HWND banda[100]; HWND tip[100]; HWND lungime[100]; HWND latime[100]; HWND data1[100]; HWND button_valideaza[100]; int button_index[100]; int i = 0, counter = 1; char buffer[10]; char textEP[20]; char textTip[20]; char textLungime[20]; char textLatime[20]; char textData[20]; char textAll[101]; /* Make the class name into a global variable */ TCHAR szClassName[] = _T("CodeBlocksWindowsApp"); int getIndex(){ fin.open("record.txt", std::ios_base::in); string line1; string line; while(getline(fin, line1)) { line = line1; } char save[line.size()]; strcpy(save, line.c_str()); char *p = strtok(save, " "); fin.close(); return atoi(p); } void refresh() { } int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nCmdShow) { MSG messages; /* Here messages to the application are saved */ WNDCLASSEX wincl; /* Data structure for the windowclass */ /* The Window structure */ wincl.hInstance = hThisInstance; wincl.lpszClassName = szClassName; wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */ wincl.style = CS_DBLCLKS; /* Catch double-clicks */ wincl.cbSize = sizeof(WNDCLASSEX); /* Use default icon and mouse-pointer */ wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION); wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; /* No menu */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbWndExtra = 0; /* structure or the window instance */ /* Use Windows's default colour as the background of the window */ wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND; /* Register the window class, and if it fails quit the program */ if (!RegisterClassEx(&wincl)) return 0; /* The class is registered, let's create the program*/ hwnd = CreateWindowEx( 0, /* Extended possibilites for variation */ szClassName, /* Classname */ _T("Flux Artego"), /* Title Text */ WS_OVERLAPPEDWINDOW, /* default window */ CW_USEDEFAULT, /* Windows decides the position */ CW_USEDEFAULT, /* where the window ends up on the screen */ 700, /* The programs width */ 300, /* and height in pixels */ HWND_DESKTOP, /* The window is a child-window to desktop */ NULL, /* No menu */ hThisInstance, /* Program Instance handler */ NULL /* No Window Creation data */ ); /* Make the window visible on the screen */ ShowWindow(hwnd, nCmdShow); /* Run the message loop. It will run until GetMessage() returns 0 */ while (GetMessage(&messages, NULL, 0, 0)) { /* Translate virtual-key messages into character messages */ TranslateMessage(&messages); /* Send message to WindowProcedure */ DispatchMessage(&messages); } /* The program return-value is 0 - The value that PostQuitMessage() gave */ return messages.wParam; } /* This function is called by the Windows function DispatchMessage() */ void scrie() { } LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { WORD cmd = LOWORD(wParam); switch (message) /* handle the messages */ { case WM_CREATE: // fac butoane, label etc counter = getIndex(); counter++; fout.open("record.txt", std::ios_base::app); std::fill_n(button_index, 100, -1); button[0] = CreateWindow("BUTTON", "Iesire", WS_VISIBLE | WS_CHILD | WS_BORDER, 560, 220, 100, 20, hwnd, (HMENU)1, NULL, NULL); // (HMENU) 1 reprezinta care case din switch se executa button[1] = CreateWindow("BUTTON", "Adauga", WS_VISIBLE | WS_CHILD | WS_BORDER, 450, 220, 100, 20, hwnd, (HMENU)2, NULL, NULL); button[2] = CreateWindow("BUTTON", "Refresh", WS_VISIBLE | WS_CHILD | WS_BORDER, 340, 220, 100, 20, hwnd, (HMENU)3, NULL, NULL); break; case WM_COMMAND: // fac instructiuni butoane switch (cmd) { case 1: //::MessageBeep(MB_ICONERROR); //::MessageBox(hwnd, "Ai salvat ?", "atentie", MB_OKCANCEL); cout << "GoodBye!"; PostQuitMessage(0); break; case 2: // Adaug nou record banda[i] = CreateWindow("EDIT", "EP", WS_BORDER | WS_CHILD | WS_VISIBLE, 20, 30 * i, 30, 25, hwnd, NULL, NULL, NULL); tip[i] = CreateWindow("EDIT", "100", WS_BORDER | WS_CHILD | WS_VISIBLE, 55, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); lungime[i] = CreateWindow("EDIT", "Lungime", WS_BORDER | WS_CHILD | WS_VISIBLE, 160, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); latime[i] = CreateWindow("EDIT", "Latime", WS_BORDER | WS_CHILD | WS_VISIBLE, 265, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); data1[i] = CreateWindow("EDIT", "Data", WS_BORDER | WS_CHILD | WS_VISIBLE, 370, 30 * i, 100, 25, hwnd, NULL, NULL, NULL); button_valideaza[i] = CreateWindow("BUTTON", "Scrie", WS_VISIBLE | WS_CHILD | WS_BORDER, 475, 30 * i, 80, 20, hwnd, (HMENU)(i+5), NULL, NULL); i++; break; case 3: // Refresh refresh(); break; case 4: // Compute break; default: if (cmd > 4 && cmd < 103) { int index; if (button_index[cmd-3] == -1){ // daca buton index nu a fost setata button_index[cmd-3] = counter; index = counter; //cout << "Prima apasare a butinului " << cmd-3 << " si primeste index "<<counter<<endl; counter++; } else { // a fost setat index = button_index[cmd-3]; //cout << "Deja apasat butonul "<< cmd-3 << " si are vechiul index " << button_index[cmd-3] << endl; ::MessageBox(hwnd, "Pentru a rescrie apasa pe REFRESH","Suprascriere", MB_OK); } int gwtstat = 0; gwtstat = GetWindowText(banda[cmd-5], &textEP[0], 20); gwtstat = 0; gwtstat = GetWindowText(tip[cmd-5], &textTip[0], 20); gwtstat = 0; gwtstat = GetWindowText(lungime[cmd-5], &textLungime[0], 20); gwtstat = 0; gwtstat = GetWindowText(latime[cmd-5], &textLatime[0], 20); gwtstat = 0; gwtstat = GetWindowText(data1[cmd-5], &textData[0], 20); itoa(index, buffer, 10); strcpy(textAll, buffer); strcat(textAll," "); strcat(textAll,textEP); strcat(textAll, " "); strcat(textAll,textTip); strcat(textAll, " "); strcat(textAll, textLungime); strcat(textAll, " "); strcat(textAll, textLatime); strcat(textAll, " "); strcat(textAll, textData); fout << textAll << "\n"; ::MessageBox(hwnd, textAll,"text", MB_OKCANCEL); } break; } break; case WM_DESTROY: fout.close(); PostQuitMessage(0); /* send a WM_QUIT to the message queue */ break; default: /* for messages that we don't deal with */ return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } #如果已定义(UNICODE)&&!已定义(_UNICODE) #定义UNICODE #elif定义(_UNICODE)&&!已定义(UNICODE) #定义UNICODE #恩迪夫 #包括 #包括 #包括 #包括 #包括 #包括 使用名称空间std; 流式流量计; 流鳍; /*声明Windows过程*/ LRESULT回调窗口过程(HWND、UINT、WPARAM、LPARAM); HWND HWND;/*这是我们窗户的把手*/ HWND按钮[5]; HWND banda[100]; HWND尖端[100]; HWND lungime[100]; HWND纬度[100]; HWND数据1[100]; HWND按钮_valideaza[100]; int按钮索引[100]; int i=0,计数器=1; 字符缓冲区[10]; char-textEP[20]; 字符文本提示[20]; char textLungime[20]; 字符文本时间[20]; 字符文本数据[20]; chartextall[101]; /*将类名设置为全局变量*/ TCHAR szClassName[]=“代码块swindowsapp”); int getIndex(){ 打开(“record.txt”,std::ios\u base::in); 字符串行1; 弦线; while(getline(fin,line1)){ line=line1; } 字符保存[line.size()]; strcpy(save,line.c_str()); char*p=strtok(保存“”); fin.close(); 返回atoi(p); } 无效刷新(){ } int WINAPI WinMain(HINSTANCE Hthis实例, HINSTANCE HPPrevenstance, LPSTR LPSZ参数, 国际展览(nCmdShow) { MSG messages;/*此处保存应用程序的消息*/ windowclass的WNDCLASSEX wincl;/*数据结构*/ /*窗口结构*/ wincl.hInstance=hthis实例; wincl.lpszClassName=szClassName; wincl.lpfnWndProc=WindowProcedure;/*此函数由windows调用*/ wincl.style=CS_DBLCLKS;/*捕捉双击*/ wincl.cbSize=sizeof(WNDCLASSEX); /*使用默认图标和鼠标指针*/ wincl.hIcon=加载图标(空,IDI_应用程序); wincl.hIconSm=加载图标(空,IDI_应用程序); wincl.hCursor=LoadCursor(空,IDC_箭头); wincl.lpszMenuName=NULL;/*无菜单*/ wincl.cbClsExtra=0;/*窗口类后没有额外字节*/ wincl.cbWndExtra=0;/*结构或窗口实例*/ /*使用Windows的默认颜色作为窗口的背景*/ wincl.hbrBackground=(HBRUSH)颜色背景; /*注册窗口类,如果失败,退出程序*/ if(!RegisterClass(&wincl)) 返回0; /*类已注册,让我们创建程序*/ hwnd=CreateWindowEx( 0,/*变化的扩展可能性*/ szClassName,/*Classname*/ _T(“通量Artego”),/*标题文本*/ WS_OVERLAPPEDWINDOW,/*默认窗口*/ CW_USEDEFAULT,/*Windows决定位置*/ CW_USEDEFAULT,/*窗口在屏幕上结束*/ 700,/*程序宽度*/ 300、/*和高度(以像素为单位)*/ HWND_DESKTOP,/*该窗口是桌面的子窗口*/ 空,/*无菜单*/ hThisInstance,/*程序实例处理程序*/ NULL/*无窗口创建数据*/ ); /*使窗口在屏幕上可见*/ 显示窗口(hwnd、nCmdShow); /*运行消息循环。它将一直运行,直到GetMessage()返回0*/ while(GetMessage(&messages,NULL,0,0)) { /*将虚拟密钥消息转换为字符消息*/ 翻译消息(和消息); /*向WindowProcedure发送消息*/ DispatchMessage(&messages); } /*程序返回值为0—PostQuitMessage()给出的值*/ 返回messages.wParam; } /*此函数由Windows函数DispatchMessage()调用*/ 无效代币(){ } LRESULT回调窗口过程(HWND HWND,UINT消息,WPARAM WPARAM,LPARAM LPARAM) { 单词cmd=LOWORD(wParam); 开关(消息)/*处理消息*/ { 案例WM_创建://fac butoane、标签等 计数器=getIndex(); 计数器++; fout.open(“record.txt”,std::ios\u base::app); 标准:填充(按钮索引,100,-1); 按钮[0]=创建窗口(“按钮”, “Iesire”, WS|U可见| WS|U儿童| WS|U边界, 560, 220, 100, 20, hwnd,(HMENU)1,空,空);/(HMENU)1个reprezinta护理箱din开关se executa 按钮[1]=创建窗口(“按钮”, “阿杜加”, WS|U可见| WS|U儿童| WS|U边界, 450, 220, 100, 20, hwnd,(HMENU)2,空,空); 按钮[2]=创建窗口(“按钮”, “刷新”, WS|U可见| WS|U儿童| WS|U边界, 340, 220, 100, 20, hwnd,(HMENU)3,空,空); 打破 案例WM_命令://fac指令UNI butoane 开关(cmd) { 案例1: //::MessageBeep(MB_icon错误); //::MessageBox(hwnd,“Ai salvat?”,“atentie”,MB_OKCANCEL); cout 4&&cmd,c++,user-interface,winapi,button,C++,User Interface,Winapi,Button,不幸的是,没有自动执行此操作的机制。您必须编写代码来侦听大小调整事件,计算每个控件的适当大小和位置,以及 case WM_SIZE: { const int cxPadding = 12; const int cyPadding = 12; // Get client rectangle for parent window. RECT rcParent; GetClientRect(hwnd, &rcParent); RECT rcBu

不幸的是,没有自动执行此操作的机制。您必须编写代码来侦听大小调整事件,计算每个控件的适当大小和位置,以及
case WM_SIZE:
{
    const int cxPadding = 12;
    const int cyPadding = 12;

    // Get client rectangle for parent window.
    RECT rcParent;
    GetClientRect(hwnd, &rcParent);

    RECT rcButton[5];

    // Adjust the position of the first button.
    // It will be the furthest one to the right.
    GetClientRect(button[0], &rcButton[0]);
    SetWindowPos(button[0],
                 NULL,
                 (rcParent.right  - cxPadding - (rcButton[0].right  - rcButton[0].left)),
                 (rcParent.bottom - cyPadding - (rcButton[0].bottom - rcButton[0].top)),
                 0,
                 0,
                 SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);

    // Adjust the position of the second button.
    // It will be the next to the first one.
    GetClientRect(button[1], &rcButton[1]);
    SetWindowPos(button[1],
                 NULL,
                 (rcParent.right  - cxPadding - (rcButton[0].right  - rcButton[0].left)
                                  - cxPadding - (rcButton[1].right  - rcButton[1].left)),
                 (rcParent.bottom - cyPadding - (rcButton[1].bottom - rcButton[1].top)),
                 0,
                 0,
                 SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER);

    // etc.
}