Creating of dialog
HWND dialog = CreateDialog(hInst, (LPSTR)"TEMPLATE", hWnd, (DLGPROC)Proc);
Creating of font
HFONT newFont = CreateFont(72, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, TEXT("Tahoma"));
SetWindowFont(dialog, newFont, true);
DWORD err = GetLastError();
err says that there aren't any errors, but the font is still the same(not changed)
I have always tried to set the font from "Proc" dialog function in case of WM_INITDIALOG message
When I set a font by calling a function SendDlgItemMessage with dialog handler and ID of Edit component (for example) in template it works fine. But I haven't such an ID for window or title of the window to try this aproach
How to set a font for a dialog caption/title?
Related
I mean this control:
When you click on this, instead of regular options, a tab control with the colors is displayed. How can I do this? is this a owner-draw combobox or something else? I'm aware on how draw text, rectangles, images, etc with a owner-draw combobox but I don't know how add controls over there. I have no code to show yet because I have no idea how do that. I've tried something like call CreateWindow() in WM_DRAWITEM using the values from DRAWITEMSTRUCT.rcItem but I can't make a control inside the groupbox's client area, the button gets behind the control.
Looks like you are looking for CBN_DROPDOWN.
Sent when the list box of a combo box is about to be made visible. The
parent window of the combo box receives this notification code through
the WM_COMMAND message.
Some code:
HWND hWndComboBox = CreateWindow(
WC_COMBOBOX,
TEXT(""),
WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,
10, 20, 70, 17,
hWnd, (HMENU)IDB_COMBOX, hInstance, NULL);
...
case WM_COMMAND:
{
int wmId = LOWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDB_COMBOX:
{
switch (HIWORD(wParam))
{
case CBN_DROPDOWN:
{
CHOOSECOLOR cc; // common dialog box structure
static COLORREF acrCustClr[16]; // array of custom colors
static DWORD rgbCurrent; // initial color selection
// Initialize CHOOSECOLOR
ZeroMemory(&cc, sizeof(cc));
cc.lStructSize = sizeof(cc);
cc.hwndOwner = hWnd;
cc.lpCustColors = (LPDWORD)acrCustClr;
cc.rgbResult = rgbCurrent;
cc.Flags = CC_FULLOPEN | CC_RGBINIT;
ChooseColor(&cc);
}
break;
...
Debug:
I have implemented a custom drawn context menu (MFT_OWNERDRAW). When I create a context menu, I get an HMENU handle when calling CreatePopupMenu(). When I handle the WM_DRAWITEM message, I get an LPDRAWITEMSTRUCT:
LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam;
The DRAWITEMSTRUCT structure documentation describes the hwndItem field this way:
A handle to the control for combo boxes, list boxes, buttons, and static controls. For menus, this member is a handle to the menu that contains the item.
I need to check if the WM_DRAWITEM message belongs to my custom context menu. Does it mean that I can compare my context menu handle (HMENU) with the hwndItem (HWND) in this way?
//getHighlightMenuId returns HMENU returned by CreatePopupMenu
if((int)highlightMenu->getHighlightMenuId() == (int)drawItem->hwndItem))
{
}
Is it correct?
Yes, you would compare the DRAWITEMSTRUCT::hwndItem to your HMENU, eg:
LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam;
if (drawItem->CtlType == ODT_MENU)
{
HMENU hMenu = (HMENU)(drawItem->hwndItem);
if (highlightMenu->getHighlightMenuId() == hMenu)
{
// draw the menu item for drawItem->itemID within hMenu as needed ...
}
}
I am writing some library with using WIN API. I have a problem with receiving WM_NOTIFY message from WC_TABCONTROL class window in parent window WinProc function.
I check by "debug prints", that parent of child was set correctly. I receives WM_COMMAND messages and correctly in some function.
I have not idea what can be a reason for this. Tab control in window looks good and responds for mouse clicks with do visual tab item select change.
for example, when I click to unselected tab, I receive following messages http://pastie.org/6571509
You can check my WIN Proc function here http://goo.gl/knJ4Z , line 346.
Create tab control:
ps_ext->d_handle = CreateWindowExW(0, // no extended styles
WC_TABCONTROL, // class name
L"", // default text
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, // overlapped window
CW_USEDEFAULT, // default horizontal position
CW_USEDEFAULT, // default vertical position
CW_USEDEFAULT, // default width
CW_USEDEFAULT, // default height
HWND_MESSAGE, // no parent or owner window
(HMENU)WINSEM_Window_NextComponentID(), // class menu used
WINSEM_Window_hInstance,// instance handle
(LPVOID)&ps_ext->s_window); // no window creation data
After it, set correct parent by SetParent function call.
Tab is resized by something like:
uFlags = SWP_NOOWNERZORDER | SWP_NOZORDER;
if (SetWindowPos(ps_window->d_handle, NULL, s0_x, s0_y, s0_w, s0_h, uFlags)==0)
{
DWORD dErr;
dErr = GetLastError();
HaveWinLastError_Error(ps_pack, WINSEM_WINDOW_fromerror_windowPos+0, dErr, dErr);
break;
}
And showing window and clicking on tab control don't generate WM_NOTIFY message received by parent window winProc function.
This is my message receive code:
bRet = PeekMessage( &msg, NULL, 0, 0, PM_REMOVE);
if (bRet==FALSE)
{
// no messages received
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Have anybody any idea about this problem? Thanks for you ideas and time.
I suspect that the tab control caches its parent window when it is created and never updates it. If you re-parent it, the messages will still go to the original parent - which is an invalid window in this case.
Why are you creating it with HWND_MESSAGE as a parent anyway? Why not just create it with its proper parent to begin with?
I have a WH_CALLWNDPROC hook code which handles WM_INITDIALOG message to get information about message boxes. I could get "Message", "Title", "Buttons" but I couldnt get "icon" information. I'm trying to use a function like below:
long getIcon(HWND hwnd) { // handle of messagebox dialog
HWND hlbl = GetDlgItem(hwnd,20);
wcout << "LABEL HWND: " << hlbl << endl;
if (hlbl != NULL) {
LRESULT r = SendMessage(hlbl,WM_GETICON,0,0);
return (long)r;
}
return 0;
}
function always returns 0. I have checked by MS Spy++ and I saw that icon handle is 0.
What is the correct way to get icon?
The icon that is displayed on the message box dialog is implemented using a STATIC control with SS_ICON style. You can obtain the icon handle by sending that control the STM_GETICON message.
In the code in your question, the variable named hlbl is actually the window handle of the STATIC control that contains the icon. I'd name it hIconWnd. With that name change, the code to obtain the icon would look like this:
HICON getIcon(HWND hwnd) { // handle of messagebox dialog
HWND hIconWnd = GetDlgItem(hwnd, 20);
if (hIconWnd != NULL) {
return (HICON)SendMessage(hIconWnd, STM_GETICON, 0, 0);
}
return NULL;
}
I am working on a sample in this I am creating a EMF file with some text in it.
To add a text I am using the API ExtTextOutW() with ETO_IGNORELANGUAGE option.
Return value of this API is TRUE. But when I open the EMF file the text is not present.
Then I saw the records. There is no entey for the ExtTextOutW.
Bellw is the code.
HDC hDC = GetDC(hWnd);
RECT Rect = {0, 0, 21590, 27940};
//Create the EMF file DC
HDC hEMFDC = ::CreateEnhMetaFile(hDC, L"c:\\del\\1.emf", &Rect, L"Test");
if (NULL != hEMFDC)
{
RECT Rect = {0, 0, 300, 155};
HBRUSH hb = CreateSolidBrush(0X00FFFF00);
FillRect(hEMFDC, &Rect, hb);
DeleteObject(hb);
int dx[12] = {25,25,25,25,25,25, 25,25,25,25,25,25};
WCHAR wcsBuffer[] = L"Text Message";
ExtTextOutW(hEMFDC, 10, 10, ETO_IGNORELANGUAGE, NULL, wcsBuffer, wcslen(wcsBuffer), dx);
HENHMETAFILE hmf = CloseEnhMetaFile(hEMFDC);
DeleteEnhMetaFile(hmf);
hEMFDC = NULL;
}
ReleaseDC(hWnd, hDC);
Please let me know any thing I am doing wrong in the above code.
Did you read the documentation for ExtTextOut[W] (MSDN), especially the part for the flags like ETO_IGNORELANGUAGE:
Reserved for system use. If an application sets this flag, it loses
international scripting support and in some cases it may display no
text at all.
Just try it without this flag.