Quantcast
Channel: CodeGuru Forums - C++ and WinAPI
Viewing all 583 articles
Browse latest View live

how use the printer?

$
0
0
i'm trying print a window DC, but seems that i mistake on scale mode between HDC(pixels) and printer(?):(
Code:

void print()
        {
            //getting the default printer name
            char szPrinterName[255];
            unsigned long lPrinterNameLength;
            GetDefaultPrinter( szPrinterName, &lPrinterNameLength );

            //getting printer DC
            HDC printerDC = CreateDC( "WINSPOOL",szPrinterName, NULL, NULL);

            //starting doc and pages:
            DOCINFO doc;
            doc.cbSize = sizeof(DOCINFO);
            doc.lpszDocName = "1st doc";
            StartDoc(printerDC, &doc);
            StartPage(printerDC);

            //draw on printer using GDI functions
            RECT windowRect;
            GetClientRect(hwnd,&windowRect);
            //SetMapMode(printerDC, GetMapMode(GetDC(hwnd)));
            long width=GetDeviceCaps(printerDC,SCALINGFACTORX);
            long height=GetDeviceCaps(printerDC,SCALINGFACTORX);

            StretchBlt(printerDC,0,0,windowRect.right*width,windowRect.bottom*height,GetDC(hwnd),0,0,windowRect.right,windowRect.bottom,SRCCOPY);

            //end pages and doc
            EndPage(printerDC);
            EndDoc(printerDC);

            //delete the printer DC
            DeleteDC(printerDC);
        }

the doc ins't printed... what i'm doing wrong on conversions?

Does WM_ERASEBKGND validate the area it erases?

$
0
0
When I does something like resizing my Window, a WM_ERASEBKGND message is sent followed by a WM_PAINT message.
The WM_ERASEBKGND (default) handler will erase the background, and the WM_PAINT handler will draw the foreground.

My question is, does the WM_ERASEBKGND handler validates the area it erases, I mean if it validates it then the WM_PAINT handler won't draw anything because the area is now validated.

Debugging problem

$
0
0
Hi

Im trying to debug a Win32 visual program because I have a "invalid pointer crash" but I cannot find it where because stepping over with F10 at a certain point debugging just stops and I cant step ahead anymore.

It blocks at the end of the MainWndProc() loop.

I dont understand why.

Code:

