Author Topic: pb to c++  (Read 267 times)

James Morgan

  • Newbie
  • *
  • Posts: 4
pb to c++
« on: October 02, 2021, 10:31:43 pm »
in wm_ctlcolorstatic i used lparam in another compiler and the handle of that control to make a wm_colorstatic color for each control difference how can i do that in c++
trying in c++ vc++
 HWND      hCtl   = CreateWindowEx(0,L"static",L"Label1" ,  WS_CHILD|WS_VISIBLE,40,40,80,30,hWnd,(HMENU)IDC_LABEL1,hIns,0);

// cl JMorgan2.cpp user32.lib gdi32.lib
#ifndef UNICODE
    #define            UNICODE
#endif
#ifndef _UNICODE
    #define            _UNICODE
#endif
#include <windows.h>
#define IDC_LABEL1     2000
#define IDC_LABEL2     2002
HWND hCTL;
HWND lParam;

//HBRUSH    hBrush;

const COLORREF rgbRed = 0X000000FF;
const COLORREF rgbGreen = 0x0000FF00;
const COLORREF rgbBlue = 0x00FF0000;
const COLORREF rgbBlack = 0x00000000;
const COLORREF rgbWhite = 0x00FFFFFF;



LRESULT CALLBACK fnWndProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
    HWND hCtl;
 switch(msg)
 {
   case WM_CREATE:
    {
        HINSTANCE hIns   = ((LPCREATESTRUCT)lParam)->hInstance;
        HBRUSH    hBrush = CreateSolidBrush(RGB(255,255,100));   // Create a non-standard color HBRUSH for main window
        HWND      hCtl   = CreateWindowEx(0,L"static",L"Label1" ,  WS_CHILD|WS_VISIBLE,40,40,80,30,hWnd,(HMENU)IDC_LABEL1,hIns,0);
        HWND      hCtl1 = CreateWindowEx(0, L"static", L"Label2", WS_CHILD | WS_VISIBLE,40,60, 80, 30, hWnd, (HMENU)IDC_LABEL2, hIns, 0);

       
        SetWindowLongPtr(hWnd,0*sizeof(void*),(LONG_PTR)hBrush); // Store HBRUSH as part of Window Class Structure
        return 0;
    }
   case WM_CTLCOLORSTATIC: // Do not allow DefWindowProc() to process this message!

       if(lParam  ( hCtl))
    {                                                            // When a WM_CTLCOLORSTATIC message comes through, return
       SetBkMode((HDC)wParam,TRANSPARENT);
       SetTextColor((HDC)wParam, rgbRed); // RGB(20, 20, 240));
     //' SetTextColor((HDC)wParam , COLORREF(0xFF, 0x00, 0x00));
       
       // from the Window Procedure call without a DefWindowProc()
        return GetWindowLongPtr(hWnd,0*sizeof(void*));           // call. Instead return the HBRUSH stored as an instance
    }                                                            // variable as part of the WNDCLASSEX object.
   case WM_DESTROY:
    {
        HBRUSH hBrush=(HBRUSH)GetWindowLongPtr(hWnd,0*sizeof(void*));
        DeleteObject(hBrush);                                    // Delete dynamically allocated GDI resource stored in
        PostQuitMessage(0);                                      // Window Class Structure
        return 0;
    }
 }

 return (DefWindowProc(hWnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
 wchar_t szClassName[]=L"Form1";
 WNDCLASSEX wc;
 MSG messages;
 HWND hWnd;

 memset(&wc,0,sizeof(WNDCLASSEX));
 wc.lpszClassName = szClassName;
 wc.lpfnWndProc   = fnWndProc;
 wc.cbSize        = sizeof(WNDCLASSEX);
 wc.hbrBackground = CreateSolidBrush(RGB(255, 255, 100));  //hBrush//(HBRUSH)COLOR_WINDOW;
 wc.hInstance     = hInstance;
 wc.cbWndExtra    = sizeof(void*);
 RegisterClassEx(&wc);
 hWnd=CreateWindowEx(0,szClassName,szClassName,WS_OVERLAPPEDWINDOW,200,175,320,200,HWND_DESKTOP,0,hInstance,0);
 ShowWindow(hWnd,iShow);
 while(GetMessage(&messages,NULL,0,0))
 {
    TranslateMessage(&messages);
    DispatchMessage(&messages);
 }
 

 return (int)messages.wParam;
}








#if 0

Note that the 'Build Model' of C or C++ is totally and completely different from PowerBASIC.By
'Build Model' I mean the steps involved in reading in text source files and creating an executable
binary.

In C or C++ the building of an executable or binary has two steps both of which are completely under
the full control of the programmer.These two steps are compilation as done by cl.exe and linking
as done by link.exe.

In PowerBASIC compilation and linking are done by the compiler in one step which the coder has no
control over.

Declare Function SetBkMode Lib "GDI32.DLL" Alias "SetBkMode" (Byval hdc As Dword, Byval nBkMode As Long) As Long

#endif
thanks



Patrice Terrier

  • Administrator
  • *****
  • Posts: 1874
    • zapsolution
Re: pb to c++
« Reply #1 on: October 02, 2021, 11:54:23 pm »
J.M.
Have a look at the code of the MIDIpiano project.
http://www.objreader.com/index.php?topic=47.0


Code: [Select]
    case WM_CTLCOLOREDIT:
    case WM_CTLCOLORLISTBOX:
        SetBkColor((HDC) wParam, GetSysColor(COLOR_INFOBK));
        SetTextColor((HDC) wParam, GetSysColor(COLOR_INFOTEXT));
        return (LRESULT) GetSysColorBrush(COLOR_INFOBK);

    case WM_CTLCOLORSTATIC:  // Simple stunt to avoid focus rect flashing in TrackBars
        switch (GetDlgCtrlID((HWND) lParam)) {
        case IDC_TRACKBAR1:
        case IDC_TRACKBAR2:
        case IDC_TRACKBAR3:
        case IDC_TRACKBAR4:
            SetFocus(gP.hPiano);
        }
        break;

and the MSDN documentation
https://docs.microsoft.com/en-us/windows/win32/controls/wm-ctlcolorstatic
Code: [Select]
   case WM_CTLCOLORSTATIC:
        {
        HDC hdcStatic = (HDC) wParam;
        SetTextColor(hdcStatic, RGB(255,255,255));
        SetBkColor(hdcStatic, RGB(0,0,0));

        if (hbrBkgnd == NULL)
        {
            hbrBkgnd = CreateSolidBrush(RGB(0,0,0));
        }
        return (INT_PTR)hbrBkgnd;
        }
« Last Edit: October 02, 2021, 11:59:17 pm by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

James Morgan

  • Newbie
  • *
  • Posts: 4
Re: pb to c++
« Reply #2 on: October 03, 2021, 01:54:31 am »
Thanks
have not tried it yet



wParam

    Handle to the device context for the static control window.
i never have understood this
thanks for quick answer

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1874
    • zapsolution
Re: pb to c++
« Reply #3 on: October 03, 2021, 10:17:37 am »
« Last Edit: October 03, 2021, 11:29:01 am by Patrice Terrier »
Patrice
(Always working with the latest Windows version available...)

James Morgan

  • Newbie
  • *
  • Posts: 4
Re: pb to c++
« Reply #4 on: October 04, 2021, 07:48:40 am »
WM_CTLCOLORSTATIC

    switch (GetDlgCtrlID((HWND) lParam)) {
        case IDC_LABEL1:
                    SetBkMode((HDC)wParam, TRANSPARENT);
            SetTextColor((HDC)wParam, rgbRed);
           return GetWindowLongPtr(hWnd, 0 * sizeof(void*));
        }
        break;
i could not get this to work
with WM_CTLCOLORSTATIC

I AM USING VS 2019

IF I TRY TO USE
 switch (GetDlgCtrlID((HWND) lParam))
I COMPILE BUT NOT EXE
I HAVE TWO LABEL
I WANT THEM IN DIFFERENCE COLORS

IN PB
I USE
 CASE %WM_CTLCOLORSTATIC           'FOR READONLY EDIT OR STASTICE

        Select Case Cb.lparam
               case hBut(29) , hBut(33)   ' DWORD HANDLE  CONTROL IS CREATED BY API CREATEWINDOW
                      lbgcolor = %RGB_SaddleBrown
                     ' SetBkColor CB.WPARAM, lbgcolor      ' set text background color
                      SetBkMode CB.WPARAM, %TRANSPARENT
                      SetTextColor CB.WPARAM, %RGB_WHITE ' set text color
                      hbrush = CreateSolidBrush(lBGColor)
                      FUNCTION = hBrush                  ' set window background color THE hBrush IS DEFINED IN %WM_PAINT
                      EXIT FUNCTION
         End Select
        Select Case Cb.lparam
               case  hBUT(27)   ' DWORD HANDLE    CONTROL IS CREATED BY API CREATEWINDOW
                      lbgcolor = %RGB_RifleGreen
                     ' SetBkColor CB.WPARAM, lbgcolor      ' set text background color
                      SetBkMode CB.WPARAM, %TRANSPARENT
                      SetTextColor CB.WPARAM, %RGB_WHITE ' set text color
                      hbrush = CreateSolidBrush(lBGColor)
                      FUNCTION = hBrush                  ' set window background color THE hBrush IS DEFINED IN %WM_PAINT
                      EXIT FUNCTION
         End Select

I AM DOING SOMETHING WRONG????
   
THANKS AND YOUR PATIENCE

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1874
    • zapsolution
Re: pb to c++
« Reply #5 on: October 04, 2021, 11:59:20 am »
case WM_COLORSTATIC:
     if (GetDlgCtrlID((HWND) lParam) == IDC_LABEL1) {
          SetTextColor((HDC) wParam, RGB(255,0,0));
          SetBkColor((HDC) wParam, TRANSPARENT);
          return (LONG_PTR) GetStockObject(NULL_BRUSH);
     }
     break;
Patrice
(Always working with the latest Windows version available...)

James Morgan

  • Newbie
  • *
  • Posts: 4
Re: pb to c++
« Reply #6 on: October 15, 2021, 04:38:19 am »
HELLO
JAMES POWERBASIC TO WIN 32API OR C++

Type INCTL
IN As String * 2
JJ as  Long
BB as  Dword
CRLF As String * 2
End Type
GLOBAL INB AS STRING
GLOBAL JJB AS LONG
GLOBAL BBJ AS DWORD
Global INCTL2 As INCTL


 Open  "CTLSW32.INC" For Random Shared As #5  Len = Len(INCTL2)
 
       Z = 1
                 Get #5, Z, INCTL2
                       INB = INCTL2.IN
                       JJB = INCTL2.JJ
                       BBJ = INCTL2.BB
               CLOSE #5
      Open  "CTLSW32.INC" For Random Shared As #5  Len = Len(INCTL2)


 
       Z = 1
                      PUT #5, Z, INCTL2
                           INCTL2.IN = INB
                           INCTL2.JJ = JJB
                           INCTL2.BB = BBJ
               CLOSE #5

I USE IN POWERBASIC SEVERAL USER-DEFINED DATA TYPES
POWERBASIC USES GET AND PUT WHAT IS NEEDED IN WINAPI OR C++?

THANKS

Patrice Terrier

  • Administrator
  • *****
  • Posts: 1874
    • zapsolution
Re: pb to c++
« Reply #7 on: October 15, 2021, 10:03:04 am »
Search MSDN for

Writing
- CreateFile
- WriteFile
- CloseHandle

Reading
- CreateFile
- ReadFile
- CloseHandle

And for a complete C/C++ example, search for zLoadSaveCoordinates in the zTrace utility here:
http://www.objreader.com/index.php?topic=91.0
Patrice
(Always working with the latest Windows version available...)