Results 1 to 16 of 16

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered 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
    , , .
    !

  2. #2

  3. #3
    Registered User
    Join Date: Oct:2008
    Location:
    Posts: 95

    Solved

    ! , !

    , . :
    Code:
    SendDlgItemMessage(hwnd, IDM_FAREN, CB_ADDSTRING, 0, (DWORD) ((LPSTR) pszMem));
    SetWindowText(hwndFaren, (LPSTR) NULL);
    :
    Code:
    SetWindowText(hwndFaren, (LPSTR) pszMem);
    Copy-Paste, Copy-Paste - . , 5 , .. , - " , ".
    WinAPI, , .

  4. #4
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    (, 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|

  5. #5
    Registered 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);

    !

  6. #6
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    CB_ADDSTRING, (" " ), , ( ), ( , ).
    , GetDlgItem, child . WinMain ( , . , , (GetWindowLongPtr, SetWindowLongPtr GWLP_USERDATA). .), GetDlgItem , , EnumChildWindows( GetDlgItem , -). xxxDlgxxx ( , , WinMain, ), , , ( ) . , , -, .

    , , Win32 API C, ,
    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|

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |