Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
WinAPI in C. Please no C++!!
I am using this stolen code:(part shown only, nice small plain C)
// create the main window
Wind[0] = CreateWindowEx( WS_EX_CONTROLPARENT,
"TINY_UNICODE","Tiny Unicode Editor",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0,500,300,NULL,NULL,Inst,NULL);
// buttons
Wind[1] = CreateWindow("BUTTON","Open",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
2,2,50,25,Wind[0],(HMENU) 1001,Inst,NULL);
Wind[2] = CreateWindow("BUTTON","Save",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
2,30,50,25,Wind[0],(HMENU) 1002,Inst,NULL);
Wind[3] = CreateWindow("BUTTON","Quit",
WS_CHILD | WS_VISIBLE | BS_FLAT,
2,60,50,25,Wind[0],(HMENU) 1003,Inst,NULL);
// edit window
Wind[4] = CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",NULL,
WS_CHILD | WS_VISIBLE |
ES_MULTILINE,
60,2,200,200,Wind[0],NULL,Inst,NULL);

Now I want to replace the edit control Wind[4] with a static control to draw graphs using SetPixel(hdc, x, y, z, 0, 0));
For that I need to get the hdc of the window Wind[4].
Please how do I do that?
Thank you
Johan Smit

No I have not solved this myself. I probably asked the follow-up question on the wrong place.
I am unsure how to place follow up questions.
Posted
Updated 3-Feb-15 19:55pm
v2

See GetDC()[^].  Be sure to call ReleaseDC()[^] when done using it.

/ravi
 
Share this answer
 
v2
Before drawing in a window I suggest you to read about GDI to have a good understanding of windows graphical interface, or you'll get lost...
To speed here you'll find documentation. Study it carefully and you'll get the solution you are looking for.
Anyway this is a simple code to draw a sinus line on a window:
C++
void GraphSomething(HWND hwnd)
{
	RECT rWin;
	GetClientRect(hwnd, &rWin);		//Get window dimensions

	HDC hDc = GetDC(hwnd);

	HPEN hPen = CreatePen(PS_DASHDOT, 2, RGB(255, 0, 0));

	HPEN hOldPen = SelectObject(hDc, hPen);

	float f = 4.0*3.14 / (float)(rWin.right-rWin.left);

	MoveToEx(hDc, rWin.left, rWin.bottom/2 - ((float)rWin.bottom/2 * sin(0.0)), NULL);

	for (int i=rWin.left; i<rWin.right; i++)
	{
		int pt = (float)rWin.bottom/2 * sin(f * (float)(i));
		LineTo(hDc, i, rWin.bottom/2 - pt);
	}

	DeleteObject(SelectObject(hDc, hOldPen));

	ReleaseDC(hwnd, hDc);
}
 
Share this answer
 
v4
Thank you Ravi.
I don't understand GetDC[^]
When I do GetDC(Wind[4]) I get struct HDC_*hdc = struct HDC_ = int unused *<f701644?>
in the Pelles C debugger, and the pixel are not set anywhere.
 
Share this answer
 
Comments
Deepu S Nair 4-Feb-15 2:01am    
Don't post your comment as solution.Instead use 'Have a Question or Comment' link so that corressponding member will get a notification
Thank you Frankie for the advice and the code. It works beautifully.
After some years of developing embedded systems, I thought I knew a bit about C.
Win32 API and GDI is something else however. I am learning.
Best Regards
Johan Smit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900