Author Topic: GDI and richedit  (Read 779 times)

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
GDI and richedit
« on: May 05, 2019, 12:03:40 AM »
I have a nasty bug,so after a while it suddenly exits
I have gone for more readable code with LOCAL variables for a smoother way to solve it,afterwards
I have very little GDI experience, I am more ddraw experienced

Code: [Select]
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

TopXY proc wDim:DWORD, sDim:DWORD

    shr sDim, 1      ; divide screen dimension by 2
    shr wDim, 1      ; divide window dimension by 2
    mov eax, wDim    ; copy window dimension into eax
    sub sDim, eax    ; sub half win dimension from half screen dimension

    return sDim

TopXY endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

Paint_Proc proc hWin:DWORD

    LOCAL hDC      :DWORD
    LOCAL btn_hi   :DWORD
    LOCAL btn_lo   :DWORD
    LOCAL rect:RECT
    LOCAL Rct      :RECT
    LOCAL Ps       :PAINTSTRUCT
    LOCAL sourcex   :DWORD
    LOCAL sourcey   :DWORD
    LOCAL destx     :DWORD
    LOCAL desty     :DWORD
    LOCAL color     :DWORD

    invoke BeginPaint,hWin,ADDR Ps
    mov hDC, eax

  ; ----------------------------------------
      ;invoke GetSysColor,COLOR_BTNHIGHLIGHT
    mov btn_hi, eax

    ;invoke GetSysColor,COLOR_BTNSHADOW
    mov btn_lo, eax
    mov edx,200
    mov ecx,200
    mov esi,310 ;X
    mov edi,200 ;Y
    mov eax,0
    @@l5:
    mov eax,0FFFFFFh
    ;mov eax,0
    pushad
    mov ecx,esi
    mov edx,edi
    sub edx,167
    sub ecx,299
    .IF pixelf==0
    invoke GetPixel,hDC,sourcex,sourcey
    .IF eax>300
    sub eax,00FF00FFh
   
    and eax,0FFFFFFh
    .ENDIF
    .ENDIF
    .IF pixelf==0
    mov edx,pixelp
    ;mov [pixelb+edx*4],eax
   
    mov pixelf,0FFFFFFFFh
    .ENDIF
    invoke SetPixel,hDC,destx,desty,eax
    popad
   
    add esi,1
    add eax,1
    dec edx
    jne @@l5
   
    add edi,1
    mov edx,200
    sub esi,200
    sub eax,200
    add eax,256
    dec ecx
    jne @@l5
    mov eax,0FFFFFFFFh
    mov pixelf,eax
  ; ----------------------------------------

    invoke EndPaint,hWin,ADDR Ps

    ret

Paint_Proc endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start

Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

jimg

  • Member
  • ***
  • Posts: 320
Re: GDI and richedit
« Reply #1 on: May 05, 2019, 02:56:56 AM »
you are doing a getpixel on a location you never set.  other than that there are too many unset things like pixelf to test.  can you post a working program to try?

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #2 on: May 05, 2019, 06:29:05 AM »
you are doing a getpixel on a location you never set.  other than that there are too many unset things like pixelf to test.  can you post a working program to try?
in the main part of program I have setup a richedit control and setText message and going from a getpixel/setpixel very slow move text from one area to another area,to only getpixel+store in a buffer once and set pixelf a flag so it only do getpixel in the loop once

maybe best to start a complete rewrite???
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

AW

  • Member
  • *****
  • Posts: 2048
  • Let's Make ASM Great Again!
Re: GDI and richedit
« Reply #3 on: May 05, 2019, 09:31:11 AM »
"bitmap must be selected within the device context, otherwise, CLR_INVALID is returned on all pixels."

HSE

  • Member
  • *****
  • Posts: 1015
  • <AMD>< 7-32>
Re: GDI and richedit
« Reply #4 on: May 05, 2019, 12:25:54 PM »
ecx is not preserved before to call get/setpixel

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #5 on: May 05, 2019, 06:25:56 PM »
it would be nice to have tiny code produce plenty bitmaps
to produce for example this:
and now tested a pic
« Last Edit: May 11, 2019, 02:12:33 AM by daydreamer »
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #6 on: May 19, 2019, 12:43:11 AM »
so let GDI draw text on screen and get it to bitmap and stretchblt it would be lot easier
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #7 on: May 25, 2019, 04:52:01 AM »
I am trying to change text on button when it gets pressed,with sendmessage WM_SETTEXT
but I am stuck with WM_COMMAND code that tries to change text???
and NULL background color its easier to make a GDI animation?
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6341
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: GDI and richedit
« Reply #8 on: May 25, 2019, 12:09:56 PM »
Try using WM_LBUTTONDOWN and WM_LBUTTONUP messages to make a custom control of that type.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #9 on: May 25, 2019, 10:18:17 PM »
Try using WM_LBUTTONDOWN and WM_LBUTTONUP messages to make a custom control of that type.
trying to understand how you get ID for several buttons and settext on them and set images
but all WCHAR texts are loaded from resource for this windows program,this I want to load my own strings

I would appreciate a example

and trying to understand GDI better,I am more dx experienced and they can be combined to create things with GDI and read screen and use the faster dx
made some drawing code on ticalculator, I want to try with GDI
reading some tutorials


Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

fearless

  • Member
  • ***
  • Posts: 394
    • LetTheLightIn
Re: GDI and richedit
« Reply #10 on: May 25, 2019, 10:56:17 PM »
You can define the ID (resource id) of the button when you create it with CreateWindow/CreateWindowEx or if its resource based you set the ID in the resource editor.
Once you have the ID you can get the handle of the button with GetDlgItem (or the returned handle value from CreateWindow/CreateWindowEx)
Then you set the text for the button or other control with SetWindowText or via SendMessage and WM_SETTEXT
For responding to the mouse click on the button you can use a button notification handled via WM_COMMAND as BN_CLICKED
Code: [Select]
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    LOCAL wNotifyCode:DWORD
   
    mov eax, uMsg
    .IF eax == WM_INITDIALOG
        ; Init Stuff Here
       
    .ELSEIF eax == WM_COMMAND
        mov eax, wParam
        shr eax, 16
        mov wNotifyCode, eax
        mov eax,wParam
        and eax,0FFFFh

        .IF eax == BUTTON1 ; button resource ID stored as a constant
            .IF wNotifyCode == BN_CLICKED
                ; do something
            .ENDIF
        .ELSEIF eax == ... other ids, menus, toolbar buttons etc or other controls.
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #11 on: May 26, 2019, 12:07:44 AM »
You can define the ID (resource id) of the button when you create it with CreateWindow/CreateWindowEx or if its resource based you set the ID in the resource editor.
Once you have the ID you can get the handle of the button with GetDlgItem (or the returned handle value from CreateWindow/CreateWindowEx)
Then you set the text for the button or other control with SetWindowText or via SendMessage and WM_SETTEXT
For responding to the mouse click on the button you can use a button notification handled via WM_COMMAND as BN_CLICKED
Code: [Select]
WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
    LOCAL wNotifyCode:DWORD
   
    mov eax, uMsg
    .IF eax == WM_INITDIALOG
        ; Init Stuff Here
       
    .ELSEIF eax == WM_COMMAND
        mov eax, wParam
        shr eax, 16
        mov wNotifyCode, eax
        mov eax,wParam
        and eax,0FFFFh

        .IF eax == BUTTON1 ; button resource ID stored as a constant
            .IF wNotifyCode == BN_CLICKED
                ; do something
            .ENDIF
        .ELSEIF eax == ... other ids, menus, toolbar buttons etc or other controls.
thanks for example code,I am not used to resource editing,so I used Createwindow with several buttons and experimented,with try iconbutton,bitmap button but didnt work with send set image with small icon,checkbox version worked

what I try with clicked anykey is change text on button with sendmessage that says its been clicked
thats what I am after also,reuse buttons with different texts
I used some constants to the different buttons and tested with check for anykey is pressed the program exits and it works  :eusa_clap:

« Last Edit: May 26, 2019, 01:17:28 AM by daydreamer »
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #12 on: May 26, 2019, 08:11:16 AM »
sendmessage WM_SETTEXT works directly after buttoncreations placed right after the main window creation
sendmessage WM_SETTEXT fails inside wndproc,using a switch checking loword for B1 clicked in WM_COMMAND
handler
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D

fearless

  • Member
  • ***
  • Posts: 394
    • LetTheLightIn
Re: GDI and richedit
« Reply #13 on: May 26, 2019, 08:48:53 AM »
Post some code please so we can see where the issue is.
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

My Github  Twitter

daydreamer

  • Member
  • ****
  • Posts: 808
  • watch Chebyshev on the backside of the Moon
Re: GDI and richedit
« Reply #14 on: May 26, 2019, 10:40:31 AM »
I am working on a mixed VC++/asm windows program,but at the same time getting more skilled in winapi is good for both masm and C++ skill
here it works to set another text,not work with set the small icon
buttontext is a WCHAR
Code: [Select]
//        In this function, we save the instance handle in a global variable and
//        create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
   hInst = hInstance; // Store instance handle in our global variable

   HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
   HWND hwndButton = CreateWindow(
   L"BUTTON",  // Predefined class; Unicode assumed
   L"THE ANY_KEY",      // Button text
   WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles
   10,         // x position
   10,         // y position
   100,        // Button width
   100,        // Button height
   hWnd,     // Parent window
   (HMENU)B1,       // No menu.
   (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
   NULL);      // Pointer not needed.
   HWND hwndButton2 = CreateWindow(
   L"BUTTON",  // Predefined class; Unicode assumed
   L"THE 2ND KEY",      // Button text
   BS_ICON | WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles
   120,         // x position
   10,         // y position
   100,        // Button width
   100,        // Button height
   hWnd,     // Parent window
   (HMENU)B2,       // No menu.
   (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
   NULL);      // Pointer not needed.
   SendMessageW(hwndButton2, BM_SETIMAGE, IMAGE_ICON, (LPARAM)IDI_SMALL);
   HWND hwndButton3 = CreateWindow(
   L"BUTTON",  // Predefined class; Unicode assumed
   L"THE 3rd KEY",      // Button text
   WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON | BS_BITMAP,  // Styles
   240,         // x position
   10,         // y position
   100,        // Button width
   100,        // Button height
   hWnd,     // Parent window
   (HMENU)B3,       // No menu.
   (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
   NULL);      // Pointer not needed.
   HWND hwndButton4 = CreateWindow(
   L"BUTTON",  // Predefined class; Unicode assumed
   L"THE 4th KEY",      // Button text
   WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_AUTO3STATE,  // Styles
   360,         // x position
   10,         // y position
   300,        // Button width
   100,        // Button height
   hWnd,     // Parent window
   (HMENU)B4,       // No menu.
   (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
   NULL);      // Pointer not needed.
   SendMessageW(hwndButton4, WM_SETTEXT, NULL, (LPARAM)buttontext);// (LPARAM)IDI_SMALL);
   if (!hWnd)
   {
      return FALSE;
   }

   ShowWindow(hWnd, nCmdShow);
   UpdateWindow(hWnd);

   return TRUE;
}
this same code doesnt respond,but destroywindow worked and quits program
buttons constants are named B1,B2,B3,B4
Code: [Select]
/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
    case WM_COMMAND:
        {
            int wmId = LOWORD(wParam);
            // Parse the menu selections:
            switch (wmId)
            {
case B1:
//handle button here
//SendMessageW(hwndButton, WM_SETTEXT, NULL, &buttontext);
SendMessageW(hwndButton, WM_SETTEXT, NULL, (LPARAM)buttontext);
//DestroyWindow(hWnd);
break;
            case IDM_ABOUT:
                DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
                break;
            case IDM_EXIT:
                DestroyWindow(hWnd);
                break;
            default:
                return DefWindowProc(hWnd, message, wParam, lParam);
            }
        }
        break;
    case WM_PAINT:
        {
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hWnd, &ps);
            // TODO: Add any drawing code that uses hdc here...
paint(hdc);
            EndPaint(hWnd, &ps);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

// Message handler for about box.
Quote from Flashdance
Nick  :  When you give up your dream, you die
*wears a flameproof asbestos suit*
MM,XMM,YMM,ZMM registers,whats next?use nonenglish 29 letter alphabet,ÅMM,ÄMM,ÖMM registers?:D