|
hi,
I needed a small help regarding the code which i have written in VC++ to get the status of a printer like ''PRINTER_STATUS_NO_TONER", "PRINTER_STATUS_PAPER_JAM" etc..
I have written the following code:
char szPrinter[255];
memset(szPrinter,'\0',255);
strcpy(szPrinter,m_szPrinterName.operator LPCTSTR());
BOOL bSuccess = FALSE;
HANDLE hPrinter = NULL;
PRINTER_DEFAULTS *lpDefaults = NULL;
BOOL bOpen = ::OpenPrinter(szPrinter, &hPrinter, lpDefaults);
DWORD dwBytesReturned;
DWORD dwBytesNeeded;
GetPrinter(hPrinter, 2, NULL, 0, &dwBytesNeeded);
PRINTER_INFO_2 *pPrinterInfo = (PRINTER_INFO_2*)GlobalAlloc(GPTR,dwBytesNeeded);
bSuccess = ::GetPrinter(hPrinter, 2, (LPBYTE)pPrinterInfo,dwBytesNeeded, &dwBytesReturned);
uint32 dwStatusID = 0;
switch(pPrinterInfo->Status)
{
case PRINTER_STATUS_BUSY:
dwStatusID = ID_STAT_PRN_BUSY;
bSuccess = TRUE;
break;
case PRINTER_STATUS_DOOR_OPEN:
dwStatusID = ID_STAT_PRN_DOOR_OPEN;
bSuccess = TRUE;
break;
case PRINTER_STATUS_ERROR:
dwStatusID = ID_STAT_PRN_ERROR;
bSuccess = FALSE;
break;
case PRINTER_STATUS_INITIALIZING:
dwStatusID = ID_STAT_PRN_INITIALIZING;
bSuccess = TRUE;
break;
case PRINTER_STATUS_IO_ACTIVE:
dwStatusID = ID_STAT_PRN_IO_ACTIVE;
bSuccess = TRUE;
break;
case PRINTER_STATUS_MANUAL_FEED:
dwStatusID = ID_STAT_PRN_MANUAL_FEED;
bSuccess = TRUE;
break;
case PRINTER_STATUS_NO_TONER:
dwStatusID = ID_STAT_PRN_NO_TONER;
bSuccess = FALSE;
break;
case PRINTER_STATUS_NOT_AVAILABLE:
dwStatusID = ID_STAT_PRN_NOT_AVAILABLE;
bSuccess = FALSE;
break;
case PRINTER_STATUS_OFFLINE:
dwStatusID = ID_STAT_PRN_OFFLINE;
bSuccess = TRUE;
break;
case PRINTER_STATUS_OUT_OF_MEMORY:
dwStatusID = ID_STAT_PRN_OUT_OF_MEMORY;
bSuccess = FALSE;
break;
case PRINTER_STATUS_OUTPUT_BIN_FULL:
dwStatusID = ID_STAT_PRN_OUTPUT_BIN_FULL;
bSuccess = TRUE;
break;
case PRINTER_STATUS_PAGE_PUNT:
dwStatusID = ID_STAT_PRN_PAGE_PUNT;
bSuccess = FALSE;
break;
case PRINTER_STATUS_PAPER_JAM:
dwStatusID = ID_STAT_PRN_PAPER_JAM;
bSuccess = FALSE;
break;
case PRINTER_STATUS_PAPER_OUT:
dwStatusID = ID_STAT_PRN_PAPER_OUT;
bSuccess = FALSE;
break;
case PRINTER_STATUS_PAPER_PROBLEM:
dwStatusID = ID_STAT_PRN_PAPER_PROBLEM;
bSuccess = FALSE;
break;
case PRINTER_STATUS_PAUSED:
dwStatusID = ID_STAT_PRN_PAUSED;
bSuccess = TRUE;
break;
case PRINTER_STATUS_PENDING_DELETION:
dwStatusID = ID_STAT_PRN_PENDING_DELETION;
bSuccess = FALSE;
break;
case PRINTER_STATUS_POWER_SAVE:
dwStatusID = ID_STAT_PRN_POWER_SAVE;
bSuccess = TRUE;
break;
case PRINTER_STATUS_PRINTING:
dwStatusID = ID_STAT_PRN_PRINTING;
bSuccess = TRUE;
break;
case PRINTER_STATUS_PROCESSING:
dwStatusID = ID_STAT_PRN_PROCESSING;
bSuccess = TRUE;
break;
case PRINTER_STATUS_SERVER_UNKNOWN:
dwStatusID = ID_STAT_PRN_SERVER_UNKNOWN;
bSuccess = FALSE;
break;
case PRINTER_STATUS_TONER_LOW:
dwStatusID = ID_STAT_PRN_TONER_LOW;
bSuccess = TRUE;
break;
case PRINTER_STATUS_USER_INTERVENTION:
dwStatusID = ID_STAT_PRN_USER_INTERVENTION;
bSuccess = FALSE;
break;
case PRINTER_STATUS_WAITING:
dwStatusID = ID_STAT_PRN_WAITING;
bSuccess = TRUE;
break;
case PRINTER_STATUS_WARMING_UP:
dwStatusID = ID_STAT_PRN_WARMING_UP;
bSuccess = TRUE;
break;
case 0:
bSuccess = TRUE;
break;
default:
dwStatusID = PRINTER_STATUS_SERVER_UNKNOWN;
bSuccess = FALSE;
break;
}
The above code works fine for a parallel port network printer,but the "pPrinterInfo->Status" parameter returns "0" for a local USB printer.
Can anyone kindly tell me what may be the problem.
|
|
|
|
|
Hi,
CMenu* pMenu = GetMenu();
ASSERT (pMenu != NULL);
for(int i=0;i< (int)pMenu->GetMenuItemCount();i++)
{
CMenu* pActionMenu = pMenu->GetSubMenu(i);
ASSERT (pActionMenu != NULL);
int nMenuItemCount = pActionMenu->GetMenuItemCount();
int nTemp = nMenuItemCount-1 ;
nMenuItemCount=nMenuItemCount-1;
while (nMenuItemCount >= 0)
{
if(!(i==0 && nMenuItemCount==nTemp))
{
pActionMenu->RemoveMenu(nMenuItemCount, MF_BYPOSITION);
//pActionMenu->EnableMenuItem( pActionMenu->GetMenuItemID
(nMenuItemCount) ,MF_BYCOMMAND|MF_DISABLED);
}
nMenuItemCount=nMenuItemCount-1;
}
}
Requirement : Disabling all menu items
I have used the above code snippet to removing Menu items in my application.
But when i attempt to use EnableMenuItem for disabling than removing it fails.
Can any one show some light on this?
for thendral
|
|
|
|
|
RemoveMenu: Deletes a menu item with an associated pop-up menu from the menu.
Try using same function i.e EnableMenuItem for enabling & diabling the menu items.
Regards,
Ashok.
|
|
|
|
|
Use ON_UPDATE_COMMAND_UI .
Nibu thomas
Software Developer
|
|
|
|
|
I can use ON_UPDATE_COMMAND_UI if i need to disable a single menu item
My requirement is to disable all menus in a single shot,How can this be done.
Thanks
for thendral
|
|
|
|
|
Hi, I think that the only solutions is to disable each item of your menu. There isn't other way to make this. Sorry and good coding!
|
|
|
|
|
You can use ON_UPDATE_COMMAND_UI_RANGE . There are certain limitations too.
Nibu thomas
Software Developer
|
|
|
|
|
From Code Project articles i have coded a C++ DLL to be used as a global hook for C# projects. I have been successful in getting a global keyboard hook working. But when i try the same with a mouse hook, computer CPU goes to 100% and C# app gets a million messages that say the same thing. I am not the greatest C++ programmer. Am i missing something here? I think i have all the code parts needed?
Below is the code i am using (40+ lines):
#include "stdafx.h"
#include "hookdll.h"
#pragma data_seg("SHARED")
HHOOK m_mouseHook = NULL;
HWND m_hHookClient = NULL;
#pragma data_seg()
#pragma comment(linker, "/SECTION:SHARED,RWS") // linker directive
HINSTANCE m_hHookDLL = NULL;
const int GH_MOUSEOTHER = WM_USER + 4099;
BOOL APIENTRY DllMain(
HANDLE hInstance,
DWORD callReason,
LPVOID reserved)
{
switch (callReason)
{
case DLL_PROCESS_ATTACH:
m_hHookDLL = (HINSTANCE)hInstance;
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport) void InstallHook(HWND hWnd)
{
m_mouseHook = NULL;
m_hHookClient = hWnd;
// set mouse hook
m_mouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)MouseHookProc,
m_hHookDLL, NULL);
}
extern "C" __declspec(dllexport) void RemoveHook()
{
UnhookWindowsHookEx(m_mouseHook);
}
LRESULT CALLBACK MouseHookProc(
int nCode,
WPARAM wParam,
LPARAM lParam)
{
if (nCode >= 0)
{
PostMessage(m_hHookClient, GH_MOUSEOTHER, wParam, lParam);
}
// pass control to next hook in the hook chain
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
-- modified at 6:15 Wednesday 22nd March, 2006
|
|
|
|
|
Hi,
is it possible for me to code a program in c++ to gather all URLs contained in a website/webpage?
or if not does anyone have a code to find URLs in a text file?
Does anyone have a sample code or a link that may give me information about this?
Your help will be appreciated. Thanks in advance
|
|
|
|
|
Use the following regular expression:
"<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\""
I've taken it from an example of boost regex library.
|
|
|
|
|
Thanks, but can u show me a more precise code?
|
|
|
|
|
If you haven't already done so, download the boost library. The regex library has an example ("regex_split_example_2.cpp"), that scans a file and returns a list of the URLs.
|
|
|
|
|
I have a picture control on the dialog.I want to get the color of the picture.or the color of the dialog(It's same to the picture).Note,not the bkColor of DC.
Thanks!
|
|
|
|
|
|
hi all
i had bitmaps or drawings on dialog.I want to print these bitmaps any idea how to do that. or any other method of doing this printings.
ddd
|
|
|
|
|
this[^] might come in handy.
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
maybe it is some helpful to you
...
HDC m_dcPrinter=CreateCompatibleDC(CreateDC(m_Printer->pDriverName,
(LPCTSTR)lpdevmode->dmDeviceName,m_Printer->pPortName,lpdevmode));
PRINTDLG lppd;
...
...
PrintDlg(&pd);
hBitmap=LoadBitmap or LoadImage
SelectObject(m_dcPrinter,hBitmap);
StartDoc (pd.hDC, &di);
StartPage (pd.hDC);
BitBlt(pd.hDC,150,300,2100,1575,m_dcPrinter,0,0,SRCCOPY);
EndPage (pd.hDC);
EndDoc (pd.hDC);
|
|
|
|
|
I am working on a mfc application. At the time the project started no automatization support was defined for it from the wizard application. Now i want to add some automatization features . Can any one help me on this matter? Do i need to recode the whole prject ?
|
|
|
|
|
|
I have a dialog box. There's a (background) bitmap on it.I can load a (foreground) jpeg on it. Now I wanted to know if,on a new dialog , I can load a background jpeg on which i can load the foreground jpeg.
-- modified at 6:24 Wednesday 22nd March, 2006
|
|
|
|
|
You are not making any sense, rephrase the question.
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
Hello,
I do have one doubt.
Iam at ppresent working with C programming in VC++ environment. I need to work with a DLL, is it possible to use for C coding also without any Dailog based file? or should i use in VC++ enviroment?
-- modified at 5:21 Wednesday 22nd March, 2006
|
|
|
|
|
Of course you can use DLL with VC++.
|
|
|
|
|
Hi Everyone,
How can we write the commandline instructions in VC++? For example, i want to copy Excel file from one location to another location in another place(LAN). I have a copy button in my dialog. When i press the copy button, the excel file should be copied over to another location. Is it possible to do so?
Thanks in Advance.
Chetan.
Helping others satisfies you...
|
|
|
|
|
system() if you directly use DOS commands.
otherwise, use CopyFile()
|
|
|
|