LRESULT CALLBACK MainWndProc(HWND hwnd,
    UINT uMsg,
    WPARAM wParam,
    LPARAM lParam)
{
    HDC      hdc;
    PAINTSTRUCT  ps;

    switch (uMsg)
    {
    case WM_CREATE:
    {

        HINSTANCE dllhinst;
        HICON hIcon;
        HIMAGELIST himgList;
        InitCommonControls();
        himgList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
            GetSystemMetrics(SM_CYSMICON), ILC_COLOR32, 4, 4);
        ImageList_SetBkColor(himgList, GetSysColor(COLOR_WINDOW));
        dllhinst = LoadLibrary("shell32.dll");

        for (int i = 1; i<50; i++)
        {
            hIcon = LoadIcon(dllhinst, MAKEINTRESOURCE(i));
            ImageList_AddIcon(himgList, hIcon);
        }

        FreeLibrary(dllhinst);

        hTreeView =
            CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, "",
                WS_CHILD | WS_VISIBLE | TVS_HASLINES |
                TVS_LINESATROOT | TVS_HASBUTTONS |
                TVS_SHOWSELALWAYS,
                0, 0, 190, 320,
                hwnd, (HMENU)ID_TREEVIEW, hinst, NULL);
        TreeView_SetImageList(hTreeView, himgList, TVSIL_NORMAL);

        /// ///// LISTVIEW ////////////////
        int r = CreateListView(hwnd);
        if (r)
        {
            ReportError("CreateListView");
            return 0;
        }

        CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("Button"), "Open",
            WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
            200, 10, 60, 25,
            hwnd, (HMENU)ID_OPEN, 0, NULL);

        // Create ComboBox
        hList = CreateWindow(TEXT("Combobox"),
            NULL, WS_CHILD | WS_VISIBLE |
            LBS_STANDARD,
            360, 10, 160, 325,
            hwnd, (HMENU)ID_LIST,
            (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
            NULL);

        // Populate ComboBox
        FillComboBox(hList);
        /// populate treeview
        sSqliteFile =
            "C:\\Users\\Asus\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\rg6g9heo.default-1419956670839\\addons.sqlite";
        if (!LoadSqliteFile(0))  ReDrawTreeView(sSqliteFile);

        return 0;
    }

    case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case ID_OPEN:

            if (!LoadSqliteFile(1))
                ReDrawTreeView(sSqliteFile);

            break;
 
        }
        return 0;

    case WM_NOTIFY:
    {
        if (((LPNMHDR)lParam)->idFrom == ID_TREEVIEW)
        {
            if (((LPNMHDR)lParam)->code == NM_CLICK)
            {

                /// TreeView_HitTest
                /* Get the cursor position for this message */
                DWORD dwPos = GetMessagePos();
                POINT pt;
                pt.x = GET_X_LPARAM(dwPos);
                pt.y = GET_Y_LPARAM(dwPos);
                //cout << " pt: " << pt.x <<" " << pt.y << endl;
                TVHITTESTINFO lpht = { 0 };
                ScreenToClient(hTreeView, &pt);
                lpht.pt = pt;

                TreeView_HitTest(hTreeView, &lpht); //
                                                    //cout << " text: " << lpht.hItem << endl;
                if (lpht.hItem)
                    GetTextItemTree(lpht.hItem, sCurrentTable);

         

                /// redraw listwiew with new info
                if (sCurrentTable != sSqliteFile)
                {
                    if (!Get_Table_Info(sCurrentTable))
                    {
                        SendMessage(hList, CB_RESETCONTENT, 0, 0);
                        FillComboBox(hList);
                        SendMessage(hList, CB_SETCURSEL, 0, 0);
                        RemoveListViewColumns();
                        AddListViewColumns();
                 
                        std::thread Column_Info_Thread(Get_Column_Info);

                        Column_Info_Thread.detach();

       
                    }
                }
            }
        }
    }
    return 0;

    case WM_PAINT:
    {
        hdc = BeginPaint(hwnd, &ps);
        TextOut(hdc, 290, 15, "Columns:", 8);
        EndPaint(hwnd, &ps);
    }
    return 0;

    case WM_CLOSE:
        DestroyWindow(hwnd);
        return 0;

    case WM_DESTROY:
        DisonnectDB();
        PostQuitMessage(0);
        return 0;

    default:
        return DefWindowProc(hwnd, uMsg, wParam, lParam);
    }
} ---> it blocks here

Can read REG_SZ but not REG_DWORD value

$
0
0
Hi,

I can read REG_SZ values but not REG_DWORD values from the registry.

Do I need another type than char* as 5th parameter of the RegQueryValueEx() function if I want to read REG_DWORD value
or something else is the problem?

Code:

#include <windows.h>
#include <winreg.h>
#include <iostream>
using namespace std;

int main()
{
    HKEY hKey;
    char Data[255];
    DWORD Datasize = sizeof(Data);
    DWORD Type;

    if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                    "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
                    0,
                    KEY_QUERY_VALUE|KEY_WOW64_32KEY,
                    &hKey)== ERROR_SUCCESS)

    {
        DWORD error = RegQueryValueEx(hKey,
                        "InstallDate",
                        NULL,
                        &Type,
                        (LPBYTE)&Data,
                        &Datasize);

        if(error == ERROR_SUCCESS)
        {
            cout << " Data = " << Data <<
                "\n Size = " << Datasize <<
                "\n Type = " << Type <<endl;
       
        }
        else
        {
          cout << "RegQueryValueEx error " << error << endl;
        }

    }
    else cout << "RegopenkeyEx error " << error << endl;

    RegCloseKey(hKey);

    return 0;
}

error LNK2038: mismatch detected for '_MSC_VER'

$
0
0
Error 8 error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1800' in EndianConverter.obj C:\Tellumat\ Test Bench\Test Bench Qt\ Test Bench Qt\qtmaind.lib(qtmain_win.obj) Test Bench Qt


