Results 1 to 16 of 16
Thread: C++ Win32 API - EDIT
Hybrid View
-
18th December 2011 20:26 #1Registered User
Join Date: Oct:2008
Location:
Posts: 95
C++ Win32 API - EDIT
,
WinAPI , -. GUI-, wxWidgets, GTK(2/+), cpptk, fltk. WinAPI. Dev-C++ MinGW gcc, C - tiny C.
EDIT-, . :
- :Code:#include <windows.h> #include <stdio.h> const char g_szClassName[] = "myWindowClass"; static HINSTANCE gInstance; char* mychar; HWND hwndCels, hwndFaren; PSTR pszMem; int cTxtLen; #define IDM_CONVERT 1 #define IDM_CELCIUS 2 #define IDM_FAREN 3 // Functions List // LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); int WINAPI WinMain(HINSTANCE gInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG Msg; //Step 1: Registering the Window Class wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = gInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wc.lpszMenuName = NULL; wc.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // if registration of main class fails if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } // Step 2: Creating the Window hwnd = CreateWindowEx( 0, g_szClassName, "Temperature Converter", WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 330, 80, NULL, NULL, gInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); // Step 3: The Message Loop while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } // Step 4: the Window Procedure LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { HWND btnConvert, fldCelcius, fldFaren; switch(msg) { case WM_CREATE: { fldCelcius = CreateWindowEx( 0, "EDIT", "cel", WS_BORDER | WS_VISIBLE | WS_CHILD, 0,5,100,20, hwnd,(HMENU)IDM_CELCIUS, gInstance, NULL); btnConvert = CreateWindowEx( 0, "BUTTON", "Convert", WS_BORDER | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 110,5,100,20, hwnd,(HMENU)IDM_CONVERT, gInstance, NULL); fldFaren = CreateWindowEx( 0, "EDIT", "far", WS_CHILD | WS_VISIBLE | WS_BORDER, 220,5,100,20, hwnd,(HMENU)IDM_FAREN, gInstance, NULL); } break; // izpylnenie na komandata case WM_COMMAND: switch(LOWORD(wParam)) { case IDM_CONVERT: hwndCels = GetDlgItem(hwnd, IDM_CELCIUS); hwndFaren = GetDlgItem(hwnd, IDM_FAREN); cTxtLen = GetWindowTextLength(hwndCels); pszMem = (PSTR) VirtualAlloc((LPVOID) NULL, (DWORD) (cTxtLen + 1), MEM_COMMIT, PAGE_READWRITE); GetWindowText(hwndCels, pszMem, cTxtLen + 1); if (pszMem != NULL) { SendDlgItemMessage(hwnd, IDM_FAREN, CB_ADDSTRING, 0, (DWORD) ((LPSTR) pszMem)); SetWindowText(hwndFaren, (LPSTR) NULL); } // Free the memory and return. VirtualFree(pszMem, 0, MEM_RELEASE); return TRUE; //break; } break; // kraj na komandata case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
, , .Code:// izpylnenie na komandite case WM_COMMAND: switch(LOWORD(wParam)) { case IDM_CONVERT: hwndCels = GetDlgItem(hwnd, IDM_CELCIUS); hwndFaren = GetDlgItem(hwnd, IDM_FAREN); cTxtLen = GetWindowTextLength(hwndCels); pszMem = (PSTR) VirtualAlloc((LPVOID) NULL, (DWORD) (cTxtLen + 1), MEM_COMMIT, PAGE_READWRITE); GetWindowText(hwndCels, pszMem, cTxtLen + 1); if (pszMem != NULL) { SendDlgItemMessage(hwnd, IDM_FAREN, CB_ADDSTRING, 0, (DWORD) ((LPSTR) pszMem)); SetWindowText(hwndFaren, (LPSTR) NULL); } // Free the memory and return. VirtualFree(pszMem, 0, MEM_RELEASE); return TRUE; //break; } break; // kraj na komandite
!
-
18th December 2011 21:21 #2
Join Date: Apr:2006
Location:
Posts: 8,666
-
19th December 2011 16:26 #3Registered User
Join Date: Oct:2008
Location:
Posts: 95
Solved
! , !
,
. :
:Code:SendDlgItemMessage(hwnd, IDM_FAREN, CB_ADDSTRING, 0, (DWORD) ((LPSTR) pszMem)); SetWindowText(hwndFaren, (LPSTR) NULL);
Copy-Paste, Copy-Paste - . , 5 , .. , - " , ".Code:SetWindowText(hwndFaren, (LPSTR) pszMem);
WinAPI, , .
-
19th December 2011 17:19 #4
(, IDM_FAREN ) , . CB_ADDSTRING , , SetWindowText. .
, , , , , ( CB_ADDSTRING) , . , , .EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|
-
19th December 2011 19:41 #5Registered User
Join Date: Oct:2008
Location:
Posts: 95
. . Edit:
fldFaren = CreateWindowEx(
0,
"EDIT",
"far",
WS_CHILD | WS_VISIBLE | WS_BORDER,
220,5,100,20,
hwnd,(HMENU) IDM_FAREN,
gInstance,
NULL);
!
-
20th December 2011 04:05 #6EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in