C++ Schriftgröße ändern



  • Hallo Zusammen,
    Ich habe eine Frage. wie kann ich die Schriftgröße ändern:
    Code:
    Main.cpp

    #include <windows.h>
    #include "main.h"
    #include <iostream>
    #include<stdlib.h>
    
    BOOL LoadFile(HWND hEdit, LPSTR pszFileName) {
    	HANDLE hFile;
    	BOOL bSuccess = FALSE;
    
    
    	hFile = CreateFile(pszFileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
    	if(hFile != INVALID_HANDLE_VALUE) {
    		DWORD dwFileSize;
    		dwFileSize = GetFileSize(hFile, NULL);
    		if(dwFileSize != 0xFFFFFFFF) {
    			LPSTR pszFileText;
    			pszFileText = (LPSTR)GlobalAlloc(GPTR, dwFileSize +1);
    	
    			if(pszFileText != NULL) {
    				DWORD dwRead;
    				if(ReadFile(hFile, pszFileText, dwFileSize, &dwRead, NULL)) {
    					pszFileText[dwFileSize] = 0; // Null terminator
    					if(SetWindowText(hEdit, pszFileText))
    						bSuccess = TRUE; // It worked!
    				}
    				GlobalFree(pszFileText);
    			}
    		}
    		CloseHandle(hFile);
    	}
    	return bSuccess;
    }
    
    BOOL SaveFile(HWND hEdit, LPSTR pszFileName) {
    	HANDLE hFile;
    	BOOL bSuccess = FALSE;
    
    	hFile = CreateFile(pszFileName, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
    	if(hFile != INVALID_HANDLE_VALUE) {
    		DWORD dwTextLength;
    		dwTextLength = GetWindowTextLength(hEdit);
    		if(dwTextLength > 0) {
    			LPSTR pszText;
    			pszText = (LPSTR)GlobalAlloc(GPTR, dwTextLength + 1);
    			if(pszText != NULL) {
    				if(GetWindowText(hEdit, pszText, dwTextLength + 1)) {
    					DWORD dwWritten;
    					if(WriteFile(hFile, pszText, dwTextLength, &dwWritten, NULL))
    						bSuccess = TRUE;
    				}
    				GlobalFree(pszText);
    			}
    		}
    		CloseHandle(hFile);
    	}
    	return bSuccess;
    }
    
    BOOL DoFileOpenSave(HWND hwnd, BOOL bSave) {
    	OPENFILENAME ofn;
    	char szFileName[MAX_PATH];
    
    	ZeroMemory(&ofn, sizeof(ofn));
    	szFileName[0] = 0;
    
    	ofn.lStructSize = sizeof(ofn);
    	ofn.hwndOwner = hwnd;
    	ofn.lpstrFilter = "Ein und Auslager system  (*.EUALS)\0*.EUALS\0DATA (*.datasystem*)\0*.datasystem*\0Internet (*.html*)\0*.html\0\0";
    	ofn.lpstrFile = szFileName;
    	ofn.nMaxFile = MAX_PATH;
    	
    
    
    	if(bSave) {
    		ofn.Flags = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
    		if(GetSaveFileName(&ofn)) {
    			if(!SaveFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName)) {
    				MessageBox(hwnd, "Save file failed.", "Error",MB_OK|MB_ICONEXCLAMATION);
    				return FALSE;
    			}
    		}
    	} else {
    		ofn.Flags = OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
    		if(GetOpenFileName(&ofn)) {
    			if(!LoadFile(GetDlgItem(hwnd, IDC_MAIN_TEXT), szFileName)) {
    				MessageBox(hwnd, "Load of file failed.", "Error",MB_OK|MB_ICONEXCLAMATION);
    				return FALSE;
    			}
    		}
    	}
    	return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
    	switch(Message) {
    		case WM_CREATE:
    			CreateWindow("EDIT", "",WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,hwnd, (HMENU)IDC_MAIN_TEXT, GetModuleHandle(NULL), NULL);
    			SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE,0));
    			break;
    		case WM_SIZE:
    			if(wParam != SIZE_MINIMIZED)
    				MoveWindow(GetDlgItem(hwnd, IDC_MAIN_TEXT), 0, 0, LOWORD(lParam),HIWORD(lParam), TRUE);
    			break;
    		case WM_SETFOCUS:
    			SetFocus(GetDlgItem(hwnd, IDC_MAIN_TEXT));
    			break;
    		case WM_COMMAND:
    			switch(LOWORD(wParam)) {
    				case CM_FILE_OPEN:
    					DoFileOpenSave(hwnd, FALSE);
    					break;
    				case CM_FILE_SAVEAS:
    					DoFileOpenSave(hwnd, TRUE);
    					break;
    				case CM_FILE_EXIT:
    					PostMessage(hwnd, WM_CLOSE, 0, 0);
    					break;
    				case CM_ABOUT:
    					MessageBox (NULL, "Name: Ein & Auslager System\n Company: MicroSpeed\n    Version 1.0.0" , "System Info", 0);
    					break;
    						case CM_HELP:
    					MessageBox (NULL, "1. You carry the data a following there is: refrigerator, and pantry.\n 2. You are wearing the item you have new or consumed!\n 3. You enter the number of pieces! \n4. You specify the MHD (minimum date).\n Done.Press Save.", "Help",  0);
    					break;
    			}
    			break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hwnd, Message, wParam, lParam);
    	}
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) {
    	WNDCLASSEX wc;
    	HWND hwnd;
    	MSG Msg;
    
    	wc.cbSize        = sizeof(WNDCLASSEX);
    	wc.style         = 0;
    	wc.lpfnWndProc   = WndProc;
    	wc.cbClsExtra    = 0;
    	wc.cbWndExtra    = 0;
    	wc.hInstance     = hInstance;
    	wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wc.lpszMenuName  = "MAINMENU";
    	wc.lpszClassName = "WindowClass";
    	wc.hIconSm       = LoadIcon(hInstance,"A"); /* A is name used by project icons */
    
    	if(!RegisterClassEx(&wc)) {
    		MessageBox(0,"Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK|MB_SYSTEMMODAL);
    		return 0;
    	}
    
    	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Ein & Auslager system",WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT,
    		CW_USEDEFAULT,
    		1000,600,
    		NULL, NULL, hInstance, NULL);
    
    	if(hwnd == NULL) {
    		MessageBox(0, "Window Creation Failed!", "Error!",MB_ICONEXCLAMATION|MB_OK|MB_SYSTEMMODAL);
    		return 0;
    	}
    
    	ShowWindow(hwnd,1);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0) {
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    

    Main.h

    #define CM_FILE_SAVEAS	9072
    #define CM_FILE_EXIT	9071
    #define CM_FILE_OPEN	9070
    #define CM_ABOUT        9069
    #define CM_HELP         9068
    
    #define IDC_MAIN_TEXT 1001
    

    resource.rc

    #include "main.h"
    
    MAINMENU MENU 
    {
     POPUP "&File"
     {
      MENUITEM "&Open...", CM_FILE_OPEN
      MENUITEM "Save &As...", CM_FILE_SAVEAS
      MENUITEM SEPARATOR
      MENUITEM "E&xit", CM_FILE_EXIT
     }
    
     POPUP "&About"
     {
      MENUITEM "&About", CM_ABOUT
     }
     POPUP "&Help"
     {
      MENUITEM "&how it works", CM_HELP
     }
    }
    


  • Schreibe bitte in eine Zeile vor Deinem Code ``` und in eine Zeile nach Deinem Code ```. Alternativ markiere Deinen Code und klicke auf das </> in der Symbolleiste über dem Eingabefeld.
    Du kannst Deine Beiträge nachträglich bearbeiten. Den Menüpunkt "Bearbeiten" findest Du in dem Drei-Punkte-Menü rechts unter Deinen Beiträgen.
    Danke.



  • Danke



  • Und welcher Text soll jetzt größer werden? Da ist nur ein Menü und ein paar Textboxes.

    Ach so, die Textbox. WM_SETFONT



  • @Swordfish Wie kann ich noch Text einfügen der beim Starten erscheint?



  • Wo einfügen? In dem Textfeld? WM_SETTEXT
    Oder meinst Du einen Splash Screen?



  • @Swordfish Bei SetText



  • z.B. so

    		case WM_CREATE: {
    			HWND hEdit = CreateWindow("EDIT", "",WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,hwnd, (HMENU)IDC_MAIN_TEXT, GetModuleHandle(NULL), NULL);
    			SetWindowText(hEdit, "trallala");
    			SendDlgItemMessage(hwnd, IDC_MAIN_TEXT, WM_SETFONT,(WPARAM)GetStockObject(DEFAULT_GUI_FONT), MAKELPARAM(TRUE,0));
    			break; }
    

    Alternativ kannst du auch analog zu dem SendDlgItemMessage(WM_SETFONT) ein SendDlgItemMessage(WM_SETTEXT) machen.


Log in to reply