Hi,

Can any one please tell me what is the error i am getting above and how to resolve that error can any one help me out finding that error.


Thanks and Regards,
Jeevan

Want to show Tool Tips on the buttons that I have placed on title bar

$
0
0
There are two files tester.c and captionButton.c.Please help me.
Also please let me know how can I change the image from monochrome to color in it.

Thanks in advance.

Vineet

Calculating the real lfWidth value of LOGFONT when lfWidth = 0

$
0
0
Hi, I'm wondering how to calculate what the real value of lfWidth in the LOGFONT structure when it is set to 0.

MSDN says that if the value is zero, the digitization aspect ratio is used to determine the width. I had hoped this meant the tmDigitizedAspectX and tmDigitizedAspectY members of TEXTMETRIC, but they always seem to be 96 and 96, regardless of font selected.

If I create a new LOGFONT with lfWidth = lfHeight, the aspect ratio of the font is often wrong - clearly fonts have aspect ratio data somewhere, for example if I do this with @Meriyo, it works almost perfectly the same as if lfWidth=0, if I do it with @Meriyo UI, it's clearly about 2x wide.

Any help would be greatly appreciated!

Are there any Unix Compatible API libraries available for windows 7 x64?

$
0
0
I want to call on the header like
#include <sys/wait.h>

fork, getpid()
etc
I am wondering how I can substitute those calls under windows 7 x64.
I've a got a library which is called Festival which is part of an application library called Smartbody
and I can't compile it because there are some unix headers to call on...

http://smartbody.ict.usc.edu/download

I don't think cygwin is appropriate because it generates .a files, I need .lib files for my final product.
I need to build it under vs2013 community

Thanks
Jack

How load an rtf file into RichEdit

$
0
0
I have been trying to streamin an rtf file that contains an image into RichEdit control. I have implemented the necessary streamin Callback and was able to load the file, but the image have refused to display. I think I have to provide some sort of storage by implementing IRichEditOleCallback::GetNewStorage interface but I don't know how and couldn't find an example code in C++ ( not MFC ). what's the right thing to do, and how.

Taskbar not appearing in auto-hide mode when cursor is placed over deskband controls

$
0
0
Hi everybody
I recently have written a deskband object using this tutorial http://www.codeproject.com/Articles/...nd-Tray-Notifi
The problem is that taskbar not appearing in auto-hide mode when cursor is placed over deskband controls.
I'm using windows 10 and it's interesting that when i restart explorer.exe everything is OK.
What's the problem? Is it windows bug? or is it a programming error?

How to create deskband objects for taskbar using Delphi XE2?

$
0
0
Hi
How to create deskband controls using Delphi XE2? Has anyone tutorial about it?

How create child window?

$
0
0
I create main window by CreateWindowEx() but I want child window like button. Child window should automatically move when parent window moves.
How create it?

How compute windows size with and without border?

$
0
0
I am working under Windows 8.1; I test window size with border and without border. Horizontal difference is 16, vertical 39. 39 = cyCaption+16;
Frame has 8 on all sides? Why cySizeFrame = 4 and cyBorder is only 1 ?
Code:

 
  SetWindowPos(hWnd,  HWND_TOP,  100,  100,  300,  70,  SWP_SHOWWINDOW);
  RECT rcClient, rcWind;
  GetClientRect(hWnd, &rcClient);
  GetWindowRect(hWnd, &rcWind);
  int xdiff =  (rcWind.right-rcWind.left)-(rcClient.right-rcClient.left);//16
  int ydiff =  (rcWind.bottom-rcWind.top)-(rcClient.bottom-rcClient.top);//39
  int cxSizeFrame = GetSystemMetrics(SM_CXSIZEFRAME);
  int cySizeFrame = GetSystemMetrics(SM_CXSIZEFRAME);
  int cyCaption = GetSystemMetrics(SM_CYCAPTION);
  int cyBorder = GetSystemMetrics(SM_CYBORDER);.

[RESOLVED] How init new window with color

$
0
0
One solution is
Code:

wincl.hbrBackground = CreateSolidBrush(RGB(202, 238, 255));
where WNDCLASSEX wincl is class.
This solution is improvident because for each window must be one class. Better is one class for popup, one for ToolTip, for Controls and main windows.
This situation is similar to wincl.hIcon and wincl.hCursor. It is possible many windows with different colors, cursors and icons without creating one class for each window?
----
I solved it: better than init with color, erase background on WM_ERASEBKGND

Sending a string to a window

$
0
0
I would like send a string to a window from a worker thread. i e to display it on it.
I got no better idea than sending the pointer and using ::SendMessage, to make sure the pointer wouldn't rot before the operation is complete.
The window is MFC, but the thread is created by non-MFC library, o I need to use Win API means, that is why I feel this forum suits best.

Binary representation of the character value

$
0
0
We want to create a table in such a way that each character value is represented by a 6 bit binary value if i enter a character it should represent in binary.Can any one help me out in finding logic in c program.


000001 A
000010 B
000100 C


if i enter CA the binary digit as to be stored in format 000100000001

How can I bend WndProc of a control?

$
0
0
Hi,

the background of my current problem is that I get the standard popupmenu when working with the grid-control from devexpress. If the inline editor is active my own popup-menu is ignored and instead I get the standard popup menu of windows (copy, paste, etc.)!

I know the technic with overwritting the WndProc(Messages::TMessage &Message) to catch the WM_-messages before they are executed to do my own stuff, but unfortunatelly I see no way to do this with this grid.


I have already put a ticket to devexpress, but waiting is not one of my virtues...so hearing from you is a pleasure for me! ^^
sincerly
Necip

DirectInput8Create

$
0
0
Greetings,

we recently had to move away from Legacy JoyPosEx to using DirectInput when we upgraded to Win8. The game controller interface is working well except the first run after a reboot. The call to DirectInput8Create leads to a heap corruption exception in ntdll. Interestingly, MS dxdiag does exactly the same (in fact, its next run asks if DirectInput check should be ignored due to the last run's exception). Our app is Win32.

We had noted that the legacy JoyPosEx was redirected to DirectInput, and there we were having runtime exceptions in dinput.dll, which was another reason we went to using the newer MS APIs.

It is a very vexing problem that sorely needs a solution in a timely manner.

Cheers & much oblidged.

Overwritting in a file

$
0
0
We are having a file.
In a file content is.
file.txt

Voltage 1000
current 100
power 600
amplitude 10

We have opened the file in r+ mode and trying to change the data in 3rd line power 1000 in a file but its is not changing we are using this logic can any one help me out finding in solution.

I cann't use fseek because in a line content may vary.

[C]code[\C]
while(count < line)
{
fscanf(fptest,"%s %d",temp,&value);
cout<<temp<<value<<endl;
count++;

if(count == line)
{
//fptest = fopen("UserConfigWrite.ini","r+");
//strcpy(temp,temp1);
value = 200;

fprintf(fptest,"%d\n",value);
cout<<temp<<value<<endl;

fclose(fptest);
break;
}
//fclose(fptest);
}
[C]code[\C]

windows c++ noob : builder, make

$
0
0
OK so I'm used to general c++ and java for a a year or 2...
now I'm learning visual c++ or winapi programming...just got used to all that typedef redefining done by windows..
some I believe not necessary at all..haha... what is the point in redefining a WORD to an ATOM??? nothing changes just the name..well..that is another discussion for another day...

the main question... I'm trying to understand the source code of an application package, in the package there are
the folders, .vs, bin, configs, include, lib, make, output, source and temp..
source folder contains : builder, buildertools, client, common, other, server, ecc..
well this are the most important folders which got my attention...
Can the more seasoned windows programmers explain to me why this organization, for example,
what must be expected in a builder folder, what in a common folder, what in a server folder, well this is obvious :D, are these divisions because of a particular design pattern... I hope I made myself clear...
to be a little bit more specific..I will appreciate more explanation on the builder folder, and what in general is a builder in an application package ...
help a noob wanting to learn :) ..thanks in advance to all who will contribute
Viewing all 583 articles
Browse latest View live