Avatar billede cblcbl Juniormester
01. december 2018 - 23:43

Hvordan får man et DWORD-værdi frem i WINAPI RichEditControl?

Hej,
Jeg er en hobby programmør der er i gang med at bestige win32 Api bjerget, jeg koder commandline med MS cl.exe compiler. Det rocks!
Nå, men jeg vil som primitiv debug funktion gerne kunne skrive værdien af en DWORD ud i en RichEdit kontrol i mit win32 program. Men, det kan jeg ikke finde ud af.
I nedenstående program som jeg fint kan kompilere uden fejl, og køre, så skrives der ikke nogen 3 eller 4 tal i min richedit kontrol.
Så er der nogen der kan hjælpe mig?



#define NTDDI_WIN7 0x06010000
#define _WIN32_WINNT_WIN7 0x0601


#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <commctrl.h>
#include <Richedit.h>

#include <strsafe.h> // For error checking

#include <ShellScalingAPI.h>

#pragma comment(lib,"Shcore.lib")

#pragma comment(lib,"user32.lib")
#pragma comment(lib,"gdi32.lib")
#pragma comment(lib,"comctl32.lib")

#define IDC_MAIN_EDIT        101
#define WM_SETTEXT                0x000C

//Definitions for the controls
#define BTN1 4000


LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


void ErrorExit(LPTSTR lpszFunction)
{
    // Retrieve the system error message for the last-error code

    LPVOID lpMsgBuf;
    LPVOID lpDisplayBuf;
    DWORD dw = GetLastError();

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER |
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    // Display the error message and exit the process

    lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
        (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
    StringCchPrintf((LPTSTR)lpDisplayBuf,
        LocalSize(lpDisplayBuf) / sizeof(TCHAR),
        TEXT("%s failed with error %d: %s"),
        lpszFunction, dw, lpMsgBuf);
    MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);

    LocalFree(lpMsgBuf);
    LocalFree(lpDisplayBuf);
    ExitProcess(dw);
}




int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow )
{
  MSG  msg ;   
  HWND hwnd;
  WNDCLASS wc;


  // InitCommonControls();

INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
//icex.dwICC = ICC_USEREX_CLASSES;

InitCommonControlsEx(&icex);
LoadLibrary("msftedit.dll");


  wc.style        = CS_HREDRAW | CS_VREDRAW;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.lpszClassName = TEXT( "RichEdit - DWORD" );
  wc.hInstance    = hInstance ;
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpszMenuName  = NULL;
  wc.lpfnWndProc  = WndProc;
  wc.hCursor      = LoadCursor(NULL, IDC_ARROW);
  wc.hIcon        = LoadIcon(NULL, IDI_APPLICATION);
 
  RegisterClass(&wc);
  hwnd = CreateWindow( wc.lpszClassName, TEXT("DWORD - udfordringen?"),
                WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                100, 100, 550, 550, NULL, NULL, hInstance, NULL); 

  ShowWindow(hwnd, nCmdShow);
  UpdateWindow(hwnd);

  while( GetMessage(&msg, NULL, 0, 0)) {
    DispatchMessage(&msg);
  }
  return (int) msg.wParam;
}

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
  switch(msg) 
  {
    case WM_CREATE:
            {
            HWND hEdit;
HWND hButton1;

 

  hEdit= CreateWindowExA(ES_SUNKEN,"RICHEDIT50W","Hjælp! Hvordan viser man værdien af et DWORD?\n",        ES_MULTILINE | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_TABSTOP | ES_WANTRETURN,        20, 20, 450, 450,        hwnd,  (HMENU)IDC_MAIN_EDIT,  GetModuleHandle(NULL), NULL);


if (!hEdit)
    {

        ErrorExit(TEXT("MSFTEDIT"));
    }


SendMessage(hEdit, EM_REPLACESEL, WPARAM(FALSE), LPARAM("Jeg kan godt skrive tekst. \n"));
SendMessage(hEdit, EM_REPLACESEL, WPARAM(FALSE), LPARAM("Men hvor er mit 3-tal og mit 4-tal?. \n"));

int tal = 3;
SendMessage(hEdit, EM_STREAMIN, FALSE, LPARAM(tal));

DWORD dw = 4;
SendMessage(hEdit, EM_STREAMIN, FALSE, LPARAM(dw));





    break;
    }
      case WM_DESTROY:
      {
        PostQuitMessage(0);
        return 0;
      }
  }
  return DefWindowProc(hwnd, msg, wParam, lParam);
}
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester